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 13 matching lines...) Expand all Loading... |
24 Dart_Port port = 1; | 24 Dart_Port port = 1; |
25 | 25 |
26 const char* str1 = "msg1"; | 26 const char* str1 = "msg1"; |
27 const char* str2 = "msg2"; | 27 const char* str2 = "msg2"; |
28 const char* str3 = "msg3"; | 28 const char* str3 = "msg3"; |
29 const char* str4 = "msg4"; | 29 const char* str4 = "msg4"; |
30 const char* str5 = "msg5"; | 30 const char* str5 = "msg5"; |
31 const char* str6 = "msg6"; | 31 const char* str6 = "msg6"; |
32 | 32 |
33 // Add two messages. | 33 // Add two messages. |
34 Message* msg1 = new Message( | 34 Message* msg1 = new Message(port, AllocMsg(str1), strlen(str1) + 1, |
35 port, AllocMsg(str1), strlen(str1) + 1, Message::kNormalPriority); | 35 Message::kNormalPriority); |
36 queue.Enqueue(msg1, false); | 36 queue.Enqueue(msg1, false); |
37 EXPECT(queue.Length() == 1); | 37 EXPECT(queue.Length() == 1); |
38 EXPECT(!queue.IsEmpty()); | 38 EXPECT(!queue.IsEmpty()); |
39 it.Reset(&queue); | 39 it.Reset(&queue); |
40 EXPECT(it.HasNext()); | 40 EXPECT(it.HasNext()); |
41 EXPECT(it.Next() == msg1); | 41 EXPECT(it.Next() == msg1); |
42 EXPECT(!it.HasNext()); | 42 EXPECT(!it.HasNext()); |
43 | 43 |
44 Message* msg2 = new Message( | 44 Message* msg2 = new Message(port, AllocMsg(str2), strlen(str2) + 1, |
45 port, AllocMsg(str2), strlen(str2) + 1, Message::kNormalPriority); | 45 Message::kNormalPriority); |
46 queue.Enqueue(msg2, false); | 46 queue.Enqueue(msg2, false); |
47 EXPECT(queue.Length() == 2); | 47 EXPECT(queue.Length() == 2); |
48 EXPECT(!queue.IsEmpty()); | 48 EXPECT(!queue.IsEmpty()); |
49 it.Reset(&queue); | 49 it.Reset(&queue); |
50 EXPECT(it.HasNext()); | 50 EXPECT(it.HasNext()); |
51 EXPECT(it.Next() == msg1); | 51 EXPECT(it.Next() == msg1); |
52 EXPECT(it.HasNext()); | 52 EXPECT(it.HasNext()); |
53 EXPECT(it.Next() == msg2); | 53 EXPECT(it.Next() == msg2); |
54 EXPECT(!it.HasNext()); | 54 EXPECT(!it.HasNext()); |
55 | 55 |
(...skipping 13 matching lines...) Expand all Loading... |
69 it.Reset(&queue); | 69 it.Reset(&queue); |
70 EXPECT(it.HasNext()); | 70 EXPECT(it.HasNext()); |
71 EXPECT(it.Next() == msg2); | 71 EXPECT(it.Next() == msg2); |
72 | 72 |
73 // Remove message 2 | 73 // Remove message 2 |
74 msg = queue.Dequeue(); | 74 msg = queue.Dequeue(); |
75 EXPECT(msg != NULL); | 75 EXPECT(msg != NULL); |
76 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); | 76 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); |
77 EXPECT(queue.IsEmpty()); | 77 EXPECT(queue.IsEmpty()); |
78 | 78 |
79 Message* msg3 = new Message(Message::kIllegalPort, | 79 Message* msg3 = new Message(Message::kIllegalPort, AllocMsg(str3), |
80 AllocMsg(str3), strlen(str3) + 1, | 80 strlen(str3) + 1, Message::kNormalPriority); |
81 Message::kNormalPriority); | |
82 queue.Enqueue(msg3, true); | 81 queue.Enqueue(msg3, true); |
83 EXPECT(!queue.IsEmpty()); | 82 EXPECT(!queue.IsEmpty()); |
84 | 83 |
85 Message* msg4 = new Message(Message::kIllegalPort, | 84 Message* msg4 = new Message(Message::kIllegalPort, AllocMsg(str4), |
86 AllocMsg(str4), strlen(str4) + 1, | 85 strlen(str4) + 1, Message::kNormalPriority); |
87 Message::kNormalPriority); | |
88 queue.Enqueue(msg4, true); | 86 queue.Enqueue(msg4, true); |
89 EXPECT(!queue.IsEmpty()); | 87 EXPECT(!queue.IsEmpty()); |
90 | 88 |
91 Message* msg5 = new Message( | 89 Message* msg5 = new Message(port, AllocMsg(str5), strlen(str5) + 1, |
92 port, AllocMsg(str5), strlen(str5) + 1, Message::kNormalPriority); | 90 Message::kNormalPriority); |
93 queue.Enqueue(msg5, false); | 91 queue.Enqueue(msg5, false); |
94 EXPECT(!queue.IsEmpty()); | 92 EXPECT(!queue.IsEmpty()); |
95 | 93 |
96 Message* msg6 = new Message(Message::kIllegalPort, | 94 Message* msg6 = new Message(Message::kIllegalPort, AllocMsg(str6), |
97 AllocMsg(str6), strlen(str6) + 1, | 95 strlen(str6) + 1, Message::kNormalPriority); |
98 Message::kNormalPriority); | |
99 queue.Enqueue(msg6, true); | 96 queue.Enqueue(msg6, true); |
100 EXPECT(!queue.IsEmpty()); | 97 EXPECT(!queue.IsEmpty()); |
101 | 98 |
102 msg = queue.Dequeue(); | 99 msg = queue.Dequeue(); |
103 EXPECT(msg != NULL); | 100 EXPECT(msg != NULL); |
104 EXPECT_STREQ(str3, reinterpret_cast<char*>(msg->data())); | 101 EXPECT_STREQ(str3, reinterpret_cast<char*>(msg->data())); |
105 EXPECT(!queue.IsEmpty()); | 102 EXPECT(!queue.IsEmpty()); |
106 | 103 |
107 msg = queue.Dequeue(); | 104 msg = queue.Dequeue(); |
108 EXPECT(msg != NULL); | 105 EXPECT(msg != NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
130 | 127 |
131 TEST_CASE(MessageQueue_Clear) { | 128 TEST_CASE(MessageQueue_Clear) { |
132 MessageQueue queue; | 129 MessageQueue queue; |
133 Dart_Port port1 = 1; | 130 Dart_Port port1 = 1; |
134 Dart_Port port2 = 2; | 131 Dart_Port port2 = 2; |
135 | 132 |
136 const char* str1 = "msg1"; | 133 const char* str1 = "msg1"; |
137 const char* str2 = "msg2"; | 134 const char* str2 = "msg2"; |
138 | 135 |
139 // Add two messages. | 136 // Add two messages. |
140 Message* msg1 = | 137 Message* msg1 = new Message(port1, AllocMsg(str1), strlen(str1) + 1, |
141 new Message(port1, AllocMsg(str1), strlen(str1) + 1, | 138 Message::kNormalPriority); |
142 Message::kNormalPriority); | |
143 queue.Enqueue(msg1, false); | 139 queue.Enqueue(msg1, false); |
144 Message* msg2 = | 140 Message* msg2 = new Message(port2, AllocMsg(str2), strlen(str2) + 1, |
145 new Message(port2, AllocMsg(str2), strlen(str2) + 1, | 141 Message::kNormalPriority); |
146 Message::kNormalPriority); | |
147 queue.Enqueue(msg2, false); | 142 queue.Enqueue(msg2, false); |
148 | 143 |
149 EXPECT(!queue.IsEmpty()); | 144 EXPECT(!queue.IsEmpty()); |
150 queue.Clear(); | 145 queue.Clear(); |
151 EXPECT(queue.IsEmpty()); | 146 EXPECT(queue.IsEmpty()); |
152 | 147 |
153 // msg1 and msg2 already delete by FlushAll. | 148 // msg1 and msg2 already delete by FlushAll. |
154 } | 149 } |
155 | 150 |
156 } // namespace dart | 151 } // namespace dart |
OLD | NEW |