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 17 matching lines...) Expand all Loading... | |
28 #else | 28 #else |
29 #include "webrtc/audio_coding/dump.pb.h" | 29 #include "webrtc/audio_coding/dump.pb.h" |
30 #endif | 30 #endif |
31 | 31 |
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()) {} | |
39 void VerifyResults(const ACMDumpEventStream& parsed_stream, | 38 void VerifyResults(const ACMDumpEventStream& parsed_stream, |
40 size_t packet_size) { | 39 size_t packet_size) { |
41 // Verify the result. | 40 // Verify the result. |
42 EXPECT_EQ(3, parsed_stream.stream_size()); | 41 EXPECT_EQ(5, parsed_stream.stream_size()); |
43 const ACMDumpEvent& start_event = parsed_stream.stream(0); | 42 const ACMDumpEvent& start_event = parsed_stream.stream(2); |
44 ASSERT_TRUE(start_event.has_type()); | 43 ASSERT_TRUE(start_event.has_type()); |
45 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type()); | 44 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type()); |
46 EXPECT_TRUE(start_event.has_timestamp_us()); | 45 EXPECT_TRUE(start_event.has_timestamp_us()); |
47 EXPECT_FALSE(start_event.has_packet()); | 46 EXPECT_FALSE(start_event.has_packet()); |
48 ASSERT_TRUE(start_event.has_debug_event()); | 47 ASSERT_TRUE(start_event.has_debug_event()); |
49 auto start_debug_event = start_event.debug_event(); | 48 auto start_debug_event = start_event.debug_event(); |
50 ASSERT_TRUE(start_debug_event.has_type()); | 49 ASSERT_TRUE(start_debug_event.has_type()); |
51 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type()); | 50 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type()); |
52 ASSERT_TRUE(start_debug_event.has_message()); | 51 ASSERT_TRUE(start_debug_event.has_message()); |
53 | 52 |
54 for (int i = 1; i < parsed_stream.stream_size(); i++) { | 53 for (int i = 0; i < parsed_stream.stream_size(); i++) { |
54 if (i == 2) { | |
55 // This is the LOG_START packet that was already verified. | |
56 continue; | |
57 } | |
55 const ACMDumpEvent& test_event = parsed_stream.stream(i); | 58 const ACMDumpEvent& test_event = parsed_stream.stream(i); |
56 ASSERT_TRUE(test_event.has_type()); | 59 ASSERT_TRUE(test_event.has_type()); |
57 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type()); | 60 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type()); |
58 EXPECT_TRUE(test_event.has_timestamp_us()); | 61 EXPECT_TRUE(test_event.has_timestamp_us()); |
59 EXPECT_FALSE(test_event.has_debug_event()); | 62 EXPECT_FALSE(test_event.has_debug_event()); |
60 ASSERT_TRUE(test_event.has_packet()); | 63 ASSERT_TRUE(test_event.has_packet()); |
61 const ACMDumpRTPPacket& test_packet = test_event.packet(); | 64 const ACMDumpRTPPacket& test_packet = test_event.packet(); |
62 ASSERT_TRUE(test_packet.has_direction()); | 65 ASSERT_TRUE(test_packet.has_direction()); |
63 if (i == 1) { | 66 if (i <= 1) { |
64 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction()); | 67 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction()); |
65 } else if (i == 2) { | 68 } else if (i >= 3) { |
66 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction()); | 69 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction()); |
67 } | 70 } |
68 ASSERT_TRUE(test_packet.has_rtp_data()); | 71 ASSERT_TRUE(test_packet.has_rtp_data()); |
69 ASSERT_EQ(packet_size, test_packet.rtp_data().size()); | 72 ASSERT_EQ(packet_size, test_packet.rtp_data().size()); |
70 for (size_t i = 0; i < packet_size; i++) { | 73 for (size_t i = 0; i < packet_size; i++) { |
71 EXPECT_EQ(rtp_packet_[i], | 74 EXPECT_EQ(rtp_packet_[i], |
72 static_cast<uint8_t>(test_packet.rtp_data()[i])); | 75 static_cast<uint8_t>(test_packet.rtp_data()[i])); |
73 } | 76 } |
74 } | 77 } |
75 } | 78 } |
76 | 79 |
77 void Run(int packet_size, int random_seed) { | 80 void Run(int packet_size, int random_seed) { |
78 rtp_packet_.clear(); | 81 rtp_packet_.clear(); |
79 rtp_packet_.reserve(packet_size); | 82 rtp_packet_.reserve(packet_size); |
80 srand(random_seed); | 83 srand(random_seed); |
81 // Fill the packet vector with random data. | 84 // Fill the packet vector with random data. |
82 for (int i = 0; i < packet_size; i++) { | 85 for (int i = 0; i < packet_size; i++) { |
83 rtp_packet_.push_back(rand()); | 86 rtp_packet_.push_back(rand()); |
84 } | 87 } |
85 // Find the name of the current test, in order to use it as a temporary | 88 // Find the name of the current test, in order to use it as a temporary |
86 // filename. | 89 // filename. |
87 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 90 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
88 const std::string temp_filename = | 91 const std::string temp_filename = |
89 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 92 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
90 | 93 |
91 log_dumper_->StartLogging(temp_filename, 10000000); | 94 { |
hlundin-webrtc
2015/06/25 13:20:56
Any reason to add the extra scope here? If so, ple
ivoc
2015/06/25 13:55:23
I added the scope so that when the AcmDump goes ou
| |
92 log_dumper_->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); | 95 rtc::scoped_ptr<AcmDump> log_dumper(AcmDump::Create()); |
93 log_dumper_->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); | 96 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); |
97 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size()); | |
98 log_dumper->StartLogging(temp_filename, 10000000); | |
99 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); | |
100 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size()); | |
101 } | |
94 | 102 |
95 // Read the generated file from disk. | 103 // Read the generated file from disk. |
96 ACMDumpEventStream parsed_stream; | 104 ACMDumpEventStream parsed_stream; |
97 | 105 |
98 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream)); | 106 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream)); |
99 | 107 |
100 VerifyResults(parsed_stream, packet_size); | 108 VerifyResults(parsed_stream, packet_size); |
101 | 109 |
102 // Clean up temporary file - can be pretty slow. | 110 // Clean up temporary file - can be pretty slow. |
103 remove(temp_filename.c_str()); | 111 remove(temp_filename.c_str()); |
104 } | 112 } |
105 | |
106 std::vector<uint8_t> rtp_packet_; | 113 std::vector<uint8_t> rtp_packet_; |
107 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 |