| 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/utils.h" | 7 #include "platform/utils.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_state.h" | 10 #include "vm/dart_api_state.h" |
| 11 #include "vm/thread.h" | 11 #include "vm/thread.h" |
| 12 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
| 13 #include "vm/verifier.h" | 13 #include "vm/verifier.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 // Only ia32 and x64 can run execution tests. | 17 // Only ia32 and x64 can run execution tests. |
| 18 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 18 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 19 | 19 |
| 20 TEST_CASE(ErrorHandles) { | 20 TEST_CASE(ErrorHandleBasics) { |
| 21 const char* kScriptChars = | 21 const char* kScriptChars = |
| 22 "void testMain() {\n" | 22 "void testMain() {\n" |
| 23 " throw new Exception(\"bad news\");\n" | 23 " throw new Exception(\"bad news\");\n" |
| 24 "}\n"; | 24 "}\n"; |
| 25 | 25 |
| 26 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 26 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 27 | 27 |
| 28 Dart_Handle instance = Dart_True(); | 28 Dart_Handle instance = Dart_True(); |
| 29 Dart_Handle error = Api::NewError("myerror"); | 29 Dart_Handle error = Api::NewError("myerror"); |
| 30 Dart_Handle exception = Dart_Invoke(lib, | 30 Dart_Handle exception = Dart_Invoke(lib, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); | 51 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); |
| 52 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); | 52 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); |
| 53 EXPECT_VALID(Dart_ErrorGetException(exception)); | 53 EXPECT_VALID(Dart_ErrorGetException(exception)); |
| 54 | 54 |
| 55 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); | 55 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); |
| 56 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 56 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); |
| 57 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 57 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 TEST_CASE(ErrorHandleTypes) { |
| 62 Isolate* isolate = Isolate::Current(); |
| 63 const String& compile_message = String::Handle(String::New("CompileError")); |
| 64 const String& fatal_message = String::Handle(String::New("FatalError")); |
| 65 |
| 66 Dart_Handle not_error = Dart_NewString("NotError"); |
| 67 Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); |
| 68 Dart_Handle exception_error = |
| 69 Dart_NewUnhandledExceptionError(Dart_NewString("ExceptionError")); |
| 70 Dart_Handle compile_error = |
| 71 Api::NewHandle(isolate, LanguageError::New(compile_message)); |
| 72 Dart_Handle fatal_error = |
| 73 Api::NewHandle(isolate, UnwindError::New(fatal_message)); |
| 74 |
| 75 EXPECT(!Dart_IsError(not_error)); |
| 76 EXPECT(Dart_IsError(api_error)); |
| 77 EXPECT(Dart_IsError(exception_error)); |
| 78 EXPECT(Dart_IsError(compile_error)); |
| 79 EXPECT(Dart_IsError(fatal_error)); |
| 80 |
| 81 EXPECT(!Dart_IsApiError(not_error)); |
| 82 EXPECT(Dart_IsApiError(api_error)); |
| 83 EXPECT(!Dart_IsApiError(exception_error)); |
| 84 EXPECT(!Dart_IsApiError(compile_error)); |
| 85 EXPECT(!Dart_IsApiError(fatal_error)); |
| 86 |
| 87 EXPECT(!Dart_IsUnhandledExceptionError(not_error)); |
| 88 EXPECT(!Dart_IsUnhandledExceptionError(api_error)); |
| 89 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
| 90 EXPECT(!Dart_IsUnhandledExceptionError(compile_error)); |
| 91 EXPECT(!Dart_IsUnhandledExceptionError(fatal_error)); |
| 92 |
| 93 EXPECT(!Dart_IsCompilationError(not_error)); |
| 94 EXPECT(!Dart_IsCompilationError(api_error)); |
| 95 EXPECT(!Dart_IsCompilationError(exception_error)); |
| 96 EXPECT(Dart_IsCompilationError(compile_error)); |
| 97 EXPECT(!Dart_IsCompilationError(fatal_error)); |
| 98 |
| 99 EXPECT(!Dart_IsFatalError(not_error)); |
| 100 EXPECT(!Dart_IsFatalError(api_error)); |
| 101 EXPECT(!Dart_IsFatalError(exception_error)); |
| 102 EXPECT(!Dart_IsFatalError(compile_error)); |
| 103 EXPECT(Dart_IsFatalError(fatal_error)); |
| 104 |
| 105 EXPECT_STREQ("", Dart_GetError(not_error)); |
| 106 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); |
| 107 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", |
| 108 Dart_GetError(exception_error)); |
| 109 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); |
| 110 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); |
| 111 } |
| 112 |
| 113 |
| 61 void PropagateErrorNative(Dart_NativeArguments args) { | 114 void PropagateErrorNative(Dart_NativeArguments args) { |
| 62 Dart_EnterScope(); | 115 Dart_EnterScope(); |
| 63 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | 116 Dart_Handle closure = Dart_GetNativeArgument(args, 0); |
| 64 EXPECT(Dart_IsClosure(closure)); | 117 EXPECT(Dart_IsClosure(closure)); |
| 65 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); | 118 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); |
| 66 EXPECT(Dart_IsError(result)); | 119 EXPECT(Dart_IsError(result)); |
| 67 result = Dart_PropagateError(result); | 120 result = Dart_PropagateError(result); |
| 68 EXPECT_VALID(result); // We do not expect to reach here. | 121 EXPECT_VALID(result); // We do not expect to reach here. |
| 69 UNREACHABLE(); | 122 UNREACHABLE(); |
| 70 } | 123 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 EXPECT(equal); | 230 EXPECT(equal); |
| 178 | 231 |
| 179 // Different objects. | 232 // Different objects. |
| 180 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); | 233 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); |
| 181 EXPECT(!equal); | 234 EXPECT(!equal); |
| 182 } | 235 } |
| 183 | 236 |
| 184 #endif | 237 #endif |
| 185 | 238 |
| 186 | 239 |
| 240 TEST_CASE(InstanceValues) { |
| 241 EXPECT(Dart_IsInstance(Dart_NewString("test"))); |
| 242 EXPECT(Dart_IsInstance(Dart_True())); |
| 243 |
| 244 // By convention, our Is*() functions exclude null. |
| 245 EXPECT(!Dart_IsInstance(Dart_Null())); |
| 246 } |
| 247 |
| 248 |
| 249 TEST_CASE(InstanceGetClass) { |
| 250 // Get the handle from a valid instance handle. |
| 251 Dart_Handle instance = Dart_True(); |
| 252 Dart_Handle cls = Dart_InstanceGetClass(instance); |
| 253 EXPECT_VALID(cls); |
| 254 EXPECT(Dart_IsClass(cls)); |
| 255 Dart_Handle cls_name = Dart_ClassName(cls); |
| 256 EXPECT_VALID(cls_name); |
| 257 const char* cls_name_cstr = ""; |
| 258 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 259 EXPECT_STREQ("Bool", cls_name_cstr); |
| 260 |
| 261 // Errors propagate. |
| 262 Dart_Handle error = Dart_NewApiError("MyError"); |
| 263 Dart_Handle error_cls = Dart_InstanceGetClass(error); |
| 264 EXPECT_ERROR(error_cls, "MyError"); |
| 265 |
| 266 // Get the handle from a non-instance handle |
| 267 ASSERT(Dart_IsClass(cls)); |
| 268 Dart_Handle cls_cls = Dart_InstanceGetClass(cls); |
| 269 EXPECT_ERROR(cls_cls, |
| 270 "Dart_InstanceGetClass expects argument 'instance' to be of " |
| 271 "type Instance."); |
| 272 } |
| 273 |
| 274 |
| 187 TEST_CASE(BooleanValues) { | 275 TEST_CASE(BooleanValues) { |
| 188 Dart_Handle str = Dart_NewString("test"); | 276 Dart_Handle str = Dart_NewString("test"); |
| 189 EXPECT(!Dart_IsBoolean(str)); | 277 EXPECT(!Dart_IsBoolean(str)); |
| 190 | 278 |
| 191 bool value = false; | 279 bool value = false; |
| 192 Dart_Handle result = Dart_BooleanValue(str, &value); | 280 Dart_Handle result = Dart_BooleanValue(str, &value); |
| 193 EXPECT(Dart_IsError(result)); | 281 EXPECT(Dart_IsError(result)); |
| 194 | 282 |
| 195 Dart_Handle val1 = Dart_NewBoolean(true); | 283 Dart_Handle val1 = Dart_NewBoolean(true); |
| 196 EXPECT(Dart_IsBoolean(val1)); | 284 EXPECT(Dart_IsBoolean(val1)); |
| (...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 2262 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| 2175 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); | 2263 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); |
| 2176 Dart_ShutdownIsolate(); | 2264 Dart_ShutdownIsolate(); |
| 2177 } | 2265 } |
| 2178 | 2266 |
| 2179 | 2267 |
| 2180 // Only ia32 and x64 can run execution tests. | 2268 // Only ia32 and x64 can run execution tests. |
| 2181 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 2269 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 2182 | 2270 |
| 2183 | 2271 |
| 2272 TEST_CASE(ClassBasics) { |
| 2273 const char* kScriptChars = |
| 2274 "class MyClass {\n" |
| 2275 "}\n" |
| 2276 "class MyDefault {\n" |
| 2277 "}\n" |
| 2278 "interface MyInterface default MyDefault {\n" |
| 2279 "}\n"; |
| 2280 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2281 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("MyClass")); |
| 2282 Dart_Handle interface = Dart_GetClass(lib, Dart_NewString("MyInterface")); |
| 2283 |
| 2284 // Test Dart_IsClass and Dart_IsInterface. |
| 2285 EXPECT(Dart_IsClass(cls)); |
| 2286 EXPECT(!Dart_IsClass(interface)); |
| 2287 EXPECT(!Dart_IsClass(Dart_True())); |
| 2288 |
| 2289 EXPECT(!Dart_IsInterface(cls)); |
| 2290 EXPECT(Dart_IsInterface(interface)); |
| 2291 EXPECT(!Dart_IsInterface(Dart_True())); |
| 2292 |
| 2293 EXPECT(!Dart_IsInterface(cls)); |
| 2294 EXPECT(Dart_IsInterface(interface)); |
| 2295 EXPECT(!Dart_IsInterface(Dart_True())); |
| 2296 |
| 2297 // Test Dart_ClassName |
| 2298 Dart_Handle cls_name = Dart_ClassName(cls); |
| 2299 EXPECT_VALID(cls_name); |
| 2300 const char* cls_name_cstr = ""; |
| 2301 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 2302 EXPECT_STREQ("MyClass", cls_name_cstr); |
| 2303 |
| 2304 cls_name = Dart_ClassName(interface); |
| 2305 EXPECT_VALID(cls_name); |
| 2306 cls_name_cstr = ""; |
| 2307 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
| 2308 EXPECT_STREQ("MyInterface", cls_name_cstr); |
| 2309 |
| 2310 EXPECT_ERROR(Dart_ClassName(Dart_True()), |
| 2311 "Dart_ClassName expects argument 'clazz' to be of type Class."); |
| 2312 EXPECT_ERROR(Dart_ClassName(Dart_NewApiError("MyError")), "MyError"); |
| 2313 |
| 2314 // Test Dart_ClassGetLibrary |
| 2315 Dart_Handle cls_lib = Dart_ClassGetLibrary(cls); |
| 2316 Dart_Handle cls_lib_name = Dart_LibraryName(cls_lib); |
| 2317 EXPECT_VALID(cls_lib_name); |
| 2318 const char* cls_lib_name_cstr = ""; |
| 2319 EXPECT_VALID(Dart_StringToCString(cls_lib_name, &cls_lib_name_cstr)); |
| 2320 EXPECT_STREQ(TestCase::url(), cls_lib_name_cstr); |
| 2321 |
| 2322 EXPECT_ERROR( |
| 2323 Dart_ClassGetLibrary(Dart_True()), |
| 2324 "Dart_ClassGetLibrary expects argument 'clazz' to be of type Class."); |
| 2325 EXPECT_ERROR(Dart_ClassGetLibrary(Dart_NewApiError("MyError")), "MyError"); |
| 2326 |
| 2327 |
| 2328 Dart_Handle dflt = Dart_ClassGetDefault(interface); |
| 2329 EXPECT_VALID(dflt); |
| 2330 EXPECT(Dart_IsClass(dflt)); |
| 2331 Dart_Handle dflt_name = Dart_ClassName(dflt); |
| 2332 EXPECT_VALID(dflt_name); |
| 2333 const char* dflt_name_cstr = ""; |
| 2334 EXPECT_VALID(Dart_StringToCString(dflt_name, &dflt_name_cstr)); |
| 2335 EXPECT_STREQ("MyDefault", dflt_name_cstr); |
| 2336 |
| 2337 EXPECT(Dart_IsNull(Dart_ClassGetDefault(cls))); |
| 2338 EXPECT_ERROR( |
| 2339 Dart_ClassGetDefault(Dart_True()), |
| 2340 "Dart_ClassGetDefault expects argument 'clazz' to be of type Class."); |
| 2341 EXPECT_ERROR(Dart_ClassGetDefault(Dart_NewApiError("MyError")), "MyError"); |
| 2342 } |
| 2343 |
| 2344 |
| 2345 #define CHECK_INTERFACE(handle, name) \ |
| 2346 { \ |
| 2347 Dart_Handle tmp = (handle); \ |
| 2348 EXPECT_VALID(tmp); \ |
| 2349 EXPECT(Dart_IsInterface(tmp)); \ |
| 2350 Dart_Handle intf_name = Dart_ClassName(tmp); \ |
| 2351 EXPECT_VALID(intf_name); \ |
| 2352 const char* intf_name_cstr = ""; \ |
| 2353 EXPECT_VALID(Dart_StringToCString(intf_name, &intf_name_cstr)); \ |
| 2354 EXPECT_STREQ((name), intf_name_cstr); \ |
| 2355 } |
| 2356 |
| 2357 |
| 2358 TEST_CASE(ClassGetInterfaces) { |
| 2359 const char* kScriptChars = |
| 2360 "class MyClass0 {\n" |
| 2361 "}\n" |
| 2362 "\n" |
| 2363 "class MyClass1 implements MyInterface1 {\n" |
| 2364 "}\n" |
| 2365 "\n" |
| 2366 "class MyClass2 implements MyInterface0, MyInterface1 {\n" |
| 2367 "}\n" |
| 2368 "\n" |
| 2369 "interface MyInterface0 {\n" |
| 2370 "}\n" |
| 2371 "\n" |
| 2372 "interface MyInterface1 extends MyInterface0 {\n" |
| 2373 "}\n"; |
| 2374 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2375 |
| 2376 Dart_Handle cls0 = Dart_GetClass(lib, Dart_NewString("MyClass0")); |
| 2377 Dart_Handle cls1 = Dart_GetClass(lib, Dart_NewString("MyClass1")); |
| 2378 Dart_Handle cls2 = Dart_GetClass(lib, Dart_NewString("MyClass2")); |
| 2379 Dart_Handle intf0 = Dart_GetClass(lib, Dart_NewString("MyInterface0")); |
| 2380 Dart_Handle intf1 = Dart_GetClass(lib, Dart_NewString("MyInterface1")); |
| 2381 |
| 2382 intptr_t len = -1; |
| 2383 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len)); |
| 2384 EXPECT_EQ(0, len); |
| 2385 |
| 2386 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0), |
| 2387 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); |
| 2388 |
| 2389 len = -1; |
| 2390 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len)); |
| 2391 EXPECT_EQ(1, len); |
| 2392 CHECK_INTERFACE(Dart_ClassGetInterfaceAt(cls1, 0), "MyInterface1"); |
| 2393 |
| 2394 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, -1), |
| 2395 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); |
| 2396 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, 1), |
| 2397 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); |
| 2398 |
| 2399 len = -1; |
| 2400 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls2, &len)); |
| 2401 EXPECT_EQ(2, len); |
| 2402 |
| 2403 // TODO(turnidge): The test relies on the ordering here. Sort this. |
| 2404 CHECK_INTERFACE(Dart_ClassGetInterfaceAt(cls2, 0), "MyInterface0"); |
| 2405 CHECK_INTERFACE(Dart_ClassGetInterfaceAt(cls2, 1), "MyInterface1"); |
| 2406 |
| 2407 len = -1; |
| 2408 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf0, &len)); |
| 2409 EXPECT_EQ(0, len); |
| 2410 |
| 2411 len = -1; |
| 2412 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf1, &len)); |
| 2413 EXPECT_EQ(1, len); |
| 2414 CHECK_INTERFACE(Dart_ClassGetInterfaceAt(intf1, 0), "MyInterface0"); |
| 2415 |
| 2416 // Error cases. |
| 2417 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len), |
| 2418 "Dart_ClassGetInterfaceCount expects argument 'clazz' to be of " |
| 2419 "type Class."); |
| 2420 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len), |
| 2421 "MyError"); |
| 2422 } |
| 2423 |
| 2424 |
| 2184 static void TestFieldOk(Dart_Handle container, | 2425 static void TestFieldOk(Dart_Handle container, |
| 2185 Dart_Handle name, | 2426 Dart_Handle name, |
| 2186 bool final, | 2427 bool final, |
| 2187 const char* initial_value) { | 2428 const char* initial_value) { |
| 2188 Dart_Handle result; | 2429 Dart_Handle result; |
| 2189 | 2430 |
| 2190 // Make sure we have the right initial value. | 2431 // Make sure we have the right initial value. |
| 2191 result = Dart_GetField(container, name); | 2432 result = Dart_GetField(container, name); |
| 2192 EXPECT_VALID(result); | 2433 EXPECT_VALID(result); |
| 2193 const char* value = ""; | 2434 const char* value = ""; |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3348 | 3589 |
| 3349 // Pass an error handle as the function name. The error is propagated. | 3590 // Pass an error handle as the function name. The error is propagated. |
| 3350 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args); | 3591 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args); |
| 3351 EXPECT(Dart_IsError(result)); | 3592 EXPECT(Dart_IsError(result)); |
| 3352 EXPECT_STREQ("myerror", Dart_GetError(result)); | 3593 EXPECT_STREQ("myerror", Dart_GetError(result)); |
| 3353 | 3594 |
| 3354 // Pass a non-instance handle as a parameter.. | 3595 // Pass a non-instance handle as a parameter.. |
| 3355 args[0] = lib; | 3596 args[0] = lib; |
| 3356 result = Dart_Invoke(lib, func_name, 1, args); | 3597 result = Dart_Invoke(lib, func_name, 1, args); |
| 3357 EXPECT(Dart_IsError(result)); | 3598 EXPECT(Dart_IsError(result)); |
| 3358 EXPECT_STREQ("Dart_Invoke expects argument 0 to be an instance of Object.", | 3599 EXPECT_STREQ("Dart_Invoke expects arguments[0] to be an Instance handle.", |
| 3359 Dart_GetError(result)); | 3600 Dart_GetError(result)); |
| 3360 | 3601 |
| 3361 // Pass an error handle as a parameter. The error is propagated. | 3602 // Pass an error handle as a parameter. The error is propagated. |
| 3362 args[0] = Api::NewError("myerror"); | 3603 args[0] = Api::NewError("myerror"); |
| 3363 result = Dart_Invoke(lib, func_name, 1, args); | 3604 result = Dart_Invoke(lib, func_name, 1, args); |
| 3364 EXPECT(Dart_IsError(result)); | 3605 EXPECT(Dart_IsError(result)); |
| 3365 EXPECT_STREQ("myerror", Dart_GetError(result)); | 3606 EXPECT_STREQ("myerror", Dart_GetError(result)); |
| 3366 } | 3607 } |
| 3367 | 3608 |
| 3368 | 3609 |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4037 | 4278 |
| 4038 result = Dart_LibraryUrl(lib); | 4279 result = Dart_LibraryUrl(lib); |
| 4039 EXPECT_VALID(result); | 4280 EXPECT_VALID(result); |
| 4040 EXPECT(Dart_IsString(result)); | 4281 EXPECT(Dart_IsString(result)); |
| 4041 const char* cstr = NULL; | 4282 const char* cstr = NULL; |
| 4042 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 4283 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
| 4043 EXPECT_STREQ("library1_url", cstr); | 4284 EXPECT_STREQ("library1_url", cstr); |
| 4044 } | 4285 } |
| 4045 | 4286 |
| 4046 | 4287 |
| 4288 TEST_CASE(LibraryGetClassNames) { |
| 4289 const char* kLibraryChars = |
| 4290 "#library('library_name');\n" |
| 4291 "\n" |
| 4292 "class A {}\n" |
| 4293 "class B {}\n" |
| 4294 "class D {}\n" |
| 4295 "interface C {}\n" |
| 4296 "interface E {}\n" |
| 4297 "\n" |
| 4298 "_compare(String a, String b) => a.compareTo(b);\n" |
| 4299 "sort(list) => list.sort(_compare);\n"; |
| 4300 |
| 4301 Dart_Handle url = Dart_NewString("library_url"); |
| 4302 Dart_Handle source = Dart_NewString(kLibraryChars); |
| 4303 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 4304 EXPECT_VALID(lib); |
| 4305 |
| 4306 Dart_Handle list = Dart_LibraryGetClassNames(lib); |
| 4307 EXPECT_VALID(list); |
| 4308 EXPECT(Dart_IsList(list)); |
| 4309 |
| 4310 // Sort the list. |
| 4311 const int kNumArgs = 1; |
| 4312 Dart_Handle args[1]; |
| 4313 args[0] = list; |
| 4314 EXPECT_VALID(Dart_Invoke(lib, Dart_NewString("sort"), kNumArgs, args)); |
| 4315 |
| 4316 Dart_Handle list_string = Dart_ToString(list); |
| 4317 EXPECT_VALID(list_string); |
| 4318 const char* list_cstr = ""; |
| 4319 EXPECT_VALID(Dart_StringToCString(list_string, &list_cstr)); |
| 4320 EXPECT_STREQ("[A, B, C, D, E]", list_cstr); |
| 4321 } |
| 4322 |
| 4323 |
| 4047 TEST_CASE(LibraryImportLibrary) { | 4324 TEST_CASE(LibraryImportLibrary) { |
| 4048 const char* kLibrary1Chars = | 4325 const char* kLibrary1Chars = |
| 4049 "#library('library1_name');"; | 4326 "#library('library1_name');"; |
| 4050 const char* kLibrary2Chars = | 4327 const char* kLibrary2Chars = |
| 4051 "#library('library2_name');"; | 4328 "#library('library2_name');"; |
| 4052 Dart_Handle error = Dart_Error("incoming error"); | 4329 Dart_Handle error = Dart_Error("incoming error"); |
| 4053 Dart_Handle result; | 4330 Dart_Handle result; |
| 4054 | 4331 |
| 4055 Dart_Handle url = Dart_NewString("library1_url"); | 4332 Dart_Handle url = Dart_NewString("library1_url"); |
| 4056 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 4333 Dart_Handle source = Dart_NewString(kLibrary1Chars); |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4891 // We should have received the expected number of interrupts. | 5168 // We should have received the expected number of interrupts. |
| 4892 EXPECT_EQ(kInterruptCount, interrupt_count); | 5169 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 4893 | 5170 |
| 4894 // Give the spawned thread enough time to properly exit. | 5171 // Give the spawned thread enough time to properly exit. |
| 4895 Isolate::SetInterruptCallback(saved); | 5172 Isolate::SetInterruptCallback(saved); |
| 4896 } | 5173 } |
| 4897 | 5174 |
| 4898 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 5175 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 4899 | 5176 |
| 4900 } // namespace dart | 5177 } // namespace dart |
| OLD | NEW |