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

Side by Side Diff: mojo/public/c/system/tests/core_unittest.cc

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // This file tests the C API. 5 // This file tests the C API.
6 6
7 #include "mojo/public/c/system/core.h" 7 #include "mojo/public/c/system/core.h"
8 8
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace { 14 namespace {
15 15
16 const MojoHandleSignals kSignalReadadableWritable =
17 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE;
18
19 const MojoHandleSignals kSignalAll = MOJO_HANDLE_SIGNAL_READABLE |
20 MOJO_HANDLE_SIGNAL_WRITABLE |
21 MOJO_HANDLE_SIGNAL_PEER_CLOSED;
22
16 TEST(CoreTest, GetTimeTicksNow) { 23 TEST(CoreTest, GetTimeTicksNow) {
17 const MojoTimeTicks start = MojoGetTimeTicksNow(); 24 const MojoTimeTicks start = MojoGetTimeTicksNow();
18 EXPECT_NE(static_cast<MojoTimeTicks>(0), start) 25 EXPECT_NE(static_cast<MojoTimeTicks>(0), start)
19 << "MojoGetTimeTicksNow should return nonzero value"; 26 << "MojoGetTimeTicksNow should return nonzero value";
20 } 27 }
21 28
22 // The only handle that's guaranteed to be invalid is |MOJO_HANDLE_INVALID|. 29 // The only handle that's guaranteed to be invalid is |MOJO_HANDLE_INVALID|.
23 // Tests that everything that takes a handle properly recognizes it. 30 // Tests that everything that takes a handle properly recognizes it.
24 TEST(CoreTest, InvalidHandle) { 31 TEST(CoreTest, InvalidHandle) {
25 MojoHandle h0, h1; 32 MojoHandle h0, h1;
26 MojoHandleSignals sig; 33 MojoHandleSignals sig;
27 char buffer[10] = {0}; 34 char buffer[10] = {0};
28 uint32_t buffer_size; 35 uint32_t buffer_size;
29 void* write_pointer; 36 void* write_pointer;
30 const void* read_pointer; 37 const void* read_pointer;
31 38
32 // Close: 39 // Close:
33 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(MOJO_HANDLE_INVALID)); 40 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(MOJO_HANDLE_INVALID));
34 41
35 // Wait: 42 // Wait:
36 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 43 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
37 MojoWait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE, 1000000)); 44 MojoNewWait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE, 1000000,
45 NULL));
46
38 h0 = MOJO_HANDLE_INVALID; 47 h0 = MOJO_HANDLE_INVALID;
39 sig = ~MOJO_HANDLE_SIGNAL_NONE; 48 sig = ~MOJO_HANDLE_SIGNAL_NONE;
40 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 49 EXPECT_EQ(
41 MojoWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE)); 50 MOJO_RESULT_INVALID_ARGUMENT,
51 MojoNewWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE, NULL, NULL));
42 52
43 // Message pipe: 53 // Message pipe:
44 EXPECT_EQ( 54 EXPECT_EQ(
45 MOJO_RESULT_INVALID_ARGUMENT, 55 MOJO_RESULT_INVALID_ARGUMENT,
46 MojoWriteMessage(h0, buffer, 3, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 56 MojoWriteMessage(h0, buffer, 3, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
47 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 57 buffer_size = static_cast<uint32_t>(sizeof(buffer));
48 EXPECT_EQ( 58 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
49 MOJO_RESULT_INVALID_ARGUMENT, 59 MojoReadMessage(h0, buffer, &buffer_size, NULL, NULL,
50 MojoReadMessage( 60 MOJO_READ_MESSAGE_FLAG_NONE));
51 h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
52 61
53 // Data pipe: 62 // Data pipe:
54 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 63 buffer_size = static_cast<uint32_t>(sizeof(buffer));
55 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 64 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
56 MojoWriteData(h0, buffer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE)); 65 MojoWriteData(h0, buffer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
57 write_pointer = NULL; 66 write_pointer = NULL;
58 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 67 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
59 MojoBeginWriteData( 68 MojoBeginWriteData(h0, &write_pointer, &buffer_size,
60 h0, &write_pointer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE)); 69 MOJO_WRITE_DATA_FLAG_NONE));
61 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1)); 70 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1));
62 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 71 buffer_size = static_cast<uint32_t>(sizeof(buffer));
63 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 72 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
64 MojoReadData(h0, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); 73 MojoReadData(h0, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
65 read_pointer = NULL; 74 read_pointer = NULL;
66 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 75 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
67 MojoBeginReadData( 76 MojoBeginReadData(h0, &read_pointer, &buffer_size,
68 h0, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); 77 MOJO_READ_DATA_FLAG_NONE));
69 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1)); 78 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1));
70 79
71 // Shared buffer: 80 // Shared buffer:
72 h1 = MOJO_HANDLE_INVALID; 81 h1 = MOJO_HANDLE_INVALID;
73 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 82 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
74 MojoDuplicateBufferHandle(h0, NULL, &h1)); 83 MojoDuplicateBufferHandle(h0, NULL, &h1));
75 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 84 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
76 MojoMapBuffer(h0, 0, 1, &write_pointer, MOJO_MAP_BUFFER_FLAG_NONE)); 85 MojoMapBuffer(h0, 0, 1, &write_pointer, MOJO_MAP_BUFFER_FLAG_NONE));
77 } 86 }
78 87
79 TEST(CoreTest, BasicMessagePipe) { 88 TEST(CoreTest, BasicMessagePipe) {
80 MojoHandle h0, h1; 89 MojoHandle h0, h1;
81 MojoHandleSignals sig; 90 MojoHandleSignals sig;
82 char buffer[10] = {0}; 91 char buffer[10] = {0};
83 uint32_t buffer_size; 92 uint32_t buffer_size;
84 93
85 h0 = MOJO_HANDLE_INVALID; 94 h0 = MOJO_HANDLE_INVALID;
86 h1 = MOJO_HANDLE_INVALID; 95 h1 = MOJO_HANDLE_INVALID;
87 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &h0, &h1)); 96 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &h0, &h1));
88 EXPECT_NE(h0, MOJO_HANDLE_INVALID); 97 EXPECT_NE(h0, MOJO_HANDLE_INVALID);
89 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 98 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
90 99
91 // Shouldn't be readable. 100 // Shouldn't be readable, we haven't written anything.
101 MojoHandleSignalsState state;
92 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 102 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
93 MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, 0)); 103 MojoNewWait(h0, MOJO_HANDLE_SIGNAL_READABLE, 0, &state));
104 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
105 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
94 106
95 // Should be writable. 107 // Should be writable.
96 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h0, MOJO_HANDLE_SIGNAL_WRITABLE, 0)); 108 EXPECT_EQ(MOJO_RESULT_OK,
109 MojoNewWait(h0, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &state));
110 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
111 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
97 112
98 // Try to read. 113 // Try to read.
99 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 114 buffer_size = static_cast<uint32_t>(sizeof(buffer));
100 EXPECT_EQ( 115 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
101 MOJO_RESULT_SHOULD_WAIT, 116 MojoReadMessage(h0, buffer, &buffer_size, NULL, NULL,
102 MojoReadMessage( 117 MOJO_READ_MESSAGE_FLAG_NONE));
103 h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
104 118
105 // Write to |h1|. 119 // Write to |h1|.
106 static const char kHello[] = "hello"; 120 static const char kHello[] = "hello";
107 buffer_size = static_cast<uint32_t>(sizeof(kHello)); 121 buffer_size = static_cast<uint32_t>(sizeof(kHello));
108 EXPECT_EQ( 122 EXPECT_EQ(MOJO_RESULT_OK, MojoWriteMessage(h1, kHello, buffer_size, NULL, 0,
109 MOJO_RESULT_OK, 123 MOJO_WRITE_MESSAGE_FLAG_NONE));
110 MojoWriteMessage(
111 h1, kHello, buffer_size, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
112 124
113 // |h0| should be readable. 125 // |h0| should be readable.
126 uint32_t result_index = 1;
127 MojoHandleSignalsState states[1];
114 sig = MOJO_HANDLE_SIGNAL_READABLE; 128 sig = MOJO_HANDLE_SIGNAL_READABLE;
115 EXPECT_EQ(MOJO_RESULT_OK, 129 EXPECT_EQ(MOJO_RESULT_OK,
116 MojoWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE)); 130 MojoNewWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE,
131 &result_index, states));
132
133 EXPECT_EQ(0u, result_index);
134 EXPECT_EQ(kSignalReadadableWritable, states[0].satisfied_signals);
135 EXPECT_EQ(kSignalAll, states[0].satisfiable_signals);
117 136
118 // Read from |h0|. 137 // Read from |h0|.
119 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 138 buffer_size = static_cast<uint32_t>(sizeof(buffer));
120 EXPECT_EQ( 139 EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(h0, buffer, &buffer_size, NULL,
121 MOJO_RESULT_OK, 140 NULL, MOJO_READ_MESSAGE_FLAG_NONE));
122 MojoReadMessage(
123 h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
124 EXPECT_EQ(static_cast<uint32_t>(sizeof(kHello)), buffer_size); 141 EXPECT_EQ(static_cast<uint32_t>(sizeof(kHello)), buffer_size);
125 EXPECT_STREQ(kHello, buffer); 142 EXPECT_STREQ(kHello, buffer);
126 143
127 // |h0| should no longer be readable. 144 // |h0| should no longer be readable.
128 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 145 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
129 MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, 10)); 146 MojoNewWait(h0, MOJO_HANDLE_SIGNAL_READABLE, 10, &state));
147
148 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
149 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
130 150
131 // Close |h0|. 151 // Close |h0|.
132 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0)); 152 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0));
133 153
134 // |h1| should no longer be readable or writable. 154 // |h1| should no longer be readable or writable.
135 EXPECT_EQ( 155 EXPECT_EQ(
136 MOJO_RESULT_FAILED_PRECONDITION, 156 MOJO_RESULT_FAILED_PRECONDITION,
137 MojoWait( 157 MojoNewWait(h1, MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
138 h1, MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1000)); 158 1000, &state));
159
160 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals);
161 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfiable_signals);
139 162
140 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); 163 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1));
141 } 164 }
142 165
143 // TODO(ncbray): enable these tests once NaCl supports the corresponding APIs. 166 // TODO(ncbray): enable these tests once NaCl supports the corresponding APIs.
144 #ifdef __native_client__ 167 #ifdef __native_client__
145 #define MAYBE_BasicDataPipe DISABLED_BasicDataPipe 168 #define MAYBE_BasicDataPipe DISABLED_BasicDataPipe
146 #define MAYBE_BasicSharedBuffer DISABLED_BasicSharedBuffer 169 #define MAYBE_BasicSharedBuffer DISABLED_BasicSharedBuffer
147 #else 170 #else
148 #define MAYBE_BasicDataPipe BasicDataPipe 171 #define MAYBE_BasicDataPipe BasicDataPipe
149 #define MAYBE_BasicSharedBuffer BasicSharedBuffer 172 #define MAYBE_BasicSharedBuffer BasicSharedBuffer
150 #endif 173 #endif
151 174
152 TEST(CoreTest, MAYBE_BasicDataPipe) { 175 TEST(CoreTest, MAYBE_BasicDataPipe) {
153 MojoHandle hp, hc; 176 MojoHandle hp, hc;
154 MojoHandleSignals sig; 177 MojoHandleSignals sig;
155 char buffer[20] = {0}; 178 char buffer[20] = {0};
156 uint32_t buffer_size; 179 uint32_t buffer_size;
157 void* write_pointer; 180 void* write_pointer;
158 const void* read_pointer; 181 const void* read_pointer;
159 182
160 hp = MOJO_HANDLE_INVALID; 183 hp = MOJO_HANDLE_INVALID;
161 hc = MOJO_HANDLE_INVALID; 184 hc = MOJO_HANDLE_INVALID;
162 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(NULL, &hp, &hc)); 185 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(NULL, &hp, &hc));
163 EXPECT_NE(hp, MOJO_HANDLE_INVALID); 186 EXPECT_NE(hp, MOJO_HANDLE_INVALID);
164 EXPECT_NE(hc, MOJO_HANDLE_INVALID); 187 EXPECT_NE(hc, MOJO_HANDLE_INVALID);
165 188
166 // The consumer |hc| shouldn't be readable. 189 // The consumer |hc| shouldn't be readable.
190 MojoHandleSignalsState state;
167 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 191 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
168 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0)); 192 MojoNewWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state));
193
194 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, state.satisfied_signals);
195 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
196 state.satisfiable_signals);
169 197
170 // The producer |hp| should be writable. 198 // The producer |hp| should be writable.
171 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(hp, MOJO_HANDLE_SIGNAL_WRITABLE, 0)); 199 EXPECT_EQ(MOJO_RESULT_OK,
200 MojoNewWait(hp, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &state));
201
202 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
203 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
204 state.satisfiable_signals);
172 205
173 // Try to read from |hc|. 206 // Try to read from |hc|.
174 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 207 buffer_size = static_cast<uint32_t>(sizeof(buffer));
175 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 208 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
176 MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); 209 MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
177 210
178 // Try to begin a two-phase read from |hc|. 211 // Try to begin a two-phase read from |hc|.
179 read_pointer = NULL; 212 read_pointer = NULL;
180 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 213 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
181 MojoBeginReadData( 214 MojoBeginReadData(hc, &read_pointer, &buffer_size,
182 hc, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); 215 MOJO_READ_DATA_FLAG_NONE));
183 216
184 // Write to |hp|. 217 // Write to |hp|.
185 static const char kHello[] = "hello "; 218 static const char kHello[] = "hello ";
186 // Don't include terminating null. 219 // Don't include terminating null.
187 buffer_size = static_cast<uint32_t>(strlen(kHello)); 220 buffer_size = static_cast<uint32_t>(strlen(kHello));
188 EXPECT_EQ( 221 EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(hp, kHello, &buffer_size,
189 MOJO_RESULT_OK, 222 MOJO_WRITE_MESSAGE_FLAG_NONE));
190 MojoWriteData(hp, kHello, &buffer_size, MOJO_WRITE_MESSAGE_FLAG_NONE));
191 223
192 // |hc| should be(come) readable. 224 // |hc| should be(come) readable.
225 uint32_t result_index = 1;
226 MojoHandleSignalsState states[1];
193 sig = MOJO_HANDLE_SIGNAL_READABLE; 227 sig = MOJO_HANDLE_SIGNAL_READABLE;
194 EXPECT_EQ(MOJO_RESULT_OK, 228 EXPECT_EQ(MOJO_RESULT_OK,
195 MojoWaitMany(&hc, &sig, 1, MOJO_DEADLINE_INDEFINITE)); 229 MojoNewWaitMany(&hc, &sig, 1, MOJO_DEADLINE_INDEFINITE,
230 &result_index, states));
231
232 EXPECT_EQ(0u, result_index);
233 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, states[0].satisfied_signals);
234 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
235 states[0].satisfiable_signals);
196 236
197 // Do a two-phase write to |hp|. 237 // Do a two-phase write to |hp|.
198 EXPECT_EQ(MOJO_RESULT_OK, 238 EXPECT_EQ(MOJO_RESULT_OK, MojoBeginWriteData(hp, &write_pointer, &buffer_size,
199 MojoBeginWriteData( 239 MOJO_WRITE_DATA_FLAG_NONE));
200 hp, &write_pointer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
201 static const char kWorld[] = "world"; 240 static const char kWorld[] = "world";
202 ASSERT_GE(buffer_size, sizeof(kWorld)); 241 ASSERT_GE(buffer_size, sizeof(kWorld));
203 // Include the terminating null. 242 // Include the terminating null.
204 memcpy(write_pointer, kWorld, sizeof(kWorld)); 243 memcpy(write_pointer, kWorld, sizeof(kWorld));
205 EXPECT_EQ(MOJO_RESULT_OK, 244 EXPECT_EQ(MOJO_RESULT_OK,
206 MojoEndWriteData(hp, static_cast<uint32_t>(sizeof(kWorld)))); 245 MojoEndWriteData(hp, static_cast<uint32_t>(sizeof(kWorld))));
207 246
208 // Read one character from |hc|. 247 // Read one character from |hc|.
209 memset(buffer, 0, sizeof(buffer)); 248 memset(buffer, 0, sizeof(buffer));
210 buffer_size = 1; 249 buffer_size = 1;
211 EXPECT_EQ(MOJO_RESULT_OK, 250 EXPECT_EQ(MOJO_RESULT_OK,
212 MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); 251 MojoReadData(hc, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
213 252
214 // Close |hp|. 253 // Close |hp|.
215 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp)); 254 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp));
216 255
217 // |hc| should still be readable. 256 // |hc| should still be readable.
218 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0)); 257 EXPECT_EQ(MOJO_RESULT_OK,
258 MojoNewWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state));
259
260 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
261 state.satisfied_signals);
262 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
263 state.satisfiable_signals);
219 264
220 // Do a two-phase read from |hc|. 265 // Do a two-phase read from |hc|.
221 read_pointer = NULL; 266 read_pointer = NULL;
222 EXPECT_EQ(MOJO_RESULT_OK, 267 EXPECT_EQ(MOJO_RESULT_OK, MojoBeginReadData(hc, &read_pointer, &buffer_size,
223 MojoBeginReadData( 268 MOJO_READ_DATA_FLAG_NONE));
224 hc, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
225 ASSERT_LE(buffer_size, sizeof(buffer) - 1); 269 ASSERT_LE(buffer_size, sizeof(buffer) - 1);
226 memcpy(&buffer[1], read_pointer, buffer_size); 270 memcpy(&buffer[1], read_pointer, buffer_size);
227 EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size)); 271 EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size));
228 EXPECT_STREQ("hello world", buffer); 272 EXPECT_STREQ("hello world", buffer);
229 273
230 // |hc| should no longer be readable. 274 // |hc| should no longer be readable.
231 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 275 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
232 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 1000)); 276 MojoNewWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 1000, &state));
277
278 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals);
279 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfiable_signals);
233 280
234 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); 281 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc));
235 282
236 // TODO(vtl): Test the other way around -- closing the consumer should make 283 // TODO(vtl): Test the other way around -- closing the consumer should make
237 // the producer never-writable? 284 // the producer never-writable?
238 } 285 }
239 286
240 TEST(CoreTest, MAYBE_BasicSharedBuffer) { 287 TEST(CoreTest, MAYBE_BasicSharedBuffer) {
241 MojoHandle h0, h1; 288 MojoHandle h0, h1;
242 void* pointer; 289 void* pointer;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // This checks that things actually work in C (not C++). 336 // This checks that things actually work in C (not C++).
290 TEST(CoreTest, MinimalCTest) { 337 TEST(CoreTest, MinimalCTest) {
291 const char* failure = MinimalCTest(); 338 const char* failure = MinimalCTest();
292 EXPECT_TRUE(failure == NULL) << failure; 339 EXPECT_TRUE(failure == NULL) << failure;
293 } 340 }
294 341
295 // TODO(vtl): Add multi-threaded tests. 342 // TODO(vtl): Add multi-threaded tests.
296 343
297 } // namespace 344 } // namespace
298 } // namespace mojo 345 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698