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

Side by Side Diff: remoting/host/audio_pump_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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
« no previous file with comments | « remoting/host/audio_pump.cc ('k') | remoting/host/backoff_timer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "remoting/host/audio_pump.h" 5 #include "remoting/host/audio_pump.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "remoting/codec/audio_encoder.h" 16 #include "remoting/codec/audio_encoder.h"
16 #include "remoting/host/audio_capturer.h" 17 #include "remoting/host/audio_capturer.h"
17 #include "remoting/proto/audio.pb.h" 18 #include "remoting/proto/audio.pb.h"
18 #include "remoting/protocol/audio_stub.h" 19 #include "remoting/protocol/audio_stub.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace remoting { 22 namespace remoting {
22 23
23 namespace { 24 namespace {
24 25
25 // Creates a dummy packet with 1k data 26 // Creates a dummy packet with 1k data
26 scoped_ptr<AudioPacket> MakeAudioPacket() { 27 std::unique_ptr<AudioPacket> MakeAudioPacket() {
27 scoped_ptr<AudioPacket> packet(new AudioPacket); 28 std::unique_ptr<AudioPacket> packet(new AudioPacket);
28 packet->add_data()->resize(1000); 29 packet->add_data()->resize(1000);
29 return packet; 30 return packet;
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 class FakeAudioCapturer : public AudioCapturer { 35 class FakeAudioCapturer : public AudioCapturer {
35 public: 36 public:
36 FakeAudioCapturer() {} 37 FakeAudioCapturer() {}
37 ~FakeAudioCapturer() override {} 38 ~FakeAudioCapturer() override {}
38 39
39 bool Start(const PacketCapturedCallback& callback) override { 40 bool Start(const PacketCapturedCallback& callback) override {
40 callback_ = callback; 41 callback_ = callback;
41 return true; 42 return true;
42 } 43 }
43 44
44 const PacketCapturedCallback& callback() { return callback_; } 45 const PacketCapturedCallback& callback() { return callback_; }
45 46
46 private: 47 private:
47 PacketCapturedCallback callback_; 48 PacketCapturedCallback callback_;
48 49
49 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer); 50 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer);
50 }; 51 };
51 52
52 class FakeAudioEncoder : public AudioEncoder { 53 class FakeAudioEncoder : public AudioEncoder {
53 public: 54 public:
54 FakeAudioEncoder() {} 55 FakeAudioEncoder() {}
55 ~FakeAudioEncoder() override {} 56 ~FakeAudioEncoder() override {}
56 57
57 scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) override { 58 std::unique_ptr<AudioPacket> Encode(
59 std::unique_ptr<AudioPacket> packet) override {
58 return packet; 60 return packet;
59 } 61 }
60 int GetBitrate() override { 62 int GetBitrate() override {
61 return 160000; 63 return 160000;
62 } 64 }
63 65
64 private: 66 private:
65 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); 67 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder);
66 }; 68 };
67 69
68 class AudioPumpTest : public testing::Test, public protocol::AudioStub { 70 class AudioPumpTest : public testing::Test, public protocol::AudioStub {
69 public: 71 public:
70 AudioPumpTest() {} 72 AudioPumpTest() {}
71 73
72 void SetUp() override; 74 void SetUp() override;
73 void TearDown() override; 75 void TearDown() override;
74 76
75 // protocol::AudioStub interface. 77 // protocol::AudioStub interface.
76 void ProcessAudioPacket(scoped_ptr<AudioPacket> audio_packet, 78 void ProcessAudioPacket(std::unique_ptr<AudioPacket> audio_packet,
77 const base::Closure& done) override; 79 const base::Closure& done) override;
78 80
79 protected: 81 protected:
80 base::MessageLoop message_loop_; 82 base::MessageLoop message_loop_;
81 83
82 // |capturer_| and |encoder_| are owned by the |pump_|. 84 // |capturer_| and |encoder_| are owned by the |pump_|.
83 FakeAudioCapturer* capturer_; 85 FakeAudioCapturer* capturer_;
84 FakeAudioEncoder* encoder_; 86 FakeAudioEncoder* encoder_;
85 87
86 scoped_ptr<AudioPump> pump_; 88 std::unique_ptr<AudioPump> pump_;
87 89
88 ScopedVector<AudioPacket> sent_packets_; 90 ScopedVector<AudioPacket> sent_packets_;
89 std::vector<base::Closure> done_closures_; 91 std::vector<base::Closure> done_closures_;
90 92
91 private: 93 private:
92 DISALLOW_COPY_AND_ASSIGN(AudioPumpTest); 94 DISALLOW_COPY_AND_ASSIGN(AudioPumpTest);
93 }; 95 };
94 96
95 void AudioPumpTest::SetUp() { 97 void AudioPumpTest::SetUp() {
96 capturer_ = new FakeAudioCapturer(); 98 capturer_ = new FakeAudioCapturer();
97 encoder_ = new FakeAudioEncoder(); 99 encoder_ = new FakeAudioEncoder();
98 pump_.reset(new AudioPump(message_loop_.task_runner(), 100 pump_.reset(new AudioPump(message_loop_.task_runner(),
99 make_scoped_ptr(capturer_), 101 base::WrapUnique(capturer_),
100 make_scoped_ptr(encoder_), this)); 102 base::WrapUnique(encoder_), this));
101 } 103 }
102 104
103 void AudioPumpTest::TearDown() { 105 void AudioPumpTest::TearDown() {
104 pump_.reset(); 106 pump_.reset();
105 107
106 // Let the message loop run to finish destroying the capturer. 108 // Let the message loop run to finish destroying the capturer.
107 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
108 } 110 }
109 111
110 void AudioPumpTest::ProcessAudioPacket( 112 void AudioPumpTest::ProcessAudioPacket(
111 scoped_ptr<AudioPacket> audio_packet, 113 std::unique_ptr<AudioPacket> audio_packet,
112 const base::Closure& done) { 114 const base::Closure& done) {
113 sent_packets_.push_back(std::move(audio_packet)); 115 sent_packets_.push_back(std::move(audio_packet));
114 done_closures_.push_back(done); 116 done_closures_.push_back(done);
115 } 117 }
116 118
117 // Verify that the pump pauses pumping when the network is congested. 119 // Verify that the pump pauses pumping when the network is congested.
118 TEST_F(AudioPumpTest, BufferSizeLimit) { 120 TEST_F(AudioPumpTest, BufferSizeLimit) {
119 // Run message loop to let the pump start the capturer. 121 // Run message loop to let the pump start the capturer.
120 base::RunLoop().RunUntilIdle(); 122 base::RunLoop().RunUntilIdle();
121 ASSERT_FALSE(capturer_->callback().is_null()); 123 ASSERT_FALSE(capturer_->callback().is_null());
(...skipping 14 matching lines...) Expand all
136 done_closures_.front().Run(); 138 done_closures_.front().Run();
137 base::RunLoop().RunUntilIdle(); 139 base::RunLoop().RunUntilIdle();
138 140
139 // Verify that the pump continues to send captured audio. 141 // Verify that the pump continues to send captured audio.
140 capturer_->callback().Run(MakeAudioPacket()); 142 capturer_->callback().Run(MakeAudioPacket());
141 base::RunLoop().RunUntilIdle(); 143 base::RunLoop().RunUntilIdle();
142 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); 144 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size());
143 } 145 }
144 146
145 } // namespace remoting 147 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/audio_pump.cc ('k') | remoting/host/backoff_timer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698