channel_buffer_unittest.cc (2205B)
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 11 #include "common_audio/channel_buffer.h" 12 13 #include <cstddef> 14 15 #include "rtc_base/checks.h" 16 #include "test/gtest.h" 17 #include "test/testsupport/rtc_expect_death.h" 18 19 namespace webrtc { 20 21 namespace { 22 23 constexpr size_t kNumFrames = 480u; 24 constexpr size_t kStereo = 2u; 25 constexpr size_t kMono = 1u; 26 27 void ExpectNumChannels(const IFChannelBuffer& ifchb, size_t num_channels) { 28 EXPECT_EQ(ifchb.ibuf_const()->num_channels(), num_channels); 29 EXPECT_EQ(ifchb.fbuf_const()->num_channels(), num_channels); 30 EXPECT_EQ(ifchb.num_channels(), num_channels); 31 } 32 33 } // namespace 34 35 TEST(ChannelBufferTest, SetNumChannelsSetsNumChannels) { 36 ChannelBuffer<float> chb(kNumFrames, kStereo); 37 EXPECT_EQ(chb.num_channels(), kStereo); 38 chb.set_num_channels(kMono); 39 EXPECT_EQ(chb.num_channels(), kMono); 40 } 41 42 TEST(IFChannelBufferTest, SetNumChannelsSetsChannelBuffersNumChannels) { 43 IFChannelBuffer ifchb(kNumFrames, kStereo); 44 ExpectNumChannels(ifchb, kStereo); 45 ifchb.set_num_channels(kMono); 46 ExpectNumChannels(ifchb, kMono); 47 } 48 49 TEST(IFChannelBufferTest, SettingNumChannelsOfOneChannelBufferSetsTheOther) { 50 IFChannelBuffer ifchb(kNumFrames, kStereo); 51 ExpectNumChannels(ifchb, kStereo); 52 ifchb.ibuf()->set_num_channels(kMono); 53 ExpectNumChannels(ifchb, kMono); 54 ifchb.fbuf()->set_num_channels(kStereo); 55 ExpectNumChannels(ifchb, kStereo); 56 } 57 58 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 59 TEST(ChannelBufferDeathTest, SetNumChannelsDeathTest) { 60 ChannelBuffer<float> chb(kNumFrames, kMono); 61 RTC_EXPECT_DEATH(chb.set_num_channels(kStereo), "num_channels"); 62 } 63 64 TEST(IFChannelBufferDeathTest, SetNumChannelsDeathTest) { 65 IFChannelBuffer ifchb(kNumFrames, kMono); 66 RTC_EXPECT_DEATH(ifchb.ibuf()->set_num_channels(kStereo), "num_channels"); 67 } 68 #endif 69 70 } // namespace webrtc