blob: 392a4c11e2e879b88f893f5caa573384886244d0 [file] [log] [blame]
ossu20a4b3f2017-04-27 09:08:521/*
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 04:47:3111#ifndef TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
12#define TEST_MOCK_AUDIO_ENCODER_FACTORY_H_
ossu20a4b3f2017-04-27 09:08:5213
14#include <memory>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadeid9708072019-01-25 19:26:4818#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 17:11:0019#include "rtc_base/ref_counted_object.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "test/gmock.h"
ossu20a4b3f2017-04-27 09:08:5221
22namespace webrtc {
23
Mirko Bonadei6a489f22019-04-09 13:11:1224class MockAudioEncoderFactory
25 : public ::testing::NiceMock<AudioEncoderFactory> {
ossu20a4b3f2017-04-27 09:08:5226 public:
Danil Chapovalov54706d62020-05-14 17:50:0127 MOCK_METHOD(std::vector<AudioCodecSpec>,
28 GetSupportedEncoders,
29 (),
30 (override));
31 MOCK_METHOD(absl::optional<AudioCodecInfo>,
32 QueryAudioEncoder,
33 (const SdpAudioFormat& format),
34 (override));
ossu20a4b3f2017-04-27 09:08:5235
Karl Wibergd6fbf2a2018-02-27 12:37:3136 std::unique_ptr<AudioEncoder> MakeAudioEncoder(
37 int payload_type,
38 const SdpAudioFormat& format,
Danil Chapovalov54706d62020-05-14 17:50:0139 absl::optional<AudioCodecPairId> codec_pair_id) override {
ossu20a4b3f2017-04-27 09:08:5240 std::unique_ptr<AudioEncoder> return_value;
Karl Wibergd6fbf2a2018-02-27 12:37:3141 MakeAudioEncoderMock(payload_type, format, codec_pair_id, &return_value);
ossu20a4b3f2017-04-27 09:08:5242 return return_value;
43 }
Danil Chapovalov54706d62020-05-14 17:50:0144 MOCK_METHOD(void,
45 MakeAudioEncoderMock,
46 (int payload_type,
47 const SdpAudioFormat& format,
48 absl::optional<AudioCodecPairId> codec_pair_id,
49 std::unique_ptr<AudioEncoder>*));
ossu20a4b3f2017-04-27 09:08:5250
51 // Creates a MockAudioEncoderFactory with no formats and that may not be
52 // invoked to create a codec - useful for initializing a voice engine, for
53 // example.
54 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
55 CreateUnusedFactory() {
Mirko Bonadei6a489f22019-04-09 13:11:1256 using ::testing::_;
57 using ::testing::AnyNumber;
58 using ::testing::Return;
ossu20a4b3f2017-04-27 09:08:5259
60 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
61 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
62 ON_CALL(*factory.get(), GetSupportedEncoders())
63 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
64 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Danil Chapovalov431abd92018-06-18 10:54:1765 .WillByDefault(Return(absl::nullopt));
ossu20a4b3f2017-04-27 09:08:5266
67 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
68 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 12:37:3169 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)).Times(0);
ossu20a4b3f2017-04-27 09:08:5270 return factory;
71 }
72
73 // Creates a MockAudioEncoderFactory with no formats that may be invoked to
74 // create a codec any number of times. It will, though, return nullptr on each
75 // call, since it supports no codecs.
76 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
77 CreateEmptyFactory() {
Mirko Bonadei6a489f22019-04-09 13:11:1278 using ::testing::_;
79 using ::testing::AnyNumber;
80 using ::testing::Return;
81 using ::testing::SetArgPointee;
ossu20a4b3f2017-04-27 09:08:5282
83 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory =
84 new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>;
85 ON_CALL(*factory.get(), GetSupportedEncoders())
86 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
87 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Danil Chapovalov431abd92018-06-18 10:54:1788 .WillByDefault(Return(absl::nullopt));
Karl Wibergd6fbf2a2018-02-27 12:37:3189 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
90 .WillByDefault(SetArgPointee<3>(nullptr));
ossu20a4b3f2017-04-27 09:08:5291
92 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
93 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 12:37:3194 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
ossu20a4b3f2017-04-27 09:08:5295 .Times(AnyNumber());
96 return factory;
97 }
98};
99
100} // namespace webrtc
101
Mirko Bonadei92ea95e2017-09-15 04:47:31102#endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_