| 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 API. | 5 // This file tests the C API. |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "mojo/public/c/system/buffer.h" | 9 #include "mojo/public/c/system/buffer.h" |
| 10 #include "mojo/public/c/system/data_pipe.h" | 10 #include "mojo/public/c/system/data_pipe.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 67 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 68 MojoWriteData(MOJO_HANDLE_INVALID, buffer, &buffer_size, | 68 MojoWriteData(MOJO_HANDLE_INVALID, buffer, &buffer_size, |
| 69 MOJO_WRITE_DATA_FLAG_NONE)); | 69 MOJO_WRITE_DATA_FLAG_NONE)); |
| 70 write_pointer = nullptr; | 70 write_pointer = nullptr; |
| 71 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 71 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 72 MojoBeginWriteData(MOJO_HANDLE_INVALID, &write_pointer, | 72 MojoBeginWriteData(MOJO_HANDLE_INVALID, &write_pointer, |
| 73 &buffer_size, MOJO_WRITE_DATA_FLAG_NONE)); | 73 &buffer_size, MOJO_WRITE_DATA_FLAG_NONE)); |
| 74 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 74 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 75 MojoEndWriteData(MOJO_HANDLE_INVALID, 1u)); | 75 MojoEndWriteData(MOJO_HANDLE_INVALID, 1u)); |
| 76 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 76 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 77 // TODO(vtl): Enable once I've added support for NaCl. | |
| 78 #ifndef __native_client__ | |
| 79 MojoDataPipeConsumerOptions dpc_options = { | 77 MojoDataPipeConsumerOptions dpc_options = { |
| 80 sizeof(MojoDataPipeConsumerOptions), 0u}; | 78 sizeof(MojoDataPipeConsumerOptions), 0u}; |
| 81 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 79 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 82 MojoSetDataPipeConsumerOptions(MOJO_HANDLE_INVALID, &dpc_options)); | 80 MojoSetDataPipeConsumerOptions(MOJO_HANDLE_INVALID, &dpc_options)); |
| 83 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 81 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 84 MojoGetDataPipeConsumerOptions( | 82 MojoGetDataPipeConsumerOptions( |
| 85 MOJO_HANDLE_INVALID, &dpc_options, | 83 MOJO_HANDLE_INVALID, &dpc_options, |
| 86 static_cast<uint32_t>(sizeof(dpc_options)))); | 84 static_cast<uint32_t>(sizeof(dpc_options)))); |
| 87 #endif | |
| 88 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 85 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 89 MojoReadData(MOJO_HANDLE_INVALID, buffer, &buffer_size, | 86 MojoReadData(MOJO_HANDLE_INVALID, buffer, &buffer_size, |
| 90 MOJO_READ_DATA_FLAG_NONE)); | 87 MOJO_READ_DATA_FLAG_NONE)); |
| 91 read_pointer = nullptr; | 88 read_pointer = nullptr; |
| 92 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 89 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 93 MojoBeginReadData(MOJO_HANDLE_INVALID, &read_pointer, &buffer_size, | 90 MojoBeginReadData(MOJO_HANDLE_INVALID, &read_pointer, &buffer_size, |
| 94 MOJO_READ_DATA_FLAG_NONE)); | 91 MOJO_READ_DATA_FLAG_NONE)); |
| 95 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 92 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 96 MojoEndReadData(MOJO_HANDLE_INVALID, 1u)); | 93 MojoEndReadData(MOJO_HANDLE_INVALID, 1u)); |
| 97 | 94 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 1000, &state)); | 308 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 1000, &state)); |
| 312 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals); | 309 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals); |
| 313 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfiable_signals); | 310 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfiable_signals); |
| 314 | 311 |
| 315 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); | 312 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); |
| 316 | 313 |
| 317 // TODO(vtl): Test the other way around -- closing the consumer should make | 314 // TODO(vtl): Test the other way around -- closing the consumer should make |
| 318 // the producer never-writable? | 315 // the producer never-writable? |
| 319 } | 316 } |
| 320 | 317 |
| 321 // TODO(vtl): Enable once I've added support for NaCl. | |
| 322 #ifndef __native_client__ | |
| 323 TEST(CoreTest, DataPipeReadThreshold) { | 318 TEST(CoreTest, DataPipeReadThreshold) { |
| 324 MojoHandle hp = MOJO_HANDLE_INVALID; | 319 MojoHandle hp = MOJO_HANDLE_INVALID; |
| 325 MojoHandle hc = MOJO_HANDLE_INVALID; | 320 MojoHandle hc = MOJO_HANDLE_INVALID; |
| 326 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &hp, &hc)); | 321 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &hp, &hc)); |
| 327 EXPECT_NE(hp, MOJO_HANDLE_INVALID); | 322 EXPECT_NE(hp, MOJO_HANDLE_INVALID); |
| 328 EXPECT_NE(hc, MOJO_HANDLE_INVALID); | 323 EXPECT_NE(hc, MOJO_HANDLE_INVALID); |
| 329 | 324 |
| 330 MojoDataPipeConsumerOptions copts; | 325 MojoDataPipeConsumerOptions copts; |
| 331 static const uint32_t kCoptsSize = static_cast<uint32_t>(sizeof(copts)); | 326 static const uint32_t kCoptsSize = static_cast<uint32_t>(sizeof(copts)); |
| 332 | 327 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 copts.read_threshold_num_bytes = 2u; | 407 copts.read_threshold_num_bytes = 2u; |
| 413 EXPECT_EQ(MOJO_RESULT_OK, MojoSetDataPipeConsumerOptions(hc, &copts)); | 408 EXPECT_EQ(MOJO_RESULT_OK, MojoSetDataPipeConsumerOptions(hc, &copts)); |
| 414 | 409 |
| 415 // Should have the read threshold signal again. | 410 // Should have the read threshold signal again. |
| 416 EXPECT_EQ(MOJO_RESULT_OK, | 411 EXPECT_EQ(MOJO_RESULT_OK, |
| 417 MojoWait(hc, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, nullptr)); | 412 MojoWait(hc, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, nullptr)); |
| 418 | 413 |
| 419 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp)); | 414 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp)); |
| 420 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); | 415 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); |
| 421 } | 416 } |
| 422 #endif | |
| 423 | 417 |
| 424 // TODO(ncbray): enable this test once NaCl supports the corresponding APIs. | 418 // TODO(ncbray): enable this test once NaCl supports the corresponding APIs. |
| 425 #ifdef __native_client__ | 419 #ifdef __native_client__ |
| 426 #define MAYBE_BasicSharedBuffer DISABLED_BasicSharedBuffer | 420 #define MAYBE_BasicSharedBuffer DISABLED_BasicSharedBuffer |
| 427 #else | 421 #else |
| 428 #define MAYBE_BasicSharedBuffer BasicSharedBuffer | 422 #define MAYBE_BasicSharedBuffer BasicSharedBuffer |
| 429 #endif | 423 #endif |
| 430 TEST(CoreTest, MAYBE_BasicSharedBuffer) { | 424 TEST(CoreTest, MAYBE_BasicSharedBuffer) { |
| 431 MojoHandle h0, h1; | 425 MojoHandle h0, h1; |
| 432 void* pointer; | 426 void* pointer; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 490 |
| 497 TEST(CoreTest, MinimalCppTest) { | 491 TEST(CoreTest, MinimalCppTest) { |
| 498 const char* failure = MinimalCppTest(); | 492 const char* failure = MinimalCppTest(); |
| 499 EXPECT_FALSE(failure) << failure; | 493 EXPECT_FALSE(failure) << failure; |
| 500 } | 494 } |
| 501 | 495 |
| 502 // TODO(vtl): Add multi-threaded tests. | 496 // TODO(vtl): Add multi-threaded tests. |
| 503 | 497 |
| 504 } // namespace | 498 } // namespace |
| 505 } // namespace mojo | 499 } // namespace mojo |
| OLD | NEW |