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

Side by Side Diff: mojo/edk/system/dispatcher_unittest.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/edk/system/dispatcher.cc ('k') | mojo/edk/system/entrypoints.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 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/dispatcher.h" 5 #include "mojo/edk/system/dispatcher.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 26 matching lines...) Expand all
37 37
38 DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); 38 DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher);
39 }; 39 };
40 40
41 TEST(DispatcherTest, Basic) { 41 TEST(DispatcherTest, Basic) {
42 scoped_refptr<Dispatcher> d(new TrivialDispatcher()); 42 scoped_refptr<Dispatcher> d(new TrivialDispatcher());
43 43
44 EXPECT_EQ(Dispatcher::kTypeUnknown, d->GetType()); 44 EXPECT_EQ(Dispatcher::kTypeUnknown, d->GetType());
45 45
46 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 46 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
47 d->WriteMessage( 47 d->WriteMessage(NullUserPointer(), 0, nullptr,
48 NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 48 MOJO_WRITE_MESSAGE_FLAG_NONE));
49 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 49 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
50 d->ReadMessage(NullUserPointer(), 50 d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr,
51 NullUserPointer(), 51 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
52 nullptr, 52 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
53 nullptr, 53 d->WriteData(NullUserPointer(), NullUserPointer(),
54 MOJO_WRITE_MESSAGE_FLAG_NONE)); 54 MOJO_WRITE_DATA_FLAG_NONE));
55 EXPECT_EQ( 55 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
56 MOJO_RESULT_INVALID_ARGUMENT, 56 d->BeginWriteData(NullUserPointer(), NullUserPointer(),
57 d->WriteData( 57 MOJO_WRITE_DATA_FLAG_NONE));
58 NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
59 EXPECT_EQ(
60 MOJO_RESULT_INVALID_ARGUMENT,
61 d->BeginWriteData(
62 NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
63 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0)); 58 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0));
64 EXPECT_EQ( 59 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
65 MOJO_RESULT_INVALID_ARGUMENT, 60 d->ReadData(NullUserPointer(), NullUserPointer(),
66 d->ReadData( 61 MOJO_READ_DATA_FLAG_NONE));
67 NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE)); 62 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
68 EXPECT_EQ( 63 d->BeginReadData(NullUserPointer(), NullUserPointer(),
69 MOJO_RESULT_INVALID_ARGUMENT, 64 MOJO_READ_DATA_FLAG_NONE));
70 d->BeginReadData(
71 NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
72 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0)); 65 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
73 Waiter w; 66 Waiter w;
74 w.Init(); 67 w.Init();
75 HandleSignalsState hss; 68 HandleSignalsState hss;
76 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 69 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
77 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); 70 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss));
78 EXPECT_EQ(0u, hss.satisfied_signals); 71 EXPECT_EQ(0u, hss.satisfied_signals);
79 EXPECT_EQ(0u, hss.satisfiable_signals); 72 EXPECT_EQ(0u, hss.satisfiable_signals);
80 // Okay to remove even if it wasn't added (or was already removed). 73 // Okay to remove even if it wasn't added (or was already removed).
81 hss = HandleSignalsState(); 74 hss = HandleSignalsState();
82 d->RemoveWaiter(&w, &hss); 75 d->RemoveWaiter(&w, &hss);
83 EXPECT_EQ(0u, hss.satisfied_signals); 76 EXPECT_EQ(0u, hss.satisfied_signals);
84 EXPECT_EQ(0u, hss.satisfiable_signals); 77 EXPECT_EQ(0u, hss.satisfiable_signals);
85 hss = HandleSignalsState(); 78 hss = HandleSignalsState();
86 d->RemoveWaiter(&w, &hss); 79 d->RemoveWaiter(&w, &hss);
87 EXPECT_EQ(0u, hss.satisfied_signals); 80 EXPECT_EQ(0u, hss.satisfied_signals);
88 EXPECT_EQ(0u, hss.satisfiable_signals); 81 EXPECT_EQ(0u, hss.satisfiable_signals);
89 82
90 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 83 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
91 84
92 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 85 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
93 d->WriteMessage( 86 d->WriteMessage(NullUserPointer(), 0, nullptr,
94 NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 87 MOJO_WRITE_MESSAGE_FLAG_NONE));
95 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 88 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
96 d->ReadMessage(NullUserPointer(), 89 d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr,
97 NullUserPointer(), 90 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
98 nullptr, 91 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
99 nullptr, 92 d->WriteData(NullUserPointer(), NullUserPointer(),
100 MOJO_WRITE_MESSAGE_FLAG_NONE)); 93 MOJO_WRITE_DATA_FLAG_NONE));
101 EXPECT_EQ( 94 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
102 MOJO_RESULT_INVALID_ARGUMENT, 95 d->BeginWriteData(NullUserPointer(), NullUserPointer(),
103 d->WriteData( 96 MOJO_WRITE_DATA_FLAG_NONE));
104 NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
105 EXPECT_EQ(
106 MOJO_RESULT_INVALID_ARGUMENT,
107 d->BeginWriteData(
108 NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
109 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0)); 97 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0));
110 EXPECT_EQ( 98 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
111 MOJO_RESULT_INVALID_ARGUMENT, 99 d->ReadData(NullUserPointer(), NullUserPointer(),
112 d->ReadData( 100 MOJO_READ_DATA_FLAG_NONE));
113 NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE)); 101 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
114 EXPECT_EQ( 102 d->BeginReadData(NullUserPointer(), NullUserPointer(),
115 MOJO_RESULT_INVALID_ARGUMENT, 103 MOJO_READ_DATA_FLAG_NONE));
116 d->BeginReadData(
117 NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
118 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0)); 104 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
119 hss = HandleSignalsState(); 105 hss = HandleSignalsState();
120 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 106 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
121 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); 107 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss));
122 EXPECT_EQ(0u, hss.satisfied_signals); 108 EXPECT_EQ(0u, hss.satisfied_signals);
123 EXPECT_EQ(0u, hss.satisfiable_signals); 109 EXPECT_EQ(0u, hss.satisfiable_signals);
124 hss = HandleSignalsState(); 110 hss = HandleSignalsState();
125 d->RemoveWaiter(&w, &hss); 111 d->RemoveWaiter(&w, &hss);
126 EXPECT_EQ(0u, hss.satisfied_signals); 112 EXPECT_EQ(0u, hss.satisfied_signals);
127 EXPECT_EQ(0u, hss.satisfiable_signals); 113 EXPECT_EQ(0u, hss.satisfiable_signals);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 151
166 waiter_.Init(); 152 waiter_.Init();
167 switch (op_) { 153 switch (op_) {
168 case CLOSE: { 154 case CLOSE: {
169 MojoResult r = dispatcher_->Close(); 155 MojoResult r = dispatcher_->Close();
170 EXPECT_TRUE(r == MOJO_RESULT_OK || r == MOJO_RESULT_INVALID_ARGUMENT) 156 EXPECT_TRUE(r == MOJO_RESULT_OK || r == MOJO_RESULT_INVALID_ARGUMENT)
171 << "Result: " << r; 157 << "Result: " << r;
172 break; 158 break;
173 } 159 }
174 case WRITE_MESSAGE: 160 case WRITE_MESSAGE:
175 EXPECT_EQ( 161 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
176 MOJO_RESULT_INVALID_ARGUMENT, 162 dispatcher_->WriteMessage(NullUserPointer(), 0, nullptr,
177 dispatcher_->WriteMessage( 163 MOJO_WRITE_MESSAGE_FLAG_NONE));
178 NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
179 break; 164 break;
180 case READ_MESSAGE: 165 case READ_MESSAGE:
181 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 166 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
182 dispatcher_->ReadMessage(NullUserPointer(), 167 dispatcher_->ReadMessage(NullUserPointer(), NullUserPointer(),
183 NullUserPointer(), 168 nullptr, nullptr,
184 nullptr,
185 nullptr,
186 MOJO_WRITE_MESSAGE_FLAG_NONE)); 169 MOJO_WRITE_MESSAGE_FLAG_NONE));
187 break; 170 break;
188 case WRITE_DATA: 171 case WRITE_DATA:
189 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 172 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
190 dispatcher_->WriteData(NullUserPointer(), 173 dispatcher_->WriteData(NullUserPointer(), NullUserPointer(),
191 NullUserPointer(),
192 MOJO_WRITE_DATA_FLAG_NONE)); 174 MOJO_WRITE_DATA_FLAG_NONE));
193 break; 175 break;
194 case BEGIN_WRITE_DATA: 176 case BEGIN_WRITE_DATA:
195 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 177 EXPECT_EQ(
196 dispatcher_->BeginWriteData(NullUserPointer(), 178 MOJO_RESULT_INVALID_ARGUMENT,
197 NullUserPointer(), 179 dispatcher_->BeginWriteData(NullUserPointer(), NullUserPointer(),
198 MOJO_WRITE_DATA_FLAG_NONE)); 180 MOJO_WRITE_DATA_FLAG_NONE));
199 break; 181 break;
200 case END_WRITE_DATA: 182 case END_WRITE_DATA:
201 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndWriteData(0)); 183 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndWriteData(0));
202 break; 184 break;
203 case READ_DATA: 185 case READ_DATA:
204 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 186 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
205 dispatcher_->ReadData(NullUserPointer(), 187 dispatcher_->ReadData(NullUserPointer(), NullUserPointer(),
206 NullUserPointer(),
207 MOJO_READ_DATA_FLAG_NONE)); 188 MOJO_READ_DATA_FLAG_NONE));
208 break; 189 break;
209 case BEGIN_READ_DATA: 190 case BEGIN_READ_DATA:
210 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 191 EXPECT_EQ(
211 dispatcher_->BeginReadData(NullUserPointer(), 192 MOJO_RESULT_INVALID_ARGUMENT,
212 NullUserPointer(), 193 dispatcher_->BeginReadData(NullUserPointer(), NullUserPointer(),
213 MOJO_READ_DATA_FLAG_NONE)); 194 MOJO_READ_DATA_FLAG_NONE));
214 break; 195 break;
215 case END_READ_DATA: 196 case END_READ_DATA:
216 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndReadData(0)); 197 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndReadData(0));
217 break; 198 break;
218 case DUPLICATE_BUFFER_HANDLE: { 199 case DUPLICATE_BUFFER_HANDLE: {
219 scoped_refptr<Dispatcher> unused; 200 scoped_refptr<Dispatcher> unused;
220 EXPECT_EQ( 201 EXPECT_EQ(
221 MOJO_RESULT_INVALID_ARGUMENT, 202 MOJO_RESULT_INVALID_ARGUMENT,
222 dispatcher_->DuplicateBufferHandle(NullUserPointer(), &unused)); 203 dispatcher_->DuplicateBufferHandle(NullUserPointer(), &unused));
223 break; 204 break;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 event.Signal(); 298 event.Signal();
318 } // Joins all the threads. 299 } // Joins all the threads.
319 300
320 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 301 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
321 } 302 }
322 } 303 }
323 304
324 } // namespace 305 } // namespace
325 } // namespace system 306 } // namespace system
326 } // namespace mojo 307 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher.cc ('k') | mojo/edk/system/entrypoints.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698