Chromium Code Reviews| Index: webrtc/modules/audio_processing/aec3/block_processor_unittest.cc |
| diff --git a/webrtc/modules/audio_processing/aec3/block_processor_unittest.cc b/webrtc/modules/audio_processing/aec3/block_processor_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..998b25d7c2f01de80d027bf497b4f37fb39f8dc6 |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/aec3/block_processor_unittest.cc |
| @@ -0,0 +1,131 @@ |
| +/* |
| + * 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_processing/aec3/block_processor.h" |
| + |
| +#include <memory> |
| +#include <sstream> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
| +#include "webrtc/test/gtest.h" |
| + |
| +namespace webrtc { |
| +namespace { |
| + |
| +// Verifies that the basic BlockProcessor functionality works and that the API |
| +// methods are callable. |
| +void RunBasicSetupAndApiCallTest(int sample_rate_hz) { |
| + std::unique_ptr<BlockProcessor> block_processor( |
| + BlockProcessor::Create(sample_rate_hz)); |
| + std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), |
| + std::vector<float>(kBlockSize, 0.f)); |
| + |
| + EXPECT_FALSE(block_processor->BufferRender(&block)); |
| + block_processor->ProcessCapture(false, false, &block); |
| + block_processor->ReportEchoLeakage(false); |
| +} |
| + |
| +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| +void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { |
| + std::unique_ptr<BlockProcessor> block_processor( |
| + BlockProcessor::Create(sample_rate_hz)); |
| + std::vector<std::vector<float>> block( |
| + NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
| + |
| + EXPECT_DEATH(block_processor->BufferRender(&block), ""); |
| +} |
| + |
| +void RunCaptureBlockSizeVerificationTest(int sample_rate_hz) { |
| + std::unique_ptr<BlockProcessor> block_processor( |
| + BlockProcessor::Create(sample_rate_hz)); |
| + std::vector<std::vector<float>> block( |
| + NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
| + |
| + EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
| +} |
| + |
| +void RunRenderNumBandsVerificationTest(int sample_rate_hz) { |
| + const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
| + ? NumBandsForRate(sample_rate_hz) + 1 |
| + : 1; |
| + std::unique_ptr<BlockProcessor> block_processor( |
| + BlockProcessor::Create(sample_rate_hz)); |
| + std::vector<std::vector<float>> block(wrong_num_bands, |
| + std::vector<float>(kBlockSize, 0.f)); |
| + |
| + EXPECT_DEATH(block_processor->BufferRender(&block), ""); |
| +} |
| + |
| +void RunCaptureNumBandsVerificationTest(int sample_rate_hz) { |
| + const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
| + ? NumBandsForRate(sample_rate_hz) + 1 |
| + : 1; |
| + std::unique_ptr<BlockProcessor> block_processor( |
| + BlockProcessor::Create(sample_rate_hz)); |
| + std::vector<std::vector<float>> block(wrong_num_bands, |
| + std::vector<float>(kBlockSize, 0.f)); |
| + |
| + EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
| +} |
| +#endif |
| + |
| +} // namespace |
| + |
| +TEST(BlockProcessor, BasicSetupAndApiCalls) { |
| + for (auto rate : {8000, 16000, 32000, 48000}) { |
| + std::ostringstream ss; |
| + ss << "Sample rate: " << rate; |
| + SCOPED_TRACE(ss.str()); |
| + RunBasicSetupAndApiCallTest(rate); |
| + } |
| +} |
| + |
| +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| +TEST(BlockProcessor, VerifyRenderBlockSizeCheck) { |
| + for (auto rate : {8000, 16000, 32000, 48000}) { |
| + std::ostringstream ss; |
|
hlundin-webrtc
2016/12/23 13:38:12
Breaks out this too.
peah-webrtc
2017/01/02 08:45:10
Done.
|
| + ss << "Sample rate: " << rate; |
| + SCOPED_TRACE(ss.str()); |
| + RunRenderBlockSizeVerificationTest(rate); |
| + } |
| +} |
| + |
| +TEST(BlockProcessor, VerifyCaptureBlockSizeCheck) { |
| + for (auto rate : {8000, 16000, 32000, 48000}) { |
| + std::ostringstream ss; |
| + ss << "Sample rate: " << rate; |
| + SCOPED_TRACE(ss.str()); |
| + RunCaptureBlockSizeVerificationTest(rate); |
| + } |
| +} |
| + |
| +TEST(BlockProcessor, VerifyRenderNumBandsCheck) { |
| + for (auto rate : {8000, 16000, 32000, 48000}) { |
| + std::ostringstream ss; |
| + ss << "Sample rate: " << rate; |
| + SCOPED_TRACE(ss.str()); |
| + RunRenderNumBandsVerificationTest(rate); |
| + } |
| +} |
| + |
| +TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { |
| + for (auto rate : {8000, 16000, 32000, 48000}) { |
| + std::ostringstream ss; |
| + ss << "Sample rate: " << rate; |
| + SCOPED_TRACE(ss.str()); |
| + RunCaptureNumBandsVerificationTest(rate); |
| + } |
| +} |
| + |
| +#endif |
| + |
| +} // namespace webrtc |