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

Unified Diff: webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reverted unnecessary change to buffer_unittest.cc Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ba5e991640c0a9a30f47dc6e48aaf95a36cfae07
--- /dev/null
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h"
+
+using ::testing::_;
+using ::testing::Invoke;
+using ::testing::Return;
+
+namespace webrtc {
+
+TEST(AudioEncoderTest, EncodeInternalRedirectsOk) {
+ const size_t kPayloadSize = 16;
+ const uint8_t payload[kPayloadSize] =
+ {0xf, 0xe, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8,
+ 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0};
+
+ int16_t raw_audio[80];
+ uint8_t output_array[kPayloadSize * 2];
+ 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.
+ MockAudioEncoderDeprecated old_impl;
+ MockAudioEncoder new_impl;
+ MockAudioEncoderHelper helper;
+ helper.info_.encoded_bytes = kPayloadSize;
+ helper.payload_ = payload;
+ helper.write_payload_ = true;
+
+ 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.
+ for (auto* impl : impls) {
+ EXPECT_CALL(*impl, Die());
+ EXPECT_CALL(*impl, MaxEncodedBytes())
+ .WillRepeatedly(Return(kPayloadSize * 2));
+ EXPECT_CALL(*impl, NumChannels()).WillRepeatedly(Return(1));
+ EXPECT_CALL(*impl, SampleRateHz()).WillRepeatedly(Return(8000));
+ }
+
+ EXPECT_CALL(old_impl, EncodeInternal(_, _, _, _))
+ .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.
+ &MockAudioEncoderHelper::DEPRECATED_Encode));
+
+ EXPECT_CALL(new_impl, EncodeInternal(_, _, _))
+ .WillRepeatedly(Invoke(&helper,
+ &MockAudioEncoderHelper::Encode));
+
+ AudioEncoder* old_encoder = &old_impl;
+ AudioEncoder* new_encoder = &new_impl;
+ 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.
+
+ auto old_info = old_encoder->Encode(0, audio_view, &output_buffer);
+ auto new_info = new_encoder->DEPRECATED_Encode(0, audio_view,
+ kPayloadSize * 2,
+ output_array);
+
+ EXPECT_EQ(old_info.encoded_bytes, kPayloadSize);
+ EXPECT_EQ(new_info.encoded_bytes, kPayloadSize);
+ EXPECT_EQ(output_buffer.size(), kPayloadSize);
+
+ for (size_t i = 0; i != kPayloadSize; ++i) {
+ 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
+ EXPECT_EQ(output_array[i], payload[i]);
+ }
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698