Chromium Code Reviews| 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 const char* str2 = "msg2"; | 24 const char* str2 = "msg2"; |
| 25 const char* str3 = "msg3"; | 25 const char* str3 = "msg3"; |
| 26 const char* str4 = "msg4"; | 26 const char* str4 = "msg4"; |
| 27 const char* str5 = "msg5"; | 27 const char* str5 = "msg5"; |
| 28 const char* str6 = "msg6"; | 28 const char* str6 = "msg6"; |
| 29 | 29 |
| 30 // Add two messages. | 30 // Add two messages. |
| 31 Message* msg1 = new Message( | 31 Message* msg1 = new Message( |
| 32 port, AllocMsg(str1), strlen(str1) + 1, Message::kNormalPriority); | 32 port, AllocMsg(str1), strlen(str1) + 1, Message::kNormalPriority); |
| 33 queue.Enqueue(msg1, false); | 33 queue.Enqueue(msg1, false); |
| 34 EXPECT(queue.Length() == 1); | |
| 34 EXPECT(!queue.IsEmpty()); | 35 EXPECT(!queue.IsEmpty()); |
| 36 // Iterate over messages. | |
| 37 MessageQueue::Iterator it(&queue); | |
| 38 for (; it.HasNext(); it.Next()) { | |
| 39 EXPECT(it.current() == msg1); | |
| 40 } | |
|
turnidge
2015/05/04 17:47:13
Unroll, as suggested below.
Cutch
2015/05/04 19:56:51
Done.
| |
| 35 | 41 |
| 36 Message* msg2 = new Message( | 42 Message* msg2 = new Message( |
| 37 port, AllocMsg(str2), strlen(str2) + 1, Message::kNormalPriority); | 43 port, AllocMsg(str2), strlen(str2) + 1, Message::kNormalPriority); |
| 38 queue.Enqueue(msg2, false); | 44 queue.Enqueue(msg2, false); |
| 45 EXPECT(queue.Length() == 2); | |
| 39 EXPECT(!queue.IsEmpty()); | 46 EXPECT(!queue.IsEmpty()); |
| 47 it.Reset(&queue); | |
| 40 | 48 |
| 41 // Remove two messages. | 49 for (intptr_t it_count = 0; it.HasNext(); it.Next(), it_count++) { |
| 50 EXPECT(it_count < 2); | |
| 51 if (it_count == 0) { | |
| 52 EXPECT(it.current() == msg1); | |
| 53 } else { | |
| 54 ASSERT(it_count == 1); | |
| 55 EXPECT(it.current() == msg2); | |
| 56 } | |
| 57 } | |
|
turnidge
2015/05/04 17:47:13
I would unroll this, I think it is shorter/simpler
Cutch
2015/05/04 19:56:51
Done.
| |
| 58 | |
| 59 // Lookup messages by id. | |
| 60 EXPECT(queue.FindMessageById(reinterpret_cast<intptr_t>(msg1)) == msg1); | |
| 61 EXPECT(queue.FindMessageById(reinterpret_cast<intptr_t>(msg2)) == msg2); | |
| 62 | |
| 63 // Lookup bad id. | |
| 64 EXPECT(queue.FindMessageById(0x1) == NULL); | |
| 65 | |
| 66 // Remove message 1 | |
| 42 Message* msg = queue.Dequeue(); | 67 Message* msg = queue.Dequeue(); |
| 43 EXPECT(msg != NULL); | 68 EXPECT(msg != NULL); |
| 44 EXPECT_STREQ(str1, reinterpret_cast<char*>(msg->data())); | 69 EXPECT_STREQ(str1, reinterpret_cast<char*>(msg->data())); |
| 45 EXPECT(!queue.IsEmpty()); | 70 EXPECT(!queue.IsEmpty()); |
| 46 | 71 |
| 72 // Check that only msg2 is left in the queue. | |
| 73 for (it.Reset(&queue); it.HasNext(); it.Next()) { | |
| 74 EXPECT(it.current() == msg2); | |
| 75 } | |
|
turnidge
2015/05/04 17:47:13
Unroll.
Cutch
2015/05/04 19:56:51
Done.
| |
| 76 | |
| 77 // Remove message 2 | |
| 47 msg = queue.Dequeue(); | 78 msg = queue.Dequeue(); |
| 48 EXPECT(msg != NULL); | 79 EXPECT(msg != NULL); |
| 49 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); | 80 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data())); |
| 50 EXPECT(queue.IsEmpty()); | 81 EXPECT(queue.IsEmpty()); |
| 51 | 82 |
| 52 Message* msg3 = new Message(Message::kIllegalPort, | 83 Message* msg3 = new Message(Message::kIllegalPort, |
| 53 AllocMsg(str3), strlen(str3) + 1, | 84 AllocMsg(str3), strlen(str3) + 1, |
| 54 Message::kNormalPriority); | 85 Message::kNormalPriority); |
| 55 queue.Enqueue(msg3, true); | 86 queue.Enqueue(msg3, true); |
| 56 EXPECT(!queue.IsEmpty()); | 87 EXPECT(!queue.IsEmpty()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 queue.Enqueue(msg2, false); | 151 queue.Enqueue(msg2, false); |
| 121 | 152 |
| 122 EXPECT(!queue.IsEmpty()); | 153 EXPECT(!queue.IsEmpty()); |
| 123 queue.Clear(); | 154 queue.Clear(); |
| 124 EXPECT(queue.IsEmpty()); | 155 EXPECT(queue.IsEmpty()); |
| 125 | 156 |
| 126 // msg1 and msg2 already delete by FlushAll. | 157 // msg1 and msg2 already delete by FlushAll. |
| 127 } | 158 } |
| 128 | 159 |
| 129 } // namespace dart | 160 } // namespace dart |
| OLD | NEW |