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

Side by Side Diff: components/copresence/mediums/audio/audio_player_unittest.cc

Issue 691223002: Replacing NULL with nullptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using EXPECT_THAT Created 6 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/copresence/mediums/audio/audio_player.h" 5 #include "components/copresence/mediums/audio/audio_player.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "components/copresence/mediums/audio/audio_player_impl.h" 9 #include "components/copresence/mediums/audio/audio_player_impl.h"
10 #include "components/copresence/public/copresence_constants.h" 10 #include "components/copresence/public/copresence_constants.h"
11 #include "components/copresence/test/audio_test_support.h" 11 #include "components/copresence/test/audio_test_support.h"
12 #include "media/audio/audio_manager.h" 12 #include "media/audio/audio_manager.h"
13 #include "media/audio/audio_manager_base.h" 13 #include "media/audio/audio_manager_base.h"
14 #include "media/base/audio_bus.h" 14 #include "media/base/audio_bus.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace { 17 namespace {
18 18
19 class TestAudioOutputStream : public media::AudioOutputStream { 19 class TestAudioOutputStream : public media::AudioOutputStream {
20 public: 20 public:
21 typedef base::Callback<void(scoped_ptr<media::AudioBus>, int frames)> 21 typedef base::Callback<void(scoped_ptr<media::AudioBus>, int frames)>
22 GatherSamplesCallback; 22 GatherSamplesCallback;
23 TestAudioOutputStream(int default_frame_count, 23 TestAudioOutputStream(int default_frame_count,
24 int max_frame_count, 24 int max_frame_count,
25 GatherSamplesCallback gather_callback) 25 GatherSamplesCallback gather_callback)
26 : default_frame_count_(default_frame_count), 26 : default_frame_count_(default_frame_count),
27 max_frame_count_(max_frame_count), 27 max_frame_count_(max_frame_count),
28 gather_callback_(gather_callback), 28 gather_callback_(gather_callback),
29 callback_(NULL) { 29 callback_(nullptr) {
30 caller_loop_ = base::MessageLoop::current(); 30 caller_loop_ = base::MessageLoop::current();
31 } 31 }
32 32
33 ~TestAudioOutputStream() override {} 33 ~TestAudioOutputStream() override {}
34 34
35 bool Open() override { return true; } 35 bool Open() override { return true; }
36 void Start(AudioSourceCallback* callback) override { 36 void Start(AudioSourceCallback* callback) override {
37 callback_ = callback; 37 callback_ = callback;
38 GatherPlayedSamples(); 38 GatherPlayedSamples();
39 } 39 }
(...skipping 26 matching lines...) Expand all
66 DISALLOW_COPY_AND_ASSIGN(TestAudioOutputStream); 66 DISALLOW_COPY_AND_ASSIGN(TestAudioOutputStream);
67 }; 67 };
68 68
69 } // namespace 69 } // namespace
70 70
71 namespace copresence { 71 namespace copresence {
72 72
73 class AudioPlayerTest : public testing::Test, 73 class AudioPlayerTest : public testing::Test,
74 public base::SupportsWeakPtr<AudioPlayerTest> { 74 public base::SupportsWeakPtr<AudioPlayerTest> {
75 public: 75 public:
76 AudioPlayerTest() : buffer_index_(0), player_(NULL) { 76 AudioPlayerTest() : buffer_index_(0), player_(nullptr) {
77 if (!media::AudioManager::Get()) 77 if (!media::AudioManager::Get())
78 media::AudioManager::CreateForTesting(); 78 media::AudioManager::CreateForTesting();
79 } 79 }
80 80
81 ~AudioPlayerTest() override { DeletePlayer(); } 81 ~AudioPlayerTest() override { DeletePlayer(); }
82 82
83 void CreatePlayer() { 83 void CreatePlayer() {
84 DeletePlayer(); 84 DeletePlayer();
85 player_ = new AudioPlayerImpl(); 85 player_ = new AudioPlayerImpl();
86 player_->set_output_stream_for_testing(new TestAudioOutputStream( 86 player_->set_output_stream_for_testing(new TestAudioOutputStream(
87 kDefaultFrameCount, 87 kDefaultFrameCount,
88 kMaxFrameCount, 88 kMaxFrameCount,
89 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); 89 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr())));
90 player_->Initialize(); 90 player_->Initialize();
91 } 91 }
92 92
93 void DeletePlayer() { 93 void DeletePlayer() {
94 if (!player_) 94 if (!player_)
95 return; 95 return;
96 player_->Finalize(); 96 player_->Finalize();
97 player_ = NULL; 97 player_ = nullptr;
98 } 98 }
99 99
100 void PlayAndVerifySamples( 100 void PlayAndVerifySamples(
101 const scoped_refptr<media::AudioBusRefCounted>& samples) { 101 const scoped_refptr<media::AudioBusRefCounted>& samples) {
102 buffer_ = media::AudioBus::Create(1, kMaxFrameCount); 102 buffer_ = media::AudioBus::Create(1, kMaxFrameCount);
103 player_->Play(samples); 103 player_->Play(samples);
104 player_->FlushAudioLoopForTesting(); 104 player_->FlushAudioLoopForTesting();
105 105
106 int differences = 0; 106 int differences = 0;
107 for (int i = 0; i < samples->frames(); ++i) 107 for (int i = 0; i < samples->frames(); ++i)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 TEST_F(AudioPlayerTest, PlayingEndToEnd) { 182 TEST_F(AudioPlayerTest, PlayingEndToEnd) {
183 const int kNumSamples = kDefaultFrameCount * 10; 183 const int kNumSamples = kDefaultFrameCount * 10;
184 CreatePlayer(); 184 CreatePlayer();
185 185
186 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); 186 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
187 187
188 DeletePlayer(); 188 DeletePlayer();
189 } 189 }
190 190
191 } // namespace copresence 191 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/mediums/audio/audio_player_impl.cc ('k') | components/copresence/mediums/audio/audio_recorder_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698