blob: 9a0279e4bf35a2a757beb2bad7b1d84d885311eb [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"
Mirko Bonadeid9708072019-01-25 20:26:48 +010018#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "test/gmock.h"
ossu20a4b3f2017-04-27 02:08:52 -070020
21namespace webrtc {
22
Mirko Bonadei6a489f22019-04-09 15:11:12 +020023class MockAudioEncoderFactory
24 : public ::testing::NiceMock<AudioEncoderFactory> {
ossu20a4b3f2017-04-27 02:08:52 -070025 public:
Danil Chapovalov54706d62020-05-14 19:50:01 +020026 MOCK_METHOD(std::vector<AudioCodecSpec>,
27 GetSupportedEncoders,
28 (),
29 (override));
30 MOCK_METHOD(absl::optional<AudioCodecInfo>,
31 QueryAudioEncoder,
32 (const SdpAudioFormat& format),
33 (override));
ossu20a4b3f2017-04-27 02:08:52 -070034
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010035 std::unique_ptr<AudioEncoder> MakeAudioEncoder(
36 int payload_type,
37 const SdpAudioFormat& format,
Danil Chapovalov54706d62020-05-14 19:50:01 +020038 absl::optional<AudioCodecPairId> codec_pair_id) override {
ossu20a4b3f2017-04-27 02:08:52 -070039 std::unique_ptr<AudioEncoder> return_value;
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010040 MakeAudioEncoderMock(payload_type, format, codec_pair_id, &return_value);
ossu20a4b3f2017-04-27 02:08:52 -070041 return return_value;
42 }
Danil Chapovalov54706d62020-05-14 19:50:01 +020043 MOCK_METHOD(void,
44 MakeAudioEncoderMock,
45 (int payload_type,
46 const SdpAudioFormat& format,
47 absl::optional<AudioCodecPairId> codec_pair_id,
48 std::unique_ptr<AudioEncoder>*));
ossu20a4b3f2017-04-27 02:08:52 -070049
50 // Creates a MockAudioEncoderFactory with no formats and that may not be
51 // invoked to create a codec - useful for initializing a voice engine, for
52 // example.
53 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
54 CreateUnusedFactory() {
Mirko Bonadei6a489f22019-04-09 15:11:12 +020055 using ::testing::_;
56 using ::testing::AnyNumber;
57 using ::testing::Return;
ossu20a4b3f2017-04-27 02:08:52 -070058
Niels Möller93b20892022-01-13 13:50:20 +010059 auto factory = rtc::make_ref_counted<webrtc::MockAudioEncoderFactory>();
ossu20a4b3f2017-04-27 02:08:52 -070060 ON_CALL(*factory.get(), GetSupportedEncoders())
61 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
62 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Danil Chapovalov431abd92018-06-18 12:54:17 +020063 .WillByDefault(Return(absl::nullopt));
ossu20a4b3f2017-04-27 02:08:52 -070064
65 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
66 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010067 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)).Times(0);
ossu20a4b3f2017-04-27 02:08:52 -070068 return factory;
69 }
70
71 // Creates a MockAudioEncoderFactory with no formats that may be invoked to
72 // create a codec any number of times. It will, though, return nullptr on each
73 // call, since it supports no codecs.
74 static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory>
75 CreateEmptyFactory() {
Mirko Bonadei6a489f22019-04-09 15:11:12 +020076 using ::testing::_;
77 using ::testing::AnyNumber;
78 using ::testing::Return;
79 using ::testing::SetArgPointee;
ossu20a4b3f2017-04-27 02:08:52 -070080
Niels Möller93b20892022-01-13 13:50:20 +010081 auto factory = rtc::make_ref_counted<webrtc::MockAudioEncoderFactory>();
ossu20a4b3f2017-04-27 02:08:52 -070082 ON_CALL(*factory.get(), GetSupportedEncoders())
83 .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>()));
84 ON_CALL(*factory.get(), QueryAudioEncoder(_))
Danil Chapovalov431abd92018-06-18 12:54:17 +020085 .WillByDefault(Return(absl::nullopt));
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010086 ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
87 .WillByDefault(SetArgPointee<3>(nullptr));
ossu20a4b3f2017-04-27 02:08:52 -070088
89 EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber());
90 EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber());
Karl Wibergd6fbf2a2018-02-27 13:37:31 +010091 EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _))
ossu20a4b3f2017-04-27 02:08:52 -070092 .Times(AnyNumber());
93 return factory;
94 }
95};
96
97} // namespace webrtc
98
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020099#endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_