OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
ossu
2016/02/24 13:24:33
I should change this to 2016.
kwiberg-webrtc
2016/02/25 00:29:04
Acknowledged.
| |
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 int16_t raw_audio[80]; | |
27 uint8_t output_array[kPayloadSize * 2]; | |
28 rtc::Buffer output_buffer; | |
kwiberg-webrtc
2016/02/25 00:29:04
Please don't declare variables so far away from th
ossu
2016/02/25 10:39:51
Acknowledged.
| |
29 MockAudioEncoderDeprecated old_impl; | |
30 MockAudioEncoder new_impl; | |
31 MockAudioEncoderHelper helper; | |
32 helper.info_.encoded_bytes = kPayloadSize; | |
33 helper.payload_ = payload; | |
34 helper.write_payload_ = true; | |
35 | |
36 MockAudioEncoderBase* impls[2] = { &old_impl, &new_impl }; | |
kwiberg-webrtc
2016/02/25 00:29:04
You can drop the explicit 2.
ossu
2016/02/25 10:39:51
Acknowledged.
| |
37 for (auto* impl : impls) { | |
38 EXPECT_CALL(*impl, Die()); | |
39 EXPECT_CALL(*impl, MaxEncodedBytes()) | |
40 .WillRepeatedly(Return(kPayloadSize * 2)); | |
41 EXPECT_CALL(*impl, NumChannels()).WillRepeatedly(Return(1)); | |
42 EXPECT_CALL(*impl, SampleRateHz()).WillRepeatedly(Return(8000)); | |
43 } | |
44 | |
45 EXPECT_CALL(old_impl, EncodeInternal(_, _, _, _)) | |
46 .WillRepeatedly(Invoke(&helper, | |
kwiberg-webrtc
2016/02/25 00:29:04
WillOnce?
ossu
2016/02/25 10:39:51
Yeah, that makes sense. The same for the one below
kwiberg-webrtc
2016/02/25 12:24:25
Yes.
| |
47 &MockAudioEncoderHelper::DEPRECATED_Encode)); | |
48 | |
49 EXPECT_CALL(new_impl, EncodeInternal(_, _, _)) | |
50 .WillRepeatedly(Invoke(&helper, | |
51 &MockAudioEncoderHelper::Encode)); | |
52 | |
53 AudioEncoder* old_encoder = &old_impl; | |
54 AudioEncoder* new_encoder = &new_impl; | |
55 rtc::ArrayView<const int16_t> audio_view(raw_audio, 80); | |
kwiberg-webrtc
2016/02/25 00:29:04
IIRC, ArrayView has a constructor for C arrays tha
ossu
2016/02/25 10:39:51
Acknowledged.
| |
56 | |
57 auto old_info = old_encoder->Encode(0, audio_view, &output_buffer); | |
58 auto new_info = new_encoder->DEPRECATED_Encode(0, audio_view, | |
59 kPayloadSize * 2, | |
60 output_array); | |
61 | |
62 EXPECT_EQ(old_info.encoded_bytes, kPayloadSize); | |
63 EXPECT_EQ(new_info.encoded_bytes, kPayloadSize); | |
64 EXPECT_EQ(output_buffer.size(), kPayloadSize); | |
65 | |
66 for (size_t i = 0; i != kPayloadSize; ++i) { | |
67 EXPECT_EQ(output_buffer.data()[i], payload[i]); | |
kwiberg-webrtc
2016/02/25 00:29:04
Hmm, Buffer doesn't have an operator[]? Are you up
ossu
2016/02/25 10:39:51
I am! However, I guess there might be an issue wit
kwiberg-webrtc
2016/02/25 12:24:25
Good point---I didn't think of that. Having it for
| |
68 EXPECT_EQ(output_array[i], payload[i]); | |
69 } | |
70 } | |
71 | |
72 } // namespace webrtc | |
OLD | NEW |