| 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 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 static Dart_Handle library_handler(Dart_LibraryTag tag, | 1784 static Dart_Handle library_handler(Dart_LibraryTag tag, |
| 1785 Dart_Handle library, | 1785 Dart_Handle library, |
| 1786 Dart_Handle url) { | 1786 Dart_Handle url) { |
| 1787 if (tag == kCanonicalizeUrl) { | 1787 if (tag == kCanonicalizeUrl) { |
| 1788 return url; | 1788 return url; |
| 1789 } | 1789 } |
| 1790 return Api::Success(); | 1790 return Api::Success(); |
| 1791 } | 1791 } |
| 1792 | 1792 |
| 1793 | 1793 |
| 1794 UNIT_TEST_CASE(LookupLibrary) { |
| 1795 const char* kScriptChars = |
| 1796 "#import('library1.dart');" |
| 1797 "main() {}"; |
| 1798 const char* kLibrary1Chars = |
| 1799 "#library('library1.dart');" |
| 1800 "#import('library2.dart');"; |
| 1801 |
| 1802 Dart_CreateIsolate(NULL, NULL); |
| 1803 Dart_EnterScope(); |
| 1804 |
| 1805 // Create a test library and Load up a test script in it. |
| 1806 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1807 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1808 Dart_Handle result = Dart_LoadScript(url, source, library_handler); |
| 1809 EXPECT_VALID(result); |
| 1810 |
| 1811 url = Dart_NewString("library1.dart"); |
| 1812 source = Dart_NewString(kLibrary1Chars); |
| 1813 result = Dart_LoadLibrary(url, source); |
| 1814 EXPECT_VALID(result); |
| 1815 |
| 1816 result = Dart_LookupLibrary(url); |
| 1817 EXPECT_VALID(result); |
| 1818 |
| 1819 result = Dart_LookupLibrary(Dart_Null()); |
| 1820 EXPECT(!Dart_IsValid(result)); |
| 1821 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", |
| 1822 Dart_GetError(result)); |
| 1823 |
| 1824 result = Dart_LookupLibrary(Dart_True()); |
| 1825 EXPECT(!Dart_IsValid(result)); |
| 1826 EXPECT_STREQ( |
| 1827 "Dart_LookupLibrary expects argument 'url' to be of type String.", |
| 1828 Dart_GetError(result)); |
| 1829 |
| 1830 result = Dart_LookupLibrary(Dart_Error("incoming error pass-thru")); |
| 1831 EXPECT(!Dart_IsValid(result)); |
| 1832 EXPECT_STREQ("incoming error pass-thru", Dart_GetError(result)); |
| 1833 |
| 1834 url = Dart_NewString("noodles.dart"); |
| 1835 result = Dart_LookupLibrary(url); |
| 1836 EXPECT(!Dart_IsValid(result)); |
| 1837 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
| 1838 Dart_GetError(result)); |
| 1839 |
| 1840 Dart_ExitScope(); |
| 1841 Dart_ShutdownIsolate(); |
| 1842 } |
| 1843 |
| 1844 |
| 1794 UNIT_TEST_CASE(ImportLibrary1) { | 1845 UNIT_TEST_CASE(ImportLibrary1) { |
| 1795 const char* kScriptChars = | 1846 const char* kScriptChars = |
| 1796 "#import('library1.dart');" | 1847 "#import('library1.dart');" |
| 1797 "#import('library2.dart');" | 1848 "#import('library2.dart');" |
| 1798 "var foo; // library2 defines foo, so should be error." | 1849 "var foo; // library2 defines foo, so should be error." |
| 1799 "main() {}"; | 1850 "main() {}"; |
| 1800 const char* kLibrary1Chars = | 1851 const char* kLibrary1Chars = |
| 1801 "#library('library1.dart');" | 1852 "#library('library1.dart');" |
| 1802 "#import('library2.dart');" | 1853 "#import('library2.dart');" |
| 1803 "var foo1;"; | 1854 "var foo1;"; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 NULL); | 2098 NULL); |
| 2048 EXPECT_VALID(result); | 2099 EXPECT_VALID(result); |
| 2049 | 2100 |
| 2050 Dart_ExitScope(); // Exit the Dart API scope. | 2101 Dart_ExitScope(); // Exit the Dart API scope. |
| 2051 } | 2102 } |
| 2052 Dart_ShutdownIsolate(); | 2103 Dart_ShutdownIsolate(); |
| 2053 } | 2104 } |
| 2054 #endif // TARGET_ARCH_IA32. | 2105 #endif // TARGET_ARCH_IA32. |
| 2055 | 2106 |
| 2056 } // namespace dart | 2107 } // namespace dart |
| OLD | NEW |