| 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" |
| 11 #include "vm/utils.h" | 11 #include "vm/utils.h" |
| 12 #include "vm/verifier.h" | 12 #include "vm/verifier.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 #if defined(TARGET_ARCH_IA32) | |
| 17 UNIT_TEST_CASE(Dart_Error) { | 16 UNIT_TEST_CASE(Dart_Error) { |
| 18 Dart_CreateIsolate(NULL, NULL); | 17 Dart_CreateIsolate(NULL, NULL); |
| 19 Dart_EnterScope(); | 18 Dart_EnterScope(); |
| 20 | 19 |
| 21 Dart_Handle error = Dart_Error("An %s", "error"); | 20 Dart_Handle error = Dart_Error("An %s", "error"); |
| 22 EXPECT(!Dart_IsValid(error)); | 21 EXPECT(!Dart_IsValid(error)); |
| 23 EXPECT_STREQ("An error", Dart_GetError(error)); | 22 EXPECT_STREQ("An error", Dart_GetError(error)); |
| 24 | 23 |
| 25 Dart_ExitScope(); | 24 Dart_ExitScope(); |
| 26 Dart_ShutdownIsolate(); | 25 Dart_ShutdownIsolate(); |
| 27 } | 26 } |
| 28 #endif | |
| 29 | 27 |
| 30 | 28 |
| 31 UNIT_TEST_CASE(Null) { | 29 UNIT_TEST_CASE(Null) { |
| 32 Dart_CreateIsolate(NULL, NULL); | 30 Dart_CreateIsolate(NULL, NULL); |
| 33 Dart_EnterScope(); // Enter a Dart API scope for the unit test. | 31 Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| 34 | 32 |
| 35 Dart_Handle null = Dart_Null(); | 33 Dart_Handle null = Dart_Null(); |
| 36 EXPECT_VALID(null); | 34 EXPECT_VALID(null); |
| 37 EXPECT(Dart_IsNull(null)); | 35 EXPECT(Dart_IsNull(null)); |
| 38 | 36 |
| (...skipping 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 static Dart_Handle library_handler(Dart_LibraryTag tag, | 1782 static Dart_Handle library_handler(Dart_LibraryTag tag, |
| 1785 Dart_Handle library, | 1783 Dart_Handle library, |
| 1786 Dart_Handle url) { | 1784 Dart_Handle url) { |
| 1787 if (tag == kCanonicalizeUrl) { | 1785 if (tag == kCanonicalizeUrl) { |
| 1788 return url; | 1786 return url; |
| 1789 } | 1787 } |
| 1790 return Api::Success(); | 1788 return Api::Success(); |
| 1791 } | 1789 } |
| 1792 | 1790 |
| 1793 | 1791 |
| 1792 UNIT_TEST_CASE(LookupLibrary) { |
| 1793 const char* kScriptChars = |
| 1794 "#import('library1.dart');" |
| 1795 "main() {}"; |
| 1796 const char* kLibrary1Chars = |
| 1797 "#library('library1.dart');" |
| 1798 "#import('library2.dart');"; |
| 1799 |
| 1800 Dart_CreateIsolate(NULL, NULL); |
| 1801 Dart_EnterScope(); |
| 1802 |
| 1803 // Create a test library and Load up a test script in it. |
| 1804 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 1805 Dart_Handle source = Dart_NewString(kScriptChars); |
| 1806 Dart_Handle result = Dart_LoadScript(url, source, library_handler); |
| 1807 EXPECT_VALID(result); |
| 1808 |
| 1809 url = Dart_NewString("library1.dart"); |
| 1810 source = Dart_NewString(kLibrary1Chars); |
| 1811 result = Dart_LoadLibrary(url, source); |
| 1812 EXPECT_VALID(result); |
| 1813 |
| 1814 result = Dart_LookupLibrary(url); |
| 1815 EXPECT_VALID(result); |
| 1816 |
| 1817 result = Dart_LookupLibrary(Dart_Null()); |
| 1818 EXPECT(!Dart_IsValid(result)); |
| 1819 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", |
| 1820 Dart_GetError(result)); |
| 1821 |
| 1822 result = Dart_LookupLibrary(Dart_True()); |
| 1823 EXPECT(!Dart_IsValid(result)); |
| 1824 EXPECT_STREQ( |
| 1825 "Dart_LookupLibrary expects argument 'url' to be of type String.", |
| 1826 Dart_GetError(result)); |
| 1827 |
| 1828 result = Dart_LookupLibrary(Dart_Error("incoming error pass-thru")); |
| 1829 EXPECT(!Dart_IsValid(result)); |
| 1830 EXPECT_STREQ("incoming error pass-thru", Dart_GetError(result)); |
| 1831 |
| 1832 url = Dart_NewString("noodles.dart"); |
| 1833 result = Dart_LookupLibrary(url); |
| 1834 EXPECT(!Dart_IsValid(result)); |
| 1835 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
| 1836 Dart_GetError(result)); |
| 1837 |
| 1838 Dart_ExitScope(); |
| 1839 Dart_ShutdownIsolate(); |
| 1840 } |
| 1841 |
| 1842 |
| 1794 UNIT_TEST_CASE(ImportLibrary1) { | 1843 UNIT_TEST_CASE(ImportLibrary1) { |
| 1795 const char* kScriptChars = | 1844 const char* kScriptChars = |
| 1796 "#import('library1.dart');" | 1845 "#import('library1.dart');" |
| 1797 "#import('library2.dart');" | 1846 "#import('library2.dart');" |
| 1798 "var foo; // library2 defines foo, so should be error." | 1847 "var foo; // library2 defines foo, so should be error." |
| 1799 "main() {}"; | 1848 "main() {}"; |
| 1800 const char* kLibrary1Chars = | 1849 const char* kLibrary1Chars = |
| 1801 "#library('library1.dart');" | 1850 "#library('library1.dart');" |
| 1802 "#import('library2.dart');" | 1851 "#import('library2.dart');" |
| 1803 "var foo1;"; | 1852 "var foo1;"; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 NULL); | 2096 NULL); |
| 2048 EXPECT_VALID(result); | 2097 EXPECT_VALID(result); |
| 2049 | 2098 |
| 2050 Dart_ExitScope(); // Exit the Dart API scope. | 2099 Dart_ExitScope(); // Exit the Dart API scope. |
| 2051 } | 2100 } |
| 2052 Dart_ShutdownIsolate(); | 2101 Dart_ShutdownIsolate(); |
| 2053 } | 2102 } |
| 2054 #endif // TARGET_ARCH_IA32. | 2103 #endif // TARGET_ARCH_IA32. |
| 2055 | 2104 |
| 2056 } // namespace dart | 2105 } // namespace dart |
| OLD | NEW |