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

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

Issue 1499853004: Adds a special case for sending an int over a port with the native API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Cleanup Created 5 years 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
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/lockers.h" 6 #include "vm/lockers.h"
7 #include "vm/message_handler.h" 7 #include "vm/message_handler.h"
8 #include "vm/os.h" 8 #include "vm/os.h"
9 #include "vm/port.h" 9 #include "vm/port.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 EXPECT(PortMap::PostMessage(new Message( 144 EXPECT(PortMap::PostMessage(new Message(
145 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, 145 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len,
146 Message::kNormalPriority))); 146 Message::kNormalPriority)));
147 147
148 // Check that the message notify callback was called. 148 // Check that the message notify callback was called.
149 EXPECT_EQ(1, handler.notify_count); 149 EXPECT_EQ(1, handler.notify_count);
150 PortMap::ClosePorts(&handler); 150 PortMap::ClosePorts(&handler);
151 } 151 }
152 152
153 153
154 TEST_CASE(PortMap_PostIntegerMessage) {
155 PortTestMessageHandler handler;
156 Dart_Port port = PortMap::CreatePort(&handler);
157 EXPECT_EQ(0, handler.notify_count);
158
159 EXPECT(PortMap::PostMessage(new Message(
160 port, Smi::New(42), Message::kNormalPriority)));
161
162 // Check that the message notify callback was called.
163 EXPECT_EQ(1, handler.notify_count);
164 PortMap::ClosePorts(&handler);
165 }
166
167
168 TEST_CASE(PortMap_PostNullMessage) {
169 PortTestMessageHandler handler;
170 Dart_Port port = PortMap::CreatePort(&handler);
171 EXPECT_EQ(0, handler.notify_count);
172
173 EXPECT(PortMap::PostMessage(new Message(
174 port, Object::null(), Message::kNormalPriority)));
175
176 // Check that the message notify callback was called.
177 EXPECT_EQ(1, handler.notify_count);
178 PortMap::ClosePorts(&handler);
179 }
180
181
154 TEST_CASE(PortMap_PostMessageClosedPort) { 182 TEST_CASE(PortMap_PostMessageClosedPort) {
155 // Create a port id and make it invalid. 183 // Create a port id and make it invalid.
156 PortTestMessageHandler handler; 184 PortTestMessageHandler handler;
157 Dart_Port port = PortMap::CreatePort(&handler); 185 Dart_Port port = PortMap::CreatePort(&handler);
158 PortMap::ClosePort(port); 186 PortMap::ClosePort(port);
159 187
160 const char* message = "msg"; 188 const char* message = "msg";
161 intptr_t message_len = strlen(message) + 1; 189 intptr_t message_len = strlen(message) + 1;
162 190
163 EXPECT(!PortMap::PostMessage(new Message( 191 EXPECT(!PortMap::PostMessage(new Message(
164 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, 192 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len,
165 Message::kNormalPriority))); 193 Message::kNormalPriority)));
166 } 194 }
167 195
168 } // namespace dart 196 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698