blob: 3eaa3b9873378d4ef83734179dc15f778cb8dc75 [file] [log] [blame]
ossu20a4b3f2017-04-27 02:08:52 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
12#define TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
ossu20a4b3f2017-04-27 02:08:52 -070013
14#include <memory>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/audio_codecs/audio_encoder_factory.h"
Sebastian Jansson41f16be2018-02-22 11:09:56 +010018#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/scoped_ref_ptr.h"
20#include "test/gmock.h"
ossu20a4b3f2017-04-27 02:08:52 -070021
22namespace webrtc {
23
Sebastian Jansson41f16be2018-02-22 11:09:56 +010024class MockAudioEncoderFactory : public testing::NiceMock<AudioEncoderFactory> {
ossu20a4b3f2017-04-27 02:08:52 -070025 public:
26 MOCK_METHOD0(GetSupportedEncoders, std::vector<AudioCodecSpec>());
27 MOCK_METHOD1(QueryAudioEncoder,
28 rtc::Optional<AudioCodecInfo>(const SdpAudioFormat& format));
29
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010030 std::unique_ptr<AudioEncoder> MakeAudioEncoder(
31 int payload_type,
32 const SdpAudioFormat& format,
33 rtc::Optional<AudioCodecPairId> codec_pair_id) {
ossu20a4b3f2017-04-27 02:08:52 -070034 std::unique_ptr<AudioEncoder> return_value;
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010035 MakeAudioEncoderMock(payload_type, format, codec_pair_id, &return_value);
ossu20a4b3f2017-04-27 02:08:52 -070036 return return_value;
37 }
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010038 MOCK_METHOD4(MakeAudioEncoderMock,
ossu20a4b3f2017-04-27 02:08:52 -070039 void(int payload_type,
40 const SdpAudioFormat& format,
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010041 rtc::Optional<AudioCodecPairId> codec_pair_id,
ossu20a4b3f2017-04-27 02:08:52 -070042 std::unique_ptr<AudioEncoder>* return_value));
43
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
53 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
54 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
55 ON_CALL(*factory.get(), GetSupportedEncoders())
56 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
57 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Oskar Sundbom3f6804d2017-11-16 10:54:58 +010058 .WillByDefault(Return(rtc::nullopt));
ossu20a4b3f2017-04-27 02:08:52 -070059
60 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
61 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010062 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)).Times(0);
ossu20a4b3f2017-04-27 02:08:52 -070063 return factory;
64 }
65
66 // Creates a MockAudioEncoderFactory with no formats that may be invoked to
67 // create a codec any number of times. It will, though, return nullptr on each
68 // call, since it supports no codecs.
69 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
70 CreateEmptyFactory() {
71 using testing::_;
72 using testing::AnyNumber;
73 using testing::Return;
74 using testing::SetArgPointee;
75
76 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
77 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
78 ON_CALL(*factory.get(), GetSupportedEncoders())
79 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
80 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Oskar Sundbom3f6804d2017-11-16 10:54:58 +010081 .WillByDefault(Return(rtc::nullopt));
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010082 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
83 .WillByDefault(SetArgPointee<3>(nullptr));
ossu20a4b3f2017-04-27 02:08:52 -070084
85 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
86 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010087 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
ossu20a4b3f2017-04-27 02:08:52 -070088 .Times(AnyNumber());
89 return factory;
90 }
91};
92
93} // namespace webrtc
94
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020095#endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_