blob: bc504d871e2254d8ef68e12b23509350a271b2ee [file] [log] [blame]
kwiberg5178ee82016-05-03 01:39:01 -07001/*
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 06:47:31 +020011#ifndef TEST_MOCK_AUDIO_DECODER_FACTORY_H_
12#define TEST_MOCK_AUDIO_DECODER_FACTORY_H_
kwiberg5178ee82016-05-03 01:39:01 -070013
kwiberg37e99fd2017-04-10 05:15:48 -070014#include <memory>
kwiberg5178ee82016-05-03 01:39:01 -070015#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/audio_codecs/audio_decoder_factory.h"
18#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Niels Möller84255bb2017-10-06 13:43:23 +020019#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/scoped_ref_ptr.h"
21#include "test/gmock.h"
kwiberg5178ee82016-05-03 01:39:01 -070022
23namespace webrtc {
24
25class MockAudioDecoderFactory : public AudioDecoderFactory {
26 public:
ossud4e9f622016-08-18 02:01:17 -070027 MOCK_METHOD0(GetSupportedDecoders, std::vector<AudioCodecSpec>());
kwibergd32bf752017-01-19 07:03:59 -080028 MOCK_METHOD1(IsSupportedDecoder, bool(const SdpAudioFormat&));
kwiberg37e99fd2017-04-10 05:15:48 -070029 std::unique_ptr<AudioDecoder> MakeAudioDecoder(const SdpAudioFormat& format) {
kwiberg5178ee82016-05-03 01:39:01 -070030 std::unique_ptr<AudioDecoder> return_value;
31 MakeAudioDecoderMock(format, &return_value);
32 return return_value;
33 }
34 MOCK_METHOD2(MakeAudioDecoderMock,
35 void(const SdpAudioFormat& format,
36 std::unique_ptr<AudioDecoder>* return_value));
ossuc54071d2016-08-17 02:45:41 -070037
38 // Creates a MockAudioDecoderFactory with no formats and that may not be
39 // invoked to create a codec - useful for initializing a voice engine, for
40 // example.
41 static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory>
42 CreateUnusedFactory() {
43 using testing::_;
44 using testing::AnyNumber;
45 using testing::Return;
46
47 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory =
48 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>;
ossud4e9f622016-08-18 02:01:17 -070049 ON_CALL(*factory.get(), GetSupportedDecoders())
50 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
51 EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber());
kwibergd32bf752017-01-19 07:03:59 -080052 ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false));
53 EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber());
ossuc54071d2016-08-17 02:45:41 -070054 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0);
55 return factory;
56 }
57
58 // Creates a MockAudioDecoderFactory with no formats that may be invoked to
59 // create a codec any number of times. It will, though, return nullptr on each
60 // call, since it supports no codecs.
61 static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory>
62 CreateEmptyFactory() {
63 using testing::_;
64 using testing::AnyNumber;
65 using testing::Return;
66 using testing::SetArgPointee;
67
68 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory =
69 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>;
ossud4e9f622016-08-18 02:01:17 -070070 ON_CALL(*factory.get(), GetSupportedDecoders())
71 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
72 EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber());
kwibergd32bf752017-01-19 07:03:59 -080073 ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false));
74 EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber());
ossuc54071d2016-08-17 02:45:41 -070075 ON_CALL(*factory.get(), MakeAudioDecoderMock(_, _))
76 .WillByDefault(SetArgPointee<1>(nullptr));
77 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(AnyNumber());
78 return factory;
79 }
kwiberg5178ee82016-05-03 01:39:01 -070080};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // TEST_MOCK_AUDIO_DECODER_FACTORY_H_