From f9d2fe983fe196373850c55acd3dc3824add480e Mon Sep 17 00:00:00 2001 From: Tommi Date: Thu, 26 May 2016 22:21:31 +0200 Subject: [PATCH] Reland of Adding a some checks and switching out a few assert for RTC_[D]CHECK. (patchset #1 id:1 of https://codereview.webrtc.org/2018553002/ ) Adding a some checks and switching out a few assert for RTC_[D]CHECK. These changes are around use of AudioFrame.data_ to help us catch issues earlier since assert() is left out in release builds, including builds with DCHECK enabled. I've also added a few full-on CHECKs to avoid reading past buffer boundaries or continuing on in a failed state. TBR=kjellander@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Committed: https://crrev.com/60c4e0ae8f124f08372645a95042f4a1246d7aa3 Cr-Commit-Position: refs/heads/master@{#12925} Committed: https://crrev.com/5771beb265129082d31736259b7dc6ca037cff4d Cr-Commit-Position: refs/heads/master@{#12926} Committed: https://crrev.com/54e1c6a500e390e543bce7b78fae65eb9bb14ab6 Cr-Commit-Position: refs/heads/master@{#12927} Review URL: https://codereview.webrtc.org/2014973002 . Cr-Commit-Position: refs/heads/master@{#12928} --- .../resampler/push_resampler_unittest.cc | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/webrtc/common_audio/resampler/push_resampler_unittest.cc b/webrtc/common_audio/resampler/push_resampler_unittest.cc index 4449f4c633..58880cc1b7 100644 --- a/webrtc/common_audio/resampler/push_resampler_unittest.cc +++ b/webrtc/common_audio/resampler/push_resampler_unittest.cc @@ -9,6 +9,7 @@ */ #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/checks.h" // force defintion of RTC_DCHECK_IS_ON #include "webrtc/common_audio/resampler/include/push_resampler.h" // Quality testing of PushResampler is handled through output_mixer_unittest.cc. @@ -17,12 +18,32 @@ namespace webrtc { TEST(PushResamplerTest, VerifiesInputParameters) { PushResampler resampler; - EXPECT_EQ(-1, resampler.InitializeIfNeeded(-1, 16000, 1)); - EXPECT_EQ(-1, resampler.InitializeIfNeeded(16000, -1, 1)); - EXPECT_EQ(-1, resampler.InitializeIfNeeded(16000, 16000, 0)); - EXPECT_EQ(-1, resampler.InitializeIfNeeded(16000, 16000, 3)); EXPECT_EQ(0, resampler.InitializeIfNeeded(16000, 16000, 1)); EXPECT_EQ(0, resampler.InitializeIfNeeded(16000, 16000, 2)); } +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +TEST(PushResamplerTest, VerifiesBadInputParameters1) { + PushResampler resampler; + EXPECT_DEATH(resampler.InitializeIfNeeded(-1, 16000, 1), + "src_sample_rate_hz"); +} + +TEST(PushResamplerTest, VerifiesBadInputParameters2) { + PushResampler resampler; + EXPECT_DEATH(resampler.InitializeIfNeeded(16000, -1, 1), + "dst_sample_rate_hz"); +} + +TEST(PushResamplerTest, VerifiesBadInputParameters3) { + PushResampler resampler; + EXPECT_DEATH(resampler.InitializeIfNeeded(16000, 16000, 0), "num_channels"); +} + +TEST(PushResamplerTest, VerifiesBadInputParameters4) { + PushResampler resampler; + EXPECT_DEATH(resampler.InitializeIfNeeded(16000, 16000, 3), "num_channels"); +} +#endif + } // namespace webrtc