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 "mojo/public/c/system/core.h" | 7 #include "mojo/public/c/system/core.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &hp, &hc)); | 185 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &hp, &hc)); |
186 EXPECT_NE(hp, MOJO_HANDLE_INVALID); | 186 EXPECT_NE(hp, MOJO_HANDLE_INVALID); |
187 EXPECT_NE(hc, MOJO_HANDLE_INVALID); | 187 EXPECT_NE(hc, MOJO_HANDLE_INVALID); |
188 | 188 |
189 // The consumer |hc| shouldn't be readable. | 189 // The consumer |hc| shouldn't be readable. |
190 MojoHandleSignalsState state; | 190 MojoHandleSignalsState state; |
191 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, | 191 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, |
192 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state)); | 192 MojoWait(hc, MOJO_HANDLE_SIGNAL_READABLE, 0, &state)); |
193 | 193 |
194 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, state.satisfied_signals); | 194 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, state.satisfied_signals); |
195 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 195 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED | |
| 196 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, |
196 state.satisfiable_signals); | 197 state.satisfiable_signals); |
197 | 198 |
198 // The producer |hp| should be writable. | 199 // The producer |hp| should be writable. |
199 EXPECT_EQ(MOJO_RESULT_OK, | 200 EXPECT_EQ(MOJO_RESULT_OK, |
200 MojoWait(hp, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &state)); | 201 MojoWait(hp, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &state)); |
201 | 202 |
202 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals); | 203 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals); |
203 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 204 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
204 state.satisfiable_signals); | 205 state.satisfiable_signals); |
205 | 206 |
(...skipping 16 matching lines...) Expand all Loading... |
222 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 223 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
223 | 224 |
224 // |hc| should be(come) readable. | 225 // |hc| should be(come) readable. |
225 uint32_t result_index = 1; | 226 uint32_t result_index = 1; |
226 MojoHandleSignalsState states[1]; | 227 MojoHandleSignalsState states[1]; |
227 sig = MOJO_HANDLE_SIGNAL_READABLE; | 228 sig = MOJO_HANDLE_SIGNAL_READABLE; |
228 EXPECT_EQ(MOJO_RESULT_OK, MojoWaitMany(&hc, &sig, 1, MOJO_DEADLINE_INDEFINITE, | 229 EXPECT_EQ(MOJO_RESULT_OK, MojoWaitMany(&hc, &sig, 1, MOJO_DEADLINE_INDEFINITE, |
229 &result_index, states)); | 230 &result_index, states)); |
230 | 231 |
231 EXPECT_EQ(0u, result_index); | 232 EXPECT_EQ(0u, result_index); |
232 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, states[0].satisfied_signals); | 233 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, |
233 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 234 states[0].satisfied_signals); |
| 235 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED | |
| 236 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, |
234 states[0].satisfiable_signals); | 237 states[0].satisfiable_signals); |
235 | 238 |
236 // Do a two-phase write to |hp|. | 239 // Do a two-phase write to |hp|. |
237 EXPECT_EQ(MOJO_RESULT_OK, MojoBeginWriteData(hp, &write_pointer, &buffer_size, | 240 EXPECT_EQ(MOJO_RESULT_OK, MojoBeginWriteData(hp, &write_pointer, &buffer_size, |
238 MOJO_WRITE_DATA_FLAG_NONE)); | 241 MOJO_WRITE_DATA_FLAG_NONE)); |
239 static const char kWorld[] = "world"; | 242 static const char kWorld[] = "world"; |
240 ASSERT_GE(buffer_size, sizeof(kWorld)); | 243 ASSERT_GE(buffer_size, sizeof(kWorld)); |
241 // Include the terminating null. | 244 // Include the terminating null. |
242 memcpy(write_pointer, kWorld, sizeof(kWorld)); | 245 memcpy(write_pointer, kWorld, sizeof(kWorld)); |
243 EXPECT_EQ(MOJO_RESULT_OK, | 246 EXPECT_EQ(MOJO_RESULT_OK, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // This checks that things actually work in C (not C++). | 339 // This checks that things actually work in C (not C++). |
337 TEST(CoreTest, MinimalCTest) { | 340 TEST(CoreTest, MinimalCTest) { |
338 const char* failure = MinimalCTest(); | 341 const char* failure = MinimalCTest(); |
339 EXPECT_FALSE(failure) << failure; | 342 EXPECT_FALSE(failure) << failure; |
340 } | 343 } |
341 | 344 |
342 // TODO(vtl): Add multi-threaded tests. | 345 // TODO(vtl): Add multi-threaded tests. |
343 | 346 |
344 } // namespace | 347 } // namespace |
345 } // namespace mojo | 348 } // namespace mojo |
OLD | NEW |