Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/memory/scoped_ptr.h" | |
| 6 #include "media/audio/audio_manager.h" | |
| 7 #include "media/audio/audio_manager_factory.h" | |
| 8 #include "media/audio/fake_audio_log_factory.h" | |
| 9 #include "media/audio/fake_audio_manager.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace media { | |
| 13 namespace { | |
| 14 | |
| 15 // Static instance for comparison | |
| 16 FakeAudioLogFactory* g_fake_audio_log_factory = nullptr; | |
| 17 AudioManager* g_fake_audio_manager = nullptr; | |
| 18 | |
| 19 class FakeAudioManagerFactory : public AudioManagerFactory { | |
| 20 public: | |
| 21 FakeAudioManagerFactory() { | |
| 22 if (!g_fake_audio_manager) { | |
| 23 g_fake_audio_log_factory = new FakeAudioLogFactory; | |
| 24 g_fake_audio_manager = new FakeAudioManager(g_fake_audio_log_factory); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 ~FakeAudioManagerFactory() override {} | |
| 29 | |
| 30 AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override { | |
| 31 return g_fake_audio_manager; | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 // Verifies that SetFactory has the intended effect. Note that the current | |
| 38 // structure supports exactly one test case (SetFactory may only be called | |
| 39 // once per process by design). | |
| 40 TEST(AudioManagerFactoryTest, CreateInstance) { | |
| 41 // Create an audio manager and verify that it is not null. | |
| 42 scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting()); | |
| 43 ASSERT_NE(nullptr, manager.get()); | |
| 44 manager.reset(); | |
| 45 | |
| 46 // Set the factory, after which the static AudioManager should be | |
| 47 // instantiated. | |
| 48 AudioManager::SetFactory(new FakeAudioManagerFactory); | |
|
DaleCurtis
2015/04/23 16:18:26
()
slan
2015/04/23 18:11:33
Done. Here and above.
| |
| 49 ASSERT_NE(nullptr, g_fake_audio_manager); | |
| 50 | |
| 51 // Get the instance and verify that it matches the instance provided by the | |
| 52 // factory. | |
| 53 manager.reset(AudioManager::CreateForTesting()); | |
| 54 ASSERT_EQ(g_fake_audio_manager, manager.get()); | |
| 55 | |
| 56 // Reset the AudioManager and AudioManagerFactory to prevent persisting state | |
|
DaleCurtis
2015/04/23 16:18:25
I don't think this is an issue. Or we'd have tripp
slan
2015/04/23 18:11:33
Any existing unittest using AudioManager wraps the
| |
| 57 // to other tests on the same process. | |
| 58 manager.reset(); | |
| 59 AudioManager::ResetFactory(); | |
| 60 } | |
| 61 | |
| 62 } // namespace media | |
| OLD | NEW |