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

Side by Side Diff: mojo/edk/system/raw_channel_unittest.cc

Issue 1427633003: Move scoped_test_dir.* and test_io_thread.* from edk/test to edk/system/test. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 "mojo/edk/system/raw_channel.h" 5 #include "mojo/edk/system/raw_channel.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "mojo/edk/embedder/platform_channel_pair.h" 17 #include "mojo/edk/embedder/platform_channel_pair.h"
18 #include "mojo/edk/embedder/platform_handle.h" 18 #include "mojo/edk/embedder/platform_handle.h"
19 #include "mojo/edk/embedder/scoped_platform_handle.h" 19 #include "mojo/edk/embedder/scoped_platform_handle.h"
20 #include "mojo/edk/system/message_in_transit.h" 20 #include "mojo/edk/system/message_in_transit.h"
21 #include "mojo/edk/system/mutex.h" 21 #include "mojo/edk/system/mutex.h"
22 #include "mojo/edk/system/test/random.h" 22 #include "mojo/edk/system/test/random.h"
23 #include "mojo/edk/system/test/scoped_test_dir.h"
23 #include "mojo/edk/system/test/simple_test_thread.h" 24 #include "mojo/edk/system/test/simple_test_thread.h"
24 #include "mojo/edk/system/test/sleep.h" 25 #include "mojo/edk/system/test/sleep.h"
26 #include "mojo/edk/system/test/test_io_thread.h"
25 #include "mojo/edk/system/transport_data.h" 27 #include "mojo/edk/system/transport_data.h"
26 #include "mojo/edk/test/scoped_test_dir.h"
27 #include "mojo/edk/test/test_io_thread.h"
28 #include "mojo/edk/test/test_utils.h" 28 #include "mojo/edk/test/test_utils.h"
29 #include "mojo/edk/util/make_unique.h" 29 #include "mojo/edk/util/make_unique.h"
30 #include "mojo/edk/util/scoped_file.h" 30 #include "mojo/edk/util/scoped_file.h"
31 #include "mojo/public/cpp/system/macros.h" 31 #include "mojo/public/cpp/system/macros.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 namespace mojo { 34 namespace mojo {
35 namespace system { 35 namespace system {
36 namespace { 36 namespace {
37 37
(...skipping 27 matching lines...) Expand all
65 size_t write_size = 0; 65 size_t write_size = 0;
66 mojo::test::BlockingWrite(handle, message->main_buffer(), 66 mojo::test::BlockingWrite(handle, message->main_buffer(),
67 message->main_buffer_size(), &write_size); 67 message->main_buffer_size(), &write_size);
68 return write_size == message->main_buffer_size(); 68 return write_size == message->main_buffer_size();
69 } 69 }
70 70
71 // ----------------------------------------------------------------------------- 71 // -----------------------------------------------------------------------------
72 72
73 class RawChannelTest : public testing::Test { 73 class RawChannelTest : public testing::Test {
74 public: 74 public:
75 RawChannelTest() : io_thread_(mojo::test::TestIOThread::StartMode::MANUAL) {} 75 RawChannelTest() : io_thread_(test::TestIOThread::StartMode::MANUAL) {}
76 ~RawChannelTest() override {} 76 ~RawChannelTest() override {}
77 77
78 void SetUp() override { 78 void SetUp() override {
79 embedder::PlatformChannelPair channel_pair; 79 embedder::PlatformChannelPair channel_pair;
80 handles[0] = channel_pair.PassServerHandle(); 80 handles[0] = channel_pair.PassServerHandle();
81 handles[1] = channel_pair.PassClientHandle(); 81 handles[1] = channel_pair.PassClientHandle();
82 io_thread_.Start(); 82 io_thread_.Start();
83 } 83 }
84 84
85 void TearDown() override { 85 void TearDown() override {
86 io_thread_.Stop(); 86 io_thread_.Stop();
87 handles[0].reset(); 87 handles[0].reset();
88 handles[1].reset(); 88 handles[1].reset();
89 } 89 }
90 90
91 protected: 91 protected:
92 mojo::test::TestIOThread* io_thread() { return &io_thread_; } 92 test::TestIOThread* io_thread() { return &io_thread_; }
93 93
94 embedder::ScopedPlatformHandle handles[2]; 94 embedder::ScopedPlatformHandle handles[2];
95 95
96 private: 96 private:
97 mojo::test::TestIOThread io_thread_; 97 test::TestIOThread io_thread_;
98 98
99 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelTest); 99 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelTest);
100 }; 100 };
101 101
102 // RawChannelTest.WriteMessage ------------------------------------------------- 102 // RawChannelTest.WriteMessage -------------------------------------------------
103 103
104 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate { 104 class WriteOnlyRawChannelDelegate : public RawChannel::Delegate {
105 public: 105 public:
106 WriteOnlyRawChannelDelegate() {} 106 WriteOnlyRawChannelDelegate() {}
107 ~WriteOnlyRawChannelDelegate() override {} 107 ~WriteOnlyRawChannelDelegate() override {}
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 772
773 void Wait() { done_event_.Wait(); } 773 void Wait() { done_event_.Wait(); }
774 774
775 private: 775 private:
776 base::WaitableEvent done_event_; 776 base::WaitableEvent done_event_;
777 777
778 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); 778 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate);
779 }; 779 };
780 780
781 TEST_F(RawChannelTest, ReadWritePlatformHandles) { 781 TEST_F(RawChannelTest, ReadWritePlatformHandles) {
782 mojo::test::ScopedTestDir test_dir; 782 test::ScopedTestDir test_dir;
783 783
784 WriteOnlyRawChannelDelegate write_delegate; 784 WriteOnlyRawChannelDelegate write_delegate;
785 std::unique_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass())); 785 std::unique_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass()));
786 io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_write.get(), 786 io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_write.get(),
787 base::Unretained(&write_delegate))); 787 base::Unretained(&write_delegate)));
788 788
789 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; 789 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate;
790 std::unique_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); 790 std::unique_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass()));
791 io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_read.get(), 791 io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_read.get(),
792 base::Unretained(&read_delegate))); 792 base::Unretained(&read_delegate)));
(...skipping 26 matching lines...) Expand all
819 819
820 io_thread()->PostTaskAndWait( 820 io_thread()->PostTaskAndWait(
821 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); 821 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get())));
822 io_thread()->PostTaskAndWait( 822 io_thread()->PostTaskAndWait(
823 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); 823 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get())));
824 } 824 }
825 825
826 } // namespace 826 } // namespace
827 } // namespace system 827 } // namespace system
828 } // namespace mojo 828 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/platform_handle_dispatcher_unittest.cc ('k') | mojo/edk/system/remote_data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698