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 "common_audio/channel_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" |
Artem Titov | 9dc209a | 2019-11-28 17:09:30 +0100 | [diff] [blame] | 14 | #include "test/testsupport/rtc_expect_death.h" |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | const size_t kNumFrames = 480u; |
| 21 | const size_t kStereo = 2u; |
| 22 | const size_t kMono = 1u; |
| 23 | |
| 24 | void ExpectNumChannels(const IFChannelBuffer& ifchb, size_t num_channels) { |
| 25 | EXPECT_EQ(ifchb.ibuf_const()->num_channels(), num_channels); |
| 26 | EXPECT_EQ(ifchb.fbuf_const()->num_channels(), num_channels); |
| 27 | EXPECT_EQ(ifchb.num_channels(), num_channels); |
| 28 | } |
| 29 | |
| 30 | } // namespace |
| 31 | |
| 32 | TEST(ChannelBufferTest, SetNumChannelsSetsNumChannels) { |
| 33 | ChannelBuffer<float> chb(kNumFrames, kStereo); |
| 34 | EXPECT_EQ(chb.num_channels(), kStereo); |
| 35 | chb.set_num_channels(kMono); |
| 36 | EXPECT_EQ(chb.num_channels(), kMono); |
| 37 | } |
| 38 | |
| 39 | TEST(IFChannelBufferTest, SetNumChannelsSetsChannelBuffersNumChannels) { |
| 40 | IFChannelBuffer ifchb(kNumFrames, kStereo); |
| 41 | ExpectNumChannels(ifchb, kStereo); |
| 42 | ifchb.set_num_channels(kMono); |
| 43 | ExpectNumChannels(ifchb, kMono); |
| 44 | } |
| 45 | |
| 46 | TEST(IFChannelBufferTest, SettingNumChannelsOfOneChannelBufferSetsTheOther) { |
| 47 | IFChannelBuffer ifchb(kNumFrames, kStereo); |
| 48 | ExpectNumChannels(ifchb, kStereo); |
| 49 | ifchb.ibuf()->set_num_channels(kMono); |
| 50 | ExpectNumChannels(ifchb, kMono); |
| 51 | ifchb.fbuf()->set_num_channels(kStereo); |
| 52 | ExpectNumChannels(ifchb, kStereo); |
| 53 | } |
| 54 | |
| 55 | #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
Tommi | 909f3a5 | 2020-05-18 16:47:56 +0200 | [diff] [blame] | 56 | TEST(ChannelBufferDeathTest, SetNumChannelsDeathTest) { |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 57 | ChannelBuffer<float> chb(kNumFrames, kMono); |
Artem Titov | 9dc209a | 2019-11-28 17:09:30 +0100 | [diff] [blame] | 58 | RTC_EXPECT_DEATH(chb.set_num_channels(kStereo), "num_channels"); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Tommi | 909f3a5 | 2020-05-18 16:47:56 +0200 | [diff] [blame] | 61 | TEST(IFChannelBufferDeathTest, SetNumChannelsDeathTest) { |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 62 | IFChannelBuffer ifchb(kNumFrames, kMono); |
Artem Titov | 9dc209a | 2019-11-28 17:09:30 +0100 | [diff] [blame] | 63 | RTC_EXPECT_DEATH(ifchb.ibuf()->set_num_channels(kStereo), "num_channels"); |
Alejandro Luebs | a181c9a | 2016-06-30 15:33:37 -0700 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
| 67 | } // namespace webrtc |