OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace webrtc { | 32 namespace webrtc { |
33 | 33 |
34 // Test for the acm dump class. Dumps some RTP packets to disk, then reads them | 34 // Test for the acm dump class. Dumps some RTP packets to disk, then reads them |
35 // back to see if they match. | 35 // back to see if they match. |
36 class AcmDumpTest : public ::testing::Test { | 36 class AcmDumpTest : public ::testing::Test { |
37 public: | 37 public: |
38 AcmDumpTest() : log_dumper_(AcmDump::Create()) {} | 38 AcmDumpTest() : log_dumper_(AcmDump::Create()) {} |
39 void VerifyResults(const ACMDumpEventStream& parsed_stream, | 39 void VerifyResults(const ACMDumpEventStream& parsed_stream, |
40 size_t packet_size) { | 40 size_t packet_size) { |
41 // Verify the result. | 41 // Verify the result. |
42 EXPECT_EQ(3, parsed_stream.stream_size()); | 42 EXPECT_EQ(5, parsed_stream.stream_size()); |
43 const ACMDumpEvent& start_event = parsed_stream.stream(0); | 43 const ACMDumpEvent& start_event = parsed_stream.stream(2); |
44 ASSERT_TRUE(start_event.has_type()); | 44 ASSERT_TRUE(start_event.has_type()); |
45 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type()); | 45 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type()); |
46 EXPECT_TRUE(start_event.has_timestamp_us()); | 46 EXPECT_TRUE(start_event.has_timestamp_us()); |
47 EXPECT_FALSE(start_event.has_packet()); | 47 EXPECT_FALSE(start_event.has_packet()); |
48 ASSERT_TRUE(start_event.has_debug_event()); | 48 ASSERT_TRUE(start_event.has_debug_event()); |
49 auto start_debug_event = start_event.debug_event(); | 49 auto start_debug_event = start_event.debug_event(); |
50 ASSERT_TRUE(start_debug_event.has_type()); | 50 ASSERT_TRUE(start_debug_event.has_type()); |
51 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type()); | 51 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type()); |
52 ASSERT_TRUE(start_debug_event.has_message()); | 52 ASSERT_TRUE(start_debug_event.has_message()); |
53 | 53 |
54 for (int i = 1; i < parsed_stream.stream_size(); i++) { | 54 for (int i = 0; i < parsed_stream.stream_size(); i++) { |
| 55 if (i==2) { |
| 56 // This is the LOG_START packet that was already verified. |
| 57 continue; |
| 58 } |
55 const ACMDumpEvent& test_event = parsed_stream.stream(i); | 59 const ACMDumpEvent& test_event = parsed_stream.stream(i); |
56 ASSERT_TRUE(test_event.has_type()); | 60 ASSERT_TRUE(test_event.has_type()); |
57 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type()); | 61 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type()); |
58 EXPECT_TRUE(test_event.has_timestamp_us()); | 62 EXPECT_TRUE(test_event.has_timestamp_us()); |
59 EXPECT_FALSE(test_event.has_debug_event()); | 63 EXPECT_FALSE(test_event.has_debug_event()); |
60 ASSERT_TRUE(test_event.has_packet()); | 64 ASSERT_TRUE(test_event.has_packet()); |
61 const ACMDumpRTPPacket& test_packet = test_event.packet(); | 65 const ACMDumpRTPPacket& test_packet = test_event.packet(); |
62 ASSERT_TRUE(test_packet.has_direction()); | 66 ASSERT_TRUE(test_packet.has_direction()); |
63 if (i == 1) { | 67 if (i <= 1) { |
64 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction()); | 68 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction()); |
65 } else if (i == 2) { | 69 } else if (i >= 3) { |
66 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction()); | 70 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction()); |
67 } | 71 } |
68 ASSERT_TRUE(test_packet.has_rtp_data()); | 72 ASSERT_TRUE(test_packet.has_rtp_data()); |
69 ASSERT_EQ(packet_size, test_packet.rtp_data().size()); | 73 ASSERT_EQ(packet_size, test_packet.rtp_data().size()); |
70 for (size_t i = 0; i < packet_size; i++) { | 74 for (size_t i = 0; i < packet_size; i++) { |
71 EXPECT_EQ(rtp_packet_[i], | 75 EXPECT_EQ(rtp_packet_[i], |
72 static_cast<uint8_t>(test_packet.rtp_data()[i])); | 76 static_cast<uint8_t>(test_packet.rtp_data()[i])); |
73 } | 77 } |
74 } | 78 } |
75 } | 79 } |
76 | 80 |
77 void Run(int packet_size, int random_seed) { | 81 void Run(int packet_size, int random_seed) { |
78 rtp_packet_.clear(); | 82 rtp_packet_.clear(); |
79 rtp_packet_.reserve(packet_size); | 83 rtp_packet_.reserve(packet_size); |
80 srand(random_seed); | 84 srand(random_seed); |
81 // Fill the packet vector with random data. | 85 // Fill the packet vector with random data. |
82 for (int i = 0; i < packet_size; i++) { | 86 for (int i = 0; i < packet_size; i++) { |
83 rtp_packet_.push_back(rand()); | 87 rtp_packet_.push_back(rand()); |
84 } | 88 } |
85 // Find the name of the current test, in order to use it as a temporary | 89 // Find the name of the current test, in order to use it as a temporary |
86 // filename. | 90 // filename. |
87 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 91 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
88 const std::string temp_filename = | 92 const std::string temp_filename = |
89 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 93 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
90 | 94 |
| 95 log_dumper_->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); |
| 96 log_dumper_->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); |
91 log_dumper_->StartLogging(temp_filename, 10000000); | 97 log_dumper_->StartLogging(temp_filename, 10000000); |
92 log_dumper_->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); | 98 log_dumper_->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); |
93 log_dumper_->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); | 99 log_dumper_->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); |
94 | 100 |
95 // Read the generated file from disk. | 101 // Read the generated file from disk. |
96 ACMDumpEventStream parsed_stream; | 102 ACMDumpEventStream parsed_stream; |
97 | 103 |
98 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream)); | 104 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream)); |
99 | 105 |
100 VerifyResults(parsed_stream, packet_size); | 106 VerifyResults(parsed_stream, packet_size); |
101 | 107 |
102 // Clean up temporary file - can be pretty slow. | 108 // Clean up temporary file - can be pretty slow. |
103 remove(temp_filename.c_str()); | 109 remove(temp_filename.c_str()); |
104 } | 110 } |
105 | 111 |
106 std::vector<uint8_t> rtp_packet_; | 112 std::vector<uint8_t> rtp_packet_; |
107 rtc::scoped_ptr<AcmDump> log_dumper_; | 113 rtc::scoped_ptr<AcmDump> log_dumper_; |
108 }; | 114 }; |
109 | 115 |
110 TEST_F(AcmDumpTest, DumpAndRead) { | 116 TEST_F(AcmDumpTest, DumpAndRead) { |
111 Run(256, 321); | 117 Run(256, 321); |
112 Run(256, 123); | |
113 } | 118 } |
114 | 119 |
115 } // namespace webrtc | 120 } // namespace webrtc |
116 | 121 |
117 #endif // RTC_AUDIOCODING_DEBUG_DUMP | 122 #endif // RTC_AUDIOCODING_DEBUG_DUMP |
OLD | NEW |