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

Unified Diff: media/audio/test_audio_input_controller_factory.h

Issue 3148003: Allow unit tests to use a mock audio input controller. (Closed)
Patch Set: Address review comments from Jeremy and Alpha Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/test_audio_input_controller_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/test_audio_input_controller_factory.h
diff --git a/media/audio/test_audio_input_controller_factory.h b/media/audio/test_audio_input_controller_factory.h
new file mode 100644
index 0000000000000000000000000000000000000000..bd8f7b927767454bc7b2a5231dfd6527c970e137
--- /dev/null
+++ b/media/audio/test_audio_input_controller_factory.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2009 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.
+
+#ifndef MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
+#define MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
+#pragma once
+
+#include "media/audio/audio_input_controller.h"
+
+namespace media {
+
+class TestAudioInputControllerFactory;
+
+// TestAudioInputController and TestAudioInputControllerFactory are used for
+// testing consumers of AudioInputController. TestAudioInputControllerFactory
+// is a AudioInputController::Factory that creates TestAudioInputControllers.
+//
+// TestAudioInputController::Record and Close are overriden to do nothing. It is
+// expected that you'll grab the EventHandler from the TestAudioInputController
+// and invoke the callback methods when appropriate. In this way it's easy to
+// mock a AudioInputController.
+//
+// Typical usage:
+// // Create and register factory.
+// TestAudioInputControllerFactory factory;
+// AudioInputController::set_factory(&factory);
+//
+// // Do something that triggers creation of an AudioInputController.
+// TestAudioInputController* controller = factory.last_controller();
+// DCHECK(controller);
+//
+// // Notify event handler with whatever data you want.
+// controller->event_handler()->OnCreated(...);
+//
+// // Do something that triggers AudioInputController::Record to be called.
+// controller->event_handler()->OnData(...);
+// controller->event_handler()->OnError(...);
+//
+// // Make sure consumer of AudioInputController does the right thing.
+// ...
+// // Reset factory.
+// AudioInputController::set_factory(NULL);
+
+class TestAudioInputController : public AudioInputController {
+ public:
+ TestAudioInputController(TestAudioInputControllerFactory* factory,
+ EventHandler* event_handler);
+ virtual ~TestAudioInputController();
+
+ // Returns the event handler installed on the AudioInputController.
+ EventHandler* event_handler() const { return event_handler_; }
+
+ // Overriden to do nothing. It is assumed the caller will notify the event
+ // handler with recorded data and other events.
+ virtual void Record() {}
+ virtual void Close() {}
+
+ private:
+ // These are not owned by us and expected to be valid for this object's
+ // lifetime.
+ TestAudioInputControllerFactory* factory_;
+ EventHandler* event_handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAudioInputController);
+};
+
+// Simple AudioInputController::Factory method that creates
+// TestAudioInputControllers.
+class TestAudioInputControllerFactory : public AudioInputController::Factory {
+ public:
+ TestAudioInputControllerFactory();
+
+ // AudioInputController::Factory methods.
+ AudioInputController* Create(
+ AudioInputController::EventHandler* event_handler,
+ AudioManager::Format format,
+ int channels,
+ int sample_rate,
+ int bits_per_sample,
+ int samples_per_packet);
+
+ TestAudioInputController* controller() const { return controller_; }
+
+ private:
+ friend class TestAudioInputController;
+
+ // Invoked by a TestAudioInputController when it gets destroyed.
+ void OnTestAudioInputControllerDestroyed(
+ TestAudioInputController* controller);
+
+ // The caller of Create owns this object.
+ TestAudioInputController* controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAudioInputControllerFactory);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/test_audio_input_controller_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698