OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2016 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 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" | |
13 | |
14 using ::testing::_; | |
15 using ::testing::Invoke; | |
16 using ::testing::Return; | |
17 | |
18 namespace webrtc { | |
19 | |
20 TEST(AudioEncoderTest, EncodeInternalRedirectsOk) { | |
21 const size_t kPayloadSize = 16; | |
22 const uint8_t payload[kPayloadSize] = | |
23 {0xf, 0xe, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, | |
24 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0}; | |
25 | |
26 MockAudioEncoderDeprecated old_impl; | |
27 MockAudioEncoder new_impl; | |
28 MockAudioEncoderBase* impls[] = { &old_impl, &new_impl }; | |
29 for (auto* impl : impls) { | |
30 EXPECT_CALL(*impl, Die()); | |
31 EXPECT_CALL(*impl, MaxEncodedBytes()) | |
32 .WillRepeatedly(Return(kPayloadSize * 2)); | |
33 EXPECT_CALL(*impl, NumChannels()).WillRepeatedly(Return(1)); | |
34 EXPECT_CALL(*impl, SampleRateHz()).WillRepeatedly(Return(8000)); | |
35 } | |
36 | |
37 EXPECT_CALL(old_impl, EncodeInternal(_, _, _, _)).WillOnce( | |
38 Invoke(MockAudioEncoderDeprecated::CopyEncoding(payload))); | |
39 | |
40 EXPECT_CALL(new_impl, EncodeImpl(_, _, _)).WillOnce( | |
41 Invoke(MockAudioEncoder::CopyEncoding(payload))); | |
42 | |
43 int16_t audio[80]; | |
44 uint8_t output_array[kPayloadSize * 2]; | |
45 rtc::Buffer output_buffer; | |
46 | |
47 AudioEncoder* old_encoder = &old_impl; | |
48 AudioEncoder* new_encoder = &new_impl; | |
49 auto old_info = old_encoder->Encode(0, audio, &output_buffer); | |
50 auto new_info = new_encoder->DEPRECATED_Encode(0, audio, | |
51 kPayloadSize * 2, | |
52 output_array); | |
53 | |
54 EXPECT_EQ(old_info.encoded_bytes, kPayloadSize); | |
55 EXPECT_EQ(new_info.encoded_bytes, kPayloadSize); | |
56 EXPECT_EQ(output_buffer.size(), kPayloadSize); | |
57 | |
58 for (size_t i = 0; i != kPayloadSize; ++i) { | |
59 EXPECT_EQ(output_buffer.data()[i], payload[i]); | |
60 EXPECT_EQ(output_array[i], payload[i]); | |
61 } | |
62 } | |
63 | |
64 } // namespace webrtc | |
OLD | NEW |