OLD | NEW |
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_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 4804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4815 root_lib = Dart_RootLibrary(); | 4815 root_lib = Dart_RootLibrary(); |
4816 Dart_Handle lib_name = Dart_LibraryName(root_lib); | 4816 Dart_Handle lib_name = Dart_LibraryName(root_lib); |
4817 EXPECT_VALID(lib_name); | 4817 EXPECT_VALID(lib_name); |
4818 EXPECT(!Dart_IsNull(root_lib)); | 4818 EXPECT(!Dart_IsNull(root_lib)); |
4819 const char* name_cstr = ""; | 4819 const char* name_cstr = ""; |
4820 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 4820 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
4821 EXPECT_STREQ(TestCase::url(), name_cstr); | 4821 EXPECT_STREQ(TestCase::url(), name_cstr); |
4822 } | 4822 } |
4823 | 4823 |
4824 | 4824 |
4825 static const char* var_mapping[] = { | |
4826 "GOOGLE3", ".", | |
4827 "ABC", "lala", | |
4828 "var1", "", | |
4829 "var2", "winner", | |
4830 }; | |
4831 static int index = 0; | 4825 static int index = 0; |
4832 | 4826 |
4833 | 4827 |
4834 static Dart_Handle import_library_handler(Dart_LibraryTag tag, | 4828 static Dart_Handle import_library_handler(Dart_LibraryTag tag, |
4835 Dart_Handle library, | 4829 Dart_Handle library, |
4836 Dart_Handle url) { | 4830 Dart_Handle url) { |
4837 if (tag == kCanonicalizeUrl) { | 4831 if (tag == kCanonicalizeUrl) { |
4838 return url; | 4832 return url; |
4839 } | 4833 } |
4840 EXPECT(Dart_IsString(url)); | 4834 EXPECT(Dart_IsString(url)); |
(...skipping 17 matching lines...) Expand all Loading... |
4858 break; | 4852 break; |
4859 default: | 4853 default: |
4860 EXPECT(false); | 4854 EXPECT(false); |
4861 return Api::NewError("invalid callback"); | 4855 return Api::NewError("invalid callback"); |
4862 } | 4856 } |
4863 index += 1; | 4857 index += 1; |
4864 return Api::Success(Isolate::Current()); | 4858 return Api::Success(Isolate::Current()); |
4865 } | 4859 } |
4866 | 4860 |
4867 | 4861 |
4868 TEST_CASE(LoadImportScript) { | |
4869 const char* kScriptChars = | |
4870 "#import('$GOOGLE3/weird.dart');" | |
4871 "#import('abc${ABC}def');" | |
4872 "#import('${var1}$var2');" | |
4873 "#import('abc${ABC}def/extra_weird.dart');" | |
4874 "#import('$var2$var2');" | |
4875 "main() {" | |
4876 " return 12345;" | |
4877 "}"; | |
4878 Dart_Handle url = Dart_NewString(TestCase::url()); | |
4879 Dart_Handle source = Dart_NewString(kScriptChars); | |
4880 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); | |
4881 Dart_Handle import_map = Dart_NewList(length); | |
4882 for (intptr_t i = 0; i < length; i++) { | |
4883 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); | |
4884 } | |
4885 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | |
4886 EXPECT_VALID(result); | |
4887 result = Dart_SetImportMap(import_map); | |
4888 EXPECT_VALID(result); | |
4889 result = Dart_LoadScript(url, source); | |
4890 EXPECT_VALID(result); | |
4891 } | |
4892 | |
4893 | |
4894 TEST_CASE(LoadImportScriptError1) { | |
4895 const char* kScriptChars = | |
4896 "#import('abc${DEF}def/extra_weird.dart');" | |
4897 "main() {" | |
4898 " return 12345;" | |
4899 "}"; | |
4900 Dart_Handle url = Dart_NewString(TestCase::url()); | |
4901 Dart_Handle source = Dart_NewString(kScriptChars); | |
4902 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | |
4903 EXPECT_VALID(result); | |
4904 result = Dart_LoadScript(url, source); | |
4905 EXPECT(Dart_IsError(result)); | |
4906 EXPECT(strstr(Dart_GetError(result), | |
4907 "import variable 'DEF' has not been defined")); | |
4908 } | |
4909 | |
4910 | |
4911 TEST_CASE(LoadImportScriptError2) { | |
4912 const char* kScriptChars = | |
4913 "#import('abc${ABC/extra_weird.dart');" | |
4914 "main() {" | |
4915 " return 12345;" | |
4916 "}"; | |
4917 Dart_Handle url = Dart_NewString(TestCase::url()); | |
4918 Dart_Handle source = Dart_NewString(kScriptChars); | |
4919 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); | |
4920 Dart_Handle import_map = Dart_NewList(length); | |
4921 for (intptr_t i = 0; i < length; i++) { | |
4922 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); | |
4923 } | |
4924 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | |
4925 EXPECT_VALID(result); | |
4926 result = Dart_SetImportMap(import_map); | |
4927 EXPECT_VALID(result); | |
4928 result = Dart_LoadScript(url, source); | |
4929 EXPECT(Dart_IsError(result)); | |
4930 EXPECT(strstr(Dart_GetError(result), "'}' expected")); | |
4931 } | |
4932 | |
4933 | |
4934 TEST_CASE(LoadScript_CompileError) { | 4862 TEST_CASE(LoadScript_CompileError) { |
4935 const char* kScriptChars = | 4863 const char* kScriptChars = |
4936 ")"; | 4864 ")"; |
4937 Dart_Handle url = Dart_NewString(TestCase::url()); | 4865 Dart_Handle url = Dart_NewString(TestCase::url()); |
4938 Dart_Handle source = Dart_NewString(kScriptChars); | 4866 Dart_Handle source = Dart_NewString(kScriptChars); |
4939 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 4867 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
4940 EXPECT_VALID(result); | 4868 EXPECT_VALID(result); |
4941 result = Dart_LoadScript(url, source); | 4869 result = Dart_LoadScript(url, source); |
4942 EXPECT(Dart_IsError(result)); | 4870 EXPECT(Dart_IsError(result)); |
4943 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 4871 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6564 EXPECT(Dart_IsString(str)); | 6492 EXPECT(Dart_IsString(str)); |
6565 len = -1; | 6493 len = -1; |
6566 EXPECT_VALID(Dart_StringLength(str, &len)); | 6494 EXPECT_VALID(Dart_StringLength(str, &len)); |
6567 EXPECT_EQ(0, len); | 6495 EXPECT_EQ(0, len); |
6568 } | 6496 } |
6569 | 6497 |
6570 | 6498 |
6571 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6499 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
6572 | 6500 |
6573 } // namespace dart | 6501 } // namespace dart |
OLD | NEW |