Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_dump_unittest.cc

Issue 1250383003: Revert "Renamed the ACMDump to RtcEventLog and moved it to webrtc/video, since it is not specific t… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifdef RTC_AUDIOCODING_DEBUG_DUMP
12
13 #include <stdio.h>
14 #include <string>
15 #include <vector>
16
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/modules/audio_coding/main/acm2/acm_dump.h"
20 #include "webrtc/system_wrappers/interface/clock.h"
21 #include "webrtc/test/test_suite.h"
22 #include "webrtc/test/testsupport/fileutils.h"
23 #include "webrtc/test/testsupport/gtest_disable.h"
24
25 // Files generated at build-time by the protobuf compiler.
26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
27 #include "external/webrtc/webrtc/modules/audio_coding/dump.pb.h"
28 #else
29 #include "webrtc/audio_coding/dump.pb.h"
30 #endif
31
32 namespace webrtc {
33
34 // Test for the acm dump class. Dumps some RTP packets to disk, then reads them
35 // back to see if they match.
36 class AcmDumpTest : public ::testing::Test {
37 public:
38 void VerifyResults(const ACMDumpEventStream& parsed_stream,
39 size_t packet_size) {
40 // Verify the result.
41 EXPECT_EQ(5, parsed_stream.stream_size());
42 const ACMDumpEvent& start_event = parsed_stream.stream(2);
43 ASSERT_TRUE(start_event.has_type());
44 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type());
45 EXPECT_TRUE(start_event.has_timestamp_us());
46 EXPECT_FALSE(start_event.has_packet());
47 ASSERT_TRUE(start_event.has_debug_event());
48 auto start_debug_event = start_event.debug_event();
49 ASSERT_TRUE(start_debug_event.has_type());
50 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type());
51 ASSERT_TRUE(start_debug_event.has_message());
52
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 }
58 const ACMDumpEvent& test_event = parsed_stream.stream(i);
59 ASSERT_TRUE(test_event.has_type());
60 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type());
61 EXPECT_TRUE(test_event.has_timestamp_us());
62 EXPECT_FALSE(test_event.has_debug_event());
63 ASSERT_TRUE(test_event.has_packet());
64 const ACMDumpRTPPacket& test_packet = test_event.packet();
65 ASSERT_TRUE(test_packet.has_direction());
66 if (i <= 1) {
67 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction());
68 } else if (i >= 3) {
69 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction());
70 }
71 ASSERT_TRUE(test_packet.has_rtp_data());
72 ASSERT_EQ(packet_size, test_packet.rtp_data().size());
73 for (size_t i = 0; i < packet_size; i++) {
74 EXPECT_EQ(rtp_packet_[i],
75 static_cast<uint8_t>(test_packet.rtp_data()[i]));
76 }
77 }
78 }
79
80 void Run(int packet_size, int random_seed) {
81 rtp_packet_.clear();
82 rtp_packet_.reserve(packet_size);
83 srand(random_seed);
84 // Fill the packet vector with random data.
85 for (int i = 0; i < packet_size; i++) {
86 rtp_packet_.push_back(rand());
87 }
88 // Find the name of the current test, in order to use it as a temporary
89 // filename.
90 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
91 const std::string temp_filename =
92 test::OutputPath() + test_info->test_case_name() + test_info->name();
93
94 // When log_dumper goes out of scope, it causes the log file to be flushed
95 // to disk.
96 {
97 rtc::scoped_ptr<AcmDump> log_dumper(AcmDump::Create());
98 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size());
99 log_dumper->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size());
100 log_dumper->StartLogging(temp_filename, 10000000);
101 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size());
102 log_dumper->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size());
103 }
104
105 // Read the generated file from disk.
106 ACMDumpEventStream parsed_stream;
107
108 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream));
109
110 VerifyResults(parsed_stream, packet_size);
111
112 // Clean up temporary file - can be pretty slow.
113 remove(temp_filename.c_str());
114 }
115 std::vector<uint8_t> rtp_packet_;
116 };
117
118 TEST_F(AcmDumpTest, DumpAndRead) {
119 Run(256, 321);
120 }
121
122 } // namespace webrtc
123
124 #endif // RTC_AUDIOCODING_DEBUG_DUMP
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/acm_dump.cc ('k') | webrtc/modules/audio_coding/main/acm2/audio_coding_module.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698