2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
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.
11 #include "webrtc/sound/automaticallychosensoundsystem.h"
12 #include "webrtc/sound/nullsoundsystem.h"
13 #include "webrtc/base/gunit.h"
17 class NeverFailsToFailSoundSystem : public NullSoundSystem {
19 // Overrides superclass.
24 static SoundSystemInterface *Create() {
25 return new NeverFailsToFailSoundSystem();
29 class InitCheckingSoundSystem1 : public NullSoundSystem {
31 // Overrides superclass.
37 static SoundSystemInterface *Create() {
38 return new InitCheckingSoundSystem1();
44 bool InitCheckingSoundSystem1::created_ = false;
46 class InitCheckingSoundSystem2 : public NullSoundSystem {
48 // Overrides superclass.
54 static SoundSystemInterface *Create() {
55 return new InitCheckingSoundSystem2();
61 bool InitCheckingSoundSystem2::created_ = false;
63 class DeletionCheckingSoundSystem1 : public NeverFailsToFailSoundSystem {
65 virtual ~DeletionCheckingSoundSystem1() {
69 static SoundSystemInterface *Create() {
70 return new DeletionCheckingSoundSystem1();
76 bool DeletionCheckingSoundSystem1::deleted_ = false;
78 class DeletionCheckingSoundSystem2 : public NeverFailsToFailSoundSystem {
80 virtual ~DeletionCheckingSoundSystem2() {
84 static SoundSystemInterface *Create() {
85 return new DeletionCheckingSoundSystem2();
91 bool DeletionCheckingSoundSystem2::deleted_ = false;
93 class DeletionCheckingSoundSystem3 : public NullSoundSystem {
95 virtual ~DeletionCheckingSoundSystem3() {
99 static SoundSystemInterface *Create() {
100 return new DeletionCheckingSoundSystem3();
103 static bool deleted_;
106 bool DeletionCheckingSoundSystem3::deleted_ = false;
108 extern const SoundSystemCreator kSingleSystemFailingCreators[] = {
109 &NeverFailsToFailSoundSystem::Create,
112 TEST(AutomaticallyChosenSoundSystem, SingleSystemFailing) {
113 AutomaticallyChosenSoundSystem<
114 kSingleSystemFailingCreators,
115 ARRAY_SIZE(kSingleSystemFailingCreators)> sound_system;
116 EXPECT_FALSE(sound_system.Init());
119 extern const SoundSystemCreator kSingleSystemSucceedingCreators[] = {
120 &NullSoundSystem::Create,
123 TEST(AutomaticallyChosenSoundSystem, SingleSystemSucceeding) {
124 AutomaticallyChosenSoundSystem<
125 kSingleSystemSucceedingCreators,
126 ARRAY_SIZE(kSingleSystemSucceedingCreators)> sound_system;
127 EXPECT_TRUE(sound_system.Init());
130 extern const SoundSystemCreator
131 kFailedFirstSystemResultsInUsingSecondCreators[] = {
132 &NeverFailsToFailSoundSystem::Create,
133 &NullSoundSystem::Create,
136 TEST(AutomaticallyChosenSoundSystem, FailedFirstSystemResultsInUsingSecond) {
137 AutomaticallyChosenSoundSystem<
138 kFailedFirstSystemResultsInUsingSecondCreators,
139 ARRAY_SIZE(kFailedFirstSystemResultsInUsingSecondCreators)> sound_system;
140 EXPECT_TRUE(sound_system.Init());
143 extern const SoundSystemCreator kEarlierEntriesHavePriorityCreators[] = {
144 &InitCheckingSoundSystem1::Create,
145 &InitCheckingSoundSystem2::Create,
148 TEST(AutomaticallyChosenSoundSystem, EarlierEntriesHavePriority) {
149 AutomaticallyChosenSoundSystem<
150 kEarlierEntriesHavePriorityCreators,
151 ARRAY_SIZE(kEarlierEntriesHavePriorityCreators)> sound_system;
152 InitCheckingSoundSystem1::created_ = false;
153 InitCheckingSoundSystem2::created_ = false;
154 EXPECT_TRUE(sound_system.Init());
155 EXPECT_TRUE(InitCheckingSoundSystem1::created_);
156 EXPECT_FALSE(InitCheckingSoundSystem2::created_);
159 extern const SoundSystemCreator kManySoundSystemsCreators[] = {
160 &NullSoundSystem::Create,
161 &NullSoundSystem::Create,
162 &NullSoundSystem::Create,
163 &NullSoundSystem::Create,
164 &NullSoundSystem::Create,
165 &NullSoundSystem::Create,
166 &NullSoundSystem::Create,
169 TEST(AutomaticallyChosenSoundSystem, ManySoundSystems) {
170 AutomaticallyChosenSoundSystem<
171 kManySoundSystemsCreators,
172 ARRAY_SIZE(kManySoundSystemsCreators)> sound_system;
173 EXPECT_TRUE(sound_system.Init());
176 extern const SoundSystemCreator kDeletesAllCreatedSoundSystemsCreators[] = {
177 &DeletionCheckingSoundSystem1::Create,
178 &DeletionCheckingSoundSystem2::Create,
179 &DeletionCheckingSoundSystem3::Create,
182 TEST(AutomaticallyChosenSoundSystem, DeletesAllCreatedSoundSystems) {
183 typedef AutomaticallyChosenSoundSystem<
184 kDeletesAllCreatedSoundSystemsCreators,
185 ARRAY_SIZE(kDeletesAllCreatedSoundSystemsCreators)> TestSoundSystem;
186 TestSoundSystem *sound_system = new TestSoundSystem();
187 DeletionCheckingSoundSystem1::deleted_ = false;
188 DeletionCheckingSoundSystem2::deleted_ = false;
189 DeletionCheckingSoundSystem3::deleted_ = false;
190 EXPECT_TRUE(sound_system->Init());
192 EXPECT_TRUE(DeletionCheckingSoundSystem1::deleted_);
193 EXPECT_TRUE(DeletionCheckingSoundSystem2::deleted_);
194 EXPECT_TRUE(DeletionCheckingSoundSystem3::deleted_);