Index: media/audio/audio_manager_factory_unittest.cc |
diff --git a/media/audio/audio_manager_factory_unittest.cc b/media/audio/audio_manager_factory_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..51e998c3231750fe1affb55227b892b2ed6ba953 |
--- /dev/null |
+++ b/media/audio/audio_manager_factory_unittest.cc |
@@ -0,0 +1,62 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "media/audio/audio_manager.h" |
+#include "media/audio/audio_manager_factory.h" |
+#include "media/audio/fake_audio_log_factory.h" |
+#include "media/audio/fake_audio_manager.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace media { |
+namespace { |
+ |
+// Static instance for comparison |
+FakeAudioLogFactory* g_fake_audio_log_factory = nullptr; |
+AudioManager* g_fake_audio_manager = nullptr; |
+ |
+class FakeAudioManagerFactory : public AudioManagerFactory { |
+ public: |
+ FakeAudioManagerFactory() { |
+ if (!g_fake_audio_manager) { |
+ g_fake_audio_log_factory = new FakeAudioLogFactory; |
+ g_fake_audio_manager = new FakeAudioManager(g_fake_audio_log_factory); |
+ } |
+ } |
+ |
+ ~FakeAudioManagerFactory() override {} |
+ |
+ AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override { |
+ return g_fake_audio_manager; |
+ } |
+}; |
+ |
+} // namespace |
+ |
+// Verifies that SetFactory has the intended effect. Note that the current |
+// structure supports exactly one test case (SetFactory may only be called |
+// once per process by design). |
+TEST(AudioManagerFactoryTest, CreateInstance) { |
+ // Create an audio manager and verify that it is not null. |
+ scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting()); |
+ ASSERT_NE(nullptr, manager.get()); |
+ manager.reset(); |
+ |
+ // Set the factory, after which the static AudioManager should be |
+ // instantiated. |
+ AudioManager::SetFactory(new FakeAudioManagerFactory); |
DaleCurtis
2015/04/23 16:18:26
()
slan
2015/04/23 18:11:33
Done. Here and above.
|
+ ASSERT_NE(nullptr, g_fake_audio_manager); |
+ |
+ // Get the instance and verify that it matches the instance provided by the |
+ // factory. |
+ manager.reset(AudioManager::CreateForTesting()); |
+ ASSERT_EQ(g_fake_audio_manager, manager.get()); |
+ |
+ // 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
|
+ // to other tests on the same process. |
+ manager.reset(); |
+ AudioManager::ResetFactory(); |
+} |
+ |
+} // namespace media |