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

Side by Side Diff: runtime/vm/message_handler_test.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 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 | « runtime/vm/message_handler.cc ('k') | runtime/vm/message_test.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/message_handler.h" 5 #include "vm/message_handler.h"
6 #include "vm/port.h" 6 #include "vm/port.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 class TestMessageHandler : public MessageHandler { 33 class TestMessageHandler : public MessageHandler {
34 public: 34 public:
35 TestMessageHandler() 35 TestMessageHandler()
36 : port_buffer_(NULL), 36 : port_buffer_(NULL),
37 port_buffer_size_(0), 37 port_buffer_size_(0),
38 notify_count_(0), 38 notify_count_(0),
39 message_count_(0), 39 message_count_(0),
40 start_called_(false), 40 start_called_(false),
41 end_called_(false), 41 end_called_(false),
42 results_(NULL) { 42 results_(NULL) {}
43 }
44 43
45 ~TestMessageHandler() { 44 ~TestMessageHandler() { delete[] port_buffer_; }
46 delete[] port_buffer_;
47 }
48 45
49 void MessageNotify(Message::Priority priority) { 46 void MessageNotify(Message::Priority priority) { notify_count_++; }
50 notify_count_++;
51 }
52 47
53 MessageStatus HandleMessage(Message* message) { 48 MessageStatus HandleMessage(Message* message) {
54 // For testing purposes, keep a list of the ports 49 // For testing purposes, keep a list of the ports
55 // for all messages we receive. 50 // for all messages we receive.
56 AddPortToBuffer(message->dest_port()); 51 AddPortToBuffer(message->dest_port());
57 delete message; 52 delete message;
58 message_count_++; 53 message_count_++;
59 MessageStatus status = kOK; 54 MessageStatus status = kOK;
60 if (results_ != NULL) { 55 if (results_ != NULL) {
61 status = results_[0]; 56 status = results_[0];
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EXPECT_EQ(port2, ports[0]); 236 EXPECT_EQ(port2, ports[0]);
242 EXPECT_EQ(port3, ports[1]); 237 EXPECT_EQ(port3, ports[1]);
243 EXPECT_EQ(port1, ports[2]); 238 EXPECT_EQ(port1, ports[2]);
244 PortMap::ClosePorts(&handler); 239 PortMap::ClosePorts(&handler);
245 } 240 }
246 241
247 242
248 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_ProcessOOBAfterError) { 243 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_ProcessOOBAfterError) {
249 TestMessageHandler handler; 244 TestMessageHandler handler;
250 MessageHandler::MessageStatus results[] = { 245 MessageHandler::MessageStatus results[] = {
251 MessageHandler::kError, // oob_message1 246 MessageHandler::kError, // oob_message1
252 MessageHandler::kOK, // oob_message2 247 MessageHandler::kOK, // oob_message2
253 MessageHandler::kOK, // unused 248 MessageHandler::kOK, // unused
254 }; 249 };
255 handler.set_results(results); 250 handler.set_results(results);
256 MessageHandlerTestPeer handler_peer(&handler); 251 MessageHandlerTestPeer handler_peer(&handler);
257 Dart_Port port1 = PortMap::CreatePort(&handler); 252 Dart_Port port1 = PortMap::CreatePort(&handler);
258 Dart_Port port2 = PortMap::CreatePort(&handler); 253 Dart_Port port2 = PortMap::CreatePort(&handler);
259 Dart_Port port3 = PortMap::CreatePort(&handler); 254 Dart_Port port3 = PortMap::CreatePort(&handler);
260 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority); 255 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority);
261 handler_peer.PostMessage(message1); 256 handler_peer.PostMessage(message1);
262 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority); 257 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority);
263 handler_peer.PostMessage(oob_message1); 258 handler_peer.PostMessage(oob_message1);
264 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority); 259 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority);
265 handler_peer.PostMessage(oob_message2); 260 handler_peer.PostMessage(oob_message2);
266 261
267 // When we get an error, we continue processing oob messages but 262 // When we get an error, we continue processing oob messages but
268 // stop handling normal messages. 263 // stop handling normal messages.
269 EXPECT_EQ(MessageHandler::kError, handler.HandleNextMessage()); 264 EXPECT_EQ(MessageHandler::kError, handler.HandleNextMessage());
270 EXPECT_EQ(2, handler.message_count()); 265 EXPECT_EQ(2, handler.message_count());
271 Dart_Port* ports = handler.port_buffer(); 266 Dart_Port* ports = handler.port_buffer();
272 EXPECT_EQ(port2, ports[0]); // oob_message1, error 267 EXPECT_EQ(port2, ports[0]); // oob_message1, error
273 EXPECT_EQ(port3, ports[1]); // oob_message2, ok 268 EXPECT_EQ(port3, ports[1]); // oob_message2, ok
274 handler_peer.CloseAllPorts(); 269 handler_peer.CloseAllPorts();
275 } 270 }
276 271
277 272
278 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) { 273 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) {
279 TestMessageHandler handler; 274 TestMessageHandler handler;
280 MessageHandler::MessageStatus results[] = { 275 MessageHandler::MessageStatus results[] = {
281 MessageHandler::kOK, // oob_message1 276 MessageHandler::kOK, // oob_message1
282 MessageHandler::kShutdown, // oob_message2 277 MessageHandler::kShutdown, // oob_message2
283 MessageHandler::kOK, // unused 278 MessageHandler::kOK, // unused
284 MessageHandler::kOK, // unused 279 MessageHandler::kOK, // unused
285 }; 280 };
286 handler.set_results(results); 281 handler.set_results(results);
287 MessageHandlerTestPeer handler_peer(&handler); 282 MessageHandlerTestPeer handler_peer(&handler);
288 Dart_Port port1 = PortMap::CreatePort(&handler); 283 Dart_Port port1 = PortMap::CreatePort(&handler);
289 Dart_Port port2 = PortMap::CreatePort(&handler); 284 Dart_Port port2 = PortMap::CreatePort(&handler);
290 Dart_Port port3 = PortMap::CreatePort(&handler); 285 Dart_Port port3 = PortMap::CreatePort(&handler);
291 Dart_Port port4 = PortMap::CreatePort(&handler); 286 Dart_Port port4 = PortMap::CreatePort(&handler);
292 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority); 287 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority);
293 handler_peer.PostMessage(message1); 288 handler_peer.PostMessage(message1);
294 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority); 289 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 UNIT_TEST_CASE(MessageHandler_Run) { 356 UNIT_TEST_CASE(MessageHandler_Run) {
362 ThreadPool pool; 357 ThreadPool pool;
363 TestMessageHandler handler; 358 TestMessageHandler handler;
364 MessageHandlerTestPeer handler_peer(&handler); 359 MessageHandlerTestPeer handler_peer(&handler);
365 int sleep = 0; 360 int sleep = 0;
366 const int kMaxSleep = 20 * 1000; // 20 seconds. 361 const int kMaxSleep = 20 * 1000; // 20 seconds.
367 362
368 EXPECT(!handler.HasLivePorts()); 363 EXPECT(!handler.HasLivePorts());
369 handler_peer.increment_live_ports(); 364 handler_peer.increment_live_ports();
370 365
371 handler.Run(&pool, 366 handler.Run(&pool, TestStartFunction, TestEndFunction,
372 TestStartFunction,
373 TestEndFunction,
374 reinterpret_cast<uword>(&handler)); 367 reinterpret_cast<uword>(&handler));
375 Dart_Port port = PortMap::CreatePort(&handler); 368 Dart_Port port = PortMap::CreatePort(&handler);
376 Message* message = new Message(port, NULL, 0, Message::kNormalPriority); 369 Message* message = new Message(port, NULL, 0, Message::kNormalPriority);
377 handler_peer.PostMessage(message); 370 handler_peer.PostMessage(message);
378 371
379 // Wait for the first message to be handled. 372 // Wait for the first message to be handled.
380 while (sleep < kMaxSleep && handler.message_count() < 1) { 373 while (sleep < kMaxSleep && handler.message_count() < 1) {
381 OS::Sleep(10); 374 OS::Sleep(10);
382 sleep += 10; 375 sleep += 10;
383 } 376 }
(...skipping 24 matching lines...) Expand all
408 EXPECT_EQ(port, handler_ports[0]); 401 EXPECT_EQ(port, handler_ports[0]);
409 for (int i = 1; i < 11; i++) { 402 for (int i = 1; i < 11; i++) {
410 EXPECT_EQ(ports[i - 1], handler_ports[i]); 403 EXPECT_EQ(ports[i - 1], handler_ports[i]);
411 } 404 }
412 handler_peer.decrement_live_ports(); 405 handler_peer.decrement_live_ports();
413 EXPECT(!handler.HasLivePorts()); 406 EXPECT(!handler.HasLivePorts());
414 PortMap::ClosePorts(&handler); 407 PortMap::ClosePorts(&handler);
415 } 408 }
416 409
417 } // namespace dart 410 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/message_handler.cc ('k') | runtime/vm/message_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698