| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "media/base/fake_single_thread_task_runner.h" |
| 10 #include "media/cast/cast_environment.h" | 11 #include "media/cast/cast_environment.h" |
| 11 #include "media/cast/net/cast_transport_defines.h" | 12 #include "media/cast/net/cast_transport_defines.h" |
| 12 #include "media/cast/net/rtcp/rtcp_utility.h" | 13 #include "media/cast/net/rtcp/rtcp_utility.h" |
| 13 #include "media/cast/net/rtcp/test_rtcp_packet_builder.h" | 14 #include "media/cast/net/rtcp/test_rtcp_packet_builder.h" |
| 14 #include "media/cast/test/fake_single_thread_task_runner.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 namespace cast { | 18 namespace cast { |
| 19 | 19 |
| 20 static const uint32_t kRemoteSsrc = 0x10203; | 20 static const uint32_t kRemoteSsrc = 0x10203; |
| 21 static const uint32_t kLocalSsrc = 0x40506; | 21 static const uint32_t kLocalSsrc = 0x40506; |
| 22 static const uint32_t kUnknownSsrc = 0xDEAD; | 22 static const uint32_t kUnknownSsrc = 0xDEAD; |
| 23 static const base::TimeDelta kTargetDelay = | 23 static const base::TimeDelta kTargetDelay = |
| 24 base::TimeDelta::FromMilliseconds(100); | 24 base::TimeDelta::FromMilliseconds(100); |
| 25 | 25 |
| 26 class RtcpParserTest : public ::testing::Test { | 26 class RtcpParserTest : public ::testing::Test { |
| 27 protected: | 27 protected: |
| 28 RtcpParserTest() | 28 RtcpParserTest() |
| 29 : testing_clock_(new base::SimpleTestTickClock()), | 29 : testing_clock_(new base::SimpleTestTickClock()), |
| 30 task_runner_(new test::FakeSingleThreadTaskRunner( | 30 task_runner_(new FakeSingleThreadTaskRunner(testing_clock_.get())) {} |
| 31 testing_clock_.get())) { | |
| 32 } | |
| 33 | 31 |
| 34 bool HasAnything(const RtcpParser& parser) { | 32 bool HasAnything(const RtcpParser& parser) { |
| 35 return parser.has_sender_report() || | 33 return parser.has_sender_report() || |
| 36 parser.has_last_report() || | 34 parser.has_last_report() || |
| 37 parser.has_receiver_log() || | 35 parser.has_receiver_log() || |
| 38 parser.has_cast_message() || | 36 parser.has_cast_message() || |
| 39 parser.has_receiver_reference_time_report(); | 37 parser.has_receiver_reference_time_report(); |
| 40 } | 38 } |
| 41 | 39 |
| 42 void ExpectSenderInfo(const RtcpParser& parser) { | 40 void ExpectSenderInfo(const RtcpParser& parser) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 EXPECT_EQ(event_expected_it->packet_id, event_incoming_it->packet_id); | 128 EXPECT_EQ(event_expected_it->packet_id, event_incoming_it->packet_id); |
| 131 } else { | 129 } else { |
| 132 EXPECT_EQ(event_expected_it->delay_delta, | 130 EXPECT_EQ(event_expected_it->delay_delta, |
| 133 event_incoming_it->delay_delta); | 131 event_incoming_it->delay_delta); |
| 134 } | 132 } |
| 135 } | 133 } |
| 136 } | 134 } |
| 137 } | 135 } |
| 138 | 136 |
| 139 scoped_ptr<base::SimpleTestTickClock> testing_clock_; | 137 scoped_ptr<base::SimpleTestTickClock> testing_clock_; |
| 140 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 138 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; |
| 141 | 139 |
| 142 private: | 140 private: |
| 143 DISALLOW_COPY_AND_ASSIGN(RtcpParserTest); | 141 DISALLOW_COPY_AND_ASSIGN(RtcpParserTest); |
| 144 }; | 142 }; |
| 145 | 143 |
| 146 TEST_F(RtcpParserTest, BrokenPacketIsIgnored) { | 144 TEST_F(RtcpParserTest, BrokenPacketIsIgnored) { |
| 147 const char bad_packet[] = {0, 0, 0, 0}; | 145 const char bad_packet[] = {0, 0, 0, 0}; |
| 148 RtcpParser parser(kLocalSsrc, kRemoteSsrc); | 146 RtcpParser parser(kLocalSsrc, kRemoteSsrc); |
| 149 base::BigEndianReader reader(bad_packet, sizeof(bad_packet)); | 147 base::BigEndianReader reader(bad_packet, sizeof(bad_packet)); |
| 150 EXPECT_FALSE(parser.Parse(&reader)); | 148 EXPECT_FALSE(parser.Parse(&reader)); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fraction_3); | 545 base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fraction_3); |
| 548 EXPECT_EQ(input_time, out_3); // Verify inverse. | 546 EXPECT_EQ(input_time, out_3); // Verify inverse. |
| 549 | 547 |
| 550 // Verify delta. | 548 // Verify delta. |
| 551 EXPECT_EQ((out_3 - out_2), time_delta); | 549 EXPECT_EQ((out_3 - out_2), time_delta); |
| 552 EXPECT_NEAR((ntp_fraction_3 - ntp_fraction_2), 0xffffffff / 2, 1); | 550 EXPECT_NEAR((ntp_fraction_3 - ntp_fraction_2), 0xffffffff / 2, 1); |
| 553 } | 551 } |
| 554 | 552 |
| 555 } // namespace cast | 553 } // namespace cast |
| 556 } // namespace media | 554 } // namespace media |
| OLD | NEW |