Index: remoting/host/audio_volume_applier_unittest.cc |
diff --git a/remoting/host/audio_volume_applier_unittest.cc b/remoting/host/audio_volume_applier_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3d8bbcb85b094512a055bfddfc09e8d3abca0742 |
--- /dev/null |
+++ b/remoting/host/audio_volume_applier_unittest.cc |
@@ -0,0 +1,79 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/host/audio_volume_applier.h" |
+ |
+#include "base/macros.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace remoting { |
+ |
+namespace { |
+ |
+class FakeAudioVolumeApplier : public AudioVolumeApplier { |
+ public: |
+ FakeAudioVolumeApplier(int silence_threshold) |
+ : AudioVolumeApplier(silence_threshold) {} |
+ ~FakeAudioVolumeApplier() override = default; |
+ |
+ void set_audio_level(float level) { level_ = level; } |
+ |
+ protected: |
+ float GetAudioLevel() override { return level_; } |
+ |
+ private: |
+ float level_ = 0; |
+}; |
+ |
+} // namespace |
+ |
+TEST(AudioVolumeApplierTest, TwoChannels) { |
+ int16_t samples[] = |
+ {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10}; |
+ FakeAudioVolumeApplier applier(0); |
+ applier.set_audio_level(0.5f); |
+ applier.Initialize(9, 2); |
+ // After applying the audio volume, the |samples| should still pass the |
+ // AudioSilenceDetector, AudioVolumeApplier::Apply() returns true under this |
+ // condition. Ditto. |
+ ASSERT_TRUE(applier.Apply(samples, arraysize(samples) / 2)); |
+} |
+ |
+TEST(AudioVolumeApplierTest, ThreeChannels) { |
+ int16_t samples[] = |
+ {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11}; |
+ FakeAudioVolumeApplier applier(0); |
+ applier.set_audio_level(0.5f); |
+ applier.Initialize(6, 3); |
+ ASSERT_TRUE(applier.Apply(samples, arraysize(samples) / 3)); |
+} |
+ |
+TEST(AudioVolumeApplierTest, SilentSamples) { |
+ int16_t samples[] = |
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
+ FakeAudioVolumeApplier applier(0); |
+ applier.set_audio_level(0.5f); |
+ applier.Initialize(9, 2); |
+ ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2)); |
+} |
+ |
+TEST(AudioVolumeApplierTest, AudioLevel0) { |
+ int16_t samples[] = |
+ {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10}; |
+ FakeAudioVolumeApplier applier(0); |
+ applier.set_audio_level(0); |
+ applier.Initialize(9, 2); |
+ ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2)); |
+} |
+ |
+TEST(AudioVolumeApplierTest, SilcentAfterApplying) { |
+ int16_t samples[] = |
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
+ FakeAudioVolumeApplier applier(0); |
+ applier.set_audio_level(0.9f); |
+ applier.Initialize(9, 2); |
+ ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2)); |
+} |
+ |
+} // namespace remoting |