| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/json.h" | 10 #include "platform/json.h" |
| (...skipping 4446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4457 | 4457 |
| 4458 int64_t value = 0; | 4458 int64_t value = 0; |
| 4459 result = Dart_IntegerToInt64(result, &value); | 4459 result = Dart_IntegerToInt64(result, &value); |
| 4460 EXPECT_VALID(result); | 4460 EXPECT_VALID(result); |
| 4461 EXPECT_EQ(3, value); | 4461 EXPECT_EQ(3, value); |
| 4462 } | 4462 } |
| 4463 | 4463 |
| 4464 | 4464 |
| 4465 TEST_CASE(GetType) { | 4465 TEST_CASE(GetType) { |
| 4466 const char* kScriptChars = | 4466 const char* kScriptChars = |
| 4467 "library testlib;\n" |
| 4467 "class Class {\n" | 4468 "class Class {\n" |
| 4468 " static var name = 'Class';\n" | 4469 " static var name = 'Class';\n" |
| 4469 "}\n" | 4470 "}\n" |
| 4470 "\n" | 4471 "\n" |
| 4471 "class _Class {\n" | 4472 "class _Class {\n" |
| 4472 " static var name = '_Class';\n" | 4473 " static var name = '_Class';\n" |
| 4473 "}\n"; | 4474 "}\n"; |
| 4474 | 4475 |
| 4475 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 4476 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 4476 | 4477 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4488 EXPECT_VALID(type); | 4489 EXPECT_VALID(type); |
| 4489 name = Dart_GetField(type, NewString("name")); | 4490 name = Dart_GetField(type, NewString("name")); |
| 4490 EXPECT_VALID(name); | 4491 EXPECT_VALID(name); |
| 4491 name_cstr = ""; | 4492 name_cstr = ""; |
| 4492 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); | 4493 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); |
| 4493 EXPECT_STREQ("_Class", name_cstr); | 4494 EXPECT_STREQ("_Class", name_cstr); |
| 4494 | 4495 |
| 4495 // Lookup a class that does not exist. | 4496 // Lookup a class that does not exist. |
| 4496 type = Dart_GetType(lib, NewString("DoesNotExist"), 0, NULL); | 4497 type = Dart_GetType(lib, NewString("DoesNotExist"), 0, NULL); |
| 4497 EXPECT(Dart_IsError(type)); | 4498 EXPECT(Dart_IsError(type)); |
| 4498 EXPECT_STREQ("Type 'DoesNotExist' not found in library 'dart:test-lib'.", | 4499 EXPECT_STREQ("Type 'DoesNotExist' not found in library 'testlib'.", |
| 4499 Dart_GetError(type)); | 4500 Dart_GetError(type)); |
| 4500 | 4501 |
| 4501 // Lookup a class from an error library. The error propagates. | 4502 // Lookup a class from an error library. The error propagates. |
| 4502 type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL); | 4503 type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL); |
| 4503 EXPECT(Dart_IsError(type)); | 4504 EXPECT(Dart_IsError(type)); |
| 4504 EXPECT_STREQ("myerror", Dart_GetError(type)); | 4505 EXPECT_STREQ("myerror", Dart_GetError(type)); |
| 4505 | 4506 |
| 4506 // Lookup a type using an error class name. The error propagates. | 4507 // Lookup a type using an error class name. The error propagates. |
| 4507 type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL); | 4508 type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL); |
| 4508 EXPECT(Dart_IsError(type)); | 4509 EXPECT(Dart_IsError(type)); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4647 result = Dart_LoadScript(url, source, 0, 0); | 4648 result = Dart_LoadScript(url, source, 0, 0); |
| 4648 EXPECT(Dart_IsError(result)); | 4649 EXPECT(Dart_IsError(result)); |
| 4649 EXPECT_STREQ("Dart_LoadScript: " | 4650 EXPECT_STREQ("Dart_LoadScript: " |
| 4650 "A script has already been loaded from 'dart:test-lib'.", | 4651 "A script has already been loaded from 'dart:test-lib'.", |
| 4651 Dart_GetError(result)); | 4652 Dart_GetError(result)); |
| 4652 } | 4653 } |
| 4653 | 4654 |
| 4654 | 4655 |
| 4655 TEST_CASE(RootLibrary) { | 4656 TEST_CASE(RootLibrary) { |
| 4656 const char* kScriptChars = | 4657 const char* kScriptChars = |
| 4658 "library testlib;" |
| 4657 "main() {" | 4659 "main() {" |
| 4658 " return 12345;" | 4660 " return 12345;" |
| 4659 "}"; | 4661 "}"; |
| 4660 | 4662 |
| 4661 Dart_Handle root_lib = Dart_RootLibrary(); | 4663 Dart_Handle root_lib = Dart_RootLibrary(); |
| 4662 EXPECT_VALID(root_lib); | 4664 EXPECT_VALID(root_lib); |
| 4663 EXPECT(Dart_IsNull(root_lib)); | 4665 EXPECT(Dart_IsNull(root_lib)); |
| 4664 | 4666 |
| 4665 // Load a script. | 4667 // Load a script. |
| 4666 Dart_Handle url = NewString(TestCase::url()); | 4668 Dart_Handle url = NewString(TestCase::url()); |
| 4667 Dart_Handle source = NewString(kScriptChars); | 4669 Dart_Handle source = NewString(kScriptChars); |
| 4668 EXPECT_VALID(Dart_LoadScript(url, source, 0, 0)); | 4670 EXPECT_VALID(Dart_LoadScript(url, source, 0, 0)); |
| 4669 | 4671 |
| 4670 root_lib = Dart_RootLibrary(); | 4672 root_lib = Dart_RootLibrary(); |
| 4671 Dart_Handle lib_name = Dart_LibraryName(root_lib); | 4673 Dart_Handle lib_name = Dart_LibraryName(root_lib); |
| 4672 EXPECT_VALID(lib_name); | 4674 EXPECT_VALID(lib_name); |
| 4673 EXPECT(!Dart_IsNull(root_lib)); | 4675 EXPECT(!Dart_IsNull(root_lib)); |
| 4674 const char* name_cstr = ""; | 4676 const char* name_cstr = ""; |
| 4675 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 4677 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
| 4676 EXPECT_STREQ(TestCase::url(), name_cstr); | 4678 EXPECT_STREQ("testlib", name_cstr); |
| 4679 |
| 4680 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); |
| 4681 EXPECT_VALID(lib_uri); |
| 4682 EXPECT(!Dart_IsNull(lib_uri)); |
| 4683 const char* uri_cstr = ""; |
| 4684 EXPECT_VALID(Dart_StringToCString(lib_uri, &uri_cstr)); |
| 4685 EXPECT_STREQ(TestCase::url(), uri_cstr); |
| 4677 } | 4686 } |
| 4678 | 4687 |
| 4679 | 4688 |
| 4680 static int index = 0; | 4689 static int index = 0; |
| 4681 | 4690 |
| 4682 | 4691 |
| 4683 static Dart_Handle import_library_handler(Dart_LibraryTag tag, | 4692 static Dart_Handle import_library_handler(Dart_LibraryTag tag, |
| 4684 Dart_Handle library, | 4693 Dart_Handle library, |
| 4685 Dart_Handle url) { | 4694 Dart_Handle url) { |
| 4686 if (tag == Dart_kCanonicalizeUrl) { | 4695 if (tag == Dart_kCanonicalizeUrl) { |
| (...skipping 2556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7243 NewString("main"), | 7252 NewString("main"), |
| 7244 0, | 7253 0, |
| 7245 NULL); | 7254 NULL); |
| 7246 int64_t value = 0; | 7255 int64_t value = 0; |
| 7247 result = Dart_IntegerToInt64(result, &value); | 7256 result = Dart_IntegerToInt64(result, &value); |
| 7248 EXPECT_VALID(result); | 7257 EXPECT_VALID(result); |
| 7249 EXPECT_EQ(8, value); | 7258 EXPECT_EQ(8, value); |
| 7250 } | 7259 } |
| 7251 | 7260 |
| 7252 } // namespace dart | 7261 } // namespace dart |
| OLD | NEW |