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

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

Issue 15689013: - Modify dart_api.h to be a proper C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« runtime/bin/dartutils.h ('K') | « runtime/vm/dart_api_message.cc ('k') | no next file » | 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Zone* zone = Isolate::Current()->current_zone(); 58 Zone* zone = Isolate::Current()->current_zone();
59 return zone->Realloc<uint8_t>(ptr, old_size, new_size); 59 return zone->Realloc<uint8_t>(ptr, old_size, new_size);
60 } 60 }
61 61
62 62
63 // Compare two Dart_CObject object graphs rooted in first and 63 // Compare two Dart_CObject object graphs rooted in first and
64 // second. The second graph will be destroyed by this operation no matter 64 // second. The second graph will be destroyed by this operation no matter
65 // whether the graphs are equal or not. 65 // whether the graphs are equal or not.
66 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) { 66 static void CompareDartCObjects(Dart_CObject* first, Dart_CObject* second) {
67 // Return immediately if entering a cycle. 67 // Return immediately if entering a cycle.
68 if (second->type == Dart_CObject::kNumberOfTypes) return; 68 if (second->type == Dart_CObject_kNumberOfTypes) return;
69 69
70 EXPECT_NE(first, second); 70 EXPECT_NE(first, second);
71 EXPECT_EQ(first->type, second->type); 71 EXPECT_EQ(first->type, second->type);
72 switch (first->type) { 72 switch (first->type) {
73 case Dart_CObject::kNull: 73 case Dart_CObject_kNull:
74 // Nothing more to compare. 74 // Nothing more to compare.
75 break; 75 break;
76 case Dart_CObject::kBool: 76 case Dart_CObject_kBool:
77 EXPECT_EQ(first->value.as_bool, second->value.as_bool); 77 EXPECT_EQ(first->value.as_bool, second->value.as_bool);
78 break; 78 break;
79 case Dart_CObject::kInt32: 79 case Dart_CObject_kInt32:
80 EXPECT_EQ(first->value.as_int32, second->value.as_int32); 80 EXPECT_EQ(first->value.as_int32, second->value.as_int32);
81 break; 81 break;
82 case Dart_CObject::kInt64: 82 case Dart_CObject_kInt64:
83 EXPECT_EQ(first->value.as_int64, second->value.as_int64); 83 EXPECT_EQ(first->value.as_int64, second->value.as_int64);
84 break; 84 break;
85 case Dart_CObject::kBigint: 85 case Dart_CObject_kBigint:
86 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint); 86 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint);
87 break; 87 break;
88 case Dart_CObject::kDouble: 88 case Dart_CObject_kDouble:
89 EXPECT_EQ(first->value.as_double, second->value.as_double); 89 EXPECT_EQ(first->value.as_double, second->value.as_double);
90 break; 90 break;
91 case Dart_CObject::kString: 91 case Dart_CObject_kString:
92 EXPECT_STREQ(first->value.as_string, second->value.as_string); 92 EXPECT_STREQ(first->value.as_string, second->value.as_string);
93 break; 93 break;
94 case Dart_CObject::kTypedData: 94 case Dart_CObject_kTypedData:
95 EXPECT_EQ(first->value.as_typed_data.length, 95 EXPECT_EQ(first->value.as_typed_data.length,
96 second->value.as_typed_data.length); 96 second->value.as_typed_data.length);
97 for (int i = 0; i < first->value.as_typed_data.length; i++) { 97 for (int i = 0; i < first->value.as_typed_data.length; i++) {
98 EXPECT_EQ(first->value.as_typed_data.values[i], 98 EXPECT_EQ(first->value.as_typed_data.values[i],
99 second->value.as_typed_data.values[i]); 99 second->value.as_typed_data.values[i]);
100 } 100 }
101 break; 101 break;
102 case Dart_CObject::kArray: 102 case Dart_CObject_kArray:
103 // Use invalid type as a visited marker to avoid infinite 103 // Use invalid type as a visited marker to avoid infinite
104 // recursion on graphs with cycles. 104 // recursion on graphs with cycles.
105 second->type = Dart_CObject::kNumberOfTypes; 105 second->type = Dart_CObject_kNumberOfTypes;
106 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length); 106 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length);
107 for (int i = 0; i < first->value.as_array.length; i++) { 107 for (int i = 0; i < first->value.as_array.length; i++) {
108 CompareDartCObjects(first->value.as_array.values[i], 108 CompareDartCObjects(first->value.as_array.values[i],
109 second->value.as_array.values[i]); 109 second->value.as_array.values[i]);
110 } 110 }
111 break; 111 break;
112 default: 112 default:
113 EXPECT(false); 113 EXPECT(false);
114 } 114 }
115 } 115 }
(...skipping 26 matching lines...) Expand all
142 SnapshotReader reader(buffer, buffer_len, 142 SnapshotReader reader(buffer, buffer_len,
143 Snapshot::kMessage, Isolate::Current()); 143 Snapshot::kMessage, Isolate::Current());
144 const Object& serialized_object = Object::Handle(reader.ReadObject()); 144 const Object& serialized_object = Object::Handle(reader.ReadObject());
145 EXPECT(Equals(null_object, serialized_object)); 145 EXPECT(Equals(null_object, serialized_object));
146 146
147 // Read object back from the snapshot into a C structure. 147 // Read object back from the snapshot into a C structure.
148 ApiNativeScope scope; 148 ApiNativeScope scope;
149 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 149 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
150 Dart_CObject* root = api_reader.ReadMessage(); 150 Dart_CObject* root = api_reader.ReadMessage();
151 EXPECT_NOTNULL(root); 151 EXPECT_NOTNULL(root);
152 EXPECT_EQ(Dart_CObject::kNull, root->type); 152 EXPECT_EQ(Dart_CObject_kNull, root->type);
153 CheckEncodeDecodeMessage(root); 153 CheckEncodeDecodeMessage(root);
154 } 154 }
155 155
156 156
157 TEST_CASE(SerializeSmi1) { 157 TEST_CASE(SerializeSmi1) {
158 StackZone zone(Isolate::Current()); 158 StackZone zone(Isolate::Current());
159 159
160 // Write snapshot with object content. 160 // Write snapshot with object content.
161 uint8_t* buffer; 161 uint8_t* buffer;
162 MessageWriter writer(&buffer, &zone_allocator); 162 MessageWriter writer(&buffer, &zone_allocator);
163 const Smi& smi = Smi::Handle(Smi::New(124)); 163 const Smi& smi = Smi::Handle(Smi::New(124));
164 writer.WriteMessage(smi); 164 writer.WriteMessage(smi);
165 intptr_t buffer_len = writer.BytesWritten(); 165 intptr_t buffer_len = writer.BytesWritten();
166 166
167 // Read object back from the snapshot. 167 // Read object back from the snapshot.
168 SnapshotReader reader(buffer, buffer_len, 168 SnapshotReader reader(buffer, buffer_len,
169 Snapshot::kMessage, Isolate::Current()); 169 Snapshot::kMessage, Isolate::Current());
170 const Object& serialized_object = Object::Handle(reader.ReadObject()); 170 const Object& serialized_object = Object::Handle(reader.ReadObject());
171 EXPECT(Equals(smi, serialized_object)); 171 EXPECT(Equals(smi, serialized_object));
172 172
173 // Read object back from the snapshot into a C structure. 173 // Read object back from the snapshot into a C structure.
174 ApiNativeScope scope; 174 ApiNativeScope scope;
175 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 175 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
176 Dart_CObject* root = api_reader.ReadMessage(); 176 Dart_CObject* root = api_reader.ReadMessage();
177 EXPECT_NOTNULL(root); 177 EXPECT_NOTNULL(root);
178 EXPECT_EQ(Dart_CObject::kInt32, root->type); 178 EXPECT_EQ(Dart_CObject_kInt32, root->type);
179 EXPECT_EQ(smi.Value(), root->value.as_int32); 179 EXPECT_EQ(smi.Value(), root->value.as_int32);
180 CheckEncodeDecodeMessage(root); 180 CheckEncodeDecodeMessage(root);
181 } 181 }
182 182
183 183
184 TEST_CASE(SerializeSmi2) { 184 TEST_CASE(SerializeSmi2) {
185 StackZone zone(Isolate::Current()); 185 StackZone zone(Isolate::Current());
186 186
187 // Write snapshot with object content. 187 // Write snapshot with object content.
188 uint8_t* buffer; 188 uint8_t* buffer;
189 MessageWriter writer(&buffer, &zone_allocator); 189 MessageWriter writer(&buffer, &zone_allocator);
190 const Smi& smi = Smi::Handle(Smi::New(-1)); 190 const Smi& smi = Smi::Handle(Smi::New(-1));
191 writer.WriteMessage(smi); 191 writer.WriteMessage(smi);
192 intptr_t buffer_len = writer.BytesWritten(); 192 intptr_t buffer_len = writer.BytesWritten();
193 193
194 // Read object back from the snapshot. 194 // Read object back from the snapshot.
195 SnapshotReader reader(buffer, buffer_len, 195 SnapshotReader reader(buffer, buffer_len,
196 Snapshot::kMessage, Isolate::Current()); 196 Snapshot::kMessage, Isolate::Current());
197 const Object& serialized_object = Object::Handle(reader.ReadObject()); 197 const Object& serialized_object = Object::Handle(reader.ReadObject());
198 EXPECT(Equals(smi, serialized_object)); 198 EXPECT(Equals(smi, serialized_object));
199 199
200 // Read object back from the snapshot into a C structure. 200 // Read object back from the snapshot into a C structure.
201 ApiNativeScope scope; 201 ApiNativeScope scope;
202 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 202 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
203 Dart_CObject* root = api_reader.ReadMessage(); 203 Dart_CObject* root = api_reader.ReadMessage();
204 EXPECT_NOTNULL(root); 204 EXPECT_NOTNULL(root);
205 EXPECT_EQ(Dart_CObject::kInt32, root->type); 205 EXPECT_EQ(Dart_CObject_kInt32, root->type);
206 EXPECT_EQ(smi.Value(), root->value.as_int32); 206 EXPECT_EQ(smi.Value(), root->value.as_int32);
207 CheckEncodeDecodeMessage(root); 207 CheckEncodeDecodeMessage(root);
208 } 208 }
209 209
210 210
211 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { 211 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) {
212 // Write snapshot with object content. 212 // Write snapshot with object content.
213 uint8_t* buffer; 213 uint8_t* buffer;
214 MessageWriter writer(&buffer, &zone_allocator); 214 MessageWriter writer(&buffer, &zone_allocator);
215 writer.WriteMessage(mint); 215 writer.WriteMessage(mint);
(...skipping 19 matching lines...) Expand all
235 235
236 Mint& mint = Mint::Handle(); 236 Mint& mint = Mint::Handle();
237 mint ^= Integer::New(value); 237 mint ^= Integer::New(value);
238 ApiNativeScope scope; 238 ApiNativeScope scope;
239 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint); 239 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint);
240 // On 64-bit platforms mints always require 64-bits as the smi range 240 // On 64-bit platforms mints always require 64-bits as the smi range
241 // here covers most of the 64-bit range. On 32-bit platforms the smi 241 // here covers most of the 64-bit range. On 32-bit platforms the smi
242 // range covers most of the 32-bit range and values outside that 242 // range covers most of the 32-bit range and values outside that
243 // range are also represented as mints. 243 // range are also represented as mints.
244 #if defined(ARCH_IS_64_BIT) 244 #if defined(ARCH_IS_64_BIT)
245 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type); 245 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type);
246 EXPECT_EQ(value, mint_cobject->value.as_int64); 246 EXPECT_EQ(value, mint_cobject->value.as_int64);
247 #else 247 #else
248 if (kMinInt32 < value && value < kMaxInt32) { 248 if (kMinInt32 < value && value < kMaxInt32) {
249 EXPECT_EQ(Dart_CObject::kInt32, mint_cobject->type); 249 EXPECT_EQ(Dart_CObject_kInt32, mint_cobject->type);
250 EXPECT_EQ(value, mint_cobject->value.as_int32); 250 EXPECT_EQ(value, mint_cobject->value.as_int32);
251 } else { 251 } else {
252 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type); 252 EXPECT_EQ(Dart_CObject_kInt64, mint_cobject->type);
253 EXPECT_EQ(value, mint_cobject->value.as_int64); 253 EXPECT_EQ(value, mint_cobject->value.as_int64);
254 } 254 }
255 #endif 255 #endif
256 } 256 }
257 257
258 258
259 TEST_CASE(SerializeMints) { 259 TEST_CASE(SerializeMints) {
260 // Min positive mint. 260 // Min positive mint.
261 CheckMint(Smi::kMaxValue + 1); 261 CheckMint(Smi::kMaxValue + 1);
262 // Min positive mint + 1. 262 // Min positive mint + 1.
(...skipping 27 matching lines...) Expand all
290 SnapshotReader reader(buffer, buffer_len, 290 SnapshotReader reader(buffer, buffer_len,
291 Snapshot::kMessage, Isolate::Current()); 291 Snapshot::kMessage, Isolate::Current());
292 const Object& serialized_object = Object::Handle(reader.ReadObject()); 292 const Object& serialized_object = Object::Handle(reader.ReadObject());
293 EXPECT(Equals(dbl, serialized_object)); 293 EXPECT(Equals(dbl, serialized_object));
294 294
295 // Read object back from the snapshot into a C structure. 295 // Read object back from the snapshot into a C structure.
296 ApiNativeScope scope; 296 ApiNativeScope scope;
297 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 297 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
298 Dart_CObject* root = api_reader.ReadMessage(); 298 Dart_CObject* root = api_reader.ReadMessage();
299 EXPECT_NOTNULL(root); 299 EXPECT_NOTNULL(root);
300 EXPECT_EQ(Dart_CObject::kDouble, root->type); 300 EXPECT_EQ(Dart_CObject_kDouble, root->type);
301 EXPECT_EQ(dbl.value(), root->value.as_double); 301 EXPECT_EQ(dbl.value(), root->value.as_double);
302 CheckEncodeDecodeMessage(root); 302 CheckEncodeDecodeMessage(root);
303 } 303 }
304 304
305 305
306 TEST_CASE(SerializeTrue) { 306 TEST_CASE(SerializeTrue) {
307 StackZone zone(Isolate::Current()); 307 StackZone zone(Isolate::Current());
308 308
309 // Write snapshot with true object. 309 // Write snapshot with true object.
310 uint8_t* buffer; 310 uint8_t* buffer;
311 MessageWriter writer(&buffer, &zone_allocator); 311 MessageWriter writer(&buffer, &zone_allocator);
312 const Bool& bl = Bool::True(); 312 const Bool& bl = Bool::True();
313 writer.WriteMessage(bl); 313 writer.WriteMessage(bl);
314 intptr_t buffer_len = writer.BytesWritten(); 314 intptr_t buffer_len = writer.BytesWritten();
315 315
316 // Read object back from the snapshot. 316 // Read object back from the snapshot.
317 SnapshotReader reader(buffer, buffer_len, 317 SnapshotReader reader(buffer, buffer_len,
318 Snapshot::kMessage, Isolate::Current()); 318 Snapshot::kMessage, Isolate::Current());
319 const Object& serialized_object = Object::Handle(reader.ReadObject()); 319 const Object& serialized_object = Object::Handle(reader.ReadObject());
320 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); 320 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString());
321 321
322 EXPECT(Equals(bl, serialized_object)); 322 EXPECT(Equals(bl, serialized_object));
323 323
324 // Read object back from the snapshot into a C structure. 324 // Read object back from the snapshot into a C structure.
325 ApiNativeScope scope; 325 ApiNativeScope scope;
326 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 326 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
327 Dart_CObject* root = api_reader.ReadMessage(); 327 Dart_CObject* root = api_reader.ReadMessage();
328 EXPECT_NOTNULL(root); 328 EXPECT_NOTNULL(root);
329 EXPECT_EQ(Dart_CObject::kBool, root->type); 329 EXPECT_EQ(Dart_CObject_kBool, root->type);
330 EXPECT_EQ(true, root->value.as_bool); 330 EXPECT_EQ(true, root->value.as_bool);
331 CheckEncodeDecodeMessage(root); 331 CheckEncodeDecodeMessage(root);
332 } 332 }
333 333
334 334
335 TEST_CASE(SerializeFalse) { 335 TEST_CASE(SerializeFalse) {
336 StackZone zone(Isolate::Current()); 336 StackZone zone(Isolate::Current());
337 337
338 // Write snapshot with false object. 338 // Write snapshot with false object.
339 uint8_t* buffer; 339 uint8_t* buffer;
340 MessageWriter writer(&buffer, &zone_allocator); 340 MessageWriter writer(&buffer, &zone_allocator);
341 const Bool& bl = Bool::False(); 341 const Bool& bl = Bool::False();
342 writer.WriteMessage(bl); 342 writer.WriteMessage(bl);
343 intptr_t buffer_len = writer.BytesWritten(); 343 intptr_t buffer_len = writer.BytesWritten();
344 344
345 // Read object back from the snapshot. 345 // Read object back from the snapshot.
346 SnapshotReader reader(buffer, buffer_len, 346 SnapshotReader reader(buffer, buffer_len,
347 Snapshot::kMessage, Isolate::Current()); 347 Snapshot::kMessage, Isolate::Current());
348 const Object& serialized_object = Object::Handle(reader.ReadObject()); 348 const Object& serialized_object = Object::Handle(reader.ReadObject());
349 EXPECT(Equals(bl, serialized_object)); 349 EXPECT(Equals(bl, serialized_object));
350 350
351 // Read object back from the snapshot into a C structure. 351 // Read object back from the snapshot into a C structure.
352 ApiNativeScope scope; 352 ApiNativeScope scope;
353 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 353 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
354 Dart_CObject* root = api_reader.ReadMessage(); 354 Dart_CObject* root = api_reader.ReadMessage();
355 EXPECT_NOTNULL(root); 355 EXPECT_NOTNULL(root);
356 EXPECT_EQ(Dart_CObject::kBool, root->type); 356 EXPECT_EQ(Dart_CObject_kBool, root->type);
357 EXPECT_EQ(false, root->value.as_bool); 357 EXPECT_EQ(false, root->value.as_bool);
358 CheckEncodeDecodeMessage(root); 358 CheckEncodeDecodeMessage(root);
359 } 359 }
360 360
361 361
362 static uword allocator(intptr_t size) { 362 static uword allocator(intptr_t size) {
363 return reinterpret_cast<uword>(malloc(size)); 363 return reinterpret_cast<uword>(malloc(size));
364 } 364 }
365 365
366 366
(...skipping 18 matching lines...) Expand all
385 385
386 EXPECT_STREQ(BigintOperations::ToHexCString(bigint, &allocator), 386 EXPECT_STREQ(BigintOperations::ToHexCString(bigint, &allocator),
387 BigintOperations::ToHexCString(obj, &allocator)); 387 BigintOperations::ToHexCString(obj, &allocator));
388 388
389 // Read object back from the snapshot into a C structure. 389 // Read object back from the snapshot into a C structure.
390 ApiNativeScope scope; 390 ApiNativeScope scope;
391 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 391 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
392 Dart_CObject* root = api_reader.ReadMessage(); 392 Dart_CObject* root = api_reader.ReadMessage();
393 // Bigint not supported. 393 // Bigint not supported.
394 EXPECT_NOTNULL(root); 394 EXPECT_NOTNULL(root);
395 EXPECT_EQ(Dart_CObject::kBigint, root->type); 395 EXPECT_EQ(Dart_CObject_kBigint, root->type);
396 EXPECT_STREQ("270FFFFFFFFFFFFFD8F0", root->value.as_bigint); 396 EXPECT_STREQ("270FFFFFFFFFFFFFD8F0", root->value.as_bigint);
397 CheckEncodeDecodeMessage(root); 397 CheckEncodeDecodeMessage(root);
398 } 398 }
399 399
400 400
401 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { 401 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) {
402 // Write snapshot with object content. 402 // Write snapshot with object content.
403 uint8_t* buffer; 403 uint8_t* buffer;
404 MessageWriter writer(&buffer, &zone_allocator); 404 MessageWriter writer(&buffer, &zone_allocator);
405 writer.WriteMessage(bigint); 405 writer.WriteMessage(bigint);
(...skipping 21 matching lines...) Expand all
427 } 427 }
428 428
429 429
430 void CheckBigint(const char* bigint_value) { 430 void CheckBigint(const char* bigint_value) {
431 StackZone zone(Isolate::Current()); 431 StackZone zone(Isolate::Current());
432 ApiNativeScope scope; 432 ApiNativeScope scope;
433 433
434 Bigint& bigint = Bigint::Handle(); 434 Bigint& bigint = Bigint::Handle();
435 bigint ^= BigintOperations::NewFromCString(bigint_value); 435 bigint ^= BigintOperations::NewFromCString(bigint_value);
436 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); 436 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint);
437 EXPECT_EQ(Dart_CObject::kBigint, bigint_cobject->type); 437 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type);
438 if (bigint_value[0] == '0') { 438 if (bigint_value[0] == '0') {
439 EXPECT_STREQ(bigint_value + 2, bigint_cobject->value.as_bigint); 439 EXPECT_STREQ(bigint_value + 2, bigint_cobject->value.as_bigint);
440 } else { 440 } else {
441 EXPECT_EQ('-', bigint_value[0]); 441 EXPECT_EQ('-', bigint_value[0]);
442 EXPECT_EQ('-', bigint_cobject->value.as_bigint[0]); 442 EXPECT_EQ('-', bigint_cobject->value.as_bigint[0]);
443 EXPECT_STREQ(bigint_value + 3, bigint_cobject->value.as_bigint + 1); 443 EXPECT_STREQ(bigint_value + 3, bigint_cobject->value.as_bigint + 1);
444 } 444 }
445 } 445 }
446 446
447 447
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 SnapshotReader reader(buffer, buffer_len, 513 SnapshotReader reader(buffer, buffer_len,
514 Snapshot::kMessage, Isolate::Current()); 514 Snapshot::kMessage, Isolate::Current());
515 String& serialized_str = String::Handle(); 515 String& serialized_str = String::Handle();
516 serialized_str ^= reader.ReadObject(); 516 serialized_str ^= reader.ReadObject();
517 EXPECT(str.Equals(serialized_str)); 517 EXPECT(str.Equals(serialized_str));
518 518
519 // Read object back from the snapshot into a C structure. 519 // Read object back from the snapshot into a C structure.
520 ApiNativeScope scope; 520 ApiNativeScope scope;
521 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 521 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
522 Dart_CObject* root = api_reader.ReadMessage(); 522 Dart_CObject* root = api_reader.ReadMessage();
523 EXPECT_EQ(Dart_CObject::kString, root->type); 523 EXPECT_EQ(Dart_CObject_kString, root->type);
524 EXPECT_STREQ(cstr, root->value.as_string); 524 EXPECT_STREQ(cstr, root->value.as_string);
525 CheckEncodeDecodeMessage(root); 525 CheckEncodeDecodeMessage(root);
526 } 526 }
527 527
528 528
529 TEST_CASE(SerializeString) { 529 TEST_CASE(SerializeString) {
530 TestString("This string shall be serialized"); 530 TestString("This string shall be serialized");
531 TestString("æøå"); // This file is UTF-8 encoded. 531 TestString("æøå"); // This file is UTF-8 encoded.
532 const char* data = "\x01" 532 const char* data = "\x01"
533 "\x7F" 533 "\x7F"
(...skipping 27 matching lines...) Expand all
561 SnapshotReader reader(buffer, buffer_len, 561 SnapshotReader reader(buffer, buffer_len,
562 Snapshot::kMessage, Isolate::Current()); 562 Snapshot::kMessage, Isolate::Current());
563 Array& serialized_array = Array::Handle(); 563 Array& serialized_array = Array::Handle();
564 serialized_array ^= reader.ReadObject(); 564 serialized_array ^= reader.ReadObject();
565 EXPECT(array.Equals(serialized_array)); 565 EXPECT(array.Equals(serialized_array));
566 566
567 // Read object back from the snapshot into a C structure. 567 // Read object back from the snapshot into a C structure.
568 ApiNativeScope scope; 568 ApiNativeScope scope;
569 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 569 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
570 Dart_CObject* root = api_reader.ReadMessage(); 570 Dart_CObject* root = api_reader.ReadMessage();
571 EXPECT_EQ(Dart_CObject::kArray, root->type); 571 EXPECT_EQ(Dart_CObject_kArray, root->type);
572 EXPECT_EQ(kArrayLength, root->value.as_array.length); 572 EXPECT_EQ(kArrayLength, root->value.as_array.length);
573 for (int i = 0; i < kArrayLength; i++) { 573 for (int i = 0; i < kArrayLength; i++) {
574 Dart_CObject* element = root->value.as_array.values[i]; 574 Dart_CObject* element = root->value.as_array.values[i];
575 EXPECT_EQ(Dart_CObject::kInt32, element->type); 575 EXPECT_EQ(Dart_CObject_kInt32, element->type);
576 EXPECT_EQ(i, element->value.as_int32); 576 EXPECT_EQ(i, element->value.as_int32);
577 } 577 }
578 CheckEncodeDecodeMessage(root); 578 CheckEncodeDecodeMessage(root);
579 } 579 }
580 580
581 581
582 TEST_CASE(SerializeEmptyArray) { 582 TEST_CASE(SerializeEmptyArray) {
583 StackZone zone(Isolate::Current()); 583 StackZone zone(Isolate::Current());
584 584
585 // Write snapshot with object content. 585 // Write snapshot with object content.
586 uint8_t* buffer; 586 uint8_t* buffer;
587 MessageWriter writer(&buffer, &zone_allocator); 587 MessageWriter writer(&buffer, &zone_allocator);
588 const int kArrayLength = 0; 588 const int kArrayLength = 0;
589 Array& array = Array::Handle(Array::New(kArrayLength)); 589 Array& array = Array::Handle(Array::New(kArrayLength));
590 writer.WriteMessage(array); 590 writer.WriteMessage(array);
591 intptr_t buffer_len = writer.BytesWritten(); 591 intptr_t buffer_len = writer.BytesWritten();
592 592
593 // Read object back from the snapshot. 593 // Read object back from the snapshot.
594 SnapshotReader reader(buffer, buffer_len, 594 SnapshotReader reader(buffer, buffer_len,
595 Snapshot::kMessage, Isolate::Current()); 595 Snapshot::kMessage, Isolate::Current());
596 Array& serialized_array = Array::Handle(); 596 Array& serialized_array = Array::Handle();
597 serialized_array ^= reader.ReadObject(); 597 serialized_array ^= reader.ReadObject();
598 EXPECT(array.Equals(serialized_array)); 598 EXPECT(array.Equals(serialized_array));
599 599
600 // Read object back from the snapshot into a C structure. 600 // Read object back from the snapshot into a C structure.
601 ApiNativeScope scope; 601 ApiNativeScope scope;
602 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 602 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
603 Dart_CObject* root = api_reader.ReadMessage(); 603 Dart_CObject* root = api_reader.ReadMessage();
604 EXPECT_EQ(Dart_CObject::kArray, root->type); 604 EXPECT_EQ(Dart_CObject_kArray, root->type);
605 EXPECT_EQ(kArrayLength, root->value.as_array.length); 605 EXPECT_EQ(kArrayLength, root->value.as_array.length);
606 EXPECT(root->value.as_array.values == NULL); 606 EXPECT(root->value.as_array.values == NULL);
607 CheckEncodeDecodeMessage(root); 607 CheckEncodeDecodeMessage(root);
608 } 608 }
609 609
610 610
611 TEST_CASE(SerializeByteArray) { 611 TEST_CASE(SerializeByteArray) {
612 StackZone zone(Isolate::Current()); 612 StackZone zone(Isolate::Current());
613 613
614 // Write snapshot with object content. 614 // Write snapshot with object content.
(...skipping 12 matching lines...) Expand all
627 SnapshotReader reader(buffer, buffer_len, 627 SnapshotReader reader(buffer, buffer_len,
628 Snapshot::kMessage, Isolate::Current()); 628 Snapshot::kMessage, Isolate::Current());
629 TypedData& serialized_typed_data = TypedData::Handle(); 629 TypedData& serialized_typed_data = TypedData::Handle();
630 serialized_typed_data ^= reader.ReadObject(); 630 serialized_typed_data ^= reader.ReadObject();
631 EXPECT(serialized_typed_data.IsTypedData()); 631 EXPECT(serialized_typed_data.IsTypedData());
632 632
633 // Read object back from the snapshot into a C structure. 633 // Read object back from the snapshot into a C structure.
634 ApiNativeScope scope; 634 ApiNativeScope scope;
635 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 635 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
636 Dart_CObject* root = api_reader.ReadMessage(); 636 Dart_CObject* root = api_reader.ReadMessage();
637 EXPECT_EQ(Dart_CObject::kTypedData, root->type); 637 EXPECT_EQ(Dart_CObject_kTypedData, root->type);
638 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); 638 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length);
639 for (int i = 0; i < kTypedDataLength; i++) { 639 for (int i = 0; i < kTypedDataLength; i++) {
640 EXPECT(root->value.as_typed_data.values[i] == i); 640 EXPECT(root->value.as_typed_data.values[i] == i);
641 } 641 }
642 CheckEncodeDecodeMessage(root); 642 CheckEncodeDecodeMessage(root);
643 } 643 }
644 644
645 645
646 #define TEST_TYPED_ARRAY(darttype, ctype) \ 646 #define TEST_TYPED_ARRAY(darttype, ctype) \
647 { \ 647 { \
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 SnapshotReader reader(buffer, buffer_len, 736 SnapshotReader reader(buffer, buffer_len,
737 Snapshot::kMessage, Isolate::Current()); 737 Snapshot::kMessage, Isolate::Current());
738 TypedData& serialized_typed_data = TypedData::Handle(); 738 TypedData& serialized_typed_data = TypedData::Handle();
739 serialized_typed_data ^= reader.ReadObject(); 739 serialized_typed_data ^= reader.ReadObject();
740 EXPECT(serialized_typed_data.IsTypedData()); 740 EXPECT(serialized_typed_data.IsTypedData());
741 741
742 // Read object back from the snapshot into a C structure. 742 // Read object back from the snapshot into a C structure.
743 ApiNativeScope scope; 743 ApiNativeScope scope;
744 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 744 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
745 Dart_CObject* root = api_reader.ReadMessage(); 745 Dart_CObject* root = api_reader.ReadMessage();
746 EXPECT_EQ(Dart_CObject::kTypedData, root->type); 746 EXPECT_EQ(Dart_CObject_kTypedData, root->type);
747 EXPECT_EQ(Dart_CObject::kUint8Array, root->value.as_typed_data.type); 747 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type);
748 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); 748 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length);
749 EXPECT(root->value.as_typed_data.values == NULL); 749 EXPECT(root->value.as_typed_data.values == NULL);
750 CheckEncodeDecodeMessage(root); 750 CheckEncodeDecodeMessage(root);
751 } 751 }
752 752
753 753
754 class TestSnapshotWriter : public SnapshotWriter { 754 class TestSnapshotWriter : public SnapshotWriter {
755 public: 755 public:
756 static const intptr_t kInitialSize = 64 * KB; 756 static const intptr_t kInitialSize = 64 * KB;
757 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) 757 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc)
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 1232
1233 static const int kArrayLength = 2; 1233 static const int kArrayLength = 2;
1234 intptr_t data[kArrayLength] = {1, 2}; 1234 intptr_t data[kArrayLength] = {1, 2};
1235 int len = kArrayLength; 1235 int len = kArrayLength;
1236 writer.WriteMessage(len, data); 1236 writer.WriteMessage(len, data);
1237 1237
1238 // Read object back from the snapshot into a C structure. 1238 // Read object back from the snapshot into a C structure.
1239 ApiNativeScope scope; 1239 ApiNativeScope scope;
1240 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator); 1240 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator);
1241 Dart_CObject* root = api_reader.ReadMessage(); 1241 Dart_CObject* root = api_reader.ReadMessage();
1242 EXPECT_EQ(Dart_CObject::kArray, root->type); 1242 EXPECT_EQ(Dart_CObject_kArray, root->type);
1243 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1243 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1244 for (int i = 0; i < kArrayLength; i++) { 1244 for (int i = 0; i < kArrayLength; i++) {
1245 Dart_CObject* element = root->value.as_array.values[i]; 1245 Dart_CObject* element = root->value.as_array.values[i];
1246 EXPECT_EQ(Dart_CObject::kInt32, element->type); 1246 EXPECT_EQ(Dart_CObject_kInt32, element->type);
1247 EXPECT_EQ(i + 1, element->value.as_int32); 1247 EXPECT_EQ(i + 1, element->value.as_int32);
1248 } 1248 }
1249 CheckEncodeDecodeMessage(root); 1249 CheckEncodeDecodeMessage(root);
1250 } 1250 }
1251 1251
1252 1252
1253 // Helper function to call a top level Dart function, serialize the 1253 // Helper function to call a top level Dart function, serialize the
1254 // result and deserialize the result into a Dart_CObject structure. 1254 // result and deserialize the result into a Dart_CObject structure.
1255 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, 1255 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib,
1256 const char* dart_function) { 1256 const char* dart_function) {
(...skipping 21 matching lines...) Expand all
1278 String& str = String::Handle(); 1278 String& str = String::Handle();
1279 str ^= Api::UnwrapHandle(dart_string); 1279 str ^= Api::UnwrapHandle(dart_string);
1280 writer.WriteMessage(str); 1280 writer.WriteMessage(str);
1281 intptr_t buffer_len = writer.BytesWritten(); 1281 intptr_t buffer_len = writer.BytesWritten();
1282 1282
1283 // Read object back from the snapshot into a C structure. 1283 // Read object back from the snapshot into a C structure.
1284 ApiNativeScope scope; 1284 ApiNativeScope scope;
1285 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1285 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1286 Dart_CObject* root = api_reader.ReadMessage(); 1286 Dart_CObject* root = api_reader.ReadMessage();
1287 EXPECT_NOTNULL(root); 1287 EXPECT_NOTNULL(root);
1288 EXPECT_EQ(Dart_CObject::kString, root->type); 1288 EXPECT_EQ(Dart_CObject_kString, root->type);
1289 EXPECT_STREQ(expected, root->value.as_string); 1289 EXPECT_STREQ(expected, root->value.as_string);
1290 CheckEncodeDecodeMessage(root); 1290 CheckEncodeDecodeMessage(root);
1291 } 1291 }
1292 1292
1293 1293
1294 static void CheckStringInvalid(Dart_Handle dart_string) { 1294 static void CheckStringInvalid(Dart_Handle dart_string) {
1295 StackZone zone(Isolate::Current()); 1295 StackZone zone(Isolate::Current());
1296 uint8_t* buffer; 1296 uint8_t* buffer;
1297 MessageWriter writer(&buffer, &zone_allocator); 1297 MessageWriter writer(&buffer, &zone_allocator);
1298 String& str = String::Handle(); 1298 String& str = String::Handle();
1299 str ^= Api::UnwrapHandle(dart_string); 1299 str ^= Api::UnwrapHandle(dart_string);
1300 writer.WriteMessage(str); 1300 writer.WriteMessage(str);
1301 intptr_t buffer_len = writer.BytesWritten(); 1301 intptr_t buffer_len = writer.BytesWritten();
1302 1302
1303 // Read object back from the snapshot into a C structure. 1303 // Read object back from the snapshot into a C structure.
1304 ApiNativeScope scope; 1304 ApiNativeScope scope;
1305 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1305 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1306 Dart_CObject* root = api_reader.ReadMessage(); 1306 Dart_CObject* root = api_reader.ReadMessage();
1307 EXPECT_NOTNULL(root); 1307 EXPECT_NOTNULL(root);
1308 EXPECT_EQ(Dart_CObject::kUnsupported, root->type); 1308 EXPECT_EQ(Dart_CObject_kUnsupported, root->type);
1309 } 1309 }
1310 1310
1311 1311
1312 UNIT_TEST_CASE(DartGeneratedMessages) { 1312 UNIT_TEST_CASE(DartGeneratedMessages) {
1313 static const char* kCustomIsolateScriptChars = 1313 static const char* kCustomIsolateScriptChars =
1314 "getSmi() {\n" 1314 "getSmi() {\n"
1315 " return 42;\n" 1315 " return 42;\n"
1316 "}\n" 1316 "}\n"
1317 "getBigint() {\n" 1317 "getBigint() {\n"
1318 " return -0x424242424242424242424242424242424242;\n" 1318 " return -0x424242424242424242424242424242424242;\n"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 Smi& smi = Smi::Handle(); 1408 Smi& smi = Smi::Handle();
1409 smi ^= Api::UnwrapHandle(smi_result); 1409 smi ^= Api::UnwrapHandle(smi_result);
1410 writer.WriteMessage(smi); 1410 writer.WriteMessage(smi);
1411 intptr_t buffer_len = writer.BytesWritten(); 1411 intptr_t buffer_len = writer.BytesWritten();
1412 1412
1413 // Read object back from the snapshot into a C structure. 1413 // Read object back from the snapshot into a C structure.
1414 ApiNativeScope scope; 1414 ApiNativeScope scope;
1415 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1415 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1416 Dart_CObject* root = api_reader.ReadMessage(); 1416 Dart_CObject* root = api_reader.ReadMessage();
1417 EXPECT_NOTNULL(root); 1417 EXPECT_NOTNULL(root);
1418 EXPECT_EQ(Dart_CObject::kInt32, root->type); 1418 EXPECT_EQ(Dart_CObject_kInt32, root->type);
1419 EXPECT_EQ(42, root->value.as_int32); 1419 EXPECT_EQ(42, root->value.as_int32);
1420 CheckEncodeDecodeMessage(root); 1420 CheckEncodeDecodeMessage(root);
1421 } 1421 }
1422 { 1422 {
1423 StackZone zone(Isolate::Current()); 1423 StackZone zone(Isolate::Current());
1424 uint8_t* buffer; 1424 uint8_t* buffer;
1425 MessageWriter writer(&buffer, &zone_allocator); 1425 MessageWriter writer(&buffer, &zone_allocator);
1426 Bigint& bigint = Bigint::Handle(); 1426 Bigint& bigint = Bigint::Handle();
1427 bigint ^= Api::UnwrapHandle(bigint_result); 1427 bigint ^= Api::UnwrapHandle(bigint_result);
1428 writer.WriteMessage(bigint); 1428 writer.WriteMessage(bigint);
1429 intptr_t buffer_len = writer.BytesWritten(); 1429 intptr_t buffer_len = writer.BytesWritten();
1430 1430
1431 // Read object back from the snapshot into a C structure. 1431 // Read object back from the snapshot into a C structure.
1432 ApiNativeScope scope; 1432 ApiNativeScope scope;
1433 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1433 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1434 Dart_CObject* root = api_reader.ReadMessage(); 1434 Dart_CObject* root = api_reader.ReadMessage();
1435 EXPECT_NOTNULL(root); 1435 EXPECT_NOTNULL(root);
1436 EXPECT_EQ(Dart_CObject::kBigint, root->type); 1436 EXPECT_EQ(Dart_CObject_kBigint, root->type);
1437 EXPECT_STREQ("-424242424242424242424242424242424242", 1437 EXPECT_STREQ("-424242424242424242424242424242424242",
1438 root->value.as_bigint); 1438 root->value.as_bigint);
1439 CheckEncodeDecodeMessage(root); 1439 CheckEncodeDecodeMessage(root);
1440 } 1440 }
1441 CheckString(ascii_string_result, "Hello, world!"); 1441 CheckString(ascii_string_result, "Hello, world!");
1442 CheckString(non_ascii_string_result, "Blåbærgrød"); 1442 CheckString(non_ascii_string_result, "Blåbærgrød");
1443 CheckString(non_bmp_string_result, 1443 CheckString(non_bmp_string_result,
1444 "\xf0\x90\x80\x80" 1444 "\xf0\x90\x80\x80"
1445 "\xf0\x9f\x98\x81" 1445 "\xf0\x9f\x98\x81"
1446 "\xf0\x9f\x98\xb7" 1446 "\xf0\x9f\x98\xb7"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1489 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1490 EXPECT_VALID(lib); 1490 EXPECT_VALID(lib);
1491 1491
1492 { 1492 {
1493 DARTSCOPE(isolate); 1493 DARTSCOPE(isolate);
1494 { 1494 {
1495 // Generate a list of nulls from Dart code. 1495 // Generate a list of nulls from Dart code.
1496 ApiNativeScope scope; 1496 ApiNativeScope scope;
1497 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); 1497 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList");
1498 EXPECT_NOTNULL(root); 1498 EXPECT_NOTNULL(root);
1499 EXPECT_EQ(Dart_CObject::kArray, root->type); 1499 EXPECT_EQ(Dart_CObject_kArray, root->type);
1500 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1500 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1501 for (int i = 0; i < kArrayLength; i++) { 1501 for (int i = 0; i < kArrayLength; i++) {
1502 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type); 1502 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type);
1503 } 1503 }
1504 CheckEncodeDecodeMessage(root); 1504 CheckEncodeDecodeMessage(root);
1505 } 1505 }
1506 { 1506 {
1507 // Generate a list of ints from Dart code. 1507 // Generate a list of ints from Dart code.
1508 ApiNativeScope scope; 1508 ApiNativeScope scope;
1509 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); 1509 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList");
1510 EXPECT_NOTNULL(root); 1510 EXPECT_NOTNULL(root);
1511 EXPECT_EQ(Dart_CObject::kArray, root->type); 1511 EXPECT_EQ(Dart_CObject_kArray, root->type);
1512 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1512 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1513 for (int i = 0; i < kArrayLength; i++) { 1513 for (int i = 0; i < kArrayLength; i++) {
1514 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[i]->type); 1514 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type);
1515 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); 1515 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32);
1516 } 1516 }
1517 CheckEncodeDecodeMessage(root); 1517 CheckEncodeDecodeMessage(root);
1518 } 1518 }
1519 { 1519 {
1520 // Generate a list of strings from Dart code. 1520 // Generate a list of strings from Dart code.
1521 ApiNativeScope scope; 1521 ApiNativeScope scope;
1522 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); 1522 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
1523 EXPECT_NOTNULL(root); 1523 EXPECT_NOTNULL(root);
1524 EXPECT_EQ(Dart_CObject::kArray, root->type); 1524 EXPECT_EQ(Dart_CObject_kArray, root->type);
1525 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1525 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1526 for (int i = 0; i < kArrayLength; i++) { 1526 for (int i = 0; i < kArrayLength; i++) {
1527 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[i]->type); 1527 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type);
1528 char buffer[3]; 1528 char buffer[3];
1529 snprintf(buffer, sizeof(buffer), "%d", i); 1529 snprintf(buffer, sizeof(buffer), "%d", i);
1530 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); 1530 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string);
1531 } 1531 }
1532 } 1532 }
1533 { 1533 {
1534 // Generate a list of objects of different types from Dart code. 1534 // Generate a list of objects of different types from Dart code.
1535 ApiNativeScope scope; 1535 ApiNativeScope scope;
1536 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); 1536 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1537 EXPECT_NOTNULL(root); 1537 EXPECT_NOTNULL(root);
1538 EXPECT_EQ(Dart_CObject::kArray, root->type); 1538 EXPECT_EQ(Dart_CObject_kArray, root->type);
1539 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1539 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1540 1540
1541 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[0]->type); 1541 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type);
1542 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); 1542 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32);
1543 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[1]->type); 1543 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type);
1544 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); 1544 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string);
1545 EXPECT_EQ(Dart_CObject::kDouble, root->value.as_array.values[2]->type); 1545 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type);
1546 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); 1546 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double);
1547 EXPECT_EQ(Dart_CObject::kBool, root->value.as_array.values[3]->type); 1547 EXPECT_EQ(Dart_CObject_kBool, root->value.as_array.values[3]->type);
1548 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool); 1548 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool);
1549 1549
1550 for (int i = 0; i < kArrayLength; i++) { 1550 for (int i = 0; i < kArrayLength; i++) {
1551 if (i > 3) { 1551 if (i > 3) {
1552 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type); 1552 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type);
1553 } 1553 }
1554 } 1554 }
1555 } 1555 }
1556 } 1556 }
1557 Dart_ExitScope(); 1557 Dart_ExitScope();
1558 Dart_ShutdownIsolate(); 1558 Dart_ShutdownIsolate();
1559 } 1559 }
1560 1560
1561 1561
1562 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { 1562 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1607 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1608 EXPECT_VALID(lib); 1608 EXPECT_VALID(lib);
1609 1609
1610 { 1610 {
1611 DARTSCOPE(isolate); 1611 DARTSCOPE(isolate);
1612 { 1612 {
1613 // Generate a list of nulls from Dart code. 1613 // Generate a list of nulls from Dart code.
1614 ApiNativeScope scope; 1614 ApiNativeScope scope;
1615 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); 1615 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList");
1616 EXPECT_NOTNULL(root); 1616 EXPECT_NOTNULL(root);
1617 EXPECT_EQ(Dart_CObject::kArray, root->type); 1617 EXPECT_EQ(Dart_CObject_kArray, root->type);
1618 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1618 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1619 for (int i = 0; i < kArrayLength; i++) { 1619 for (int i = 0; i < kArrayLength; i++) {
1620 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type); 1620 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type);
1621 } 1621 }
1622 CheckEncodeDecodeMessage(root); 1622 CheckEncodeDecodeMessage(root);
1623 } 1623 }
1624 { 1624 {
1625 // Generate a list of ints from Dart code. 1625 // Generate a list of ints from Dart code.
1626 ApiNativeScope scope; 1626 ApiNativeScope scope;
1627 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); 1627 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList");
1628 EXPECT_NOTNULL(root); 1628 EXPECT_NOTNULL(root);
1629 EXPECT_EQ(Dart_CObject::kArray, root->type); 1629 EXPECT_EQ(Dart_CObject_kArray, root->type);
1630 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1630 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1631 for (int i = 0; i < kArrayLength; i++) { 1631 for (int i = 0; i < kArrayLength; i++) {
1632 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[i]->type); 1632 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type);
1633 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); 1633 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32);
1634 } 1634 }
1635 CheckEncodeDecodeMessage(root); 1635 CheckEncodeDecodeMessage(root);
1636 } 1636 }
1637 { 1637 {
1638 // Generate a list of strings from Dart code. 1638 // Generate a list of strings from Dart code.
1639 ApiNativeScope scope; 1639 ApiNativeScope scope;
1640 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); 1640 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
1641 EXPECT_NOTNULL(root); 1641 EXPECT_NOTNULL(root);
1642 EXPECT_EQ(Dart_CObject::kArray, root->type); 1642 EXPECT_EQ(Dart_CObject_kArray, root->type);
1643 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1643 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1644 for (int i = 0; i < kArrayLength; i++) { 1644 for (int i = 0; i < kArrayLength; i++) {
1645 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[i]->type); 1645 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type);
1646 char buffer[3]; 1646 char buffer[3];
1647 snprintf(buffer, sizeof(buffer), "%d", i); 1647 snprintf(buffer, sizeof(buffer), "%d", i);
1648 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); 1648 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string);
1649 } 1649 }
1650 } 1650 }
1651 { 1651 {
1652 // Generate a list of lists from Dart code. 1652 // Generate a list of lists from Dart code.
1653 ApiNativeScope scope; 1653 ApiNativeScope scope;
1654 Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList"); 1654 Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList");
1655 EXPECT_NOTNULL(root); 1655 EXPECT_NOTNULL(root);
1656 EXPECT_EQ(Dart_CObject::kArray, root->type); 1656 EXPECT_EQ(Dart_CObject_kArray, root->type);
1657 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1657 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1658 for (int i = 0; i < kArrayLength; i++) { 1658 for (int i = 0; i < kArrayLength; i++) {
1659 Dart_CObject* element = root->value.as_array.values[i]; 1659 Dart_CObject* element = root->value.as_array.values[i];
1660 EXPECT_EQ(Dart_CObject::kArray, element->type); 1660 EXPECT_EQ(Dart_CObject_kArray, element->type);
1661 EXPECT_EQ(i, element->value.as_array.length); 1661 EXPECT_EQ(i, element->value.as_array.length);
1662 for (int j = 0; j < i; j++) { 1662 for (int j = 0; j < i; j++) {
1663 EXPECT_EQ(Dart_CObject::kInt32, 1663 EXPECT_EQ(Dart_CObject_kInt32,
1664 element->value.as_array.values[j]->type); 1664 element->value.as_array.values[j]->type);
1665 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32); 1665 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32);
1666 } 1666 }
1667 } 1667 }
1668 } 1668 }
1669 { 1669 {
1670 // Generate a list of objects of different types from Dart code. 1670 // Generate a list of objects of different types from Dart code.
1671 ApiNativeScope scope; 1671 ApiNativeScope scope;
1672 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); 1672 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1673 EXPECT_NOTNULL(root); 1673 EXPECT_NOTNULL(root);
1674 EXPECT_EQ(Dart_CObject::kArray, root->type); 1674 EXPECT_EQ(Dart_CObject_kArray, root->type);
1675 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1675 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1676 1676
1677 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[0]->type); 1677 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type);
1678 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); 1678 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32);
1679 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[1]->type); 1679 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type);
1680 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); 1680 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string);
1681 EXPECT_EQ(Dart_CObject::kDouble, root->value.as_array.values[2]->type); 1681 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type);
1682 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); 1682 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double);
1683 EXPECT_EQ(Dart_CObject::kBool, root->value.as_array.values[3]->type); 1683 EXPECT_EQ(Dart_CObject_kBool, root->value.as_array.values[3]->type);
1684 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool); 1684 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool);
1685 1685
1686 for (int i = 0; i < kArrayLength; i++) { 1686 for (int i = 0; i < kArrayLength; i++) {
1687 if (i > 3) { 1687 if (i > 3) {
1688 EXPECT_EQ(Dart_CObject::kArray, root->value.as_array.values[i]->type); 1688 EXPECT_EQ(Dart_CObject_kArray, root->value.as_array.values[i]->type);
1689 } 1689 }
1690 } 1690 }
1691 1691
1692 Dart_CObject* element; 1692 Dart_CObject* element;
1693 Dart_CObject* e; 1693 Dart_CObject* e;
1694 1694
1695 // [] 1695 // []
1696 element = root->value.as_array.values[4]; 1696 element = root->value.as_array.values[4];
1697 EXPECT_EQ(0, element->value.as_array.length); 1697 EXPECT_EQ(0, element->value.as_array.length);
1698 1698
1699 // [[]] 1699 // [[]]
1700 element = root->value.as_array.values[5]; 1700 element = root->value.as_array.values[5];
1701 EXPECT_EQ(1, element->value.as_array.length); 1701 EXPECT_EQ(1, element->value.as_array.length);
1702 element = element->value.as_array.values[0]; 1702 element = element->value.as_array.values[0];
1703 EXPECT_EQ(Dart_CObject::kArray, element->type); 1703 EXPECT_EQ(Dart_CObject_kArray, element->type);
1704 EXPECT_EQ(0, element->value.as_array.length); 1704 EXPECT_EQ(0, element->value.as_array.length);
1705 1705
1706 // [[[]]]" 1706 // [[[]]]"
1707 element = root->value.as_array.values[6]; 1707 element = root->value.as_array.values[6];
1708 EXPECT_EQ(1, element->value.as_array.length); 1708 EXPECT_EQ(1, element->value.as_array.length);
1709 element = element->value.as_array.values[0]; 1709 element = element->value.as_array.values[0];
1710 EXPECT_EQ(Dart_CObject::kArray, element->type); 1710 EXPECT_EQ(Dart_CObject_kArray, element->type);
1711 EXPECT_EQ(1, element->value.as_array.length); 1711 EXPECT_EQ(1, element->value.as_array.length);
1712 element = element->value.as_array.values[0]; 1712 element = element->value.as_array.values[0];
1713 EXPECT_EQ(Dart_CObject::kArray, element->type); 1713 EXPECT_EQ(Dart_CObject_kArray, element->type);
1714 EXPECT_EQ(0, element->value.as_array.length); 1714 EXPECT_EQ(0, element->value.as_array.length);
1715 1715
1716 // [1, [2, [3]]] 1716 // [1, [2, [3]]]
1717 element = root->value.as_array.values[7]; 1717 element = root->value.as_array.values[7];
1718 EXPECT_EQ(2, element->value.as_array.length); 1718 EXPECT_EQ(2, element->value.as_array.length);
1719 e = element->value.as_array.values[0]; 1719 e = element->value.as_array.values[0];
1720 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1720 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1721 EXPECT_EQ(1, e->value.as_int32); 1721 EXPECT_EQ(1, e->value.as_int32);
1722 element = element->value.as_array.values[1]; 1722 element = element->value.as_array.values[1];
1723 EXPECT_EQ(Dart_CObject::kArray, element->type); 1723 EXPECT_EQ(Dart_CObject_kArray, element->type);
1724 EXPECT_EQ(2, element->value.as_array.length); 1724 EXPECT_EQ(2, element->value.as_array.length);
1725 e = element->value.as_array.values[0]; 1725 e = element->value.as_array.values[0];
1726 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1726 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1727 EXPECT_EQ(2, e->value.as_int32); 1727 EXPECT_EQ(2, e->value.as_int32);
1728 element = element->value.as_array.values[1]; 1728 element = element->value.as_array.values[1];
1729 EXPECT_EQ(Dart_CObject::kArray, element->type); 1729 EXPECT_EQ(Dart_CObject_kArray, element->type);
1730 EXPECT_EQ(1, element->value.as_array.length); 1730 EXPECT_EQ(1, element->value.as_array.length);
1731 e = element->value.as_array.values[0]; 1731 e = element->value.as_array.values[0];
1732 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1732 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1733 EXPECT_EQ(3, e->value.as_int32); 1733 EXPECT_EQ(3, e->value.as_int32);
1734 1734
1735 // [1, [1, 2, [1, 2, 3]]] 1735 // [1, [1, 2, [1, 2, 3]]]
1736 element = root->value.as_array.values[8]; 1736 element = root->value.as_array.values[8];
1737 EXPECT_EQ(2, element->value.as_array.length); 1737 EXPECT_EQ(2, element->value.as_array.length);
1738 e = element->value.as_array.values[0]; 1738 e = element->value.as_array.values[0];
1739 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1739 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1740 e = element->value.as_array.values[0]; 1740 e = element->value.as_array.values[0];
1741 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1741 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1742 EXPECT_EQ(1, e->value.as_int32); 1742 EXPECT_EQ(1, e->value.as_int32);
1743 element = element->value.as_array.values[1]; 1743 element = element->value.as_array.values[1];
1744 EXPECT_EQ(Dart_CObject::kArray, element->type); 1744 EXPECT_EQ(Dart_CObject_kArray, element->type);
1745 EXPECT_EQ(3, element->value.as_array.length); 1745 EXPECT_EQ(3, element->value.as_array.length);
1746 for (int i = 0; i < 2; i++) { 1746 for (int i = 0; i < 2; i++) {
1747 e = element->value.as_array.values[i]; 1747 e = element->value.as_array.values[i];
1748 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1748 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1749 EXPECT_EQ(i + 1, e->value.as_int32); 1749 EXPECT_EQ(i + 1, e->value.as_int32);
1750 } 1750 }
1751 element = element->value.as_array.values[2]; 1751 element = element->value.as_array.values[2];
1752 EXPECT_EQ(Dart_CObject::kArray, element->type); 1752 EXPECT_EQ(Dart_CObject_kArray, element->type);
1753 EXPECT_EQ(3, element->value.as_array.length); 1753 EXPECT_EQ(3, element->value.as_array.length);
1754 for (int i = 0; i < 3; i++) { 1754 for (int i = 0; i < 3; i++) {
1755 e = element->value.as_array.values[i]; 1755 e = element->value.as_array.values[i];
1756 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1756 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1757 EXPECT_EQ(i + 1, e->value.as_int32); 1757 EXPECT_EQ(i + 1, e->value.as_int32);
1758 } 1758 }
1759 1759
1760 // [1, 2, 3] 1760 // [1, 2, 3]
1761 element = root->value.as_array.values[9]; 1761 element = root->value.as_array.values[9];
1762 EXPECT_EQ(3, element->value.as_array.length); 1762 EXPECT_EQ(3, element->value.as_array.length);
1763 for (int i = 0; i < 3; i++) { 1763 for (int i = 0; i < 3; i++) {
1764 e = element->value.as_array.values[i]; 1764 e = element->value.as_array.values[i];
1765 EXPECT_EQ(Dart_CObject::kInt32, e->type); 1765 EXPECT_EQ(Dart_CObject_kInt32, e->type);
1766 EXPECT_EQ(i + 1, e->value.as_int32); 1766 EXPECT_EQ(i + 1, e->value.as_int32);
1767 } 1767 }
1768 } 1768 }
1769 } 1769 }
1770 Dart_ExitScope(); 1770 Dart_ExitScope();
1771 Dart_ShutdownIsolate(); 1771 Dart_ShutdownIsolate();
1772 } 1772 }
1773 1773
1774 1774
1775 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { 1775 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 EXPECT_VALID(lib); 1840 EXPECT_VALID(lib);
1841 1841
1842 { 1842 {
1843 DARTSCOPE(isolate); 1843 DARTSCOPE(isolate);
1844 1844
1845 { 1845 {
1846 // Generate a list of strings from Dart code. 1846 // Generate a list of strings from Dart code.
1847 ApiNativeScope scope; 1847 ApiNativeScope scope;
1848 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); 1848 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
1849 EXPECT_NOTNULL(root); 1849 EXPECT_NOTNULL(root);
1850 EXPECT_EQ(Dart_CObject::kArray, root->type); 1850 EXPECT_EQ(Dart_CObject_kArray, root->type);
1851 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1851 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1852 for (int i = 0; i < kArrayLength; i++) { 1852 for (int i = 0; i < kArrayLength; i++) {
1853 Dart_CObject* element = root->value.as_array.values[i]; 1853 Dart_CObject* element = root->value.as_array.values[i];
1854 EXPECT_EQ(root->value.as_array.values[0], element); 1854 EXPECT_EQ(root->value.as_array.values[0], element);
1855 EXPECT_EQ(Dart_CObject::kString, element->type); 1855 EXPECT_EQ(Dart_CObject_kString, element->type);
1856 EXPECT_STREQ("Hello, world!", element->value.as_string); 1856 EXPECT_STREQ("Hello, world!", element->value.as_string);
1857 } 1857 }
1858 } 1858 }
1859 { 1859 {
1860 // Generate a list of medium ints from Dart code. 1860 // Generate a list of medium ints from Dart code.
1861 ApiNativeScope scope; 1861 ApiNativeScope scope;
1862 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); 1862 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList");
1863 EXPECT_NOTNULL(root); 1863 EXPECT_NOTNULL(root);
1864 EXPECT_EQ(Dart_CObject::kArray, root->type); 1864 EXPECT_EQ(Dart_CObject_kArray, root->type);
1865 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1865 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1866 for (int i = 0; i < kArrayLength; i++) { 1866 for (int i = 0; i < kArrayLength; i++) {
1867 Dart_CObject* element = root->value.as_array.values[i]; 1867 Dart_CObject* element = root->value.as_array.values[i];
1868 EXPECT_EQ(root->value.as_array.values[0], element); 1868 EXPECT_EQ(root->value.as_array.values[0], element);
1869 EXPECT_EQ(Dart_CObject::kInt64, element->type); 1869 EXPECT_EQ(Dart_CObject_kInt64, element->type);
1870 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); 1870 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64);
1871 } 1871 }
1872 } 1872 }
1873 { 1873 {
1874 // Generate a list of bigints from Dart code. 1874 // Generate a list of bigints from Dart code.
1875 ApiNativeScope scope; 1875 ApiNativeScope scope;
1876 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); 1876 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList");
1877 EXPECT_NOTNULL(root); 1877 EXPECT_NOTNULL(root);
1878 EXPECT_EQ(Dart_CObject::kArray, root->type); 1878 EXPECT_EQ(Dart_CObject_kArray, root->type);
1879 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1879 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1880 for (int i = 0; i < kArrayLength; i++) { 1880 for (int i = 0; i < kArrayLength; i++) {
1881 Dart_CObject* element = root->value.as_array.values[i]; 1881 Dart_CObject* element = root->value.as_array.values[i];
1882 EXPECT_EQ(root->value.as_array.values[0], element); 1882 EXPECT_EQ(root->value.as_array.values[0], element);
1883 EXPECT_EQ(Dart_CObject::kBigint, element->type); 1883 EXPECT_EQ(Dart_CObject_kBigint, element->type);
1884 EXPECT_STREQ("1234567890123456789012345678901234567890", 1884 EXPECT_STREQ("1234567890123456789012345678901234567890",
1885 element->value.as_bigint); 1885 element->value.as_bigint);
1886 } 1886 }
1887 } 1887 }
1888 { 1888 {
1889 // Generate a list of doubles from Dart code. 1889 // Generate a list of doubles from Dart code.
1890 ApiNativeScope scope; 1890 ApiNativeScope scope;
1891 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); 1891 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList");
1892 EXPECT_NOTNULL(root); 1892 EXPECT_NOTNULL(root);
1893 EXPECT_EQ(Dart_CObject::kArray, root->type); 1893 EXPECT_EQ(Dart_CObject_kArray, root->type);
1894 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1894 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1895 for (int i = 0; i < kArrayLength; i++) { 1895 for (int i = 0; i < kArrayLength; i++) {
1896 Dart_CObject* element = root->value.as_array.values[i]; 1896 Dart_CObject* element = root->value.as_array.values[i];
1897 EXPECT_EQ(root->value.as_array.values[0], element); 1897 EXPECT_EQ(root->value.as_array.values[0], element);
1898 EXPECT_EQ(Dart_CObject::kDouble, element->type); 1898 EXPECT_EQ(Dart_CObject_kDouble, element->type);
1899 EXPECT_EQ(3.14, element->value.as_double); 1899 EXPECT_EQ(3.14, element->value.as_double);
1900 } 1900 }
1901 } 1901 }
1902 { 1902 {
1903 // Generate a list of Uint8Lists from Dart code. 1903 // Generate a list of Uint8Lists from Dart code.
1904 ApiNativeScope scope; 1904 ApiNativeScope scope;
1905 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); 1905 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
1906 EXPECT_NOTNULL(root); 1906 EXPECT_NOTNULL(root);
1907 EXPECT_EQ(Dart_CObject::kArray, root->type); 1907 EXPECT_EQ(Dart_CObject_kArray, root->type);
1908 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1908 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1909 for (int i = 0; i < kArrayLength; i++) { 1909 for (int i = 0; i < kArrayLength; i++) {
1910 Dart_CObject* element = root->value.as_array.values[i]; 1910 Dart_CObject* element = root->value.as_array.values[i];
1911 EXPECT_EQ(root->value.as_array.values[0], element); 1911 EXPECT_EQ(root->value.as_array.values[0], element);
1912 EXPECT_EQ(Dart_CObject::kTypedData, element->type); 1912 EXPECT_EQ(Dart_CObject_kTypedData, element->type);
1913 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); 1913 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type);
1914 EXPECT_EQ(256, element->value.as_typed_data.length); 1914 EXPECT_EQ(256, element->value.as_typed_data.length);
1915 } 1915 }
1916 } 1916 }
1917 { 1917 {
1918 // Generate a list of Uint8List views from Dart code. 1918 // Generate a list of Uint8List views from Dart code.
1919 ApiNativeScope scope; 1919 ApiNativeScope scope;
1920 Dart_CObject* root = 1920 Dart_CObject* root =
1921 GetDeserializedDartMessage(lib, "getTypedDataViewList"); 1921 GetDeserializedDartMessage(lib, "getTypedDataViewList");
1922 EXPECT_NOTNULL(root); 1922 EXPECT_NOTNULL(root);
1923 EXPECT_EQ(Dart_CObject::kArray, root->type); 1923 EXPECT_EQ(Dart_CObject_kArray, root->type);
1924 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1924 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1925 for (int i = 0; i < kArrayLength; i++) { 1925 for (int i = 0; i < kArrayLength; i++) {
1926 Dart_CObject* element = root->value.as_array.values[i]; 1926 Dart_CObject* element = root->value.as_array.values[i];
1927 EXPECT_EQ(root->value.as_array.values[0], element); 1927 EXPECT_EQ(root->value.as_array.values[0], element);
1928 EXPECT_EQ(Dart_CObject::kTypedData, element->type); 1928 EXPECT_EQ(Dart_CObject_kTypedData, element->type);
1929 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); 1929 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type);
1930 EXPECT_EQ(128, element->value.as_typed_data.length); 1930 EXPECT_EQ(128, element->value.as_typed_data.length);
1931 EXPECT_EQ(1, element->value.as_typed_data.values[0]); 1931 EXPECT_EQ(1, element->value.as_typed_data.values[0]);
1932 EXPECT_EQ(0, element->value.as_typed_data.values[1]); 1932 EXPECT_EQ(0, element->value.as_typed_data.values[1]);
1933 } 1933 }
1934 } 1934 }
1935 { 1935 {
1936 // Generate a list of objects of different types from Dart code. 1936 // Generate a list of objects of different types from Dart code.
1937 ApiNativeScope scope; 1937 ApiNativeScope scope;
1938 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); 1938 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1939 EXPECT_NOTNULL(root); 1939 EXPECT_NOTNULL(root);
1940 EXPECT_EQ(Dart_CObject::kArray, root->type); 1940 EXPECT_EQ(Dart_CObject_kArray, root->type);
1941 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1941 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1942 for (int i = 0; i < kArrayLength; i++) { 1942 for (int i = 0; i < kArrayLength; i++) {
1943 Dart_CObject* element = root->value.as_array.values[i]; 1943 Dart_CObject* element = root->value.as_array.values[i];
1944 if ((i % 2) == 0) { 1944 if ((i % 2) == 0) {
1945 EXPECT_EQ(root->value.as_array.values[0], element); 1945 EXPECT_EQ(root->value.as_array.values[0], element);
1946 EXPECT_EQ(Dart_CObject::kString, element->type); 1946 EXPECT_EQ(Dart_CObject_kString, element->type);
1947 EXPECT_STREQ("A", element->value.as_string); 1947 EXPECT_STREQ("A", element->value.as_string);
1948 } else { 1948 } else {
1949 EXPECT_EQ(root->value.as_array.values[1], element); 1949 EXPECT_EQ(root->value.as_array.values[1], element);
1950 EXPECT_EQ(Dart_CObject::kDouble, element->type); 1950 EXPECT_EQ(Dart_CObject_kDouble, element->type);
1951 EXPECT_STREQ(2.72, element->value.as_double); 1951 EXPECT_STREQ(2.72, element->value.as_double);
1952 } 1952 }
1953 } 1953 }
1954 } 1954 }
1955 { 1955 {
1956 // Generate a list of objects of different types from Dart code. 1956 // Generate a list of objects of different types from Dart code.
1957 ApiNativeScope scope; 1957 ApiNativeScope scope;
1958 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); 1958 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList");
1959 EXPECT_NOTNULL(root); 1959 EXPECT_NOTNULL(root);
1960 EXPECT_EQ(Dart_CObject::kArray, root->type); 1960 EXPECT_EQ(Dart_CObject_kArray, root->type);
1961 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1961 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1962 for (int i = 0; i < kArrayLength; i++) { 1962 for (int i = 0; i < kArrayLength; i++) {
1963 Dart_CObject* element = root->value.as_array.values[i]; 1963 Dart_CObject* element = root->value.as_array.values[i];
1964 EXPECT_EQ(Dart_CObject::kArray, element->type); 1964 EXPECT_EQ(Dart_CObject_kArray, element->type);
1965 EXPECT_EQ(root, element); 1965 EXPECT_EQ(root, element);
1966 } 1966 }
1967 } 1967 }
1968 } 1968 }
1969 Dart_ExitScope(); 1969 Dart_ExitScope();
1970 Dart_ShutdownIsolate(); 1970 Dart_ShutdownIsolate();
1971 } 1971 }
1972 1972
1973 1973
1974 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { 1974 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2044 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2045 EXPECT_VALID(lib); 2045 EXPECT_VALID(lib);
2046 2046
2047 { 2047 {
2048 DARTSCOPE(isolate); 2048 DARTSCOPE(isolate);
2049 { 2049 {
2050 // Generate a list of strings from Dart code. 2050 // Generate a list of strings from Dart code.
2051 ApiNativeScope scope; 2051 ApiNativeScope scope;
2052 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); 2052 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
2053 EXPECT_NOTNULL(root); 2053 EXPECT_NOTNULL(root);
2054 EXPECT_EQ(Dart_CObject::kArray, root->type); 2054 EXPECT_EQ(Dart_CObject_kArray, root->type);
2055 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2055 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2056 for (int i = 0; i < kArrayLength; i++) { 2056 for (int i = 0; i < kArrayLength; i++) {
2057 Dart_CObject* element = root->value.as_array.values[i]; 2057 Dart_CObject* element = root->value.as_array.values[i];
2058 EXPECT_EQ(root->value.as_array.values[0], element); 2058 EXPECT_EQ(root->value.as_array.values[0], element);
2059 EXPECT_EQ(Dart_CObject::kString, element->type); 2059 EXPECT_EQ(Dart_CObject_kString, element->type);
2060 EXPECT_STREQ("Hello, world!", element->value.as_string); 2060 EXPECT_STREQ("Hello, world!", element->value.as_string);
2061 } 2061 }
2062 } 2062 }
2063 { 2063 {
2064 // Generate a list of medium ints from Dart code. 2064 // Generate a list of medium ints from Dart code.
2065 ApiNativeScope scope; 2065 ApiNativeScope scope;
2066 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); 2066 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList");
2067 EXPECT_NOTNULL(root); 2067 EXPECT_NOTNULL(root);
2068 EXPECT_EQ(Dart_CObject::kArray, root->type); 2068 EXPECT_EQ(Dart_CObject_kArray, root->type);
2069 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2069 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2070 for (int i = 0; i < kArrayLength; i++) { 2070 for (int i = 0; i < kArrayLength; i++) {
2071 Dart_CObject* element = root->value.as_array.values[i]; 2071 Dart_CObject* element = root->value.as_array.values[i];
2072 EXPECT_EQ(root->value.as_array.values[0], element); 2072 EXPECT_EQ(root->value.as_array.values[0], element);
2073 EXPECT_EQ(Dart_CObject::kInt64, element->type); 2073 EXPECT_EQ(Dart_CObject_kInt64, element->type);
2074 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); 2074 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64);
2075 } 2075 }
2076 } 2076 }
2077 { 2077 {
2078 // Generate a list of bigints from Dart code. 2078 // Generate a list of bigints from Dart code.
2079 ApiNativeScope scope; 2079 ApiNativeScope scope;
2080 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); 2080 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList");
2081 EXPECT_NOTNULL(root); 2081 EXPECT_NOTNULL(root);
2082 EXPECT_EQ(Dart_CObject::kArray, root->type); 2082 EXPECT_EQ(Dart_CObject_kArray, root->type);
2083 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2083 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2084 for (int i = 0; i < kArrayLength; i++) { 2084 for (int i = 0; i < kArrayLength; i++) {
2085 Dart_CObject* element = root->value.as_array.values[i]; 2085 Dart_CObject* element = root->value.as_array.values[i];
2086 EXPECT_EQ(root->value.as_array.values[0], element); 2086 EXPECT_EQ(root->value.as_array.values[0], element);
2087 EXPECT_EQ(Dart_CObject::kBigint, element->type); 2087 EXPECT_EQ(Dart_CObject_kBigint, element->type);
2088 EXPECT_STREQ("1234567890123456789012345678901234567890", 2088 EXPECT_STREQ("1234567890123456789012345678901234567890",
2089 element->value.as_bigint); 2089 element->value.as_bigint);
2090 } 2090 }
2091 } 2091 }
2092 { 2092 {
2093 // Generate a list of doubles from Dart code. 2093 // Generate a list of doubles from Dart code.
2094 ApiNativeScope scope; 2094 ApiNativeScope scope;
2095 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); 2095 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList");
2096 EXPECT_NOTNULL(root); 2096 EXPECT_NOTNULL(root);
2097 EXPECT_EQ(Dart_CObject::kArray, root->type); 2097 EXPECT_EQ(Dart_CObject_kArray, root->type);
2098 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2098 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2099 for (int i = 0; i < kArrayLength; i++) { 2099 for (int i = 0; i < kArrayLength; i++) {
2100 Dart_CObject* element = root->value.as_array.values[i]; 2100 Dart_CObject* element = root->value.as_array.values[i];
2101 EXPECT_EQ(root->value.as_array.values[0], element); 2101 EXPECT_EQ(root->value.as_array.values[0], element);
2102 EXPECT_EQ(Dart_CObject::kDouble, element->type); 2102 EXPECT_EQ(Dart_CObject_kDouble, element->type);
2103 EXPECT_EQ(3.14, element->value.as_double); 2103 EXPECT_EQ(3.14, element->value.as_double);
2104 } 2104 }
2105 } 2105 }
2106 { 2106 {
2107 // Generate a list of Uint8Lists from Dart code. 2107 // Generate a list of Uint8Lists from Dart code.
2108 ApiNativeScope scope; 2108 ApiNativeScope scope;
2109 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); 2109 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
2110 EXPECT_NOTNULL(root); 2110 EXPECT_NOTNULL(root);
2111 EXPECT_EQ(Dart_CObject::kArray, root->type); 2111 EXPECT_EQ(Dart_CObject_kArray, root->type);
2112 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2112 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2113 for (int i = 0; i < kArrayLength; i++) { 2113 for (int i = 0; i < kArrayLength; i++) {
2114 Dart_CObject* element = root->value.as_array.values[i]; 2114 Dart_CObject* element = root->value.as_array.values[i];
2115 EXPECT_EQ(root->value.as_array.values[0], element); 2115 EXPECT_EQ(root->value.as_array.values[0], element);
2116 EXPECT_EQ(Dart_CObject::kTypedData, element->type); 2116 EXPECT_EQ(Dart_CObject_kTypedData, element->type);
2117 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); 2117 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type);
2118 EXPECT_EQ(256, element->value.as_typed_data.length); 2118 EXPECT_EQ(256, element->value.as_typed_data.length);
2119 } 2119 }
2120 } 2120 }
2121 { 2121 {
2122 // Generate a list of Uint8List views from Dart code. 2122 // Generate a list of Uint8List views from Dart code.
2123 ApiNativeScope scope; 2123 ApiNativeScope scope;
2124 Dart_CObject* root = 2124 Dart_CObject* root =
2125 GetDeserializedDartMessage(lib, "getTypedDataViewList"); 2125 GetDeserializedDartMessage(lib, "getTypedDataViewList");
2126 EXPECT_NOTNULL(root); 2126 EXPECT_NOTNULL(root);
2127 EXPECT_EQ(Dart_CObject::kArray, root->type); 2127 EXPECT_EQ(Dart_CObject_kArray, root->type);
2128 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2128 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2129 for (int i = 0; i < kArrayLength; i++) { 2129 for (int i = 0; i < kArrayLength; i++) {
2130 Dart_CObject* element = root->value.as_array.values[i]; 2130 Dart_CObject* element = root->value.as_array.values[i];
2131 EXPECT_EQ(root->value.as_array.values[0], element); 2131 EXPECT_EQ(root->value.as_array.values[0], element);
2132 EXPECT_EQ(Dart_CObject::kTypedData, element->type); 2132 EXPECT_EQ(Dart_CObject_kTypedData, element->type);
2133 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); 2133 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type);
2134 EXPECT_EQ(128, element->value.as_typed_data.length); 2134 EXPECT_EQ(128, element->value.as_typed_data.length);
2135 EXPECT_EQ(1, element->value.as_typed_data.values[0]); 2135 EXPECT_EQ(1, element->value.as_typed_data.values[0]);
2136 EXPECT_EQ(0, element->value.as_typed_data.values[1]); 2136 EXPECT_EQ(0, element->value.as_typed_data.values[1]);
2137 } 2137 }
2138 } 2138 }
2139 { 2139 {
2140 // Generate a list of objects of different types from Dart code. 2140 // Generate a list of objects of different types from Dart code.
2141 ApiNativeScope scope; 2141 ApiNativeScope scope;
2142 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); 2142 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
2143 EXPECT_NOTNULL(root); 2143 EXPECT_NOTNULL(root);
2144 EXPECT_EQ(Dart_CObject::kArray, root->type); 2144 EXPECT_EQ(Dart_CObject_kArray, root->type);
2145 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2145 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2146 for (int i = 0; i < kArrayLength; i++) { 2146 for (int i = 0; i < kArrayLength; i++) {
2147 Dart_CObject* element = root->value.as_array.values[i]; 2147 Dart_CObject* element = root->value.as_array.values[i];
2148 if ((i % 2) == 0) { 2148 if ((i % 2) == 0) {
2149 EXPECT_EQ(root->value.as_array.values[0], element); 2149 EXPECT_EQ(root->value.as_array.values[0], element);
2150 EXPECT_EQ(Dart_CObject::kString, element->type); 2150 EXPECT_EQ(Dart_CObject_kString, element->type);
2151 EXPECT_STREQ(".", element->value.as_string); 2151 EXPECT_STREQ(".", element->value.as_string);
2152 } else { 2152 } else {
2153 EXPECT_EQ(root->value.as_array.values[1], element); 2153 EXPECT_EQ(root->value.as_array.values[1], element);
2154 EXPECT_EQ(Dart_CObject::kDouble, element->type); 2154 EXPECT_EQ(Dart_CObject_kDouble, element->type);
2155 EXPECT_STREQ(2.72, element->value.as_double); 2155 EXPECT_STREQ(2.72, element->value.as_double);
2156 } 2156 }
2157 } 2157 }
2158 } 2158 }
2159 { 2159 {
2160 // Generate a list of objects of different types from Dart code. 2160 // Generate a list of objects of different types from Dart code.
2161 ApiNativeScope scope; 2161 ApiNativeScope scope;
2162 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); 2162 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList");
2163 EXPECT_NOTNULL(root); 2163 EXPECT_NOTNULL(root);
2164 EXPECT_EQ(Dart_CObject::kArray, root->type); 2164 EXPECT_EQ(Dart_CObject_kArray, root->type);
2165 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2165 EXPECT_EQ(kArrayLength, root->value.as_array.length);
2166 for (int i = 0; i < kArrayLength; i++) { 2166 for (int i = 0; i < kArrayLength; i++) {
2167 Dart_CObject* element = root->value.as_array.values[i]; 2167 Dart_CObject* element = root->value.as_array.values[i];
2168 EXPECT_EQ(Dart_CObject::kArray, element->type); 2168 EXPECT_EQ(Dart_CObject_kArray, element->type);
2169 EXPECT_EQ(root, element); 2169 EXPECT_EQ(root, element);
2170 } 2170 }
2171 } 2171 }
2172 } 2172 }
2173 Dart_ExitScope(); 2173 Dart_ExitScope();
2174 Dart_ShutdownIsolate(); 2174 Dart_ShutdownIsolate();
2175 } 2175 }
2176 2176
2177 2177
2178 static void CheckTypedData(Dart_CObject* object, 2178 static void CheckTypedData(Dart_CObject* object,
2179 Dart_CObject::TypedDataType typed_data_type, 2179 Dart_TypedData_Type typed_data_type,
2180 int len) { 2180 int len) {
2181 EXPECT_EQ(Dart_CObject::kTypedData, object->type); 2181 EXPECT_EQ(Dart_CObject_kTypedData, object->type);
2182 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); 2182 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type);
2183 EXPECT_EQ(len, object->value.as_typed_data.length); 2183 EXPECT_EQ(len, object->value.as_typed_data.length);
2184 } 2184 }
2185 2185
2186 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { 2186 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
2187 static const char* kScriptChars = 2187 static const char* kScriptChars =
2188 "import 'dart:typed_data';\n" 2188 "import 'dart:typed_data';\n"
2189 "getTypedDataList() {\n" 2189 "getTypedDataList() {\n"
2190 " var list = new List(10);\n" 2190 " var list = new List(10);\n"
2191 " var index = 0;\n" 2191 " var index = 0;\n"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2263 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2264 EXPECT_VALID(lib); 2264 EXPECT_VALID(lib);
2265 2265
2266 { 2266 {
2267 DARTSCOPE(isolate); 2267 DARTSCOPE(isolate);
2268 { 2268 {
2269 // Generate a list of Uint8Lists from Dart code. 2269 // Generate a list of Uint8Lists from Dart code.
2270 ApiNativeScope scope; 2270 ApiNativeScope scope;
2271 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); 2271 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
2272 EXPECT_NOTNULL(root); 2272 EXPECT_NOTNULL(root);
2273 EXPECT_EQ(Dart_CObject::kArray, root->type); 2273 EXPECT_EQ(Dart_CObject_kArray, root->type);
2274 struct { 2274 struct {
2275 Dart_CObject::TypedDataType type; 2275 Dart_TypedData_Type type;
2276 int size; 2276 int size;
2277 } expected[] = { 2277 } expected[] = {
2278 { Dart_CObject::kInt8Array, 256}, 2278 { Dart_TypedData_kInt8, 256},
2279 { Dart_CObject::kUint8Array, 256}, 2279 { Dart_TypedData_kUint8, 256},
2280 { Dart_CObject::kInt16Array, 512}, 2280 { Dart_TypedData_kInt16, 512},
2281 { Dart_CObject::kUint16Array, 512}, 2281 { Dart_TypedData_kUint16, 512},
2282 { Dart_CObject::kInt32Array, 1024}, 2282 { Dart_TypedData_kInt32, 1024},
2283 { Dart_CObject::kUint32Array, 1024}, 2283 { Dart_TypedData_kUint32, 1024},
2284 { Dart_CObject::kInt64Array, 2048}, 2284 { Dart_TypedData_kInt64, 2048},
2285 { Dart_CObject::kUint64Array, 2048}, 2285 { Dart_TypedData_kUint64, 2048},
2286 { Dart_CObject::kFloat32Array, 1024}, 2286 { Dart_TypedData_kFloat32, 1024},
2287 { Dart_CObject::kFloat64Array, 2048}, 2287 { Dart_TypedData_kFloat64, 2048},
2288 { Dart_CObject::kNumberOfTypedDataTypes, -1 } 2288 { Dart_TypedData_kInvalid, -1 }
2289 }; 2289 };
2290 2290
2291 int i = 0; 2291 int i = 0;
2292 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { 2292 while (expected[i].type != Dart_TypedData_kInvalid) {
2293 CheckTypedData(root->value.as_array.values[i], 2293 CheckTypedData(root->value.as_array.values[i],
2294 expected[i].type, 2294 expected[i].type,
2295 expected[i].size); 2295 expected[i].size);
2296 i++; 2296 i++;
2297 } 2297 }
2298 EXPECT_EQ(i, root->value.as_array.length); 2298 EXPECT_EQ(i, root->value.as_array.length);
2299 } 2299 }
2300 { 2300 {
2301 // Generate a list of Uint8List views from Dart code. 2301 // Generate a list of Uint8List views from Dart code.
2302 2302
2303 ApiNativeScope scope; 2303 ApiNativeScope scope;
2304 Dart_CObject* root = 2304 Dart_CObject* root =
2305 GetDeserializedDartMessage(lib, "getTypedDataViewList"); 2305 GetDeserializedDartMessage(lib, "getTypedDataViewList");
2306 EXPECT_NOTNULL(root); 2306 EXPECT_NOTNULL(root);
2307 EXPECT_EQ(Dart_CObject::kArray, root->type); 2307 EXPECT_EQ(Dart_CObject_kArray, root->type);
2308 struct { 2308 struct {
2309 Dart_CObject::TypedDataType type; 2309 Dart_TypedData_Type type;
2310 int size; 2310 int size;
2311 } expected[] = { 2311 } expected[] = {
2312 { Dart_CObject::kInt8Array, 256}, 2312 { Dart_TypedData_kInt8, 256},
2313 { Dart_CObject::kUint8Array, 256}, 2313 { Dart_TypedData_kUint8, 256},
2314 { Dart_CObject::kInt16Array, 512}, 2314 { Dart_TypedData_kInt16, 512},
2315 { Dart_CObject::kUint16Array, 512}, 2315 { Dart_TypedData_kUint16, 512},
2316 { Dart_CObject::kInt32Array, 1024}, 2316 { Dart_TypedData_kInt32, 1024},
2317 { Dart_CObject::kUint32Array, 1024}, 2317 { Dart_TypedData_kUint32, 1024},
2318 { Dart_CObject::kInt64Array, 2048}, 2318 { Dart_TypedData_kInt64, 2048},
2319 { Dart_CObject::kUint64Array, 2048}, 2319 { Dart_TypedData_kUint64, 2048},
2320 { Dart_CObject::kFloat32Array, 1024}, 2320 { Dart_TypedData_kFloat32, 1024},
2321 { Dart_CObject::kFloat64Array, 2048}, 2321 { Dart_TypedData_kFloat64, 2048},
2322 2322
2323 { Dart_CObject::kInt8Array, 512}, 2323 { Dart_TypedData_kInt8, 512},
2324 { Dart_CObject::kUint8Array, 512}, 2324 { Dart_TypedData_kUint8, 512},
2325 { Dart_CObject::kInt8Array, 1024}, 2325 { Dart_TypedData_kInt8, 1024},
2326 { Dart_CObject::kUint8Array, 1024}, 2326 { Dart_TypedData_kUint8, 1024},
2327 { Dart_CObject::kInt8Array, 2048}, 2327 { Dart_TypedData_kInt8, 2048},
2328 { Dart_CObject::kUint8Array, 2048}, 2328 { Dart_TypedData_kUint8, 2048},
2329 { Dart_CObject::kInt8Array, 1024}, 2329 { Dart_TypedData_kInt8, 1024},
2330 { Dart_CObject::kUint8Array, 1024}, 2330 { Dart_TypedData_kUint8, 1024},
2331 { Dart_CObject::kInt8Array, 2048}, 2331 { Dart_TypedData_kInt8, 2048},
2332 { Dart_CObject::kUint8Array, 2048}, 2332 { Dart_TypedData_kUint8, 2048},
2333 2333
2334 { Dart_CObject::kInt16Array, 256}, 2334 { Dart_TypedData_kInt16, 256},
2335 { Dart_CObject::kUint16Array, 256}, 2335 { Dart_TypedData_kUint16, 256},
2336 { Dart_CObject::kInt16Array, 1024}, 2336 { Dart_TypedData_kInt16, 1024},
2337 { Dart_CObject::kUint16Array, 1024}, 2337 { Dart_TypedData_kUint16, 1024},
2338 { Dart_CObject::kInt16Array, 2048}, 2338 { Dart_TypedData_kInt16, 2048},
2339 { Dart_CObject::kUint16Array, 2048}, 2339 { Dart_TypedData_kUint16, 2048},
2340 { Dart_CObject::kInt16Array, 1024}, 2340 { Dart_TypedData_kInt16, 1024},
2341 { Dart_CObject::kUint16Array, 1024}, 2341 { Dart_TypedData_kUint16, 1024},
2342 { Dart_CObject::kInt16Array, 2048}, 2342 { Dart_TypedData_kInt16, 2048},
2343 { Dart_CObject::kUint16Array, 2048}, 2343 { Dart_TypedData_kUint16, 2048},
2344 2344
2345 { Dart_CObject::kNumberOfTypedDataTypes, -1 } 2345 { Dart_TypedData_kInvalid, -1 }
2346 }; 2346 };
2347 2347
2348 int i = 0; 2348 int i = 0;
2349 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { 2349 while (expected[i].type != Dart_TypedData_kInvalid) {
2350 CheckTypedData(root->value.as_array.values[i], 2350 CheckTypedData(root->value.as_array.values[i],
2351 expected[i].type, 2351 expected[i].type,
2352 expected[i].size); 2352 expected[i].size);
2353 i++; 2353 i++;
2354 } 2354 }
2355 EXPECT_EQ(i, root->value.as_array.length); 2355 EXPECT_EQ(i, root->value.as_array.length);
2356 } 2356 }
2357 { 2357 {
2358 // Generate a list of Uint8Lists from Dart code. 2358 // Generate a list of Uint8Lists from Dart code.
2359 ApiNativeScope scope; 2359 ApiNativeScope scope;
2360 Dart_CObject* root = 2360 Dart_CObject* root =
2361 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList"); 2361 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList");
2362 EXPECT_NOTNULL(root); 2362 EXPECT_NOTNULL(root);
2363 EXPECT_EQ(Dart_CObject::kArray, root->type); 2363 EXPECT_EQ(Dart_CObject_kArray, root->type);
2364 struct { 2364 struct {
2365 Dart_CObject::TypedDataType type; 2365 Dart_TypedData_Type type;
2366 int size; 2366 int size;
2367 } expected[] = { 2367 } expected[] = {
2368 { Dart_CObject::kInt8Array, 256}, 2368 { Dart_TypedData_kInt8, 256},
2369 { Dart_CObject::kUint8Array, 256}, 2369 { Dart_TypedData_kUint8, 256},
2370 { Dart_CObject::kInt16Array, 256}, 2370 { Dart_TypedData_kInt16, 256},
2371 { Dart_CObject::kUint16Array, 256}, 2371 { Dart_TypedData_kUint16, 256},
2372 { Dart_CObject::kInt32Array, 256}, 2372 { Dart_TypedData_kInt32, 256},
2373 { Dart_CObject::kUint32Array, 256}, 2373 { Dart_TypedData_kUint32, 256},
2374 { Dart_CObject::kInt64Array, 256}, 2374 { Dart_TypedData_kInt64, 256},
2375 { Dart_CObject::kUint64Array, 256}, 2375 { Dart_TypedData_kUint64, 256},
2376 { Dart_CObject::kFloat32Array, 256}, 2376 { Dart_TypedData_kFloat32, 256},
2377 { Dart_CObject::kFloat64Array, 256}, 2377 { Dart_TypedData_kFloat64, 256},
2378 { Dart_CObject::kNumberOfTypedDataTypes, -1 } 2378 { Dart_TypedData_kInvalid, -1 }
2379 }; 2379 };
2380 2380
2381 int i = 0; 2381 int i = 0;
2382 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { 2382 while (expected[i].type != Dart_TypedData_kInvalid) {
2383 CheckTypedData(root->value.as_array.values[i], 2383 CheckTypedData(root->value.as_array.values[i],
2384 expected[i].type, 2384 expected[i].type,
2385 expected[i].size); 2385 expected[i].size);
2386 2386
2387 // All views point to the same data. 2387 // All views point to the same data.
2388 EXPECT_EQ(root->value.as_array.values[0]->value.as_typed_data.values, 2388 EXPECT_EQ(root->value.as_array.values[0]->value.as_typed_data.values,
2389 root->value.as_array.values[i]->value.as_typed_data.values); 2389 root->value.as_array.values[i]->value.as_typed_data.values);
2390 i++; 2390 i++;
2391 } 2391 }
2392 EXPECT_EQ(i, root->value.as_array.length); 2392 EXPECT_EQ(i, root->value.as_array.length);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 Dart_Handle result = Dart_GetField(send_port, NewString("_id")); 2428 Dart_Handle result = Dart_GetField(send_port, NewString("_id"));
2429 ASSERT(!Dart_IsError(result)); 2429 ASSERT(!Dart_IsError(result));
2430 ASSERT(Dart_IsInteger(result)); 2430 ASSERT(Dart_IsInteger(result));
2431 int64_t send_port_id; 2431 int64_t send_port_id;
2432 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); 2432 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id);
2433 ASSERT(!Dart_IsError(result2)); 2433 ASSERT(!Dart_IsError(result2));
2434 2434
2435 // Setup single object message. 2435 // Setup single object message.
2436 Dart_CObject object; 2436 Dart_CObject object;
2437 2437
2438 object.type = Dart_CObject::kNull; 2438 object.type = Dart_CObject_kNull;
2439 EXPECT(Dart_PostCObject(send_port_id, &object)); 2439 EXPECT(Dart_PostCObject(send_port_id, &object));
2440 2440
2441 object.type = Dart_CObject::kBool; 2441 object.type = Dart_CObject_kBool;
2442 object.value.as_bool = true; 2442 object.value.as_bool = true;
2443 EXPECT(Dart_PostCObject(send_port_id, &object)); 2443 EXPECT(Dart_PostCObject(send_port_id, &object));
2444 2444
2445 object.type = Dart_CObject::kBool; 2445 object.type = Dart_CObject_kBool;
2446 object.value.as_bool = false; 2446 object.value.as_bool = false;
2447 EXPECT(Dart_PostCObject(send_port_id, &object)); 2447 EXPECT(Dart_PostCObject(send_port_id, &object));
2448 2448
2449 object.type = Dart_CObject::kInt32; 2449 object.type = Dart_CObject_kInt32;
2450 object.value.as_int32 = 123; 2450 object.value.as_int32 = 123;
2451 EXPECT(Dart_PostCObject(send_port_id, &object)); 2451 EXPECT(Dart_PostCObject(send_port_id, &object));
2452 2452
2453 object.type = Dart_CObject::kString; 2453 object.type = Dart_CObject_kString;
2454 object.value.as_string = const_cast<char*>("456"); 2454 object.value.as_string = const_cast<char*>("456");
2455 EXPECT(Dart_PostCObject(send_port_id, &object)); 2455 EXPECT(Dart_PostCObject(send_port_id, &object));
2456 2456
2457 object.type = Dart_CObject::kString; 2457 object.type = Dart_CObject_kString;
2458 object.value.as_string = const_cast<char*>("æøå"); 2458 object.value.as_string = const_cast<char*>("æøå");
2459 EXPECT(Dart_PostCObject(send_port_id, &object)); 2459 EXPECT(Dart_PostCObject(send_port_id, &object));
2460 2460
2461 object.type = Dart_CObject::kDouble; 2461 object.type = Dart_CObject_kDouble;
2462 object.value.as_double = 3.14; 2462 object.value.as_double = 3.14;
2463 EXPECT(Dart_PostCObject(send_port_id, &object)); 2463 EXPECT(Dart_PostCObject(send_port_id, &object));
2464 2464
2465 object.type = Dart_CObject::kArray; 2465 object.type = Dart_CObject_kArray;
2466 object.value.as_array.length = 0; 2466 object.value.as_array.length = 0;
2467 EXPECT(Dart_PostCObject(send_port_id, &object)); 2467 EXPECT(Dart_PostCObject(send_port_id, &object));
2468 2468
2469 static const int kArrayLength = 10; 2469 static const int kArrayLength = 10;
2470 Dart_CObject* array = 2470 Dart_CObject* array =
2471 reinterpret_cast<Dart_CObject*>( 2471 reinterpret_cast<Dart_CObject*>(
2472 Dart_ScopeAllocate( 2472 Dart_ScopeAllocate(
2473 sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT 2473 sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT
2474 array->type = Dart_CObject::kArray; 2474 array->type = Dart_CObject_kArray;
2475 array->value.as_array.length = kArrayLength; 2475 array->value.as_array.length = kArrayLength;
2476 array->value.as_array.values = 2476 array->value.as_array.values =
2477 reinterpret_cast<Dart_CObject**>(array + 1); 2477 reinterpret_cast<Dart_CObject**>(array + 1);
2478 for (int i = 0; i < kArrayLength; i++) { 2478 for (int i = 0; i < kArrayLength; i++) {
2479 Dart_CObject* element = 2479 Dart_CObject* element =
2480 reinterpret_cast<Dart_CObject*>( 2480 reinterpret_cast<Dart_CObject*>(
2481 Dart_ScopeAllocate(sizeof(Dart_CObject))); 2481 Dart_ScopeAllocate(sizeof(Dart_CObject)));
2482 element->type = Dart_CObject::kInt32; 2482 element->type = Dart_CObject_kInt32;
2483 element->value.as_int32 = i; 2483 element->value.as_int32 = i;
2484 array->value.as_array.values[i] = element; 2484 array->value.as_array.values[i] = element;
2485 } 2485 }
2486 EXPECT(Dart_PostCObject(send_port_id, array)); 2486 EXPECT(Dart_PostCObject(send_port_id, array));
2487 2487
2488 result = Dart_RunLoop(); 2488 result = Dart_RunLoop();
2489 EXPECT(Dart_IsError(result)); 2489 EXPECT(Dart_IsError(result));
2490 EXPECT(Dart_ErrorHasException(result)); 2490 EXPECT(Dart_ErrorHasException(result));
2491 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2491 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2492 Dart_GetError(result)); 2492 Dart_GetError(result));
2493 2493
2494 Dart_ExitScope(); 2494 Dart_ExitScope();
2495 } 2495 }
2496 2496
2497 } // namespace dart 2497 } // namespace dart
OLDNEW
« runtime/bin/dartutils.h ('K') | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698