mock_audio_encoder_factory.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2017 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. #ifndef TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
  11. #define TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/audio_codecs/audio_encoder_factory.h"
  15. #include "api/scoped_refptr.h"
  16. #include "rtc_base/ref_counted_object.h"
  17. #include "test/gmock.h"
  18. namespace webrtc {
  19. class MockAudioEncoderFactory
  20. : public ::testing::NiceMock<AudioEncoderFactory> {
  21. public:
  22. MOCK_METHOD(std::vector<AudioCodecSpec>,
  23. GetSupportedEncoders,
  24. (),
  25. (override));
  26. MOCK_METHOD(absl::optional<AudioCodecInfo>,
  27. QueryAudioEncoder,
  28. (const SdpAudioFormat& format),
  29. (override));
  30. std::unique_ptr<AudioEncoder> MakeAudioEncoder(
  31. int payload_type,
  32. const SdpAudioFormat& format,
  33. absl::optional<AudioCodecPairId> codec_pair_id) override {
  34. std::unique_ptr<AudioEncoder> return_value;
  35. MakeAudioEncoderMock(payload_type, format, codec_pair_id, &return_value);
  36. return return_value;
  37. }
  38. MOCK_METHOD(void,
  39. MakeAudioEncoderMock,
  40. (int payload_type,
  41. const SdpAudioFormat& format,
  42. absl::optional<AudioCodecPairId> codec_pair_id,
  43. std::unique_ptr<AudioEncoder>*));
  44. // Creates a MockAudioEncoderFactory with no formats and that may not be
  45. // invoked to create a codec - useful for initializing a voice engine, for
  46. // example.
  47. static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
  48. CreateUnusedFactory() {
  49. using ::testing::_;
  50. using ::testing::AnyNumber;
  51. using ::testing::Return;
  52. rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
  53. new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
  54. ON_CALL(*factory.get(), GetSupportedEncoders())
  55. .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
  56. ON_CALL(*factory.get(), QueryAudioEncoder(_))
  57. .WillByDefault(Return(absl::nullopt));
  58. EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
  59. EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
  60. EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)).Times(0);
  61. return factory;
  62. }
  63. // Creates a MockAudioEncoderFactory with no formats that may be invoked to
  64. // create a codec any number of times. It will, though, return nullptr on each
  65. // call, since it supports no codecs.
  66. static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
  67. CreateEmptyFactory() {
  68. using ::testing::_;
  69. using ::testing::AnyNumber;
  70. using ::testing::Return;
  71. using ::testing::SetArgPointee;
  72. rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
  73. new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
  74. ON_CALL(*factory.get(), GetSupportedEncoders())
  75. .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
  76. ON_CALL(*factory.get(), QueryAudioEncoder(_))
  77. .WillByDefault(Return(absl::nullopt));
  78. ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
  79. .WillByDefault(SetArgPointee<3>(nullptr));
  80. EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
  81. EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
  82. EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
  83. .Times(AnyNumber());
  84. return factory;
  85. }
  86. };
  87. } // namespace webrtc
  88. #endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_