Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: mojo/public/c/system/tests/core_unittest_pure_c.c

Issue 2744943002: Mojo: Move waiting APIs to public library (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/system/tests/core_unittest.cc ('k') | mojo/public/c/system/thunks.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifdef __cplusplus 5 #ifdef __cplusplus
6 #error "This file should be compiled as C, not C++." 6 #error "This file should be compiled as C, not C++."
7 #endif 7 #endif
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 24 matching lines...) Expand all
35 35
36 // This function exists mainly to be compiled and linked. We do some cursory 36 // This function exists mainly to be compiled and linked. We do some cursory
37 // checks and call it from a unit test, to make sure that link problems aren't 37 // checks and call it from a unit test, to make sure that link problems aren't
38 // missed due to deadstripping. Returns null on success and a string on failure 38 // missed due to deadstripping. Returns null on success and a string on failure
39 // (describing the failure). 39 // (describing the failure).
40 const char* MinimalCTest(void) { 40 const char* MinimalCTest(void) {
41 // MSVS before 2013 *really* only supports C90: All variables must be declared 41 // MSVS before 2013 *really* only supports C90: All variables must be declared
42 // at the top. (MSVS 2013 is more reasonable.) 42 // at the top. (MSVS 2013 is more reasonable.)
43 MojoTimeTicks ticks; 43 MojoTimeTicks ticks;
44 MojoHandle handle0, handle1; 44 MojoHandle handle0, handle1;
45 MojoHandleSignals signals;
46 const char kHello[] = "hello"; 45 const char kHello[] = "hello";
47 char buffer[200] = {0}; 46 char buffer[200] = {0};
48 uint32_t num_bytes; 47 uint32_t num_bytes;
49 48
50 ticks = MojoGetTimeTicksNow(); 49 ticks = MojoGetTimeTicksNow();
51 EXPECT_NE(ticks, 0); 50 EXPECT_NE(ticks, 0);
52 51
53 handle0 = MOJO_HANDLE_INVALID; 52 handle0 = MOJO_HANDLE_INVALID;
54 EXPECT_NE(MOJO_RESULT_OK, MojoClose(handle0)); 53 EXPECT_NE(MOJO_RESULT_OK, MojoClose(handle0));
55 54
56 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 55 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
57 MojoQueryHandleSignalsState(handle0, NULL)); 56 MojoQueryHandleSignalsState(handle0, NULL));
58 57
59 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
60 MojoWait(handle0, ~MOJO_HANDLE_SIGNAL_NONE,
61 MOJO_DEADLINE_INDEFINITE, NULL));
62
63 handle1 = MOJO_HANDLE_INVALID; 58 handle1 = MOJO_HANDLE_INVALID;
64 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &handle0, &handle1)); 59 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &handle0, &handle1));
65 60
66 signals = MOJO_HANDLE_SIGNAL_READABLE;
67 uint32_t result_index = 123;
68 struct MojoHandleSignalsState states[1];
69 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
70 MojoWaitMany(&handle0, &signals, 1, 1, &result_index, states));
71
72 // "Deadline exceeded" doesn't apply to a single handle, so this should leave
73 // |result_index| untouched.
74 EXPECT_EQ(123u, result_index);
75 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, states[0].satisfied_signals);
76 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
77 MOJO_HANDLE_SIGNAL_PEER_CLOSED,
78 states[0].satisfiable_signals);
79
80 EXPECT_EQ(MOJO_RESULT_OK, 61 EXPECT_EQ(MOJO_RESULT_OK,
81 MojoWriteMessage(handle0, kHello, (uint32_t)sizeof(kHello), NULL, 62 MojoWriteMessage(handle0, kHello, (uint32_t)sizeof(kHello), NULL,
82 0u, MOJO_WRITE_DATA_FLAG_NONE)); 63 0u, MOJO_WRITE_DATA_FLAG_NONE));
83 64
84 struct MojoHandleSignalsState state;
85 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(handle1, MOJO_HANDLE_SIGNAL_READABLE,
86 MOJO_DEADLINE_INDEFINITE, &state));
87
88 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
89 state.satisfied_signals);
90 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
91 MOJO_HANDLE_SIGNAL_PEER_CLOSED,
92 state.satisfiable_signals);
93
94 num_bytes = (uint32_t)sizeof(buffer); 65 num_bytes = (uint32_t)sizeof(buffer);
95 EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(handle1, buffer, &num_bytes, NULL, 66 EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(handle1, buffer, &num_bytes, NULL,
96 NULL, MOJO_READ_MESSAGE_FLAG_NONE)); 67 NULL, MOJO_READ_MESSAGE_FLAG_NONE));
97 EXPECT_EQ((uint32_t)sizeof(kHello), num_bytes); 68 EXPECT_EQ((uint32_t)sizeof(kHello), num_bytes);
98 EXPECT_EQ(0, memcmp(buffer, kHello, sizeof(kHello))); 69 EXPECT_EQ(0, memcmp(buffer, kHello, sizeof(kHello)));
99 70
100 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle0)); 71 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle0));
101 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle1)); 72 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle1));
102 73
103 // TODO(vtl): data pipe 74 // TODO(vtl): data pipe
104 75
105 return NULL; 76 return NULL;
106 } 77 }
OLDNEW
« no previous file with comments | « mojo/public/c/system/tests/core_unittest.cc ('k') | mojo/public/c/system/thunks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698