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..576aedc718354eec62c4a1a969f919bde10837bd |
--- /dev/null |
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc |
@@ -0,0 +1,96 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * 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 "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
+#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
+#include "webrtc/test/field_trial.h" |
+#include "webrtc/test/gmock.h" |
+#include "webrtc/test/gtest.h" |
+ |
+namespace webrtc { |
+ |
+using testing::_; |
michaelt
2016/11/28 09:26:57
testing::_ not used at the moment.
|
+using testing::Invoke; |
michaelt
2016/11/28 09:26:57
testing::Invoke not used at the moment.
|
+using testing::Return; |
+using testing::StrictMock; |
+ |
+TEST(AudioEncoderTest, DoNotInvokeSetTargetBitrateIfOverheadUnknown) { |
+ test::ScopedFieldTrials override_field_trials( |
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
+ |
+ // In this test, we want to test logics within |
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder| |
+ // since this method is not mocked. If it needs to be mocked in the future, we |
+ // can maintain the test by letting the mocked method invoke the original |
+ // method. |
michaelt
2016/11/28 09:26:57
I think i would prefer to add the mock function an
|
+ StrictMock<MockAudioEncoder> mock_audio_encoder; |
+ EXPECT_CALL(mock_audio_encoder, Die()); |
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(12345); |
+ // Since |OnReceivedOverhead| has not been called, |
+ // |mock_audio_encoder.SetTargetBitrate| should not be invoked. |
+} |
+ |
+TEST(AudioEncoderTest, OverheadRemovedFromTargetAudioBitrate) { |
+ test::ScopedFieldTrials override_field_trials( |
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
+ |
+ // In this test, we want to test logics within |
+ // |AudioEncoder::OnReceivedOverhead| and |
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder| |
+ // since these methods are not mocked. If they needs to be mocked in the |
+ // future, we can maintain the test by letting the mocked methods invoke the |
+ // original methods. |
+ StrictMock<MockAudioEncoder> mock_audio_encoder; |
+ EXPECT_CALL(mock_audio_encoder, Die()); |
+ |
+ constexpr int kFrameLengthMs = 60; |
+ constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10; |
+ EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket()) |
+ .WillOnce(Return(kNum10MsFramesPerPacket)); |
+ |
+ constexpr size_t kOverheadBytesPerPacket = 64; |
+ mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket); |
+ |
+ constexpr size_t kTargetBitrateBps = 12345; |
+ EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(kTargetBitrateBps - |
+ kOverheadBytesPerPacket * 8 * |
+ 1000 / kFrameLengthMs)); |
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps); |
+} |
+ |
+TEST(AudioEncoderTest, BitrateNeverBecomesNegative) { |
+ test::ScopedFieldTrials override_field_trials( |
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
+ |
+ // In this test, we want to test logics within |
+ // |AudioEncoder::OnReceivedOverhead| and |
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder| |
+ // since these methods are not mocked. If they needs to be mocked in the |
+ // future, we can maintain the test by letting the mocked methods invoke the |
+ // original methods. |
+ StrictMock<MockAudioEncoder> mock_audio_encoder; |
+ EXPECT_CALL(mock_audio_encoder, Die()); |
+ |
+ constexpr int kFrameLengthMs = 60; |
+ constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10; |
+ EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket()) |
+ .WillOnce(Return(kNum10MsFramesPerPacket)); |
+ |
+ constexpr size_t kOverheadBytesPerPacket = 64; |
+ mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket); |
+ |
+ // Set a target rate smaller than overhead rate, the bitrate is bounded by 0. |
+ constexpr size_t kTargetBitrateBps = |
+ kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1; |
+ EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(0)); |
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps); |
+} |
+ |
+} // namespace webrtc |