Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc

Issue 2936773005: Templated AudioDecoderFactory (Closed)
Patch Set: update from encoder factory Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/audio_codecs/test/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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
11 #include "webrtc/api/audio_codecs/audio_decoder_factory_template.h"
12 #include "webrtc/base/ptr_util.h"
13 #include "webrtc/test/gmock.h"
14 #include "webrtc/test/gtest.h"
15 #include "webrtc/test/mock_audio_decoder.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 struct BogusParams {
22 static SdpAudioFormat AudioFormat() { return {"bogus", 8000, 1}; }
23 static AudioCodecInfo CodecInfo() { return {8000, 1, 12345}; }
24 };
25
26 struct ShamParams {
27 static SdpAudioFormat AudioFormat() {
28 return {"sham", 16000, 2, {{"param", "value"}}};
29 }
30 static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; }
31 };
32
33 struct MyLittleConfig {
34 SdpAudioFormat audio_format;
35 };
36
37 template <typename Params>
38 struct AudioDecoderFakeApi {
39 static rtc::Optional<MyLittleConfig> SdpToConfig(
40 const SdpAudioFormat& audio_format) {
41 if (Params::AudioFormat() == audio_format) {
42 MyLittleConfig config = {audio_format};
43 return rtc::Optional<MyLittleConfig>(config);
44 } else {
45 return rtc::Optional<MyLittleConfig>();
46 }
47 }
48
49 static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) {
50 specs->push_back({Params::AudioFormat(), Params::CodecInfo()});
51 }
52
53 static AudioCodecInfo QueryAudioDecoder(const MyLittleConfig&) {
54 return Params::CodecInfo();
55 }
56
57 static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const MyLittleConfig&) {
58 auto dec = rtc::MakeUnique<testing::StrictMock<MockAudioDecoder>>();
59 EXPECT_CALL(*dec, SampleRateHz())
60 .WillOnce(testing::Return(Params::CodecInfo().sample_rate_hz));
61 EXPECT_CALL(*dec, Die());
62 return std::move(dec);
63 }
64 };
65
66 } // namespace
67
68 TEST(AudioDecoderFactoryTemplateTest, NoDecoderTypes) {
69 rtc::scoped_refptr<AudioDecoderFactory> factory(
70 new rtc::RefCountedObject<
71 audio_decoder_factory_template_impl::AudioDecoderFactoryT<>>());
72 EXPECT_THAT(factory->GetSupportedDecoders(), testing::IsEmpty());
73 EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1}));
74 EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1}));
75 }
76
77 TEST(AudioDecoderFactoryTemplateTest, OneDecoderType) {
78 auto factory = CreateAudioDecoderFactory<AudioDecoderFakeApi<BogusParams>>();
79 EXPECT_THAT(factory->GetSupportedDecoders(),
80 testing::ElementsAre(
81 AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}}));
82 EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1}));
83 EXPECT_TRUE(factory->IsSupportedDecoder({"bogus", 8000, 1}));
84 EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1}));
85 auto dec = factory->MakeAudioDecoder({"bogus", 8000, 1});
86 ASSERT_NE(nullptr, dec);
87 EXPECT_EQ(8000, dec->SampleRateHz());
88 }
89
90 TEST(AudioDecoderFactoryTemplateTest, TwoDecoderTypes) {
91 auto factory = CreateAudioDecoderFactory<AudioDecoderFakeApi<BogusParams>,
92 AudioDecoderFakeApi<ShamParams>>();
93 EXPECT_THAT(factory->GetSupportedDecoders(),
94 testing::ElementsAre(
95 AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}},
96 AudioCodecSpec{{"sham", 16000, 2, {{"param", "value"}}},
97 {16000, 2, 23456}}));
98 EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1}));
99 EXPECT_TRUE(factory->IsSupportedDecoder({"bogus", 8000, 1}));
100 EXPECT_TRUE(
101 factory->IsSupportedDecoder({"sham", 16000, 2, {{"param", "value"}}}));
102 EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1}));
103 auto dec1 = factory->MakeAudioDecoder({"bogus", 8000, 1});
104 ASSERT_NE(nullptr, dec1);
105 EXPECT_EQ(8000, dec1->SampleRateHz());
106 EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"sham", 16000, 2}));
107 auto dec2 =
108 factory->MakeAudioDecoder({"sham", 16000, 2, {{"param", "value"}}});
109 ASSERT_NE(nullptr, dec2);
110 EXPECT_EQ(16000, dec2->SampleRateHz());
111 }
112
113 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/audio_codecs/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698