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

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

Issue 10916207: Support receiving GrowableObjectArray on native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type); 1313 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type);
1314 } 1314 }
1315 } 1315 }
1316 } 1316 }
1317 } 1317 }
1318 Dart_ExitScope(); 1318 Dart_ExitScope();
1319 Dart_ShutdownIsolate(); 1319 Dart_ShutdownIsolate();
1320 } 1320 }
1321 1321
1322 1322
1323 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
1324 const int kArrayLength = 10;
1325 static const char* kScriptChars =
1326 "final int kArrayLength = 10;\n"
1327 "getList() {\n"
1328 " return [null, null, null, null, null, null, null, null, null, null];\n"
1329 "}\n"
1330 "getIntList() {\n"
1331 " return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\n"
1332 "}\n"
1333 "getStringList() {\n"
1334 " return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];\n"
1335 "}\n"
1336 "getMixedList() {\n"
1337 " var list = [];\n"
1338 " list.add(0);\n"
1339 " list.add('1');\n"
1340 " list.add(2.2);\n"
1341 " list.add(true);\n"
1342 " list.add(null);\n"
1343 " list.add(null);\n"
1344 " list.add(null);\n"
1345 " list.add(null);\n"
1346 " list.add(null);\n"
1347 " list.add(null);\n"
1348 " return list;\n"
1349 "}\n";
1350
1351 TestCase::CreateTestIsolate();
1352 Isolate* isolate = Isolate::Current();
1353 EXPECT(isolate != NULL);
1354 Dart_EnterScope();
1355
1356 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1357 EXPECT_VALID(lib);
1358
1359 {
1360 DARTSCOPE_NOCHECKS(isolate);
1361 {
1362 // Generate a list of nulls from Dart code.
1363 ApiNativeScope scope;
1364 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList");
1365 EXPECT_NOTNULL(root);
1366 EXPECT_EQ(Dart_CObject::kArray, root->type);
1367 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1368 for (int i = 0; i < kArrayLength; i++) {
1369 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type);
1370 }
1371 CheckEncodeDecodeMessage(root);
1372 }
1373 {
1374 // Generate a list of ints from Dart code.
1375 ApiNativeScope scope;
1376 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList");
1377 EXPECT_NOTNULL(root);
1378 EXPECT_EQ(Dart_CObject::kArray, root->type);
1379 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1380 for (int i = 0; i < kArrayLength; i++) {
1381 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[i]->type);
1382 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32);
1383 }
1384 CheckEncodeDecodeMessage(root);
1385 }
1386 {
1387 // Generate a list of strings from Dart code.
1388 ApiNativeScope scope;
1389 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
1390 EXPECT_NOTNULL(root);
1391 EXPECT_EQ(Dart_CObject::kArray, root->type);
1392 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1393 for (int i = 0; i < kArrayLength; i++) {
1394 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[i]->type);
1395 char buffer[3];
1396 snprintf(buffer, sizeof(buffer), "%d", i);
1397 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string);
1398 }
1399 }
1400 {
1401 // Generate a list of objects of different types from Dart code.
1402 ApiNativeScope scope;
1403 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1404 EXPECT_NOTNULL(root);
1405 EXPECT_EQ(Dart_CObject::kArray, root->type);
1406 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1407
1408 EXPECT_EQ(Dart_CObject::kInt32, root->value.as_array.values[0]->type);
1409 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32);
1410 EXPECT_EQ(Dart_CObject::kString, root->value.as_array.values[1]->type);
1411 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string);
1412 EXPECT_EQ(Dart_CObject::kDouble, root->value.as_array.values[2]->type);
1413 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double);
1414 EXPECT_EQ(Dart_CObject::kBool, root->value.as_array.values[3]->type);
1415 EXPECT_EQ(true, root->value.as_array.values[3]->value.as_bool);
1416
1417 for (int i = 0; i < kArrayLength; i++) {
1418 if (i > 3) {
1419 EXPECT_EQ(Dart_CObject::kNull, root->value.as_array.values[i]->type);
1420 }
1421 }
1422 }
1423 }
1424 Dart_ExitScope();
1425 Dart_ShutdownIsolate();
1426 }
1427
1428
1323 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { 1429 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
1324 const int kArrayLength = 10; 1430 const int kArrayLength = 10;
1325 static const char* kScriptChars = 1431 static const char* kScriptChars =
1326 "final int kArrayLength = 10;\n" 1432 "final int kArrayLength = 10;\n"
1327 "getStringList() {\n" 1433 "getStringList() {\n"
1328 " var s = 'Hello, world!';\n" 1434 " var s = 'Hello, world!';\n"
1329 " var list = new List<String>(kArrayLength);\n" 1435 " var list = new List<String>(kArrayLength);\n"
1330 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n" 1436 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n"
1331 " return list;\n" 1437 " return list;\n"
1332 "}\n" 1438 "}\n"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 EXPECT_EQ(Dart_CObject::kArray, element->type); 1586 EXPECT_EQ(Dart_CObject::kArray, element->type);
1481 EXPECT_EQ(root, element); 1587 EXPECT_EQ(root, element);
1482 } 1588 }
1483 } 1589 }
1484 } 1590 }
1485 Dart_ExitScope(); 1591 Dart_ExitScope();
1486 Dart_ShutdownIsolate(); 1592 Dart_ShutdownIsolate();
1487 } 1593 }
1488 1594
1489 1595
1596 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
1597 const int kArrayLength = 10;
1598 static const char* kScriptChars =
1599 "final int kArrayLength = 10;\n"
1600 "getStringList() {\n"
1601 " var s = 'Hello, world!';\n"
1602 " var list = [s, s, s, s, s, s, s, s, s, s];\n"
1603 " return list;\n"
1604 "}\n"
1605 "getMintList() {\n"
1606 " var mint = 0x7FFFFFFFFFFFFFFF;\n"
1607 " var list = [mint, mint, mint, mint, mint,\n"
1608 " mint, mint, mint, mint, mint];\n"
1609 " return list;\n"
1610 "}\n"
1611 "getBigintList() {\n"
1612 " var bigint = 0x1234567890123456789012345678901234567890;\n"
1613 " var list = [bigint, bigint, bigint, bigint, bigint,\n"
1614 " bigint, bigint, bigint, bigint, bigint];\n"
1615 " return list;\n"
1616 "}\n"
1617 "getDoubleList() {\n"
1618 " var d = 3.14;\n"
1619 " var list = [3.14, 3.14, 3.14, 3.14, 3.14, 3.14];\n"
1620 " list.add(3.14);;\n"
1621 " list.add(3.14);;\n"
1622 " list.add(3.14);;\n"
1623 " list.add(3.14);;\n"
1624 " return list;\n"
1625 "}\n"
1626 "getByteArrayList() {\n"
1627 " var byte_array = new Uint8List(256);\n"
1628 " var list = [];\n"
1629 " for (var i = 0; i < kArrayLength; i++) {\n"
1630 " list.add(byte_array);\n"
1631 " }\n"
1632 " return list;\n"
1633 "}\n"
1634 "getMixedList() {\n"
1635 " var list = [];\n"
1636 " for (var i = 0; i < kArrayLength; i++) {\n"
1637 " list.add(((i % 2) == 0) ? 'A' : 2.72);\n"
1638 " }\n"
1639 " return list;\n"
1640 "}\n"
1641 "getSelfRefList() {\n"
1642 " var list = [];\n"
1643 " for (var i = 0; i < kArrayLength; i++) {\n"
1644 " list.add(list);\n"
1645 " }\n"
1646 " return list;\n"
1647 "}\n";
1648
1649 TestCase::CreateTestIsolate();
1650 Isolate* isolate = Isolate::Current();
1651 EXPECT(isolate != NULL);
1652 Dart_EnterScope();
1653
1654 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1655 EXPECT_VALID(lib);
1656
1657 {
1658 DARTSCOPE_NOCHECKS(isolate);
1659
1660 {
1661 // Generate a list of strings from Dart code.
1662 ApiNativeScope scope;
1663 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
1664 EXPECT_NOTNULL(root);
1665 EXPECT_EQ(Dart_CObject::kArray, root->type);
1666 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1667 for (int i = 0; i < kArrayLength; i++) {
1668 Dart_CObject* element = root->value.as_array.values[i];
1669 EXPECT_EQ(root->value.as_array.values[0], element);
1670 EXPECT_EQ(Dart_CObject::kString, element->type);
1671 EXPECT_STREQ("Hello, world!", element->value.as_string);
1672 }
1673 }
1674 {
1675 // Generate a list of medium ints from Dart code.
1676 ApiNativeScope scope;
1677 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList");
1678 EXPECT_NOTNULL(root);
1679 EXPECT_EQ(Dart_CObject::kArray, root->type);
1680 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1681 for (int i = 0; i < kArrayLength; i++) {
1682 Dart_CObject* element = root->value.as_array.values[i];
1683 EXPECT_EQ(root->value.as_array.values[0], element);
1684 EXPECT_EQ(Dart_CObject::kInt64, element->type);
1685 }
1686 }
1687 {
1688 // Generate a list of bigints from Dart code.
1689 ApiNativeScope scope;
1690 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList");
1691 EXPECT_NOTNULL(root);
1692 EXPECT_EQ(Dart_CObject::kArray, root->type);
1693 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1694 for (int i = 0; i < kArrayLength; i++) {
1695 Dart_CObject* element = root->value.as_array.values[i];
1696 EXPECT_EQ(root->value.as_array.values[0], element);
1697 EXPECT_EQ(Dart_CObject::kBigint, element->type);
1698 }
1699 }
1700 {
1701 // Generate a list of doubles from Dart code.
1702 ApiNativeScope scope;
1703 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList");
1704 EXPECT_NOTNULL(root);
1705 EXPECT_EQ(Dart_CObject::kArray, root->type);
1706 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1707 for (int i = 0; i < kArrayLength; i++) {
1708 Dart_CObject* element = root->value.as_array.values[i];
1709 EXPECT_EQ(root->value.as_array.values[0], element);
1710 EXPECT_EQ(Dart_CObject::kDouble, element->type);
1711 EXPECT_EQ(3.14, element->value.as_double);
1712 }
1713 }
1714 {
1715 // Generate a list of doubles from Dart code.
1716 ApiNativeScope scope;
1717 Dart_CObject* root = GetDeserializedDartMessage(lib, "getByteArrayList");
1718 EXPECT_NOTNULL(root);
1719 EXPECT_EQ(Dart_CObject::kArray, root->type);
1720 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1721 for (int i = 0; i < kArrayLength; i++) {
1722 Dart_CObject* element = root->value.as_array.values[i];
1723 EXPECT_EQ(root->value.as_array.values[0], element);
1724 EXPECT_EQ(Dart_CObject::kUint8Array, element->type);
1725 EXPECT_EQ(256, element->value.as_byte_array.length);
1726 }
1727 }
1728 {
1729 // Generate a list of objects of different types from Dart code.
1730 ApiNativeScope scope;
1731 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
1732 EXPECT_NOTNULL(root);
1733 EXPECT_EQ(Dart_CObject::kArray, root->type);
1734 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1735 for (int i = 0; i < kArrayLength; i++) {
1736 Dart_CObject* element = root->value.as_array.values[i];
1737 if ((i % 2) == 0) {
1738 EXPECT_EQ(root->value.as_array.values[0], element);
1739 EXPECT_EQ(Dart_CObject::kString, element->type);
1740 EXPECT_STREQ("A", element->value.as_string);
1741 } else {
1742 EXPECT_EQ(root->value.as_array.values[1], element);
1743 EXPECT_EQ(Dart_CObject::kDouble, element->type);
1744 EXPECT_STREQ(2.72, element->value.as_double);
1745 }
1746 }
1747 }
1748 {
1749 // Generate a list of objects of different types from Dart code.
1750 ApiNativeScope scope;
1751 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList");
1752 EXPECT_NOTNULL(root);
1753 EXPECT_EQ(Dart_CObject::kArray, root->type);
1754 EXPECT_EQ(kArrayLength, root->value.as_array.length);
1755 for (int i = 0; i < kArrayLength; i++) {
1756 Dart_CObject* element = root->value.as_array.values[i];
1757 EXPECT_EQ(Dart_CObject::kArray, element->type);
1758 EXPECT_EQ(root, element);
1759 }
1760 }
1761 }
1762 Dart_ExitScope();
1763 Dart_ShutdownIsolate();
1764 }
1765
1766
1490 UNIT_TEST_CASE(PostCObject) { 1767 UNIT_TEST_CASE(PostCObject) {
1491 // Create a native port for posting from C to Dart 1768 // Create a native port for posting from C to Dart
1492 TestIsolateScope __test_isolate__; 1769 TestIsolateScope __test_isolate__;
1493 const char* kScriptChars = 1770 const char* kScriptChars =
1494 "#import('dart:isolate');\n" 1771 "#import('dart:isolate');\n"
1495 "main() {\n" 1772 "main() {\n"
1496 " var messageCount = 0;\n" 1773 " var messageCount = 0;\n"
1497 " var exception = '';\n" 1774 " var exception = '';\n"
1498 " var port = new ReceivePort();\n" 1775 " var port = new ReceivePort();\n"
1499 " port.receive((message, replyTo) {\n" 1776 " port.receive((message, replyTo) {\n"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 EXPECT(Dart_ErrorHasException(result)); 1854 EXPECT(Dart_ErrorHasException(result));
1578 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", 1855 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n",
1579 Dart_GetError(result)); 1856 Dart_GetError(result));
1580 1857
1581 Dart_ExitScope(); 1858 Dart_ExitScope();
1582 } 1859 }
1583 1860
1584 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1861 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1585 1862
1586 } // namespace dart 1863 } // namespace dart
OLDNEW
« runtime/vm/dart_api_message.cc ('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