blob: 425ea38f9c82a0366874ab8220bd114b2cf391fa [file] [log] [blame]
kwiberg5178ee82016-05-03 08:39:011/*
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 Bonadei92ea95e2017-09-15 04:47:3111#ifndef TEST_MOCK_AUDIO_DECODER_FACTORY_H_
12#define TEST_MOCK_AUDIO_DECODER_FACTORY_H_
kwiberg5178ee82016-05-03 08:39:0113
kwiberg37e99fd2017-04-10 12:15:4814#include <memory>
kwiberg5178ee82016-05-03 08:39:0115#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/audio_codecs/audio_decoder_factory.h"
18#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Niels Möller105711e2022-06-14 13:48:2619#include "api/make_ref_counted.h"
Mirko Bonadeid9708072019-01-25 19:26:4820#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "test/gmock.h"
kwiberg5178ee82016-05-03 08:39:0122
23namespace webrtc {
24
25class MockAudioDecoderFactory : public AudioDecoderFactory {
26 public:
Danil Chapovalov54706d62020-05-14 17:50:0127 MOCK_METHOD(std::vector<AudioCodecSpec>,
28 GetSupportedDecoders,
29 (),
30 (override));
31 MOCK_METHOD(bool, IsSupportedDecoder, (const SdpAudioFormat&), (override));
Karl Wibergd6fbf2a2018-02-27 12:37:3132 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
33 const SdpAudioFormat& format,
Danil Chapovalov54706d62020-05-14 17:50:0134 absl::optional<AudioCodecPairId> codec_pair_id) override {
kwiberg5178ee82016-05-03 08:39:0135 std::unique_ptr<AudioDecoder> return_value;
Karl Wibergd6fbf2a2018-02-27 12:37:3136 MakeAudioDecoderMock(format, codec_pair_id, &return_value);
kwiberg5178ee82016-05-03 08:39:0137 return return_value;
38 }
Danil Chapovalov54706d62020-05-14 17:50:0139 MOCK_METHOD(void,
40 MakeAudioDecoderMock,
41 (const SdpAudioFormat& format,
42 absl::optional<AudioCodecPairId> codec_pair_id,
43 std::unique_ptr<AudioDecoder>*));
ossuc54071d2016-08-17 09:45:4144
45 // Creates a MockAudioDecoderFactory with no formats and that may not be
46 // invoked to create a codec - useful for initializing a voice engine, for
47 // example.
48 static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory>
49 CreateUnusedFactory() {
Mirko Bonadei6a489f22019-04-09 13:11:1250 using ::testing::_;
51 using ::testing::AnyNumber;
52 using ::testing::Return;
ossuc54071d2016-08-17 09:45:4153
54 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory =
Tommi87f70902021-04-27 12:43:0855 rtc::make_ref_counted<webrtc::MockAudioDecoderFactory>();
ossud4e9f622016-08-18 09:01:1756 ON_CALL(*factory.get(), GetSupportedDecoders())
57 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
58 EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber());
kwibergd32bf752017-01-19 15:03:5959 ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false));
60 EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 12:37:3161 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _)).Times(0);
ossuc54071d2016-08-17 09:45:4162 return factory;
63 }
64
65 // Creates a MockAudioDecoderFactory with no formats that may be invoked to
66 // create a codec any number of times. It will, though, return nullptr on each
67 // call, since it supports no codecs.
68 static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory>
69 CreateEmptyFactory() {
Mirko Bonadei6a489f22019-04-09 13:11:1270 using ::testing::_;
71 using ::testing::AnyNumber;
72 using ::testing::Return;
73 using ::testing::SetArgPointee;
ossuc54071d2016-08-17 09:45:4174
75 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory =
Tommi87f70902021-04-27 12:43:0876 rtc::make_ref_counted<webrtc::MockAudioDecoderFactory>();
ossud4e9f622016-08-18 09:01:1777 ON_CALL(*factory.get(), GetSupportedDecoders())
78 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
79 EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber());
kwibergd32bf752017-01-19 15:03:5980 ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false));
81 EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 12:37:3182 ON_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _))
83 .WillByDefault(SetArgPointee<2>(nullptr));
84 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _))
85 .Times(AnyNumber());
ossuc54071d2016-08-17 09:45:4186 return factory;
87 }
kwiberg5178ee82016-05-03 08:39:0188};
89
90} // namespace webrtc
91
Mirko Bonadei92ea95e2017-09-15 04:47:3192#endif // TEST_MOCK_AUDIO_DECODER_FACTORY_H_