| 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 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 result = Dart_IntegerValue(obj); | 1291 result = Dart_IntegerValue(obj); |
| 1292 EXPECT_EQ(5, Dart_GetResultAsCInt64(result)); | 1292 EXPECT_EQ(5, Dart_GetResultAsCInt64(result)); |
| 1293 | 1293 |
| 1294 Dart_ExitScope(); // Exit the Dart API scope. | 1294 Dart_ExitScope(); // Exit the Dart API scope. |
| 1295 EXPECT_EQ(size, state->ZoneSizeInBytes()); | 1295 EXPECT_EQ(size, state->ZoneSizeInBytes()); |
| 1296 } | 1296 } |
| 1297 Dart_ShutdownIsolate(); | 1297 Dart_ShutdownIsolate(); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 | 1300 |
| 1301 void NativeArgumentCounter(Dart_NativeArguments args) { |
| 1302 Dart_EnterScope(); |
| 1303 int count = Dart_GetNativeArgumentCount(args); |
| 1304 Dart_SetReturnValue(args, Dart_NewInteger(count)); |
| 1305 Dart_ExitScope(); |
| 1306 } |
| 1307 |
| 1308 |
| 1309 static Dart_NativeFunction gnac_lookup(Dart_Handle name, int argument_count) { |
| 1310 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); |
| 1311 } |
| 1312 |
| 1313 |
| 1314 UNIT_TEST_CASE(GetNativeArgumentCount) { |
| 1315 const char* kScriptChars = |
| 1316 "class MyObject {" |
| 1317 " int method1(int i, int j) native 'Name_Does_Not_Matter';" |
| 1318 "}" |
| 1319 "class Test {" |
| 1320 " static testMain() {" |
| 1321 " MyObject obj = new MyObject();" |
| 1322 " return obj.method1(77, 125);" |
| 1323 " }" |
| 1324 "}"; |
| 1325 |
| 1326 Dart_CreateIsolate(NULL, NULL); |
| 1327 { |
| 1328 Dart_EnterScope(); |
| 1329 Dart_Handle lib = TestCase::LoadTestScript( |
| 1330 kScriptChars, |
| 1331 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup)); |
| 1332 |
| 1333 Dart_Result result = Dart_InvokeStatic(lib, |
| 1334 Dart_NewString("Test"), |
| 1335 Dart_NewString("testMain"), |
| 1336 0, |
| 1337 NULL); |
| 1338 EXPECT(Dart_IsValidResult(result)); |
| 1339 Dart_Handle result_obj = Dart_GetResult(result); |
| 1340 EXPECT(Dart_IsInteger(result_obj)); |
| 1341 |
| 1342 result = Dart_IntegerValue(result_obj); |
| 1343 EXPECT(Dart_IsValidResult(result)); |
| 1344 int64_t value = Dart_GetResultAsCInt64(result); |
| 1345 EXPECT_EQ(3, value); |
| 1346 |
| 1347 Dart_ExitScope(); |
| 1348 } |
| 1349 Dart_ShutdownIsolate(); |
| 1350 } |
| 1351 |
| 1352 |
| 1301 UNIT_TEST_CASE(InstanceOf) { | 1353 UNIT_TEST_CASE(InstanceOf) { |
| 1302 const char* kScriptChars = | 1354 const char* kScriptChars = |
| 1303 "class OtherClass {\n" | 1355 "class OtherClass {\n" |
| 1304 " static returnNull() { return null; }\n" | 1356 " static returnNull() { return null; }\n" |
| 1305 "}\n" | 1357 "}\n" |
| 1306 "class InstanceOfTest {\n" | 1358 "class InstanceOfTest {\n" |
| 1307 " InstanceOfTest() {}\n" | 1359 " InstanceOfTest() {}\n" |
| 1308 " static InstanceOfTest testMain() {\n" | 1360 " static InstanceOfTest testMain() {\n" |
| 1309 " return new InstanceOfTest();\n" | 1361 " return new InstanceOfTest();\n" |
| 1310 " }\n" | 1362 " }\n" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 NULL); | 1739 NULL); |
| 1688 assert(Dart_IsValidResult(result)); | 1740 assert(Dart_IsValidResult(result)); |
| 1689 | 1741 |
| 1690 Dart_ExitScope(); // Exit the Dart API scope. | 1742 Dart_ExitScope(); // Exit the Dart API scope. |
| 1691 } | 1743 } |
| 1692 Dart_ShutdownIsolate(); | 1744 Dart_ShutdownIsolate(); |
| 1693 } | 1745 } |
| 1694 #endif // TARGET_ARCH_IA32. | 1746 #endif // TARGET_ARCH_IA32. |
| 1695 | 1747 |
| 1696 } // namespace dart | 1748 } // namespace dart |
| OLD | NEW |