mock_audio_decoder_factory.h 3.6 KB

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