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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #ifndef MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
6 #define MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
7 #pragma once
8
9 #include "media/audio/audio_input_controller.h"
10
11 namespace media {
12
13 class TestAudioInputControllerFactory;
14
15 // TestAudioInputController and TestAudioInputControllerFactory are used for
16 // testing consumers of AudioInputController. TestAudioInputControllerFactory
17 // is a AudioInputController::Factory that creates TestAudioInputControllers.
18 //
19 // TestAudioInputController::Record and Close are overriden to do nothing. It is
20 // expected that you'll grab the EventHandler from the TestAudioInputController
21 // and invoke the callback methods when appropriate. In this way it's easy to
22 // mock a AudioInputController.
23 //
24 // Typical usage:
25 // // Create and register factory.
26 // TestAudioInputControllerFactory factory;
27 // AudioInputController::set_factory(&factory);
28 //
29 // // Do something that triggers creation of an AudioInputController.
30 // TestAudioInputController* controller = factory.last_controller();
31 // DCHECK(controller);
32 //
33 // // Notify event handler with whatever data you want.
34 // controller->event_handler()->OnCreated(...);
35 //
36 // // Do something that triggers AudioInputController::Record to be called.
37 // controller->event_handler()->OnData(...);
38 // controller->event_handler()->OnError(...);
39 //
40 // // Make sure consumer of AudioInputController does the right thing.
41 // ...
42 // // Reset factory.
43 // AudioInputController::set_factory(NULL);
44
45 class TestAudioInputController : public AudioInputController {
46 public:
47 TestAudioInputController(TestAudioInputControllerFactory* factory,
48 EventHandler* event_handler);
49 virtual ~TestAudioInputController();
50
51 // Returns the event handler installed on the AudioInputController.
52 EventHandler* event_handler() const { return event_handler_; }
53
54 // Overriden to do nothing. It is assumed the caller will notify the event
55 // handler with recorded data and other events.
56 virtual void Record() {}
57 virtual void Close() {}
58
59 private:
60 // These are not owned by us and expected to be valid for this object's
61 // lifetime.
62 TestAudioInputControllerFactory* factory_;
63 EventHandler* event_handler_;
64
65 DISALLOW_COPY_AND_ASSIGN(TestAudioInputController);
66 };
67
68 // Simple AudioInputController::Factory method that creates
69 // TestAudioInputControllers.
70 class TestAudioInputControllerFactory : public AudioInputController::Factory {
71 public:
72 TestAudioInputControllerFactory();
73
74 // AudioInputController::Factory methods.
75 AudioInputController* Create(
76 AudioInputController::EventHandler* event_handler,
77 AudioManager::Format format,
78 int channels,
79 int sample_rate,
80 int bits_per_sample,
81 int samples_per_packet);
82
83 TestAudioInputController* controller() const { return controller_; }
84
85 private:
86 friend class TestAudioInputController;
87
88 // Invoked by a TestAudioInputController when it gets destroyed.
89 void OnTestAudioInputControllerDestroyed(
90 TestAudioInputController* controller);
91
92 // The caller of Create owns this object.
93 TestAudioInputController* controller_;
94
95 DISALLOW_COPY_AND_ASSIGN(TestAudioInputControllerFactory);
96 };
97
98 } // namespace media
99
100 #endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
OLDNEW
« 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