Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/audio_buffer.h" |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "test/gtest.h" |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace { |
| 18 | |
Per Åhgren | 81c0cf2 | 2019-08-21 15:02:37 +0200 | [diff] [blame^] | 19 | const size_t kSampleRateHz = 48000u; |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 20 | const size_t kStereo = 2u; |
| 21 | const size_t kMono = 1u; |
| 22 | |
| 23 | void ExpectNumChannels(const AudioBuffer& ab, size_t num_channels) { |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 24 | EXPECT_EQ(ab.num_channels(), num_channels); |
| 25 | } |
| 26 | |
| 27 | } // namespace |
| 28 | |
| 29 | TEST(AudioBufferTest, SetNumChannelsSetsChannelBuffersNumChannels) { |
Per Åhgren | 81c0cf2 | 2019-08-21 15:02:37 +0200 | [diff] [blame^] | 30 | AudioBuffer ab(kSampleRateHz, kStereo, kSampleRateHz, kStereo, kSampleRateHz); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 31 | ExpectNumChannels(ab, kStereo); |
Per Åhgren | 81c0cf2 | 2019-08-21 15:02:37 +0200 | [diff] [blame^] | 32 | ab.set_num_channels(1); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 33 | ExpectNumChannels(ab, kMono); |
Per Åhgren | 81c0cf2 | 2019-08-21 15:02:37 +0200 | [diff] [blame^] | 34 | ab.RestoreNumChannels(); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 35 | ExpectNumChannels(ab, kStereo); |
| 36 | } |
| 37 | |
| 38 | #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 39 | TEST(AudioBufferTest, SetNumChannelsDeathTest) { |
Per Åhgren | 81c0cf2 | 2019-08-21 15:02:37 +0200 | [diff] [blame^] | 40 | AudioBuffer ab(kSampleRateHz, kMono, kSampleRateHz, kMono, kSampleRateHz); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 41 | EXPECT_DEATH(ab.set_num_channels(kStereo), "num_channels"); |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | } // namespace webrtc |