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

Side by Side Diff: media/audio/audio_input_unittest.cc

Issue 10837118: Dead code elimination: scythe.chrome_functions:segment.path %media% edition, round 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "media/audio/audio_io.h" 10 #include "media/audio/audio_io.h"
11 #include "media/audio/audio_manager_base.h" 11 #include "media/audio/audio_manager_base.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 static const int kSamplingRate = 8000; 16 static const int kSamplingRate = 8000;
17 static const int kSamplesPerPacket = kSamplingRate / 20; 17 static const int kSamplesPerPacket = kSamplingRate / 20;
18 18
19 // This class allows to find out if the callbacks are occurring as 19 // This class allows to find out if the callbacks are occurring as
20 // expected and if any error has been reported. 20 // expected and if any error has been reported.
21 class TestInputCallback : public AudioInputStream::AudioInputCallback { 21 class TestInputCallback : public AudioInputStream::AudioInputCallback {
22 public: 22 public:
23 explicit TestInputCallback(int max_data_bytes) 23 explicit TestInputCallback(int max_data_bytes)
24 : callback_count_(0), 24 : callback_count_(0),
25 had_error_(0), 25 had_error_(0),
26 was_closed_(0),
27 max_data_bytes_(max_data_bytes) { 26 max_data_bytes_(max_data_bytes) {
28 } 27 }
29 virtual void OnData(AudioInputStream* stream, const uint8* data, 28 virtual void OnData(AudioInputStream* stream, const uint8* data,
30 uint32 size, uint32 hardware_delay_bytes, double volume) { 29 uint32 size, uint32 hardware_delay_bytes, double volume) {
31 ++callback_count_; 30 ++callback_count_;
32 // Read the first byte to make sure memory is good. 31 // Read the first byte to make sure memory is good.
33 if (size) { 32 if (size) {
34 ASSERT_LE(static_cast<int>(size), max_data_bytes_); 33 ASSERT_LE(static_cast<int>(size), max_data_bytes_);
35 int value = data[0]; 34 int value = data[0];
36 EXPECT_GE(value, 0); 35 EXPECT_GE(value, 0);
37 } 36 }
38 } 37 }
39 virtual void OnClose(AudioInputStream* stream) { 38 virtual void OnClose(AudioInputStream* stream) {}
40 ++was_closed_;
41 }
42 virtual void OnError(AudioInputStream* stream, int code) { 39 virtual void OnError(AudioInputStream* stream, int code) {
43 ++had_error_; 40 ++had_error_;
44 } 41 }
45 // Returns how many times OnData() has been called. 42 // Returns how many times OnData() has been called.
46 int callback_count() const { 43 int callback_count() const {
47 return callback_count_; 44 return callback_count_;
48 } 45 }
49 // Returns how many times the OnError callback was called. 46 // Returns how many times the OnError callback was called.
50 int had_error() const { 47 int had_error() const {
51 return had_error_; 48 return had_error_;
52 } 49 }
53 50
54 void set_error(bool error) {
55 had_error_ += error ? 1 : 0;
56 }
57 // Returns how many times the OnClose callback was called.
58 int was_closed() const {
59 return was_closed_;
60 }
61
62 private: 51 private:
63 int callback_count_; 52 int callback_count_;
64 int had_error_; 53 int had_error_;
65 int was_closed_;
66 int max_data_bytes_; 54 int max_data_bytes_;
67 }; 55 };
68 56
69 static bool CanRunAudioTests(AudioManager* audio_man) { 57 static bool CanRunAudioTests(AudioManager* audio_man) {
70 bool has_input = audio_man->HasAudioInputDevices(); 58 bool has_input = audio_man->HasAudioInputDevices();
71 59
72 if (!has_input) 60 if (!has_input)
73 LOG(WARNING) << "No input devices detected"; 61 LOG(WARNING) << "No input devices detected";
74 62
75 return has_input; 63 return has_input;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 base::TimeDelta::FromMilliseconds(590)); 155 base::TimeDelta::FromMilliseconds(590));
168 message_loop.Run(); 156 message_loop.Run();
169 EXPECT_GE(test_callback.callback_count(), 10); 157 EXPECT_GE(test_callback.callback_count(), 10);
170 EXPECT_FALSE(test_callback.had_error()); 158 EXPECT_FALSE(test_callback.had_error());
171 159
172 ais->Stop(); 160 ais->Stop();
173 ais->Close(); 161 ais->Close();
174 } 162 }
175 163
176 } // namespace media 164 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698