| 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 #include "mojo/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 990 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
| 991 | 991 |
| 992 // Try a two-phase read of the remaining two bytes with peek. Should fail. | 992 // Try a two-phase read of the remaining two bytes with peek. Should fail. |
| 993 const void* read_ptr = nullptr; | 993 const void* read_ptr = nullptr; |
| 994 num_bytes = 2; | 994 num_bytes = 2; |
| 995 ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 995 ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 996 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), | 996 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), |
| 997 MakeUserPointer(&num_bytes), | 997 MakeUserPointer(&num_bytes), |
| 998 MOJO_READ_DATA_FLAG_PEEK)); | 998 MOJO_READ_DATA_FLAG_PEEK)); |
| 999 | 999 |
| 1000 // Read the remaining two characters, in two-phase mode (all-or-none). | 1000 // Read the remaining two characters, in two-phase mode. |
| 1001 num_bytes = 2; | 1001 num_bytes = 2; |
| 1002 ASSERT_EQ(MOJO_RESULT_OK, | 1002 ASSERT_EQ(MOJO_RESULT_OK, |
| 1003 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), | 1003 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), |
| 1004 MakeUserPointer(&num_bytes), | 1004 MakeUserPointer(&num_bytes), |
| 1005 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 1005 MOJO_READ_DATA_FLAG_NONE)); |
| 1006 // Note: Count on still being able to do the contiguous read here. | 1006 // Note: Count on still being able to do the contiguous read here. |
| 1007 ASSERT_EQ(2u, num_bytes); | 1007 ASSERT_EQ(2u, num_bytes); |
| 1008 | 1008 |
| 1009 // Discarding right now should fail. | 1009 // Discarding right now should fail. |
| 1010 num_bytes = 1; | 1010 num_bytes = 1; |
| 1011 EXPECT_EQ(MOJO_RESULT_BUSY, | 1011 EXPECT_EQ(MOJO_RESULT_BUSY, |
| 1012 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), | 1012 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), |
| 1013 MOJO_READ_DATA_FLAG_DISCARD)); | 1013 MOJO_READ_DATA_FLAG_DISCARD)); |
| 1014 | 1014 |
| 1015 // Actually check our data and end the two-phase read. | 1015 // Actually check our data and end the two-phase read. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); | 1229 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); |
| 1230 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1230 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 1231 hss.satisfiable_signals); | 1231 hss.satisfiable_signals); |
| 1232 | 1232 |
| 1233 // Make sure that |ch| can't be sent if it's in a two-phase read. | 1233 // Make sure that |ch| can't be sent if it's in a two-phase read. |
| 1234 const void* read_ptr = nullptr; | 1234 const void* read_ptr = nullptr; |
| 1235 num_bytes = 1; | 1235 num_bytes = 1; |
| 1236 ASSERT_EQ(MOJO_RESULT_OK, | 1236 ASSERT_EQ(MOJO_RESULT_OK, |
| 1237 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), | 1237 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), |
| 1238 MakeUserPointer(&num_bytes), | 1238 MakeUserPointer(&num_bytes), |
| 1239 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 1239 MOJO_READ_DATA_FLAG_NONE)); |
| 1240 EXPECT_EQ(MOJO_RESULT_BUSY, | 1240 EXPECT_EQ(MOJO_RESULT_BUSY, |
| 1241 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), | 1241 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), |
| 1242 kHelloSize, MakeUserPointer(&ch), 1, | 1242 kHelloSize, MakeUserPointer(&ch), 1, |
| 1243 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1243 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 1244 | 1244 |
| 1245 // But |ph| can, even if |ch| is in a two-phase read. | 1245 // But |ph| can, even if |ch| is in a two-phase read. |
| 1246 EXPECT_EQ(MOJO_RESULT_OK, | 1246 EXPECT_EQ(MOJO_RESULT_OK, |
| 1247 core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld), | 1247 core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld), |
| 1248 kWorldSize, MakeUserPointer(&ph), 1, | 1248 kWorldSize, MakeUserPointer(&ph), 1, |
| 1249 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1249 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); | 1308 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); |
| 1309 | 1309 |
| 1310 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); | 1310 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); |
| 1311 } | 1311 } |
| 1312 | 1312 |
| 1313 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. | 1313 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. |
| 1314 | 1314 |
| 1315 } // namespace | 1315 } // namespace |
| 1316 } // namespace system | 1316 } // namespace system |
| 1317 } // namespace mojo | 1317 } // namespace mojo |
| OLD | NEW |