| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 data pipe API (the functions declared in | 5 // This file tests the C data pipe API (the functions declared in |
| 6 // mojo/public/c/system/data_pipe.h). | 6 // mojo/public/c/system/data_pipe.h). |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "mojo/public/c/system/data_pipe.h" | 10 #include "mojo/public/c/system/data_pipe.h" |
| 11 #include "mojo/public/c/system/handle.h" | 11 #include "mojo/public/c/system/handle.h" |
| 12 #include "mojo/public/c/system/result.h" | 12 #include "mojo/public/c/system/result.h" |
| 13 #include "mojo/public/c/system/wait.h" | 13 #include "mojo/public/c/system/wait.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const MojoHandleRights kDefaultDataPipeProducerHandleRights = | 18 const MojoHandleRights kDefaultDataPipeProducerHandleRights = |
| 19 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_WRITE | | 19 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_WRITE | |
| 20 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS; | 20 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS; |
| 21 const MojoHandleRights kDefaultDataPipeConsumerHandleRights = | 21 const MojoHandleRights kDefaultDataPipeConsumerHandleRights = |
| 22 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ | | 22 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ | |
| 23 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS; | 23 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS; |
| 24 | 24 |
| 25 TEST(DataPipeTest, InvalidHandle) { | 25 TEST(DataPipeTest, InvalidHandle) { |
| 26 // Data pipe: | |
| 27 MojoDataPipeProducerOptions dpp_options = { | 26 MojoDataPipeProducerOptions dpp_options = { |
| 28 sizeof(MojoDataPipeProducerOptions), 0u}; | 27 sizeof(MojoDataPipeProducerOptions), 0u}; |
| 29 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 28 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 30 MojoSetDataPipeProducerOptions(MOJO_HANDLE_INVALID, &dpp_options)); | 29 MojoSetDataPipeProducerOptions(MOJO_HANDLE_INVALID, &dpp_options)); |
| 31 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 30 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 32 MojoGetDataPipeProducerOptions( | 31 MojoGetDataPipeProducerOptions( |
| 33 MOJO_HANDLE_INVALID, &dpp_options, | 32 MOJO_HANDLE_INVALID, &dpp_options, |
| 34 static_cast<uint32_t>(sizeof(dpp_options)))); | 33 static_cast<uint32_t>(sizeof(dpp_options)))); |
| 35 char buffer[10] = {}; | 34 char buffer[10] = {}; |
| 36 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 35 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 EXPECT_EQ(MOJO_RESULT_OK, | 436 EXPECT_EQ(MOJO_RESULT_OK, |
| 438 MojoWait(hc, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, nullptr)); | 437 MojoWait(hc, MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 0, nullptr)); |
| 439 | 438 |
| 440 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp)); | 439 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hp)); |
| 441 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); | 440 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(hc)); |
| 442 } | 441 } |
| 443 | 442 |
| 444 // TODO(vtl): Add multi-threaded tests. | 443 // TODO(vtl): Add multi-threaded tests. |
| 445 | 444 |
| 446 } // namespace | 445 } // namespace |
| OLD | NEW |