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

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

Issue 1195963002: Revert "Added ACM_dump protobuf, class for reading/writing and unittest." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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 AcmDumpTest() : log_dumper_(AcmDump::Create()) {}
39 void VerifyResults(const ACMDumpEventStream& parsed_stream,
40 size_t packet_size) {
41 // Verify the result.
42 EXPECT_EQ(3, parsed_stream.stream_size());
43 const ACMDumpEvent& start_event = parsed_stream.stream(0);
44 ASSERT_TRUE(start_event.has_type());
45 EXPECT_EQ(ACMDumpEvent::DEBUG_EVENT, start_event.type());
46 EXPECT_TRUE(start_event.has_timestamp_us());
47 EXPECT_FALSE(start_event.has_packet());
48 ASSERT_TRUE(start_event.has_debug_event());
49 auto start_debug_event = start_event.debug_event();
50 ASSERT_TRUE(start_debug_event.has_type());
51 EXPECT_EQ(ACMDumpDebugEvent::LOG_START, start_debug_event.type());
52 ASSERT_TRUE(start_debug_event.has_message());
53
54 for (int i = 1; i < parsed_stream.stream_size(); i++) {
55 const ACMDumpEvent& test_event = parsed_stream.stream(i);
56 ASSERT_TRUE(test_event.has_type());
57 EXPECT_EQ(ACMDumpEvent::RTP_EVENT, test_event.type());
58 EXPECT_TRUE(test_event.has_timestamp_us());
59 EXPECT_FALSE(test_event.has_debug_event());
60 ASSERT_TRUE(test_event.has_packet());
61 const ACMDumpRTPPacket& test_packet = test_event.packet();
62 ASSERT_TRUE(test_packet.has_direction());
63 if (i == 1) {
64 EXPECT_EQ(ACMDumpRTPPacket::INCOMING, test_packet.direction());
65 } else if (i == 2) {
66 EXPECT_EQ(ACMDumpRTPPacket::OUTGOING, test_packet.direction());
67 }
68 ASSERT_TRUE(test_packet.has_rtp_data());
69 ASSERT_EQ(packet_size, test_packet.rtp_data().size());
70 for (size_t i = 0; i < packet_size; i++) {
71 EXPECT_EQ(rtp_packet_[i],
72 static_cast<uint8_t>(test_packet.rtp_data()[i]));
73 }
74 }
75 }
76
77 void Run(int packet_size, int random_seed) {
78 rtp_packet_.clear();
79 rtp_packet_.reserve(packet_size);
80 srand(random_seed);
81 // Fill the packet vector with random data.
82 for (int i = 0; i < packet_size; i++) {
83 rtp_packet_.push_back(rand());
84 }
85 // Find the name of the current test, in order to use it as a temporary
86 // filename.
87 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
88 const std::string temp_filename =
89 test::OutputPath() + test_info->test_case_name() + test_info->name();
90
91 log_dumper_->StartLogging(temp_filename, 10000000);
92 log_dumper_->LogRtpPacket(true, rtp_packet_.data(), rtp_packet_.size());
93 log_dumper_->LogRtpPacket(false, rtp_packet_.data(), rtp_packet_.size());
94
95 // Read the generated file from disk.
96 ACMDumpEventStream parsed_stream;
97
98 ASSERT_EQ(true, AcmDump::ParseAcmDump(temp_filename, &parsed_stream));
99
100 VerifyResults(parsed_stream, packet_size);
101
102 // Clean up temporary file - can be pretty slow.
103 remove(temp_filename.c_str());
104 }
105
106 std::vector<uint8_t> rtp_packet_;
107 rtc::scoped_ptr<AcmDump> log_dumper_;
108 };
109
110 TEST_F(AcmDumpTest, DumpAndRead) {
111 Run(256, 321);
112 Run(256, 123);
113 }
114
115 } // namespace webrtc
116
117 #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