OLD | NEW |
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 "remoting/host/linux/audio_pipe_reader.h" | 5 #include "remoting/host/linux/audio_pipe_reader.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 | 20 |
21 class AudioPipeReaderTest : public testing::Test, | 21 class AudioPipeReaderTest : public testing::Test, |
22 public AudioPipeReader::StreamObserver { | 22 public AudioPipeReader::StreamObserver { |
23 public: | 23 public: |
24 AudioPipeReaderTest() | 24 AudioPipeReaderTest() |
25 : stop_at_position_(-1) { | 25 : stop_at_position_(-1) { |
26 } | 26 } |
27 | 27 |
28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() override { |
29 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
30 pipe_path_ = test_dir_.path().AppendASCII("test_pipe"); | 30 pipe_path_ = test_dir_.path().AppendASCII("test_pipe"); |
31 audio_thread_.reset(new base::Thread("TestAudioThread")); | 31 audio_thread_.reset(new base::Thread("TestAudioThread")); |
32 audio_thread_->StartWithOptions( | 32 audio_thread_->StartWithOptions( |
33 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 33 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
34 reader_ = AudioPipeReader::Create(audio_thread_->message_loop_proxy(), | 34 reader_ = AudioPipeReader::Create(audio_thread_->message_loop_proxy(), |
35 pipe_path_); | 35 pipe_path_); |
36 reader_->AddObserver(this); | 36 reader_->AddObserver(this); |
37 } | 37 } |
38 | 38 |
39 // AudioPipeReader::StreamObserver interface. | 39 // AudioPipeReader::StreamObserver interface. |
40 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) OVERRIDE { | 40 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) override { |
41 read_data_ += data->data(); | 41 read_data_ += data->data(); |
42 if (stop_at_position_ > 0 && | 42 if (stop_at_position_ > 0 && |
43 static_cast<int>(read_data_.size()) >= stop_at_position_) { | 43 static_cast<int>(read_data_.size()) >= stop_at_position_) { |
44 stop_at_position_ = -1; | 44 stop_at_position_ = -1; |
45 run_loop_->Quit(); | 45 run_loop_->Quit(); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void CreatePipe() { | 49 void CreatePipe() { |
50 ASSERT_EQ(0, mkfifo(pipe_path_.value().c_str(), 0600)); | 50 ASSERT_EQ(0, mkfifo(pipe_path_.value().c_str(), 0600)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 base::TimeTicks start_time = base::TimeTicks::Now(); | 111 base::TimeTicks start_time = base::TimeTicks::Now(); |
112 ASSERT_NO_FATAL_FAILURE(WriteAndWait(test_data)); | 112 ASSERT_NO_FATAL_FAILURE(WriteAndWait(test_data)); |
113 base::TimeDelta time_passed = base::TimeTicks::Now() - start_time; | 113 base::TimeDelta time_passed = base::TimeTicks::Now() - start_time; |
114 | 114 |
115 EXPECT_EQ(test_data, read_data_); | 115 EXPECT_EQ(test_data, read_data_); |
116 EXPECT_GE(time_passed, base::TimeDelta::FromMilliseconds(500)); | 116 EXPECT_GE(time_passed, base::TimeDelta::FromMilliseconds(500)); |
117 } | 117 } |
118 | 118 |
119 } // namespace remoting | 119 } // namespace remoting |
OLD | NEW |