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

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

Issue 10989074: Handle receiving GrowableObjectArrays correctly on native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/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 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 "final int kArrayLength = 10;\n" 1323 "final int kArrayLength = 10;\n"
1324 "getList() {\n" 1324 "getList() {\n"
1325 " return [null, null, null, null, null, null, null, null, null, null];\n" 1325 " return [null, null, null, null, null, null, null, null, null, null];\n"
1326 "}\n" 1326 "}\n"
1327 "getIntList() {\n" 1327 "getIntList() {\n"
1328 " return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n" 1328 " return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n"
1329 "}\n" 1329 "}\n"
1330 "getStringList() {\n" 1330 "getStringList() {\n"
1331 " return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\n" 1331 " return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\n"
1332 "}\n" 1332 "}\n"
1333 "getListList() {\n"
1334 " return [[],"
1335 " [0],"
1336 " [0, 1],"
1337 " [0, 1, 2],"
1338 " [0, 1, 2, 3],"
1339 " [0, 1, 2, 3, 4],"
1340 " [0, 1, 2, 3, 4, 5],"
1341 " [0, 1, 2, 3, 4, 5, 6],"
1342 " [0, 1, 2, 3, 4, 5, 6, 7],"
1343 " [0, 1, 2, 3, 4, 5, 6, 7, 8]];\n"
1344 "}\n"
1333 "getMixedList() {\n" 1345 "getMixedList() {\n"
1334 " var list = [];\n" 1346 " var list = [];\n"
1335 " list.add(0);\n" 1347 " list.add(0);\n"
1336 " list.add('1');\n" 1348 " list.add('1');\n"
1337 " list.add(2.2);\n" 1349 " list.add(2.2);\n"
1338 " list.add(true);\n" 1350 " list.add(true);\n"
1339 " list.add(null);\n" 1351 " list.add([]);\n"
1340 " list.add(null);\n" 1352 " list.add([[]]);\n"
1341 " list.add(null);\n" 1353 " list.add([[[]]]);\n"
1342 " list.add(null);\n" 1354 " list.add([1, [2, [3]]]);\n"
1343 " list.add(null);\n" 1355 " list.add([1, [1, 2, [1, 2, 3]]]);\n"
1344 " list.add(null);\n" 1356 " list.add([1, 2, 3]);\n"
1345 " return list;\n" 1357 " return list;\n"
1346 "}\n"; 1358 "}\n";
1347 1359
1348 TestCase::CreateTestIsolate(); 1360 TestCase::CreateTestIsolate();
1349 Isolate* isolate = Isolate::Current(); 1361 Isolate* isolate = Isolate::Current();
1350 EXPECT(isolate != NULL); 1362 EXPECT(isolate != NULL);
1351 Dart_EnterScope(); 1363 Dart_EnterScope();
1352 1364
1353 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1365 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1354 EXPECT_VALID(lib); 1366 EXPECT_VALID(lib);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 EXPECT_EQ(Dart_CObject::kArray, root->type); 1400 EXPECT_EQ(Dart_CObject::kArray, root->type);
1389 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1401 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1390 for (int i = 0; i < kArrayLength; i++) { 1402 for (int i = 0; i < kArrayLength; i++) {
1391 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[i]->type); 1403 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[i]->type);
1392 char buffer[3]; 1404 char buffer[3];
1393 snprintf(buffer, sizeof(buffer), "%d", i); 1405 snprintf(buffer, sizeof(buffer), "%d", i);
1394 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); 1406 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string);
1395 } 1407 }
1396 } 1408 }
1397 { 1409 {
1410 // Generate a list of lists from Dart code.
1411 ApiNativeScope scope;
1412 Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList");
1413 EXPECT_NOTNULL(root);
1414 EXPECT_EQ(Dart_CObject::kArray, root->type);
1415 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1416 for (int i = 0; i < kArrayLength; i++) {
1417 Dart_CObject* element = root->value.as_array.values[i];
1418 EXPECT_EQ(Dart_CObject::kArray, element->type);
1419 EXPECT_EQ(i, element->value.as_array.length);
1420 for (int j = 0; j < i; j++) {
1421 EXPECT_EQ(Dart_CObject::kInt32,
1422 element->value.as_array.values[j]->type);
1423 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32);
1424 }
1425 }
1426 }
1427 {
1398 // Generate a list of objects of different types from Dart code. 1428 // Generate a list of objects of different types from Dart code.
1399 ApiNativeScope scope; 1429 ApiNativeScope scope;
1400 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); 1430 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1401 EXPECT_NOTNULL(root); 1431 EXPECT_NOTNULL(root);
1402 EXPECT_EQ(Dart_CObject::kArray, root->type); 1432 EXPECT_EQ(Dart_CObject::kArray, root->type);
1403 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1433 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1404 1434
1405 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[0]->type); 1435 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[0]->type);
1406 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); 1436 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32);
1407 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[1]->type); 1437 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[1]->type);
1408 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); 1438 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string);
1409 EXPECT_EQ(Dart_CObject::kDouble, root->value.as_array.values[2]->type); 1439 EXPECT_EQ(Dart_CObject::kDouble, root->value.as_array.values[2]->type);
1410 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); 1440 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double);
1411 EXPECT_EQ(Dart_CObject::kBool, root->value.as_array.values[3]->type); 1441 EXPECT_EQ(Dart_CObject::kBool, root->value.as_array.values[3]->type);
1412 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool); 1442 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool);
1413 1443
1414 for (int i = 0; i < kArrayLength; i++) { 1444 for (int i = 0; i < kArrayLength; i++) {
1415 if (i > 3) { 1445 if (i > 3) {
1416 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type); 1446 EXPECT_EQ(Dart_CObject::kArray, root->value.as_array.values[i]->type);
1417 } 1447 }
1418 } 1448 }
1449
1450 Dart_CObject* element;
1451 Dart_CObject* e;
1452
1453 // []
1454 element = root->value.as_array.values[4];
1455 EXPECT_EQ(0, element->value.as_array.length);
1456
1457 // [[]]
1458 element = root->value.as_array.values[5];
1459 EXPECT_EQ(1, element->value.as_array.length);
1460 element = element->value.as_array.values[0];
1461 EXPECT_EQ(Dart_CObject::kArray, element->type);
1462 EXPECT_EQ(0, element->value.as_array.length);
1463
1464 // [[[]]]"
1465 element = root->value.as_array.values[6];
1466 EXPECT_EQ(1, element->value.as_array.length);
1467 element = element->value.as_array.values[0];
1468 EXPECT_EQ(Dart_CObject::kArray, element->type);
1469 EXPECT_EQ(1, element->value.as_array.length);
1470 element = element->value.as_array.values[0];
1471 EXPECT_EQ(Dart_CObject::kArray, element->type);
1472 EXPECT_EQ(0, element->value.as_array.length);
1473
1474 // [1, [2, [3]]]
1475 element = root->value.as_array.values[7];
1476 EXPECT_EQ(2, element->value.as_array.length);
1477 e = element->value.as_array.values[0];
1478 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1479 EXPECT_EQ(1, e->value.as_int32);
1480 element = element->value.as_array.values[1];
1481 EXPECT_EQ(Dart_CObject::kArray, element->type);
1482 EXPECT_EQ(2, element->value.as_array.length);
1483 e = element->value.as_array.values[0];
1484 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1485 EXPECT_EQ(2, e->value.as_int32);
1486 element = element->value.as_array.values[1];
1487 EXPECT_EQ(Dart_CObject::kArray, element->type);
1488 EXPECT_EQ(1, element->value.as_array.length);
1489 e = element->value.as_array.values[0];
1490 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1491 EXPECT_EQ(3, e->value.as_int32);
1492
1493 // [1, [1, 2, [1, 2, 3]]]
1494 element = root->value.as_array.values[8];
1495 EXPECT_EQ(2, element->value.as_array.length);
1496 e = element->value.as_array.values[0];
1497 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1498 e = element->value.as_array.values[0];
1499 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1500 EXPECT_EQ(1, e->value.as_int32);
1501 element = element->value.as_array.values[1];
1502 EXPECT_EQ(Dart_CObject::kArray, element->type);
1503 EXPECT_EQ(3, element->value.as_array.length);
1504 for (int i = 0; i < 2; i++) {
1505 e = element->value.as_array.values[i];
1506 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1507 EXPECT_EQ(i + 1, e->value.as_int32);
1508 }
1509 element = element->value.as_array.values[2];
1510 EXPECT_EQ(Dart_CObject::kArray, element->type);
1511 EXPECT_EQ(3, element->value.as_array.length);
1512 for (int i = 0; i < 3; i++) {
1513 e = element->value.as_array.values[i];
1514 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1515 EXPECT_EQ(i + 1, e->value.as_int32);
1516 }
1517
1518 // [1, 2, 3]
1519 element = root->value.as_array.values[9];
1520 EXPECT_EQ(3, element->value.as_array.length);
1521 for (int i = 0; i < 3; i++) {
1522 e = element->value.as_array.values[i];
1523 EXPECT_EQ(Dart_CObject::kInt32, e->type);
1524 EXPECT_EQ(i + 1, e->value.as_int32);
1525 }
1419 } 1526 }
1420 } 1527 }
1421 Dart_ExitScope(); 1528 Dart_ExitScope();
1422 Dart_ShutdownIsolate(); 1529 Dart_ShutdownIsolate();
1423 } 1530 }
1424 1531
1425 1532
1426 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { 1533 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
1427 const int kArrayLength = 10; 1534 const int kArrayLength = 10;
1428 static const char* kScriptChars = 1535 static const char* kScriptChars =
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 EXPECT(Dart_ErrorHasException(result)); 1966 EXPECT(Dart_ErrorHasException(result));
1860 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", 1967 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n",
1861 Dart_GetError(result)); 1968 Dart_GetError(result));
1862 1969
1863 Dart_ExitScope(); 1970 Dart_ExitScope();
1864 } 1971 }
1865 1972
1866 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1973 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1867 1974
1868 } // namespace dart 1975 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698