Index: webrtc/modules/audio_mixer/test/audio_frame_manipulator_unittest.cc |
diff --git a/webrtc/modules/audio_mixer/test/audio_frame_manipulator_unittest.cc b/webrtc/modules/audio_mixer/test/audio_frame_manipulator_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..56c968d0c97fdfa2f13db1b7308b317d51cf77a7 |
--- /dev/null |
+++ b/webrtc/modules/audio_mixer/test/audio_frame_manipulator_unittest.cc |
@@ -0,0 +1,63 @@ |
+/* |
the sun
2016/10/11 10:57:05
This file should live next to the .h and .cc - no
aleloi
2016/10/11 11:27:26
Done.
hlundin-webrtc
2016/10/11 11:29:58
Acknowledged.
|
+ * 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 <algorithm> |
+ |
+#include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" |
+#include "webrtc/modules/include/module_common_types.h" |
+#include "webrtc/test/gmock.h" |
hlundin-webrtc
2016/10/11 11:29:58
gmock -> gtest
You are not using mocks.
aleloi
2016/10/11 12:43:14
Done.
|
+ |
+namespace webrtc { |
+namespace { |
+ |
+void FillFrameWithConstants(int samples_per_channel, |
the sun
2016/10/11 10:57:05
size_t
aleloi
2016/10/11 11:27:26
Done.
|
+ int number_of_channels, |
the sun
2016/10/11 10:57:05
size_t
aleloi
2016/10/11 11:27:26
Done.
|
+ int value, |
the sun
2016/10/11 10:57:06
int16_t
aleloi
2016/10/11 11:27:26
Of course! Thanks for noticing :)
|
+ AudioFrame* frame) { |
+ frame->num_channels_ = number_of_channels; |
+ frame->samples_per_channel_ = samples_per_channel; |
+ std::fill(frame->data_, |
+ frame->data_ + samples_per_channel * number_of_channels, value); |
+} |
+} // namespace |
+ |
+TEST(AudioFrameManipulator, CompareForwardRampWithExpectedResult) { |
the sun
2016/10/11 10:57:06
Add "Stereo" to the name here
aleloi
2016/10/11 11:27:26
Done.
|
+ constexpr int samples_per_channel = 5; |
the sun
2016/10/11 10:57:06
Although there's been debate around the naming of
aleloi
2016/10/11 11:27:26
You are correct, I missed that.
hlundin-webrtc
2016/10/11 11:29:58
Debate it has been. I prefer kConstantName, but I
|
+ constexpr int number_of_channels = 2; |
+ |
+ // Create a frame with values 5, 5, 5, ... and channels & samples as above. |
+ AudioFrame frame; |
+ FillFrameWithConstants(samples_per_channel, number_of_channels, 5, &frame); |
+ |
+ Ramp(0, 1, &frame); |
the sun
2016/10/11 10:57:05
0.0f, 1.0f
aleloi
2016/10/11 11:27:26
Done.
|
+ |
+ const int total_samples = samples_per_channel * number_of_channels; |
+ const int16_t expected_result[total_samples] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4}; |
+ EXPECT_TRUE( |
+ std::equal(frame.data_, frame.data_ + total_samples, expected_result)); |
+} |
+ |
+TEST(AudioFrameManipulator, CompareBackwardRampWithExpectedResultMono) { |
+ constexpr int samples_per_channel = 5; |
+ constexpr int number_of_channels = 1; |
+ |
+ // Create a frame with values 5, 5, 5, ... and channels & samples as above. |
+ AudioFrame frame; |
+ FillFrameWithConstants(samples_per_channel, number_of_channels, 5, &frame); |
+ |
+ Ramp(1, 0, &frame); |
+ |
+ const int total_samples = samples_per_channel * number_of_channels; |
+ const int16_t expected_result[total_samples] = {5, 4, 3, 2, 1}; |
+ EXPECT_TRUE( |
+ std::equal(frame.data_, frame.data_ + total_samples, expected_result)); |
+} |
+ |
+} // namespace webrtc |