Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 8382017: Add Dart_GetNativeArgumentCount() and a test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {\n"
1317 " int method1(int i, int j) native \"Name_Does_Not_Matter\";"
siva 2011/10/24 22:58:43 The new style now seems to be use ' e.g: 'Name_Doe
turnidge 2011/10/24 23:44:19 Done.
1318 "}\n"
1319 "class Test {\n"
1320 " static testMain() {\n"
1321 " MyObject obj = new MyObject();\n"
1322 " return obj.method1(77, 125);\n"
1323 " }\n"
1324 "}\n";
siva 2011/10/24 22:58:43 I believe in some of the newer tests we also remov
turnidge 2011/10/24 23:44:19 Done.
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
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
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698