blob: c0951974986cc63d783b4ec3b4ca0aa2027e865f [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
ossueb1fde42017-05-02 06:46:30 -070011#ifndef WEBRTC_TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
12#define WEBRTC_TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
ossu20a4b3f2017-04-27 02:08:52 -070013
14#include <memory>
15#include <vector>
16
ossueb1fde42017-05-02 06:46:30 -070017#include "webrtc/api/audio_codecs/audio_encoder_factory.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/scoped_ref_ptr.h"
ossu20a4b3f2017-04-27 02:08:52 -070019#include "webrtc/test/gmock.h"
20
21namespace webrtc {
22
23class MockAudioEncoderFactory : public AudioEncoderFactory {
24 public:
25 MOCK_METHOD0(GetSupportedEncoders, std::vector<AudioCodecSpec>());
26 MOCK_METHOD1(QueryAudioEncoder,
27 rtc::Optional<AudioCodecInfo>(const SdpAudioFormat& format));
28
29 std::unique_ptr<AudioEncoder> MakeAudioEncoder(int payload_type,
30 const SdpAudioFormat& format) {
31 std::unique_ptr<AudioEncoder> return_value;
32 MakeAudioEncoderMock(payload_type, format, &return_value);
33 return return_value;
34 }
35 MOCK_METHOD3(MakeAudioEncoderMock,
36 void(int payload_type,
37 const SdpAudioFormat& format,
38 std::unique_ptr<AudioEncoder>* return_value));
39
40 // Creates a MockAudioEncoderFactory with no formats and that may not be
41 // invoked to create a codec - useful for initializing a voice engine, for
42 // example.
43 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
44 CreateUnusedFactory() {
45 using testing::_;
46 using testing::AnyNumber;
47 using testing::Return;
48
49 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
50 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
51 ON_CALL(*factory.get(), GetSupportedEncoders())
52 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
53 ON_CALL(*factory.get(), QueryAudioEncoder(_))
54 .WillByDefault(Return(rtc::Optional<AudioCodecInfo>()));
55
56 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
57 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
58 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _)).Times(0);
59 return factory;
60 }
61
62 // Creates a MockAudioEncoderFactory with no formats that may be invoked to
63 // create a codec any number of times. It will, though, return nullptr on each
64 // call, since it supports no codecs.
65 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
66 CreateEmptyFactory() {
67 using testing::_;
68 using testing::AnyNumber;
69 using testing::Return;
70 using testing::SetArgPointee;
71
72 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
73 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
74 ON_CALL(*factory.get(), GetSupportedEncoders())
75 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
76 ON_CALL(*factory.get(), QueryAudioEncoder(_))
77 .WillByDefault(Return(rtc::Optional<AudioCodecInfo>()));
78 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
79 .WillByDefault(SetArgPointee<2>(nullptr));
80
81 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
82 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
83 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
84 .Times(AnyNumber());
85 return factory;
86 }
87};
88
89} // namespace webrtc
90
ossueb1fde42017-05-02 06:46:30 -070091#endif // WEBRTC_TEST_MOCK_AUDIO_ENCODER_FACTORY_H_