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

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

Issue 10829444: Avoid trusting the length encoded in the Snapshot if there is an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/native_message_handler.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 "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 22 matching lines...) Expand all
33 } 33 }
34 34
35 35
36 TEST_CASE(MessageQueue_BasicOperations) { 36 TEST_CASE(MessageQueue_BasicOperations) {
37 MessageQueue queue; 37 MessageQueue queue;
38 MessageQueueTestPeer queue_peer(&queue); 38 MessageQueueTestPeer queue_peer(&queue);
39 EXPECT(!queue_peer.HasMessage()); 39 EXPECT(!queue_peer.HasMessage());
40 40
41 Dart_Port port = 1; 41 Dart_Port port = 1;
42 42
43 const char* str1 = "msg1";
44 const char* str2 = "msg2";
45
43 // Add two messages. 46 // Add two messages.
44 Message* msg1 = 47 Message* msg1 =
45 new Message(port, 0, AllocMsg("msg1"), Message::kNormalPriority); 48 new Message(port, 0, AllocMsg(str1), strlen(str1) + 1,
49 Message::kNormalPriority);
46 queue.Enqueue(msg1); 50 queue.Enqueue(msg1);
47 EXPECT(queue_peer.HasMessage()); 51 EXPECT(queue_peer.HasMessage());
48 52
49 Message* msg2 = 53 Message* msg2 =
50 new Message(port, 0, AllocMsg("msg2"), Message::kNormalPriority); 54 new Message(port, 0, AllocMsg(str2), strlen(str2) + 1,
55 Message::kNormalPriority);
51 56
52 queue.Enqueue(msg2); 57 queue.Enqueue(msg2);
53 EXPECT(queue_peer.HasMessage()); 58 EXPECT(queue_peer.HasMessage());
54 59
55 // Remove two messages. 60 // Remove two messages.
56 Message* msg = queue.Dequeue(); 61 Message* msg = queue.Dequeue();
57 EXPECT(msg != NULL); 62 EXPECT(msg != NULL);
58 EXPECT_STREQ("msg1", reinterpret_cast<char*>(msg->data())); 63 EXPECT_STREQ(str1, reinterpret_cast<char*>(msg->data()));
59 EXPECT(queue_peer.HasMessage()); 64 EXPECT(queue_peer.HasMessage());
60 65
61 msg = queue.Dequeue(); 66 msg = queue.Dequeue();
62 EXPECT(msg != NULL); 67 EXPECT(msg != NULL);
63 EXPECT_STREQ("msg2", reinterpret_cast<char*>(msg->data())); 68 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data()));
64 EXPECT(!queue_peer.HasMessage()); 69 EXPECT(!queue_peer.HasMessage());
65 70
66 delete msg1; 71 delete msg1;
67 delete msg2; 72 delete msg2;
68 } 73 }
69 74
70 75
71 TEST_CASE(MessageQueue_FlushAll) { 76 TEST_CASE(MessageQueue_FlushAll) {
72 MessageQueue queue; 77 MessageQueue queue;
73 MessageQueueTestPeer queue_peer(&queue); 78 MessageQueueTestPeer queue_peer(&queue);
74 Dart_Port port1 = 1; 79 Dart_Port port1 = 1;
75 Dart_Port port2 = 2; 80 Dart_Port port2 = 2;
76 81
82 const char* str1 = "msg1";
83 const char* str2 = "msg2";
84
77 // Add two messages. 85 // Add two messages.
78 Message* msg1 = 86 Message* msg1 =
79 new Message(port1, 0, AllocMsg("msg1"), Message::kNormalPriority); 87 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1,
88 Message::kNormalPriority);
80 queue.Enqueue(msg1); 89 queue.Enqueue(msg1);
81 Message* msg2 = 90 Message* msg2 =
82 new Message(port2, 0, AllocMsg("msg2"), Message::kNormalPriority); 91 new Message(port2, 0, AllocMsg(str2), strlen(str2) + 1,
92 Message::kNormalPriority);
83 queue.Enqueue(msg2); 93 queue.Enqueue(msg2);
84 94
85 EXPECT(queue_peer.HasMessage()); 95 EXPECT(queue_peer.HasMessage());
86 queue.FlushAll(); 96 queue.FlushAll();
87 EXPECT(!queue_peer.HasMessage()); 97 EXPECT(!queue_peer.HasMessage());
88 98
89 // msg1 and msg2 already delete by FlushAll. 99 // msg1 and msg2 already delete by FlushAll.
90 } 100 }
91 101
92 102
93 TEST_CASE(MessageQueue_Flush) { 103 TEST_CASE(MessageQueue_Flush) {
94 MessageQueue queue; 104 MessageQueue queue;
95 MessageQueueTestPeer queue_peer(&queue); 105 MessageQueueTestPeer queue_peer(&queue);
96 Dart_Port port1 = 1; 106 Dart_Port port1 = 1;
97 Dart_Port port2 = 2; 107 Dart_Port port2 = 2;
98 108
109 const char* str1 = "msg1";
110 const char* str2 = "msg2";
111
99 // Add two messages on different ports. 112 // Add two messages on different ports.
100 Message* msg1 = 113 Message* msg1 =
101 new Message(port1, 0, AllocMsg("msg1"), Message::kNormalPriority); 114 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1,
115 Message::kNormalPriority);
102 queue.Enqueue(msg1); 116 queue.Enqueue(msg1);
103 Message* msg2 = 117 Message* msg2 =
104 new Message(port2, 0, AllocMsg("msg2"), Message::kNormalPriority); 118 new Message(port2, 0, AllocMsg(str2), strlen(str2) + 1,
119 Message::kNormalPriority);
105 queue.Enqueue(msg2); 120 queue.Enqueue(msg2);
106 EXPECT(queue_peer.HasMessage()); 121 EXPECT(queue_peer.HasMessage());
107 122
108 queue.Flush(port1); 123 queue.Flush(port1);
109 124
110 // One message is left in the queue. 125 // One message is left in the queue.
111 EXPECT(queue_peer.HasMessage()); 126 EXPECT(queue_peer.HasMessage());
112 Message* msg = queue.Dequeue(); 127 Message* msg = queue.Dequeue();
113 EXPECT(msg != NULL); 128 EXPECT(msg != NULL);
114 EXPECT_STREQ("msg2", reinterpret_cast<char*>(msg->data())); 129 EXPECT_STREQ(str2, reinterpret_cast<char*>(msg->data()));
115 130
116 EXPECT(!queue_peer.HasMessage()); 131 EXPECT(!queue_peer.HasMessage());
117 132
118 // msg1 is already deleted by Flush. 133 // msg1 is already deleted by Flush.
119 delete msg2; 134 delete msg2;
120 } 135 }
121 136
122 137
123 TEST_CASE(MessageQueue_Flush_MultipleMessages) { 138 TEST_CASE(MessageQueue_Flush_MultipleMessages) {
124 MessageQueue queue; 139 MessageQueue queue;
125 MessageQueueTestPeer queue_peer(&queue); 140 MessageQueueTestPeer queue_peer(&queue);
126 Dart_Port port1 = 1; 141 Dart_Port port1 = 1;
127 142
143 const char* str1 = "msg1";
144 const char* str2 = "msg2";
145
128 Message* msg1 = 146 Message* msg1 =
129 new Message(port1, 0, AllocMsg("msg1"), Message::kNormalPriority); 147 new Message(port1, 0, AllocMsg(str1), strlen(str1) + 1,
148 Message::kNormalPriority);
130 queue.Enqueue(msg1); 149 queue.Enqueue(msg1);
131 Message* msg2 = 150 Message* msg2 =
132 new Message(port1, 0, AllocMsg("msg2"), Message::kNormalPriority); 151 new Message(port1, 0, AllocMsg(str2), strlen(str2) + 1,
152 Message::kNormalPriority);
133 queue.Enqueue(msg2); 153 queue.Enqueue(msg2);
134 EXPECT(queue_peer.HasMessage()); 154 EXPECT(queue_peer.HasMessage());
135 155
136 queue.Flush(port1); 156 queue.Flush(port1);
137 157
138 // Queue is empty. 158 // Queue is empty.
139 EXPECT(!queue_peer.HasMessage()); 159 EXPECT(!queue_peer.HasMessage());
140 // msg1 and msg2 are already deleted by Flush. 160 // msg1 and msg2 are already deleted by Flush.
141 } 161 }
142 162
143 163
144 TEST_CASE(MessageQueue_Flush_EmptyQueue) { 164 TEST_CASE(MessageQueue_Flush_EmptyQueue) {
145 MessageQueue queue; 165 MessageQueue queue;
146 MessageQueueTestPeer queue_peer(&queue); 166 MessageQueueTestPeer queue_peer(&queue);
147 Dart_Port port1 = 1; 167 Dart_Port port1 = 1;
148 168
149 EXPECT(!queue_peer.HasMessage()); 169 EXPECT(!queue_peer.HasMessage());
150 queue.Flush(port1); 170 queue.Flush(port1);
151 171
152 // Queue is still empty. 172 // Queue is still empty.
153 EXPECT(!queue_peer.HasMessage()); 173 EXPECT(!queue_peer.HasMessage());
154 } 174 }
155 175
156 } // namespace dart 176 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/native_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698