You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "common_audio/channel_buffer.h"
  11. #include "test/gtest.h"
  12. namespace webrtc {
  13. namespace {
  14. const size_t kNumFrames = 480u;
  15. const size_t kStereo = 2u;
  16. const size_t kMono = 1u;
  17. void ExpectNumChannels(const IFChannelBuffer& ifchb, size_t num_channels) {
  18. EXPECT_EQ(ifchb.ibuf_const()->num_channels(), num_channels);
  19. EXPECT_EQ(ifchb.fbuf_const()->num_channels(), num_channels);
  20. EXPECT_EQ(ifchb.num_channels(), num_channels);
  21. }
  22. } // namespace
  23. TEST(ChannelBufferTest, SetNumChannelsSetsNumChannels) {
  24. ChannelBuffer<float> chb(kNumFrames, kStereo);
  25. EXPECT_EQ(chb.num_channels(), kStereo);
  26. chb.set_num_channels(kMono);
  27. EXPECT_EQ(chb.num_channels(), kMono);
  28. }
  29. TEST(IFChannelBufferTest, SetNumChannelsSetsChannelBuffersNumChannels) {
  30. IFChannelBuffer ifchb(kNumFrames, kStereo);
  31. ExpectNumChannels(ifchb, kStereo);
  32. ifchb.set_num_channels(kMono);
  33. ExpectNumChannels(ifchb, kMono);
  34. }
  35. TEST(IFChannelBufferTest, SettingNumChannelsOfOneChannelBufferSetsTheOther) {
  36. IFChannelBuffer ifchb(kNumFrames, kStereo);
  37. ExpectNumChannels(ifchb, kStereo);
  38. ifchb.ibuf()->set_num_channels(kMono);
  39. ExpectNumChannels(ifchb, kMono);
  40. ifchb.fbuf()->set_num_channels(kStereo);
  41. ExpectNumChannels(ifchb, kStereo);
  42. }
  43. #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
  44. TEST(ChannelBufferTest, SetNumChannelsDeathTest) {
  45. ChannelBuffer<float> chb(kNumFrames, kMono);
  46. EXPECT_DEATH(chb.set_num_channels(kStereo), "num_channels");
  47. }
  48. TEST(IFChannelBufferTest, SetNumChannelsDeathTest) {
  49. IFChannelBuffer ifchb(kNumFrames, kMono);
  50. EXPECT_DEATH(ifchb.ibuf()->set_num_channels(kStereo), "num_channels");
  51. }
  52. #endif
  53. } // namespace webrtc