OLD | NEW |
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 MessageHandlerTestPeer handler_peer(&handler); | 158 MessageHandlerTestPeer handler_peer(&handler); |
159 | 159 |
160 EXPECT(!handler.HasOOBMessages()); | 160 EXPECT(!handler.HasOOBMessages()); |
161 | 161 |
162 // Post a normal message. | 162 // Post a normal message. |
163 Message* message = new Message(1, NULL, 0, Message::kNormalPriority); | 163 Message* message = new Message(1, NULL, 0, Message::kNormalPriority); |
164 handler_peer.PostMessage(message); | 164 handler_peer.PostMessage(message); |
165 EXPECT(!handler.HasOOBMessages()); | 165 EXPECT(!handler.HasOOBMessages()); |
166 { | 166 { |
167 // Acquire ownership of message handler queues, verify one regular message. | 167 // Acquire ownership of message handler queues, verify one regular message. |
168 MessageHandler::AcquiredQueues aq; | 168 MessageHandler::AcquiredQueues aq(&handler); |
169 handler.AcquireQueues(&aq); | |
170 EXPECT(aq.queue()->Length() == 1); | 169 EXPECT(aq.queue()->Length() == 1); |
171 } | 170 } |
172 | 171 |
173 // Post an oob message. | 172 // Post an oob message. |
174 message = new Message(1, NULL, 0, Message::kOOBPriority); | 173 message = new Message(1, NULL, 0, Message::kOOBPriority); |
175 handler_peer.PostMessage(message); | 174 handler_peer.PostMessage(message); |
176 EXPECT(handler.HasOOBMessages()); | 175 EXPECT(handler.HasOOBMessages()); |
177 { | 176 { |
178 // Acquire ownership of message handler queues, verify one regular and one | 177 // Acquire ownership of message handler queues, verify one regular and one |
179 // OOB message. | 178 // OOB message. |
180 MessageHandler::AcquiredQueues aq; | 179 MessageHandler::AcquiredQueues aq(&handler); |
181 handler.AcquireQueues(&aq); | |
182 EXPECT(aq.queue()->Length() == 1); | 180 EXPECT(aq.queue()->Length() == 1); |
183 EXPECT(aq.oob_queue()->Length() == 1); | 181 EXPECT(aq.oob_queue()->Length() == 1); |
184 } | 182 } |
185 | 183 |
186 // Delete all pending messages. | 184 // Delete all pending messages. |
187 handler_peer.CloseAllPorts(); | 185 handler_peer.CloseAllPorts(); |
188 } | 186 } |
189 | 187 |
190 | 188 |
191 UNIT_TEST_CASE(MessageHandler_ClosePort) { | 189 UNIT_TEST_CASE(MessageHandler_ClosePort) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 handler_peer.PostMessage(oob_message3); | 299 handler_peer.PostMessage(oob_message3); |
302 | 300 |
303 // When we get a shutdown message, we stop processing all messages. | 301 // When we get a shutdown message, we stop processing all messages. |
304 EXPECT_EQ(MessageHandler::kShutdown, handler.HandleNextMessage()); | 302 EXPECT_EQ(MessageHandler::kShutdown, handler.HandleNextMessage()); |
305 EXPECT_EQ(2, handler.message_count()); | 303 EXPECT_EQ(2, handler.message_count()); |
306 Dart_Port* ports = handler.port_buffer(); | 304 Dart_Port* ports = handler.port_buffer(); |
307 EXPECT_EQ(port2, ports[0]); // oob_message1, ok | 305 EXPECT_EQ(port2, ports[0]); // oob_message1, ok |
308 EXPECT_EQ(port3, ports[1]); // oob_message2, shutdown | 306 EXPECT_EQ(port3, ports[1]); // oob_message2, shutdown |
309 { | 307 { |
310 // The oob queue has been cleared. oob_message3 is gone. | 308 // The oob queue has been cleared. oob_message3 is gone. |
311 MessageHandler::AcquiredQueues aq; | 309 MessageHandler::AcquiredQueues aq(&handler); |
312 handler.AcquireQueues(&aq); | |
313 EXPECT(aq.oob_queue()->Length() == 0); | 310 EXPECT(aq.oob_queue()->Length() == 0); |
314 } | 311 } |
315 handler_peer.CloseAllPorts(); | 312 handler_peer.CloseAllPorts(); |
316 } | 313 } |
317 | 314 |
318 | 315 |
319 UNIT_TEST_CASE(MessageHandler_HandleOOBMessages) { | 316 UNIT_TEST_CASE(MessageHandler_HandleOOBMessages) { |
320 TestMessageHandler handler; | 317 TestMessageHandler handler; |
321 MessageHandlerTestPeer handler_peer(&handler); | 318 MessageHandlerTestPeer handler_peer(&handler); |
322 Dart_Port port1 = PortMap::CreatePort(&handler); | 319 Dart_Port port1 = PortMap::CreatePort(&handler); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 EXPECT_EQ(port, handler_ports[0]); | 408 EXPECT_EQ(port, handler_ports[0]); |
412 for (int i = 1; i < 11; i++) { | 409 for (int i = 1; i < 11; i++) { |
413 EXPECT_EQ(ports[i - 1], handler_ports[i]); | 410 EXPECT_EQ(ports[i - 1], handler_ports[i]); |
414 } | 411 } |
415 handler_peer.decrement_live_ports(); | 412 handler_peer.decrement_live_ports(); |
416 EXPECT(!handler.HasLivePorts()); | 413 EXPECT(!handler.HasLivePorts()); |
417 PortMap::ClosePorts(&handler); | 414 PortMap::ClosePorts(&handler); |
418 } | 415 } |
419 | 416 |
420 } // namespace dart | 417 } // namespace dart |
OLD | NEW |