OLD | NEW |
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++ Mojo system core wrappers. | 5 // This file tests the C++ Mojo system core wrappers. |
6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets | 6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets |
7 // compiled into a different binary from the C API tests. | 7 // compiled into a different binary from the C API tests. |
8 | 8 |
9 #include "mojo/public/cpp/system/core.h" | 9 #include "mojo/public/cpp/system/core.h" |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 MOJO_READ_MESSAGE_FLAG_NONE)); | 146 MOJO_READ_MESSAGE_FLAG_NONE)); |
147 | 147 |
148 // Basic tests of waiting and closing. | 148 // Basic tests of waiting and closing. |
149 MojoHandle hv0 = kInvalidHandleValue; | 149 MojoHandle hv0 = kInvalidHandleValue; |
150 { | 150 { |
151 ScopedMessagePipeHandle h0; | 151 ScopedMessagePipeHandle h0; |
152 ScopedMessagePipeHandle h1; | 152 ScopedMessagePipeHandle h1; |
153 EXPECT_FALSE(h0.get().is_valid()); | 153 EXPECT_FALSE(h0.get().is_valid()); |
154 EXPECT_FALSE(h1.get().is_valid()); | 154 EXPECT_FALSE(h1.get().is_valid()); |
155 | 155 |
156 CreateMessagePipe(&h0, &h1); | 156 CreateMessagePipe(NULL, &h0, &h1); |
157 EXPECT_TRUE(h0.get().is_valid()); | 157 EXPECT_TRUE(h0.get().is_valid()); |
158 EXPECT_TRUE(h1.get().is_valid()); | 158 EXPECT_TRUE(h1.get().is_valid()); |
159 EXPECT_NE(h0.get().value(), h1.get().value()); | 159 EXPECT_NE(h0.get().value(), h1.get().value()); |
160 // Save the handle values, so we can check that things got closed | 160 // Save the handle values, so we can check that things got closed |
161 // correctly. | 161 // correctly. |
162 hv0 = h0.get().value(); | 162 hv0 = h0.get().value(); |
163 MojoHandle hv1 = h1.get().value(); | 163 MojoHandle hv1 = h1.get().value(); |
164 | 164 |
165 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, | 165 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, |
166 Wait(h0.get(), MOJO_WAIT_FLAG_READABLE, 0)); | 166 Wait(h0.get(), MOJO_WAIT_FLAG_READABLE, 0)); |
(...skipping 19 matching lines...) Expand all Loading... |
186 MOJO_DEADLINE_INDEFINITE)); | 186 MOJO_DEADLINE_INDEFINITE)); |
187 } | 187 } |
188 // |hv0| should have been closed when |h0| went out of scope, so this close | 188 // |hv0| should have been closed when |h0| went out of scope, so this close |
189 // should fail. | 189 // should fail. |
190 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(hv0)); | 190 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(hv0)); |
191 | 191 |
192 // Actually test writing/reading messages. | 192 // Actually test writing/reading messages. |
193 { | 193 { |
194 ScopedMessagePipeHandle h0; | 194 ScopedMessagePipeHandle h0; |
195 ScopedMessagePipeHandle h1; | 195 ScopedMessagePipeHandle h1; |
196 CreateMessagePipe(&h0, &h1); | 196 CreateMessagePipe(NULL, &h0, &h1); |
197 | 197 |
198 const char kHello[] = "hello"; | 198 const char kHello[] = "hello"; |
199 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); | 199 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); |
200 EXPECT_EQ(MOJO_RESULT_OK, | 200 EXPECT_EQ(MOJO_RESULT_OK, |
201 WriteMessageRaw(h0.get(), | 201 WriteMessageRaw(h0.get(), |
202 kHello, kHelloSize, | 202 kHello, kHelloSize, |
203 NULL, 0, | 203 NULL, 0, |
204 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 204 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
205 EXPECT_EQ(MOJO_RESULT_OK, | 205 EXPECT_EQ(MOJO_RESULT_OK, |
206 Wait(h1.get(), MOJO_WAIT_FLAG_READABLE, | 206 Wait(h1.get(), MOJO_WAIT_FLAG_READABLE, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // TODO(vtl): Test |CloseRaw()|. | 289 // TODO(vtl): Test |CloseRaw()|. |
290 // TODO(vtl): Test |reset()| more thoroughly? | 290 // TODO(vtl): Test |reset()| more thoroughly? |
291 } | 291 } |
292 | 292 |
293 TEST(CoreCppTest, TearDownWithMessagesEnqueued) { | 293 TEST(CoreCppTest, TearDownWithMessagesEnqueued) { |
294 // Tear down a message pipe which still has a message enqueued, with the | 294 // Tear down a message pipe which still has a message enqueued, with the |
295 // message also having a valid message pipe handle. | 295 // message also having a valid message pipe handle. |
296 { | 296 { |
297 ScopedMessagePipeHandle h0; | 297 ScopedMessagePipeHandle h0; |
298 ScopedMessagePipeHandle h1; | 298 ScopedMessagePipeHandle h1; |
299 CreateMessagePipe(&h0, &h1); | 299 CreateMessagePipe(NULL, &h0, &h1); |
300 | 300 |
301 // Send a handle over the previously-establish message pipe. | 301 // Send a handle over the previously-establish message pipe. |
302 ScopedMessagePipeHandle h2; | 302 ScopedMessagePipeHandle h2; |
303 ScopedMessagePipeHandle h3; | 303 ScopedMessagePipeHandle h3; |
304 CreateMessagePipe(&h2, &h3); | 304 CreateMessagePipe(NULL, &h2, &h3); |
305 | 305 |
306 // Write a message to |h2|, before we send |h3|. | 306 // Write a message to |h2|, before we send |h3|. |
307 const char kWorld[] = "world!"; | 307 const char kWorld[] = "world!"; |
308 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); | 308 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); |
309 EXPECT_EQ(MOJO_RESULT_OK, | 309 EXPECT_EQ(MOJO_RESULT_OK, |
310 WriteMessageRaw(h2.get(), | 310 WriteMessageRaw(h2.get(), |
311 kWorld, kWorldSize, | 311 kWorld, kWorldSize, |
312 NULL, 0, | 312 NULL, 0, |
313 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 313 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
314 // And also a message to |h3|. | 314 // And also a message to |h3|. |
(...skipping 21 matching lines...) Expand all Loading... |
336 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); | 336 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); |
337 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); | 337 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); |
338 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); | 338 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); |
339 } | 339 } |
340 | 340 |
341 // Do this in a different order: make the enqueued message pipe handle only | 341 // Do this in a different order: make the enqueued message pipe handle only |
342 // half-alive. | 342 // half-alive. |
343 { | 343 { |
344 ScopedMessagePipeHandle h0; | 344 ScopedMessagePipeHandle h0; |
345 ScopedMessagePipeHandle h1; | 345 ScopedMessagePipeHandle h1; |
346 CreateMessagePipe(&h0, &h1); | 346 CreateMessagePipe(NULL, &h0, &h1); |
347 | 347 |
348 // Send a handle over the previously-establish message pipe. | 348 // Send a handle over the previously-establish message pipe. |
349 ScopedMessagePipeHandle h2; | 349 ScopedMessagePipeHandle h2; |
350 ScopedMessagePipeHandle h3; | 350 ScopedMessagePipeHandle h3; |
351 CreateMessagePipe(&h2, &h3); | 351 CreateMessagePipe(NULL, &h2, &h3); |
352 | 352 |
353 // Write a message to |h2|, before we send |h3|. | 353 // Write a message to |h2|, before we send |h3|. |
354 const char kWorld[] = "world!"; | 354 const char kWorld[] = "world!"; |
355 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); | 355 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); |
356 EXPECT_EQ(MOJO_RESULT_OK, | 356 EXPECT_EQ(MOJO_RESULT_OK, |
357 WriteMessageRaw(h2.get(), | 357 WriteMessageRaw(h2.get(), |
358 kWorld, kWorldSize, | 358 kWorld, kWorldSize, |
359 NULL, 0, | 359 NULL, 0, |
360 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 360 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
361 // And also a message to |h3|. | 361 // And also a message to |h3|. |
(...skipping 21 matching lines...) Expand all Loading... |
383 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); | 383 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); |
384 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); | 384 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); |
385 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); | 385 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); |
386 } | 386 } |
387 } | 387 } |
388 | 388 |
389 // TODO(vtl): Write data pipe tests. | 389 // TODO(vtl): Write data pipe tests. |
390 | 390 |
391 } // namespace | 391 } // namespace |
392 } // namespace mojo | 392 } // namespace mojo |
OLD | NEW |