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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/message.h" | 6 #include "vm/message.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 msg = queue.Dequeue(); | 66 msg = queue.Dequeue(); |
67 EXPECT(msg != NULL); | 67 EXPECT(msg != NULL); |
68 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); | 68 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); |
69 EXPECT(!queue_peer.HasMessage()); | 69 EXPECT(!queue_peer.HasMessage()); |
70 | 70 |
71 delete msg1; | 71 delete msg1; |
72 delete msg2; | 72 delete msg2; |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 TEST_CASE(MessageQueue_Clear) { | 76 TEST_CASE(MessageQueue_FlushAll) { |
77 MessageQueue queue; | 77 MessageQueue queue; |
78 MessageQueueTestPeer queue_peer(&queue); | 78 MessageQueueTestPeer queue_peer(&queue); |
79 Dart_Port port1 = 1; | 79 Dart_Port port1 = 1; |
80 Dart_Port port2 = 2; | 80 Dart_Port port2 = 2; |
81 | 81 |
82 const char* str1 = "msg1"; | 82 const char* str1 = "msg1"; |
83 const char* str2 = "msg2"; | 83 const char* str2 = "msg2"; |
84 | 84 |
85 // Add two messages. | 85 // Add two messages. |
86 Message* msg1 = | 86 Message* msg1 = |
87 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1, | 87 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1, |
88 Message::kNormalPriority); | 88 Message::kNormalPriority); |
89 queue.Enqueue(msg1); | 89 queue.Enqueue(msg1); |
90 Message* msg2 = | 90 Message* msg2 = |
91 new Message(port2, 0, AllocMsg(str2), strlen(str2) + 1, | 91 new Message(port2, 0, AllocMsg(str2), strlen(str2) + 1, |
92 Message::kNormalPriority); | 92 Message::kNormalPriority); |
93 queue.Enqueue(msg2); | 93 queue.Enqueue(msg2); |
94 | 94 |
95 EXPECT(queue_peer.HasMessage()); | 95 EXPECT(queue_peer.HasMessage()); |
96 queue.Clear(); | 96 queue.FlushAll(); |
97 EXPECT(!queue_peer.HasMessage()); | 97 EXPECT(!queue_peer.HasMessage()); |
98 | 98 |
99 // msg1 and msg2 already delete by FlushAll. | 99 // msg1 and msg2 already delete by FlushAll. |
100 } | 100 } |
101 | 101 |
| 102 |
| 103 TEST_CASE(MessageQueue_Flush) { |
| 104 MessageQueue queue; |
| 105 MessageQueueTestPeer queue_peer(&queue); |
| 106 Dart_Port port1 = 1; |
| 107 Dart_Port port2 = 2; |
| 108 |
| 109 const char* str1 = "msg1"; |
| 110 const char* str2 = "msg2"; |
| 111 |
| 112 // Add two messages on different ports. |
| 113 Message* msg1 = |
| 114 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1, |
| 115 Message::kNormalPriority); |
| 116 queue.Enqueue(msg1); |
| 117 Message* msg2 = |
| 118 new Message(port2, 0, AllocMsg(str2), strlen(str2) + 1, |
| 119 Message::kNormalPriority); |
| 120 queue.Enqueue(msg2); |
| 121 EXPECT(queue_peer.HasMessage()); |
| 122 |
| 123 queue.Flush(port1); |
| 124 |
| 125 // One message is left in the queue. |
| 126 EXPECT(queue_peer.HasMessage()); |
| 127 Message* msg = queue.Dequeue(); |
| 128 EXPECT(msg != NULL); |
| 129 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); |
| 130 |
| 131 EXPECT(!queue_peer.HasMessage()); |
| 132 |
| 133 // msg1 is already deleted by Flush. |
| 134 delete msg2; |
| 135 } |
| 136 |
| 137 |
| 138 TEST_CASE(MessageQueue_Flush_MultipleMessages) { |
| 139 MessageQueue queue; |
| 140 MessageQueueTestPeer queue_peer(&queue); |
| 141 Dart_Port port1 = 1; |
| 142 |
| 143 const char* str1 = "msg1"; |
| 144 const char* str2 = "msg2"; |
| 145 |
| 146 Message* msg1 = |
| 147 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1, |
| 148 Message::kNormalPriority); |
| 149 queue.Enqueue(msg1); |
| 150 Message* msg2 = |
| 151 new Message(port1, 0, AllocMsg(str2), strlen(str2) + 1, |
| 152 Message::kNormalPriority); |
| 153 queue.Enqueue(msg2); |
| 154 EXPECT(queue_peer.HasMessage()); |
| 155 |
| 156 queue.Flush(port1); |
| 157 |
| 158 // Queue is empty. |
| 159 EXPECT(!queue_peer.HasMessage()); |
| 160 // msg1 and msg2 are already deleted by Flush. |
| 161 } |
| 162 |
| 163 |
| 164 TEST_CASE(MessageQueue_Flush_EmptyQueue) { |
| 165 MessageQueue queue; |
| 166 MessageQueueTestPeer queue_peer(&queue); |
| 167 Dart_Port port1 = 1; |
| 168 |
| 169 EXPECT(!queue_peer.HasMessage()); |
| 170 queue.Flush(port1); |
| 171 |
| 172 // Queue is still empty. |
| 173 EXPECT(!queue_peer.HasMessage()); |
| 174 } |
| 175 |
102 } // namespace dart | 176 } // namespace dart |
OLD | NEW |