blob: 5b2ca336124780d3ccfaa217f9f2bc8debdb76fa [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
30 std::unique_ptr<AudioEncoder> MakeAudioEncoder(int payload_type,
31 const SdpAudioFormat& format) {
32 std::unique_ptr<AudioEncoder> return_value;
33 MakeAudioEncoderMock(payload_type, format, &return_value);
34 return return_value;
35 }
36 MOCK_METHOD3(MakeAudioEncoderMock,
37 void(int payload_type,
38 const SdpAudioFormat& format,
39 std::unique_ptr<AudioEncoder>* return_value));
40
41 // Creates a MockAudioEncoderFactory with no formats and that may not be
42 // invoked to create a codec - useful for initializing a voice engine, for
43 // example.
44 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
45 CreateUnusedFactory() {
46 using testing::_;
47 using testing::AnyNumber;
48 using testing::Return;
49
50 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
51 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
52 ON_CALL(*factory.get(), GetSupportedEncoders())
53 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
54 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Oskar Sundbom3f6804d2017-11-16 10:54:58 +010055 .WillByDefault(Return(rtc::nullopt));
ossu20a4b3f2017-04-27 02:08:52 -070056
57 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
58 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
59 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _)).Times(0);
60 return factory;
61 }
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
73 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
74 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
75 ON_CALL(*factory.get(), GetSupportedEncoders())
76 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
77 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Oskar Sundbom3f6804d2017-11-16 10:54:58 +010078 .WillByDefault(Return(rtc::nullopt));
ossu20a4b3f2017-04-27 02:08:52 -070079 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
80 .WillByDefault(SetArgPointee<2>(nullptr));
81
82 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
83 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
84 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
85 .Times(AnyNumber());
86 return factory;
87 }
88};
89
90} // namespace webrtc
91
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020092#endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_