OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 number_of_arguments, | 1413 number_of_arguments, |
1414 dart_arguments); | 1414 dart_arguments); |
1415 EXPECT(Dart_IsValidResult(result)); | 1415 EXPECT(Dart_IsValidResult(result)); |
1416 retobj = Dart_GetResult(result); | 1416 retobj = Dart_GetResult(result); |
1417 EXPECT(Dart_ExceptionOccurred(retobj)); */ | 1417 EXPECT(Dart_ExceptionOccurred(retobj)); */ |
1418 } | 1418 } |
1419 Dart_ExitScope(); // Exit the Dart API scope. | 1419 Dart_ExitScope(); // Exit the Dart API scope. |
1420 Dart_ShutdownIsolate(); | 1420 Dart_ShutdownIsolate(); |
1421 } | 1421 } |
1422 | 1422 |
| 1423 |
| 1424 static Dart_Result library_handler(Dart_LibraryTag tag, |
| 1425 Dart_Handle library, |
| 1426 Dart_Handle url) { |
| 1427 if (tag == kCanonicalizeUrl) { |
| 1428 return Dart_ResultAsObject(url); |
| 1429 } |
| 1430 return Dart_ResultAsObject(Dart_NewBoolean(true)); |
| 1431 } |
| 1432 |
| 1433 |
| 1434 UNIT_TEST_CASE(ImportLibrary1) { |
| 1435 const char* kScriptChars = |
| 1436 "#import('library1.dart');" |
| 1437 "#import('library2.dart');" |
| 1438 "var foo; // library2 defines foo, so should be error." |
| 1439 "main() {}"; |
| 1440 const char* kLibrary1Chars = |
| 1441 "#library('library1.dart');" |
| 1442 "#import('library2.dart');" |
| 1443 "var foo1;"; |
| 1444 const char* kLibrary2Chars = |
| 1445 "#library('library2.dart');" |
| 1446 "var foo;"; |
| 1447 Dart_Result result; |
| 1448 |
| 1449 Dart_CreateIsolate(NULL, NULL); |
| 1450 { |
| 1451 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1452 |
| 1453 // Create a test library and Load up a test script in it. |
| 1454 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1455 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1456 result = Dart_LoadScript(url, source, library_handler); |
| 1457 |
| 1458 url = Dart_NewString("library1.dart"); |
| 1459 source = Dart_NewString(kLibrary1Chars); |
| 1460 Dart_LoadLibrary(url, source); |
| 1461 |
| 1462 url = Dart_NewString("library2.dart"); |
| 1463 source = Dart_NewString(kLibrary2Chars); |
| 1464 Dart_LoadLibrary(url, source); |
| 1465 |
| 1466 result = Dart_InvokeStatic(Dart_GetResult(result), |
| 1467 Dart_NewString(""), |
| 1468 Dart_NewString("main"), |
| 1469 0, |
| 1470 NULL); |
| 1471 assert(!Dart_IsValidResult(result)); |
| 1472 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" |
| 1473 " 'library2.dart' and 'dart:test-lib'\n", |
| 1474 Dart_GetErrorCString(result)); |
| 1475 |
| 1476 Dart_ExitScope(); // Exit the Dart API scope. |
| 1477 } |
| 1478 Dart_ShutdownIsolate(); |
| 1479 } |
| 1480 |
| 1481 |
| 1482 UNIT_TEST_CASE(ImportLibrary2) { |
| 1483 const char* kScriptChars = |
| 1484 "#import('library1.dart');" |
| 1485 "var foo;" |
| 1486 "main() {}"; |
| 1487 const char* kLibrary1Chars = |
| 1488 "#library('library1.dart');" |
| 1489 "#import('library2.dart');" |
| 1490 "var foo1;"; |
| 1491 const char* kLibrary2Chars = |
| 1492 "#library('library2.dart');" |
| 1493 "#import('library1.dart');" |
| 1494 "var foo;"; |
| 1495 Dart_Result result; |
| 1496 |
| 1497 Dart_CreateIsolate(NULL, NULL); |
| 1498 { |
| 1499 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1500 |
| 1501 // Create a test library and Load up a test script in it. |
| 1502 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1503 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1504 result = Dart_LoadScript(url, source, library_handler); |
| 1505 |
| 1506 url = Dart_NewString("library1.dart"); |
| 1507 source = Dart_NewString(kLibrary1Chars); |
| 1508 Dart_LoadLibrary(url, source); |
| 1509 |
| 1510 url = Dart_NewString("library2.dart"); |
| 1511 source = Dart_NewString(kLibrary2Chars); |
| 1512 Dart_LoadLibrary(url, source); |
| 1513 |
| 1514 result = Dart_InvokeStatic(Dart_GetResult(result), |
| 1515 Dart_NewString(""), |
| 1516 Dart_NewString("main"), |
| 1517 0, |
| 1518 NULL); |
| 1519 assert(Dart_IsValidResult(result)); |
| 1520 |
| 1521 Dart_ExitScope(); // Exit the Dart API scope. |
| 1522 } |
| 1523 Dart_ShutdownIsolate(); |
| 1524 } |
| 1525 |
| 1526 |
| 1527 UNIT_TEST_CASE(ImportLibrary3) { |
| 1528 const char* kScriptChars = |
| 1529 "#import('library2.dart');" |
| 1530 "#import('library1.dart');" |
| 1531 "var foo_top = 10; // foo has dup def. So should be an error." |
| 1532 "main() {}"; |
| 1533 const char* kLibrary1Chars = |
| 1534 "#library('library1.dart');" |
| 1535 "var foo;"; |
| 1536 const char* kLibrary2Chars = |
| 1537 "#library('library2.dart');" |
| 1538 "var foo;"; |
| 1539 Dart_Result result; |
| 1540 |
| 1541 Dart_CreateIsolate(NULL, NULL); |
| 1542 { |
| 1543 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1544 |
| 1545 // Create a test library and Load up a test script in it. |
| 1546 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1547 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1548 result = Dart_LoadScript(url, source, library_handler); |
| 1549 |
| 1550 url = Dart_NewString("library2.dart"); |
| 1551 source = Dart_NewString(kLibrary2Chars); |
| 1552 Dart_LoadLibrary(url, source); |
| 1553 |
| 1554 url = Dart_NewString("library1.dart"); |
| 1555 source = Dart_NewString(kLibrary1Chars); |
| 1556 Dart_LoadLibrary(url, source); |
| 1557 |
| 1558 result = Dart_InvokeStatic(Dart_GetResult(result), |
| 1559 Dart_NewString(""), |
| 1560 Dart_NewString("main"), |
| 1561 0, |
| 1562 NULL); |
| 1563 assert(!Dart_IsValidResult(result)); |
| 1564 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" |
| 1565 " 'library1.dart' and 'library2.dart'\n", |
| 1566 Dart_GetErrorCString(result)); |
| 1567 |
| 1568 Dart_ExitScope(); // Exit the Dart API scope. |
| 1569 } |
| 1570 Dart_ShutdownIsolate(); |
| 1571 } |
| 1572 |
| 1573 |
| 1574 UNIT_TEST_CASE(ImportLibrary4) { |
| 1575 const char* kScriptChars = |
| 1576 "#import('libraryA.dart');" |
| 1577 "#import('libraryB.dart');" |
| 1578 "#import('libraryD.dart');" |
| 1579 "#import('libraryE.dart');" |
| 1580 "var fooApp;" |
| 1581 "main() {}"; |
| 1582 const char* kLibraryAChars = |
| 1583 "#library('libraryA.dart');" |
| 1584 "#import('libraryC.dart');" |
| 1585 "var fooA;"; |
| 1586 const char* kLibraryBChars = |
| 1587 "#library('libraryB.dart');" |
| 1588 "#import('libraryC.dart');" |
| 1589 "var fooB;"; |
| 1590 const char* kLibraryCChars = |
| 1591 "#library('libraryC.dart');" |
| 1592 "var fooC;"; |
| 1593 const char* kLibraryDChars = |
| 1594 "#library('libraryD.dart');" |
| 1595 "#import('libraryF.dart');" |
| 1596 "var fooD;"; |
| 1597 const char* kLibraryEChars = |
| 1598 "#library('libraryE.dart');" |
| 1599 "#import('libraryC.dart');" |
| 1600 "#import('libraryF.dart');" |
| 1601 "var fooE = 10; //fooC has duplicate def. so should be an error."; |
| 1602 const char* kLibraryFChars = |
| 1603 "#library('libraryF.dart');" |
| 1604 "var fooC;"; |
| 1605 Dart_Result result; |
| 1606 |
| 1607 Dart_CreateIsolate(NULL, NULL); |
| 1608 { |
| 1609 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1610 |
| 1611 // Create a test library and Load up a test script in it. |
| 1612 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1613 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1614 result = Dart_LoadScript(url, source, library_handler); |
| 1615 |
| 1616 url = Dart_NewString("libraryA.dart"); |
| 1617 source = Dart_NewString(kLibraryAChars); |
| 1618 Dart_LoadLibrary(url, source); |
| 1619 |
| 1620 url = Dart_NewString("libraryC.dart"); |
| 1621 source = Dart_NewString(kLibraryCChars); |
| 1622 Dart_LoadLibrary(url, source); |
| 1623 |
| 1624 url = Dart_NewString("libraryB.dart"); |
| 1625 source = Dart_NewString(kLibraryBChars); |
| 1626 Dart_LoadLibrary(url, source); |
| 1627 |
| 1628 url = Dart_NewString("libraryD.dart"); |
| 1629 source = Dart_NewString(kLibraryDChars); |
| 1630 Dart_LoadLibrary(url, source); |
| 1631 |
| 1632 url = Dart_NewString("libraryF.dart"); |
| 1633 source = Dart_NewString(kLibraryFChars); |
| 1634 Dart_LoadLibrary(url, source); |
| 1635 |
| 1636 url = Dart_NewString("libraryE.dart"); |
| 1637 source = Dart_NewString(kLibraryEChars); |
| 1638 Dart_LoadLibrary(url, source); |
| 1639 |
| 1640 result = Dart_InvokeStatic(Dart_GetResult(result), |
| 1641 Dart_NewString(""), |
| 1642 Dart_NewString("main"), |
| 1643 0, |
| 1644 NULL); |
| 1645 assert(!Dart_IsValidResult(result)); |
| 1646 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" |
| 1647 " 'libraryF.dart' and 'libraryC.dart'\n", |
| 1648 Dart_GetErrorCString(result)); |
| 1649 |
| 1650 Dart_ExitScope(); // Exit the Dart API scope. |
| 1651 } |
| 1652 Dart_ShutdownIsolate(); |
| 1653 } |
| 1654 |
1423 #endif // TARGET_ARCH_IA32. | 1655 #endif // TARGET_ARCH_IA32. |
1424 | 1656 |
1425 } // namespace dart | 1657 } // namespace dart |
OLD | NEW |