Chromium Code Reviews| Index: webrtc/modules/module_common_types_unittest.cc |
| diff --git a/webrtc/modules/module_common_types_unittest.cc b/webrtc/modules/module_common_types_unittest.cc |
| index 159e26babe92a59ee5245829c9ea1e24e29f9600..0de3fe857f5f0796b4e89e4fb4dd1bd002fd409e 100644 |
| --- a/webrtc/modules/module_common_types_unittest.cc |
| +++ b/webrtc/modules/module_common_types_unittest.cc |
| @@ -10,10 +10,116 @@ |
| #include "webrtc/modules/include/module_common_types.h" |
| +#include <cstring> // memcmp |
| + |
| #include "webrtc/test/gtest.h" |
| namespace webrtc { |
| +class AudioFrameTest : public ::testing::Test { |
| + protected: |
| + static bool AllSamplesAre(int16_t sample, const AudioFrame& frame) { |
| + const int16_t* frame_data = frame.data(); |
| + for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| + if (frame_data[i] != sample) { |
| + return false; |
| + } |
| + } |
| + return true; |
| + } |
| + |
| + static constexpr int kId = 16; |
| + static constexpr uint32_t kTimestamp = 27; |
| + static constexpr int kSampleRateHz = 16000; |
| + static constexpr size_t kNumChannels = 1; |
| + static constexpr size_t kSamplesPerChannel = kSampleRateHz / 100; |
| +}; |
| + |
| +constexpr int AudioFrameTest::kId; |
| +constexpr uint32_t AudioFrameTest::kTimestamp; |
| +constexpr int AudioFrameTest::kSampleRateHz; |
| +constexpr size_t AudioFrameTest::kNumChannels; |
| +constexpr size_t AudioFrameTest::kSamplesPerChannel; |
| + |
| +TEST_F(AudioFrameTest, FrameStartsMuted) { |
| + AudioFrame frame; |
| + EXPECT_TRUE(frame.muted()); |
| + EXPECT_TRUE(AllSamplesAre(0, frame)); |
|
hlundin-webrtc
2017/03/22 12:07:26
I think you can replace this with
EXPECT_THAT(fram
yujo
2017/03/22 19:45:45
Deleted the unnecessary test fixture.
data() retu
hlundin-webrtc
2017/03/23 07:04:03
Don't change any more. This is good enough. I did
|
| +} |
| + |
| +TEST_F(AudioFrameTest, UnmutedFrameIsInitiallyZeroed) { |
| + AudioFrame frame; |
| + frame.mutable_data(); |
| + EXPECT_FALSE(frame.muted()); |
| + EXPECT_TRUE(AllSamplesAre(0, frame)); |
| +} |
| + |
| +TEST_F(AudioFrameTest, MutedFrameBufferIsZeroed) { |
| + AudioFrame frame; |
| + int16_t* frame_data = frame.mutable_data(); |
| + for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| + frame_data[i] = 17; |
| + } |
| + ASSERT_TRUE(AllSamplesAre(17, frame)); |
| + frame.Mute(); |
| + EXPECT_TRUE(frame.muted()); |
| + EXPECT_TRUE(AllSamplesAre(0, frame)); |
| +} |
| + |
| +TEST_F(AudioFrameTest, UpdateFrame) { |
| + AudioFrame frame; |
| + int16_t samples[kNumChannels * kSamplesPerChannel] = {17}; |
| + frame.UpdateFrame(kId, kTimestamp, samples, kSamplesPerChannel, kSampleRateHz, |
| + AudioFrame::kPLC, AudioFrame::kVadActive, kNumChannels); |
| + |
| + EXPECT_EQ(kId, frame.id_); |
| + EXPECT_EQ(kTimestamp, frame.timestamp_); |
| + EXPECT_EQ(kSamplesPerChannel, frame.samples_per_channel_); |
| + EXPECT_EQ(kSampleRateHz, frame.sample_rate_hz_); |
| + EXPECT_EQ(AudioFrame::kPLC, frame.speech_type_); |
| + EXPECT_EQ(AudioFrame::kVadActive, frame.vad_activity_); |
| + EXPECT_EQ(kNumChannels, frame.num_channels_); |
| + |
| + EXPECT_FALSE(frame.muted()); |
| + EXPECT_EQ(0, std::memcmp(samples, frame.data(), sizeof(samples))); |
|
hlundin-webrtc
2017/03/22 12:07:26
Can you use
EXPECT_THAT(frame.data(), ::testing::E
yujo
2017/03/22 19:45:45
Yes here, but not in the other two cases below. Le
hlundin-webrtc
2017/03/23 07:04:03
Acknowledged.
|
| + |
| + frame.UpdateFrame(kId, kTimestamp, nullptr /* data*/, kSamplesPerChannel, |
| + kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive, |
| + kNumChannels); |
| + EXPECT_TRUE(frame.muted()); |
| + EXPECT_TRUE(AllSamplesAre(0, frame)); |
| +} |
| + |
| +TEST_F(AudioFrameTest, CopyFrom) { |
| + AudioFrame frame1; |
| + AudioFrame frame2; |
| + |
| + int16_t samples[kNumChannels * kSamplesPerChannel] = {17}; |
| + frame2.UpdateFrame(kId, kTimestamp, samples, kSamplesPerChannel, |
| + kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive, |
| + kNumChannels); |
| + frame1.CopyFrom(frame2); |
| + |
| + EXPECT_EQ(frame2.id_, frame1.id_); |
| + EXPECT_EQ(frame2.timestamp_, frame1.timestamp_); |
| + EXPECT_EQ(frame2.samples_per_channel_, frame1.samples_per_channel_); |
| + EXPECT_EQ(frame2.sample_rate_hz_, frame1.sample_rate_hz_); |
| + EXPECT_EQ(frame2.speech_type_, frame1.speech_type_); |
| + EXPECT_EQ(frame2.vad_activity_, frame1.vad_activity_); |
| + EXPECT_EQ(frame2.num_channels_, frame1.num_channels_); |
| + |
| + EXPECT_EQ(frame2.muted(), frame1.muted()); |
| + EXPECT_EQ(0, std::memcmp(frame2.data(), frame1.data(), sizeof(samples))); |
|
hlundin-webrtc
2017/03/22 12:07:26
EXPECT_THAT(...)
|
| + |
| + frame2.UpdateFrame(kId, kTimestamp, nullptr /* data */, kSamplesPerChannel, |
| + kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive, |
| + kNumChannels); |
| + frame1.CopyFrom(frame2); |
| + |
| + EXPECT_EQ(frame2.muted(), frame1.muted()); |
| + EXPECT_EQ(0, std::memcmp(frame2.data(), frame1.data(), sizeof(samples))); |
|
hlundin-webrtc
2017/03/22 12:07:26
EXPECT_THAT(...)
|
| +} |
| + |
| TEST(IsNewerSequenceNumber, Equal) { |
| EXPECT_FALSE(IsNewerSequenceNumber(0x0001, 0x0001)); |
| } |