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

Side by Side Diff: mojo/system/embedder/embedder_unittest.cc

Issue 187383007: Mojo: Replace TestWithIOThreadBase with just a helper TestIOThread class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | mojo/system/raw_channel_unittest.cc » ('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 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/system/embedder/embedder.h" 5 #include "mojo/system/embedder/embedder.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "mojo/public/system/core.h" 13 #include "mojo/public/system/core.h"
14 #include "mojo/system/embedder/platform_channel_pair.h" 14 #include "mojo/system/embedder/platform_channel_pair.h"
15 #include "mojo/system/embedder/test_embedder.h" 15 #include "mojo/system/embedder/test_embedder.h"
16 #include "mojo/system/test_utils.h" 16 #include "mojo/system/test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace mojo { 19 namespace mojo {
19 namespace embedder { 20 namespace embedder {
20 namespace { 21 namespace {
21 22
22 typedef system::test::TestWithIOThreadBase EmbedderTest; 23 class EmbedderTest : public testing::Test {
24 public:
25 EmbedderTest() {}
26 virtual ~EmbedderTest() {}
27
28 protected:
29 system::test::TestIOThread* io_thread() { return &io_thread_; }
30
31 private:
32 system::test::TestIOThread io_thread_;
33
34 DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
35 };
23 36
24 void StoreChannelInfo(ChannelInfo** store_channel_info_here, 37 void StoreChannelInfo(ChannelInfo** store_channel_info_here,
25 ChannelInfo* channel_info) { 38 ChannelInfo* channel_info) {
26 CHECK(store_channel_info_here); 39 CHECK(store_channel_info_here);
27 CHECK(channel_info); 40 CHECK(channel_info);
28 *store_channel_info_here = channel_info; 41 *store_channel_info_here = channel_info;
29 } 42 }
30 43
31 TEST_F(EmbedderTest, ChannelsBasic) { 44 TEST_F(EmbedderTest, ChannelsBasic) {
32 Init(); 45 Init();
33 46
34 PlatformChannelPair channel_pair; 47 PlatformChannelPair channel_pair;
35 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 48 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
36 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 49 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
37 50
38 ChannelInfo* server_channel_info = NULL; 51 ChannelInfo* server_channel_info = NULL;
39 MojoHandle server_mp = CreateChannel(server_handle.Pass(), 52 MojoHandle server_mp = CreateChannel(server_handle.Pass(),
40 io_thread_task_runner(), 53 io_thread()->task_runner(),
41 base::Bind(&StoreChannelInfo, 54 base::Bind(&StoreChannelInfo,
42 &server_channel_info)); 55 &server_channel_info));
43 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 56 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
44 57
45 ChannelInfo* client_channel_info = NULL; 58 ChannelInfo* client_channel_info = NULL;
46 MojoHandle client_mp = CreateChannel(client_handle.Pass(), 59 MojoHandle client_mp = CreateChannel(client_handle.Pass(),
47 io_thread_task_runner(), 60 io_thread()->task_runner(),
48 base::Bind(&StoreChannelInfo, 61 base::Bind(&StoreChannelInfo,
49 &client_channel_info)); 62 &client_channel_info));
50 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 63 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
51 64
52 // We can write to a message pipe handle immediately. 65 // We can write to a message pipe handle immediately.
53 const char kHello[] = "hello"; 66 const char kHello[] = "hello";
54 EXPECT_EQ(MOJO_RESULT_OK, 67 EXPECT_EQ(MOJO_RESULT_OK,
55 MojoWriteMessage(server_mp, kHello, 68 MojoWriteMessage(server_mp, kHello,
56 static_cast<uint32_t>(sizeof(kHello)), NULL, 0, 69 static_cast<uint32_t>(sizeof(kHello)), NULL, 0,
57 MOJO_WRITE_MESSAGE_FLAG_NONE)); 70 MOJO_WRITE_MESSAGE_FLAG_NONE));
58 71
59 // Now wait for the other side to become readable. 72 // Now wait for the other side to become readable.
60 EXPECT_EQ(MOJO_RESULT_OK, 73 EXPECT_EQ(MOJO_RESULT_OK,
61 MojoWait(client_mp, MOJO_WAIT_FLAG_READABLE, 74 MojoWait(client_mp, MOJO_WAIT_FLAG_READABLE,
62 MOJO_DEADLINE_INDEFINITE)); 75 MOJO_DEADLINE_INDEFINITE));
63 76
64 char buffer[1000] = {}; 77 char buffer[1000] = {};
65 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 78 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
66 EXPECT_EQ(MOJO_RESULT_OK, 79 EXPECT_EQ(MOJO_RESULT_OK,
67 MojoReadMessage(client_mp, buffer, &num_bytes, NULL, NULL, 80 MojoReadMessage(client_mp, buffer, &num_bytes, NULL, NULL,
68 MOJO_READ_MESSAGE_FLAG_NONE)); 81 MOJO_READ_MESSAGE_FLAG_NONE));
69 EXPECT_EQ(sizeof(kHello), num_bytes); 82 EXPECT_EQ(sizeof(kHello), num_bytes);
70 EXPECT_STREQ(kHello, buffer); 83 EXPECT_STREQ(kHello, buffer);
71 84
72 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 85 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
73 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 86 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
74 87
75 EXPECT_TRUE(server_channel_info != NULL); 88 EXPECT_TRUE(server_channel_info != NULL);
76 system::test::PostTaskAndWait(io_thread_task_runner(), 89 system::test::PostTaskAndWait(io_thread()->task_runner(),
77 FROM_HERE, 90 FROM_HERE,
78 base::Bind(&DestroyChannelOnIOThread, 91 base::Bind(&DestroyChannelOnIOThread,
79 server_channel_info)); 92 server_channel_info));
80 93
81 EXPECT_TRUE(client_channel_info != NULL); 94 EXPECT_TRUE(client_channel_info != NULL);
82 system::test::PostTaskAndWait(io_thread_task_runner(), 95 system::test::PostTaskAndWait(io_thread()->task_runner(),
83 FROM_HERE, 96 FROM_HERE,
84 base::Bind(&DestroyChannelOnIOThread, 97 base::Bind(&DestroyChannelOnIOThread,
85 client_channel_info)); 98 client_channel_info));
86 99
87 EXPECT_TRUE(test::Shutdown()); 100 EXPECT_TRUE(test::Shutdown());
88 } 101 }
89 102
90 TEST_F(EmbedderTest, ChannelsHandlePassing) { 103 TEST_F(EmbedderTest, ChannelsHandlePassing) {
91 Init(); 104 Init();
92 105
93 PlatformChannelPair channel_pair; 106 PlatformChannelPair channel_pair;
94 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 107 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
95 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 108 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
96 109
97 ChannelInfo* server_channel_info = NULL; 110 ChannelInfo* server_channel_info = NULL;
98 MojoHandle server_mp = CreateChannel(server_handle.Pass(), 111 MojoHandle server_mp = CreateChannel(server_handle.Pass(),
99 io_thread_task_runner(), 112 io_thread()->task_runner(),
100 base::Bind(&StoreChannelInfo, 113 base::Bind(&StoreChannelInfo,
101 &server_channel_info)); 114 &server_channel_info));
102 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 115 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
103 116
104 ChannelInfo* client_channel_info = NULL; 117 ChannelInfo* client_channel_info = NULL;
105 MojoHandle client_mp = CreateChannel(client_handle.Pass(), 118 MojoHandle client_mp = CreateChannel(client_handle.Pass(),
106 io_thread_task_runner(), 119 io_thread()->task_runner(),
107 base::Bind(&StoreChannelInfo, 120 base::Bind(&StoreChannelInfo,
108 &client_channel_info)); 121 &client_channel_info));
109 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 122 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
110 123
111 MojoHandle h0, h1; 124 MojoHandle h0, h1;
112 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&h0, &h1)); 125 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&h0, &h1));
113 126
114 // Write a message to |h0| (attaching nothing). 127 // Write a message to |h0| (attaching nothing).
115 const char kHello[] = "hello"; 128 const char kHello[] = "hello";
116 EXPECT_EQ(MOJO_RESULT_OK, 129 EXPECT_EQ(MOJO_RESULT_OK,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 221
209 EXPECT_TRUE(test::Shutdown()); 222 EXPECT_TRUE(test::Shutdown());
210 } 223 }
211 224
212 // TODO(vtl): Test immediate write & close. 225 // TODO(vtl): Test immediate write & close.
213 // TODO(vtl): Test broken-connection cases. 226 // TODO(vtl): Test broken-connection cases.
214 227
215 } // namespace 228 } // namespace
216 } // namespace embedder 229 } // namespace embedder
217 } // namespace mojo 230 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/system/raw_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698