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

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

Issue 8585049: Add an interface for retrieving the value of unsigned 64-bit integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years 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
« runtime/vm/dart_api_impl.cc ('K') | « 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 EXPECT_VALID(result); 294 EXPECT_VALID(result);
295 EXPECT(fits); 295 EXPECT(fits);
296 296
297 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); 297 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3);
298 EXPECT(Dart_IsInteger(val3)); 298 EXPECT(Dart_IsInteger(val3));
299 result = Dart_IntegerFitsIntoInt64(val3, &fits); 299 result = Dart_IntegerFitsIntoInt64(val3, &fits);
300 EXPECT_VALID(result); 300 EXPECT_VALID(result);
301 EXPECT(!fits); 301 EXPECT(!fits);
302 302
303 int64_t out = 0; 303 int64_t out = 0;
304 result = Dart_IntegerValue(val1, &out); 304 result = Dart_IntegerToInt64(val1, &out);
305 EXPECT_VALID(result); 305 EXPECT_VALID(result);
306 EXPECT_EQ(kIntegerVal1, out); 306 EXPECT_EQ(kIntegerVal1, out);
307 307
308 result = Dart_IntegerValue(val2, &out); 308 result = Dart_IntegerToInt64(val2, &out);
309 EXPECT_VALID(result); 309 EXPECT_VALID(result);
310 EXPECT_EQ(kIntegerVal2, out); 310 EXPECT_EQ(kIntegerVal2, out);
311 311
312 const char* chars = NULL; 312 const char* chars = NULL;
313 result = Dart_IntegerValueHexCString(val3, &chars); 313 result = Dart_IntegerToHexCString(val3, &chars);
314 EXPECT_VALID(result); 314 EXPECT_VALID(result);
315 EXPECT(!strcmp(kIntegerVal3, chars)); 315 EXPECT(!strcmp(kIntegerVal3, chars));
316 } 316 }
317 317
318 318
319 UNIT_TEST_CASE(IntegerFitsInto) {
turnidge 2011/12/08 18:26:25 Could you make this test check 4 values for each t
cshapiro 2011/12/08 22:50:50 Done.
320 TestIsolateScope __test_isolate__;
321
322 const int64_t kLongLongMax = DART_INT64_C(0x7FFFFFFFFFFFFFFF);
323 const int64_t kLongLongMin = -kLongLongMax - 1;
324
325 const char* kUnsignedLongLongMax = "0xFFFFFFFFFFFFFFFF";
326 const uint64_t kUnsignedLongLongMin = DART_UINT64_C(0x0);
327
328 Dart_Handle long_long_min = Dart_NewInteger(kLongLongMin);
329 EXPECT(Dart_IsInteger(long_long_min));
330 bool fits = false;
331 Dart_Handle result = Dart_IntegerFitsIntoInt64(long_long_min, &fits);
332 EXPECT_VALID(result);
333 EXPECT(fits);
334 fits = true;
335 result = Dart_IntegerFitsIntoUint64(long_long_min, &fits);
336 EXPECT_VALID(result);
337 EXPECT(!fits);
338
339 Dart_Handle zero = Dart_NewInteger(kUnsignedLongLongMin);
340 EXPECT(Dart_IsInteger(zero));
341 fits = false;
342 result = Dart_IntegerFitsIntoInt64(zero, &fits);
343 EXPECT_VALID(result);
344 EXPECT(fits);
345 fits = false;
346 result = Dart_IntegerFitsIntoUint64(zero, &fits);
347 EXPECT_VALID(result);
348 EXPECT(fits);
349
350 Dart_Handle long_long_max = Dart_NewInteger(kLongLongMax);
351 EXPECT(Dart_IsInteger(long_long_max));
352 fits = false;
353 result = Dart_IntegerFitsIntoInt64(long_long_max, &fits);
354 EXPECT_VALID(result);
355 EXPECT(fits);
356 fits = false;
357 result = Dart_IntegerFitsIntoUint64(long_long_max, &fits);
358 EXPECT_VALID(result);
359 EXPECT(fits);
360
361 Dart_Handle unsigned_long_long_max =
362 Dart_NewIntegerFromHexCString(kUnsignedLongLongMax);
363 EXPECT(Dart_IsInteger(unsigned_long_long_max));
364 fits = false;
365 result = Dart_IntegerFitsIntoInt64(unsigned_long_long_max, &fits);
366 EXPECT_VALID(result);
367 EXPECT(!fits);
368 fits = false;
369 result = Dart_IntegerFitsIntoUint64(unsigned_long_long_max, &fits);
370 EXPECT_VALID(result);
371 EXPECT(fits);
372 }
373
374
319 UNIT_TEST_CASE(ArrayValues) { 375 UNIT_TEST_CASE(ArrayValues) {
320 TestIsolateScope __test_isolate__; 376 TestIsolateScope __test_isolate__;
321 377
322 const int kArrayLength = 10; 378 const int kArrayLength = 10;
323 Dart_Handle str = Dart_NewString("test"); 379 Dart_Handle str = Dart_NewString("test");
324 EXPECT(!Dart_IsList(str)); 380 EXPECT(!Dart_IsList(str));
325 Dart_Handle val = Dart_NewList(kArrayLength); 381 Dart_Handle val = Dart_NewList(kArrayLength);
326 EXPECT(Dart_IsList(val)); 382 EXPECT(Dart_IsList(val));
327 intptr_t len = 0; 383 intptr_t len = 0;
328 Dart_Handle result = Dart_ListLength(val, &len); 384 Dart_Handle result = Dart_ListLength(val, &len);
(...skipping 11 matching lines...) Expand all
340 EXPECT(Dart_IsError(result)); 396 EXPECT(Dart_IsError(result));
341 397
342 for (int i = 0; i < kArrayLength; i++) { 398 for (int i = 0; i < kArrayLength; i++) {
343 result = Dart_ListSetAt(val, i, Dart_NewInteger(i)); 399 result = Dart_ListSetAt(val, i, Dart_NewInteger(i));
344 EXPECT_VALID(result); 400 EXPECT_VALID(result);
345 } 401 }
346 for (int i = 0; i < kArrayLength; i++) { 402 for (int i = 0; i < kArrayLength; i++) {
347 result = Dart_ListGetAt(val, i); 403 result = Dart_ListGetAt(val, i);
348 EXPECT_VALID(result); 404 EXPECT_VALID(result);
349 int64_t value; 405 int64_t value;
350 result = Dart_IntegerValue(result, &value); 406 result = Dart_IntegerToInt64(result, &value);
351 EXPECT_VALID(result); 407 EXPECT_VALID(result);
352 EXPECT_EQ(i, value); 408 EXPECT_EQ(i, value);
353 } 409 }
354 } 410 }
355 411
356 412
357 UNIT_TEST_CASE(IsString) { 413 UNIT_TEST_CASE(IsString) {
358 TestIsolateScope __test_isolate__; 414 TestIsolateScope __test_isolate__;
359 415
360 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 416 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 intptr_t len = 0; 547 intptr_t len = 0;
492 result = Dart_ListLength(ListAccessTestObj, &len); 548 result = Dart_ListLength(ListAccessTestObj, &len);
493 EXPECT_VALID(result); 549 EXPECT_VALID(result);
494 EXPECT_EQ(3, len); 550 EXPECT_EQ(3, len);
495 551
496 // Access elements in the array. 552 // Access elements in the array.
497 int64_t value; 553 int64_t value;
498 554
499 result = Dart_ListGetAt(ListAccessTestObj, 0); 555 result = Dart_ListGetAt(ListAccessTestObj, 0);
500 EXPECT_VALID(result); 556 EXPECT_VALID(result);
501 result = Dart_IntegerValue(result, &value); 557 result = Dart_IntegerToInt64(result, &value);
502 EXPECT_VALID(result); 558 EXPECT_VALID(result);
503 EXPECT_EQ(10, value); 559 EXPECT_EQ(10, value);
504 560
505 result = Dart_ListGetAt(ListAccessTestObj, 1); 561 result = Dart_ListGetAt(ListAccessTestObj, 1);
506 EXPECT_VALID(result); 562 EXPECT_VALID(result);
507 result = Dart_IntegerValue(result, &value); 563 result = Dart_IntegerToInt64(result, &value);
508 EXPECT_VALID(result); 564 EXPECT_VALID(result);
509 EXPECT_EQ(20, value); 565 EXPECT_EQ(20, value);
510 566
511 result = Dart_ListGetAt(ListAccessTestObj, 2); 567 result = Dart_ListGetAt(ListAccessTestObj, 2);
512 EXPECT_VALID(result); 568 EXPECT_VALID(result);
513 result = Dart_IntegerValue(result, &value); 569 result = Dart_IntegerToInt64(result, &value);
514 EXPECT_VALID(result); 570 EXPECT_VALID(result);
515 EXPECT_EQ(30, value); 571 EXPECT_EQ(30, value);
516 572
517 // Set some elements in the array. 573 // Set some elements in the array.
518 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); 574 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0));
519 EXPECT_VALID(result); 575 EXPECT_VALID(result);
520 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); 576 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1));
521 EXPECT_VALID(result); 577 EXPECT_VALID(result);
522 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); 578 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2));
523 EXPECT_VALID(result); 579 EXPECT_VALID(result);
524 580
525 // Get length of array object. 581 // Get length of array object.
526 result = Dart_ListLength(ListAccessTestObj, &len); 582 result = Dart_ListLength(ListAccessTestObj, &len);
527 EXPECT_VALID(result); 583 EXPECT_VALID(result);
528 EXPECT_EQ(3, len); 584 EXPECT_EQ(3, len);
529 585
530 // Now try and access these elements in the array. 586 // Now try and access these elements in the array.
531 result = Dart_ListGetAt(ListAccessTestObj, 0); 587 result = Dart_ListGetAt(ListAccessTestObj, 0);
532 EXPECT_VALID(result); 588 EXPECT_VALID(result);
533 result = Dart_IntegerValue(result, &value); 589 result = Dart_IntegerToInt64(result, &value);
534 EXPECT_VALID(result); 590 EXPECT_VALID(result);
535 EXPECT_EQ(0, value); 591 EXPECT_EQ(0, value);
536 592
537 result = Dart_ListGetAt(ListAccessTestObj, 1); 593 result = Dart_ListGetAt(ListAccessTestObj, 1);
538 EXPECT_VALID(result); 594 EXPECT_VALID(result);
539 result = Dart_IntegerValue(result, &value); 595 result = Dart_IntegerToInt64(result, &value);
540 EXPECT_VALID(result); 596 EXPECT_VALID(result);
541 EXPECT_EQ(1, value); 597 EXPECT_EQ(1, value);
542 598
543 result = Dart_ListGetAt(ListAccessTestObj, 2); 599 result = Dart_ListGetAt(ListAccessTestObj, 2);
544 EXPECT_VALID(result); 600 EXPECT_VALID(result);
545 result = Dart_IntegerValue(result, &value); 601 result = Dart_IntegerToInt64(result, &value);
546 EXPECT_VALID(result); 602 EXPECT_VALID(result);
547 EXPECT_EQ(2, value); 603 EXPECT_EQ(2, value);
548 604
549 uint8_t native_array[3]; 605 uint8_t native_array[3];
550 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 606 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
551 EXPECT_VALID(result); 607 EXPECT_VALID(result);
552 EXPECT_EQ(0, native_array[0]); 608 EXPECT_EQ(0, native_array[0]);
553 EXPECT_EQ(1, native_array[1]); 609 EXPECT_EQ(1, native_array[1]);
554 EXPECT_EQ(2, native_array[2]); 610 EXPECT_EQ(2, native_array[2]);
555 611
556 native_array[0] = 10; 612 native_array[0] = 10;
557 native_array[1] = 20; 613 native_array[1] = 20;
558 native_array[2] = 30; 614 native_array[2] = 30;
559 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); 615 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3);
560 EXPECT_VALID(result); 616 EXPECT_VALID(result);
561 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 617 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
562 EXPECT_VALID(result); 618 EXPECT_VALID(result);
563 EXPECT_EQ(10, native_array[0]); 619 EXPECT_EQ(10, native_array[0]);
564 EXPECT_EQ(20, native_array[1]); 620 EXPECT_EQ(20, native_array[1]);
565 EXPECT_EQ(30, native_array[2]); 621 EXPECT_EQ(30, native_array[2]);
566 result = Dart_ListGetAt(ListAccessTestObj, 2); 622 result = Dart_ListGetAt(ListAccessTestObj, 2);
567 EXPECT_VALID(result); 623 EXPECT_VALID(result);
568 result = Dart_IntegerValue(result, &value); 624 result = Dart_IntegerToInt64(result, &value);
569 EXPECT_VALID(result); 625 EXPECT_VALID(result);
570 EXPECT_EQ(30, value); 626 EXPECT_EQ(30, value);
571 627
572 // Check if we get an exception when accessing beyond limit. 628 // Check if we get an exception when accessing beyond limit.
573 result = Dart_ListGetAt(ListAccessTestObj, 4); 629 result = Dart_ListGetAt(ListAccessTestObj, 4);
574 EXPECT(Dart_IsError(result)); 630 EXPECT(Dart_IsError(result));
575 } 631 }
576 } 632 }
577 633
578 #endif // TARGET_ARCH_IA32. 634 #endif // TARGET_ARCH_IA32.
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 // Now access and set various static fields of Fields class. 949 // Now access and set various static fields of Fields class.
894 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); 950 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields"));
895 EXPECT_VALID(cls); 951 EXPECT_VALID(cls);
896 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); 952 result = Dart_GetStaticField(cls, Dart_NewString("fld1"));
897 EXPECT(Dart_IsError(result)); 953 EXPECT(Dart_IsError(result));
898 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 954 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
899 EXPECT(Dart_IsError(result)); 955 EXPECT(Dart_IsError(result));
900 result = Dart_GetStaticField(cls, Dart_NewString("fld4")); 956 result = Dart_GetStaticField(cls, Dart_NewString("fld4"));
901 EXPECT_VALID(result); 957 EXPECT_VALID(result);
902 int64_t value = 0; 958 int64_t value = 0;
903 result = Dart_IntegerValue(result, &value); 959 result = Dart_IntegerToInt64(result, &value);
904 EXPECT_EQ(10, value); 960 EXPECT_EQ(10, value);
905 result = Dart_SetStaticField(cls, 961 result = Dart_SetStaticField(cls,
906 Dart_NewString("fld4"), 962 Dart_NewString("fld4"),
907 Dart_NewInteger(20)); 963 Dart_NewInteger(20));
908 EXPECT(Dart_IsError(result)); 964 EXPECT(Dart_IsError(result));
909 result = Dart_GetStaticField(cls, Dart_NewString("fld3")); 965 result = Dart_GetStaticField(cls, Dart_NewString("fld3"));
910 EXPECT_VALID(result); 966 EXPECT_VALID(result);
911 result = Dart_SetStaticField(cls, 967 result = Dart_SetStaticField(cls,
912 Dart_NewString("fld3"), 968 Dart_NewString("fld3"),
913 Dart_NewInteger(200)); 969 Dart_NewInteger(200));
914 EXPECT_VALID(result); 970 EXPECT_VALID(result);
915 result = Dart_IntegerValue(result, &value); 971 result = Dart_IntegerToInt64(result, &value);
916 EXPECT_EQ(200, value); 972 EXPECT_EQ(200, value);
917 973
918 // Now access and set various instance fields of the returned object. 974 // Now access and set various instance fields of the returned object.
919 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 975 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
920 EXPECT(Dart_IsError(result)); 976 EXPECT(Dart_IsError(result));
921 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 977 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
922 EXPECT_VALID(result); 978 EXPECT_VALID(result);
923 result = Dart_IntegerValue(result, &value); 979 result = Dart_IntegerToInt64(result, &value);
924 EXPECT_EQ(10, value); 980 EXPECT_EQ(10, value);
925 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 981 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
926 EXPECT_VALID(result); 982 EXPECT_VALID(result);
927 result = Dart_IntegerValue(result, &value); 983 result = Dart_IntegerToInt64(result, &value);
928 EXPECT_EQ(20, value); 984 EXPECT_EQ(20, value);
929 result = Dart_SetInstanceField(retobj, 985 result = Dart_SetInstanceField(retobj,
930 Dart_NewString("fld2"), 986 Dart_NewString("fld2"),
931 Dart_NewInteger(40)); 987 Dart_NewInteger(40));
932 EXPECT(Dart_IsError(result)); 988 EXPECT(Dart_IsError(result));
933 result = Dart_SetInstanceField(retobj, 989 result = Dart_SetInstanceField(retobj,
934 Dart_NewString("fld1"), 990 Dart_NewString("fld1"),
935 Dart_NewInteger(40)); 991 Dart_NewInteger(40));
936 EXPECT_VALID(result); 992 EXPECT_VALID(result);
937 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 993 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
938 EXPECT_VALID(result); 994 EXPECT_VALID(result);
939 result = Dart_IntegerValue(result, &value); 995 result = Dart_IntegerToInt64(result, &value);
940 EXPECT_EQ(40, value); 996 EXPECT_EQ(40, value);
941 } 997 }
942 } 998 }
943 999
944 1000
945 UNIT_TEST_CASE(HiddenFieldAccess) { 1001 UNIT_TEST_CASE(HiddenFieldAccess) {
946 const char* kScriptChars = 1002 const char* kScriptChars =
947 "class HiddenFields {\n" 1003 "class HiddenFields {\n"
948 " HiddenFields(int i, int j) : _fld1 = i, _fld2 = j {}\n" 1004 " HiddenFields(int i, int j) : _fld1 = i, _fld2 = j {}\n"
949 " int _fld1;\n" 1005 " int _fld1;\n"
(...skipping 25 matching lines...) Expand all
975 // Now access and set various static fields of HiddenFields class. 1031 // Now access and set various static fields of HiddenFields class.
976 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields")); 1032 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields"));
977 EXPECT_VALID(cls); 1033 EXPECT_VALID(cls);
978 result = Dart_GetStaticField(cls, Dart_NewString("_fld1")); 1034 result = Dart_GetStaticField(cls, Dart_NewString("_fld1"));
979 EXPECT(Dart_IsError(result)); 1035 EXPECT(Dart_IsError(result));
980 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); 1036 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
981 EXPECT(Dart_IsError(result)); 1037 EXPECT(Dart_IsError(result));
982 result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); 1038 result = Dart_GetStaticField(cls, Dart_NewString("_fld4"));
983 EXPECT_VALID(result); 1039 EXPECT_VALID(result);
984 int64_t value = 0; 1040 int64_t value = 0;
985 result = Dart_IntegerValue(result, &value); 1041 result = Dart_IntegerToInt64(result, &value);
986 EXPECT_EQ(10, value); 1042 EXPECT_EQ(10, value);
987 result = Dart_SetStaticField(cls, 1043 result = Dart_SetStaticField(cls,
988 Dart_NewString("_fld4"), 1044 Dart_NewString("_fld4"),
989 Dart_NewInteger(20)); 1045 Dart_NewInteger(20));
990 EXPECT(Dart_IsError(result)); 1046 EXPECT(Dart_IsError(result));
991 result = Dart_GetStaticField(cls, Dart_NewString("_fld3")); 1047 result = Dart_GetStaticField(cls, Dart_NewString("_fld3"));
992 EXPECT_VALID(result); 1048 EXPECT_VALID(result);
993 result = Dart_SetStaticField(cls, 1049 result = Dart_SetStaticField(cls,
994 Dart_NewString("_fld3"), 1050 Dart_NewString("_fld3"),
995 Dart_NewInteger(200)); 1051 Dart_NewInteger(200));
996 EXPECT_VALID(result); 1052 EXPECT_VALID(result);
997 result = Dart_IntegerValue(result, &value); 1053 result = Dart_IntegerToInt64(result, &value);
998 EXPECT_EQ(200, value); 1054 EXPECT_EQ(200, value);
999 1055
1000 // Now access and set various instance fields of the returned object. 1056 // Now access and set various instance fields of the returned object.
1001 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); 1057 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
1002 EXPECT(Dart_IsError(result)); 1058 EXPECT(Dart_IsError(result));
1003 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); 1059 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1004 EXPECT_VALID(result); 1060 EXPECT_VALID(result);
1005 result = Dart_IntegerValue(result, &value); 1061 result = Dart_IntegerToInt64(result, &value);
1006 EXPECT_EQ(10, value); 1062 EXPECT_EQ(10, value);
1007 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2")); 1063 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2"));
1008 EXPECT_VALID(result); 1064 EXPECT_VALID(result);
1009 result = Dart_IntegerValue(result, &value); 1065 result = Dart_IntegerToInt64(result, &value);
1010 EXPECT_EQ(20, value); 1066 EXPECT_EQ(20, value);
1011 result = Dart_SetInstanceField(retobj, 1067 result = Dart_SetInstanceField(retobj,
1012 Dart_NewString("_fld2"), 1068 Dart_NewString("_fld2"),
1013 Dart_NewInteger(40)); 1069 Dart_NewInteger(40));
1014 EXPECT(Dart_IsError(result)); 1070 EXPECT(Dart_IsError(result));
1015 result = Dart_SetInstanceField(retobj, 1071 result = Dart_SetInstanceField(retobj,
1016 Dart_NewString("_fld1"), 1072 Dart_NewString("_fld1"),
1017 Dart_NewInteger(40)); 1073 Dart_NewInteger(40));
1018 EXPECT_VALID(result); 1074 EXPECT_VALID(result);
1019 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); 1075 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1020 EXPECT_VALID(result); 1076 EXPECT_VALID(result);
1021 result = Dart_IntegerValue(result, &value); 1077 result = Dart_IntegerToInt64(result, &value);
1022 EXPECT_EQ(40, value); 1078 EXPECT_EQ(40, value);
1023 } 1079 }
1024 } 1080 }
1025 1081
1026 1082
1027 void NativeFieldLookup(Dart_NativeArguments args) { 1083 void NativeFieldLookup(Dart_NativeArguments args) {
1028 UNREACHABLE(); 1084 UNREACHABLE();
1029 } 1085 }
1030 1086
1031 1087
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1274 }
1219 1275
1220 1276
1221 static void TestNativeFields(Dart_Handle retobj) { 1277 static void TestNativeFields(Dart_Handle retobj) {
1222 // Access and set various instance fields of the object. 1278 // Access and set various instance fields of the object.
1223 Dart_Handle result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 1279 Dart_Handle result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1224 EXPECT(Dart_IsError(result)); 1280 EXPECT(Dart_IsError(result));
1225 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 1281 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1226 EXPECT_VALID(result); 1282 EXPECT_VALID(result);
1227 int64_t value = 0; 1283 int64_t value = 0;
1228 result = Dart_IntegerValue(result, &value); 1284 result = Dart_IntegerToInt64(result, &value);
1229 EXPECT_EQ(10, value); 1285 EXPECT_EQ(10, value);
1230 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 1286 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1231 EXPECT_VALID(result); 1287 EXPECT_VALID(result);
1232 result = Dart_IntegerValue(result, &value); 1288 result = Dart_IntegerToInt64(result, &value);
1233 EXPECT_EQ(20, value); 1289 EXPECT_EQ(20, value);
1234 result = Dart_SetInstanceField(retobj, 1290 result = Dart_SetInstanceField(retobj,
1235 Dart_NewString("fld2"), 1291 Dart_NewString("fld2"),
1236 Dart_NewInteger(40)); 1292 Dart_NewInteger(40));
1237 EXPECT(Dart_IsError(result)); 1293 EXPECT(Dart_IsError(result));
1238 result = Dart_SetInstanceField(retobj, 1294 result = Dart_SetInstanceField(retobj,
1239 Dart_NewString("fld1"), 1295 Dart_NewString("fld1"),
1240 Dart_NewInteger(40)); 1296 Dart_NewInteger(40));
1241 EXPECT_VALID(result); 1297 EXPECT_VALID(result);
1242 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 1298 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1243 EXPECT_VALID(result); 1299 EXPECT_VALID(result);
1244 result = Dart_IntegerValue(result, &value); 1300 result = Dart_IntegerToInt64(result, &value);
1245 EXPECT_EQ(40, value); 1301 EXPECT_EQ(40, value);
1246 1302
1247 // Now access and set various native instance fields of the returned object. 1303 // Now access and set various native instance fields of the returned object.
1248 const int kNativeFld0 = 0; 1304 const int kNativeFld0 = 0;
1249 const int kNativeFld1 = 1; 1305 const int kNativeFld1 = 1;
1250 const int kNativeFld2 = 2; 1306 const int kNativeFld2 = 2;
1251 const int kNativeFld3 = 3; 1307 const int kNativeFld3 = 3;
1252 const int kNativeFld4 = 4; 1308 const int kNativeFld4 = 4;
1253 intptr_t field_value = 0; 1309 intptr_t field_value = 0;
1254 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value); 1310 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value);
(...skipping 18 matching lines...) Expand all
1273 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000); 1329 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 4000);
1274 EXPECT_VALID(result); 1330 EXPECT_VALID(result);
1275 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value); 1331 result = Dart_GetNativeInstanceField(retobj, kNativeFld3, &field_value);
1276 EXPECT_VALID(result); 1332 EXPECT_VALID(result);
1277 EXPECT_EQ(4000, field_value); 1333 EXPECT_EQ(4000, field_value);
1278 1334
1279 // Now re-access various dart instance fields of the returned object 1335 // Now re-access various dart instance fields of the returned object
1280 // to ensure that there was no corruption while setting native fields. 1336 // to ensure that there was no corruption while setting native fields.
1281 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); 1337 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1282 EXPECT_VALID(result); 1338 EXPECT_VALID(result);
1283 result = Dart_IntegerValue(result, &value); 1339 result = Dart_IntegerToInt64(result, &value);
1284 EXPECT_EQ(40, value); 1340 EXPECT_EQ(40, value);
1285 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 1341 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1286 EXPECT_VALID(result); 1342 EXPECT_VALID(result);
1287 result = Dart_IntegerValue(result, &value); 1343 result = Dart_IntegerToInt64(result, &value);
1288 EXPECT_EQ(20, value); 1344 EXPECT_EQ(20, value);
1289 } 1345 }
1290 1346
1291 1347
1292 UNIT_TEST_CASE(NativeFieldAccess) { 1348 UNIT_TEST_CASE(NativeFieldAccess) {
1293 const char* kScriptChars = 1349 const char* kScriptChars =
1294 "class NativeFields extends NativeFieldsWrapper {\n" 1350 "class NativeFields extends NativeFieldsWrapper {\n"
1295 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1351 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1296 " int fld1;\n" 1352 " int fld1;\n"
1297 " final int fld2;\n" 1353 " final int fld2;\n"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 0, 1534 0,
1479 NULL); 1535 NULL);
1480 1536
1481 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); 1537 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass"));
1482 EXPECT_VALID(cls); 1538 EXPECT_VALID(cls);
1483 1539
1484 // For uninitialized fields, the getter is returned 1540 // For uninitialized fields, the getter is returned
1485 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); 1541 result = Dart_GetStaticField(cls, Dart_NewString("fld1"));
1486 EXPECT_VALID(result); 1542 EXPECT_VALID(result);
1487 int64_t value = 0; 1543 int64_t value = 0;
1488 result = Dart_IntegerValue(result, &value); 1544 result = Dart_IntegerToInt64(result, &value);
1489 EXPECT_EQ(7, value); 1545 EXPECT_EQ(7, value);
1490 1546
1491 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); 1547 result = Dart_GetStaticField(cls, Dart_NewString("fld2"));
1492 EXPECT_VALID(result); 1548 EXPECT_VALID(result);
1493 result = Dart_IntegerValue(result, &value); 1549 result = Dart_IntegerToInt64(result, &value);
1494 EXPECT_EQ(11, value); 1550 EXPECT_EQ(11, value);
1495 1551
1496 // Overwrite fld2 1552 // Overwrite fld2
1497 result = Dart_SetStaticField(cls, 1553 result = Dart_SetStaticField(cls,
1498 Dart_NewString("fld2"), 1554 Dart_NewString("fld2"),
1499 Dart_NewInteger(13)); 1555 Dart_NewInteger(13));
1500 EXPECT_VALID(result); 1556 EXPECT_VALID(result);
1501 1557
1502 // We now get the new value for fld2, not the initializer 1558 // We now get the new value for fld2, not the initializer
1503 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); 1559 result = Dart_GetStaticField(cls, Dart_NewString("fld2"));
1504 EXPECT_VALID(result); 1560 EXPECT_VALID(result);
1505 result = Dart_IntegerValue(result, &value); 1561 result = Dart_IntegerToInt64(result, &value);
1506 EXPECT_EQ(13, value); 1562 EXPECT_EQ(13, value);
1507 } 1563 }
1508 } 1564 }
1509 1565
1510 1566
1511 UNIT_TEST_CASE(StaticFieldNotFound) { 1567 UNIT_TEST_CASE(StaticFieldNotFound) {
1512 const char* kScriptChars = 1568 const char* kScriptChars =
1513 "class TestClass {\n" 1569 "class TestClass {\n"
1514 " static void testMain() {\n" 1570 " static void testMain() {\n"
1515 " }\n" 1571 " }\n"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 // Now invoke a dynamic method and check the result. 1639 // Now invoke a dynamic method and check the result.
1584 Dart_Handle dart_arguments[1]; 1640 Dart_Handle dart_arguments[1];
1585 dart_arguments[0] = Dart_NewInteger(1); 1641 dart_arguments[0] = Dart_NewInteger(1);
1586 result = Dart_InvokeDynamic(retobj, 1642 result = Dart_InvokeDynamic(retobj,
1587 Dart_NewString("method1"), 1643 Dart_NewString("method1"),
1588 1, 1644 1,
1589 dart_arguments); 1645 dart_arguments);
1590 EXPECT_VALID(result); 1646 EXPECT_VALID(result);
1591 EXPECT(Dart_IsInteger(result)); 1647 EXPECT(Dart_IsInteger(result));
1592 int64_t value = 0; 1648 int64_t value = 0;
1593 result = Dart_IntegerValue(result, &value); 1649 result = Dart_IntegerToInt64(result, &value);
1594 EXPECT_EQ(41, value); 1650 EXPECT_EQ(41, value);
1595 1651
1596 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1652 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1597 EXPECT(Dart_IsError(result)); 1653 EXPECT(Dart_IsError(result));
1598 1654
1599 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL); 1655 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL);
1600 EXPECT(Dart_IsError(result)); 1656 EXPECT(Dart_IsError(result));
1601 } 1657 }
1602 } 1658 }
1603 1659
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 EXPECT(Dart_IsClosure(retobj)); 1703 EXPECT(Dart_IsClosure(retobj));
1648 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); 1704 EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
1649 1705
1650 // Now invoke the closure and check the result. 1706 // Now invoke the closure and check the result.
1651 Dart_Handle dart_arguments[1]; 1707 Dart_Handle dart_arguments[1];
1652 dart_arguments[0] = Dart_NewInteger(1); 1708 dart_arguments[0] = Dart_NewInteger(1);
1653 result = Dart_InvokeClosure(retobj, 1, dart_arguments); 1709 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1654 EXPECT_VALID(result); 1710 EXPECT_VALID(result);
1655 EXPECT(Dart_IsInteger(result)); 1711 EXPECT(Dart_IsInteger(result));
1656 int64_t value = 0; 1712 int64_t value = 0;
1657 result = Dart_IntegerValue(result, &value); 1713 result = Dart_IntegerToInt64(result, &value);
1658 EXPECT_EQ(51, value); 1714 EXPECT_EQ(51, value);
1659 1715
1660 // Invoke closure with wrong number of args, should result in exception. 1716 // Invoke closure with wrong number of args, should result in exception.
1661 result = Dart_InvokeClosure(retobj, 0, NULL); 1717 result = Dart_InvokeClosure(retobj, 0, NULL);
1662 EXPECT(Dart_IsError(result)); 1718 EXPECT(Dart_IsError(result));
1663 EXPECT(Dart_ErrorHasException(result)); 1719 EXPECT(Dart_ErrorHasException(result));
1664 1720
1665 // Invoke a function which returns a closure. 1721 // Invoke a function which returns a closure.
1666 retobj = Dart_InvokeStatic(lib, 1722 retobj = Dart_InvokeStatic(lib,
1667 Dart_NewString("InvokeClosureTest"), 1723 Dart_NewString("InvokeClosureTest"),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 result = Dart_ThrowException(retobj); 1798 result = Dart_ThrowException(retobj);
1743 EXPECT(Dart_IsError(result)); 1799 EXPECT(Dart_IsError(result));
1744 1800
1745 // Now invoke method2 which invokes a natve method where it is 1801 // Now invoke method2 which invokes a natve method where it is
1746 // ok to throw an exception, check the result which would indicate 1802 // ok to throw an exception, check the result which would indicate
1747 // if an exception was thrown or not. 1803 // if an exception was thrown or not.
1748 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1804 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1749 EXPECT_VALID(result); 1805 EXPECT_VALID(result);
1750 EXPECT(Dart_IsInteger(result)); 1806 EXPECT(Dart_IsInteger(result));
1751 int64_t value = 0; 1807 int64_t value = 0;
1752 result = Dart_IntegerValue(result, &value); 1808 result = Dart_IntegerToInt64(result, &value);
1753 EXPECT_EQ(5, value); 1809 EXPECT_EQ(5, value);
1754 1810
1755 Dart_ExitScope(); // Exit the Dart API scope. 1811 Dart_ExitScope(); // Exit the Dart API scope.
1756 EXPECT_EQ(size, state->ZoneSizeInBytes()); 1812 EXPECT_EQ(size, state->ZoneSizeInBytes());
1757 } 1813 }
1758 } 1814 }
1759 1815
1760 1816
1761 void NativeArgumentCounter(Dart_NativeArguments args) { 1817 void NativeArgumentCounter(Dart_NativeArguments args) {
1762 Dart_EnterScope(); 1818 Dart_EnterScope();
(...skipping 28 matching lines...) Expand all
1791 1847
1792 Dart_Handle result = Dart_InvokeStatic(lib, 1848 Dart_Handle result = Dart_InvokeStatic(lib,
1793 Dart_NewString("Test"), 1849 Dart_NewString("Test"),
1794 Dart_NewString("testMain"), 1850 Dart_NewString("testMain"),
1795 0, 1851 0,
1796 NULL); 1852 NULL);
1797 EXPECT_VALID(result); 1853 EXPECT_VALID(result);
1798 EXPECT(Dart_IsInteger(result)); 1854 EXPECT(Dart_IsInteger(result));
1799 1855
1800 int64_t value = 0; 1856 int64_t value = 0;
1801 result = Dart_IntegerValue(result, &value); 1857 result = Dart_IntegerToInt64(result, &value);
1802 EXPECT_VALID(result); 1858 EXPECT_VALID(result);
1803 EXPECT_EQ(3, value); 1859 EXPECT_EQ(3, value);
1804 } 1860 }
1805 } 1861 }
1806 1862
1807 1863
1808 UNIT_TEST_CASE(GetClass) { 1864 UNIT_TEST_CASE(GetClass) {
1809 const char* kScriptChars = 1865 const char* kScriptChars =
1810 "class DoesExist {" 1866 "class DoesExist {"
1811 "}"; 1867 "}";
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 EXPECT_VALID(result); 2046 EXPECT_VALID(result);
1991 2047
1992 result = Dart_InvokeStatic(result, 2048 result = Dart_InvokeStatic(result,
1993 Dart_NewString(""), 2049 Dart_NewString(""),
1994 Dart_NewString("main"), 2050 Dart_NewString("main"),
1995 0, 2051 0,
1996 NULL); 2052 NULL);
1997 EXPECT_VALID(result); 2053 EXPECT_VALID(result);
1998 EXPECT(Dart_IsInteger(result)); 2054 EXPECT(Dart_IsInteger(result));
1999 int64_t value = 0; 2055 int64_t value = 0;
2000 EXPECT_VALID(Dart_IntegerValue(result, &value)); 2056 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
2001 EXPECT_EQ(12345, value); 2057 EXPECT_EQ(12345, value);
2002 2058
2003 // Further calls to LoadScript are errors. 2059 // Further calls to LoadScript are errors.
2004 result = Dart_LoadScript(url, source, library_handler); 2060 result = Dart_LoadScript(url, source, library_handler);
2005 EXPECT(Dart_IsError(result)); 2061 EXPECT(Dart_IsError(result));
2006 EXPECT_STREQ("Dart_LoadScript: " 2062 EXPECT_STREQ("Dart_LoadScript: "
2007 "A script has already been loaded from 'dart:test-lib'.", 2063 "A script has already been loaded from 'dart:test-lib'.",
2008 Dart_GetError(result)); 2064 Dart_GetError(result));
2009 } 2065 }
2010 2066
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 2448
2393 // Call a function and make sure native resolution works. 2449 // Call a function and make sure native resolution works.
2394 result = Dart_InvokeStatic(lib, 2450 result = Dart_InvokeStatic(lib,
2395 Dart_NewString("Test"), 2451 Dart_NewString("Test"),
2396 Dart_NewString("foo"), 2452 Dart_NewString("foo"),
2397 0, 2453 0,
2398 NULL); 2454 NULL);
2399 EXPECT_VALID(result); 2455 EXPECT_VALID(result);
2400 EXPECT(Dart_IsInteger(result)); 2456 EXPECT(Dart_IsInteger(result));
2401 int64_t value = 0; 2457 int64_t value = 0;
2402 EXPECT_VALID(Dart_IntegerValue(result, &value)); 2458 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
2403 EXPECT_EQ(654321, value); 2459 EXPECT_EQ(654321, value);
2404 2460
2405 // A second call succeeds. 2461 // A second call succeeds.
2406 result = Dart_SetNativeResolver(lib, &MyNativeResolver2); 2462 result = Dart_SetNativeResolver(lib, &MyNativeResolver2);
2407 EXPECT_VALID(result); 2463 EXPECT_VALID(result);
2408 2464
2409 // 'foo' has already been resolved so gets the old value. 2465 // 'foo' has already been resolved so gets the old value.
2410 result = Dart_InvokeStatic(lib, 2466 result = Dart_InvokeStatic(lib,
2411 Dart_NewString("Test"), 2467 Dart_NewString("Test"),
2412 Dart_NewString("foo"), 2468 Dart_NewString("foo"),
2413 0, 2469 0,
2414 NULL); 2470 NULL);
2415 EXPECT_VALID(result); 2471 EXPECT_VALID(result);
2416 EXPECT(Dart_IsInteger(result)); 2472 EXPECT(Dart_IsInteger(result));
2417 value = 0; 2473 value = 0;
2418 EXPECT_VALID(Dart_IntegerValue(result, &value)); 2474 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
2419 EXPECT_EQ(654321, value); 2475 EXPECT_EQ(654321, value);
2420 2476
2421 // 'bar' has not yet been resolved so gets the new value. 2477 // 'bar' has not yet been resolved so gets the new value.
2422 result = Dart_InvokeStatic(lib, 2478 result = Dart_InvokeStatic(lib,
2423 Dart_NewString("Test"), 2479 Dart_NewString("Test"),
2424 Dart_NewString("bar"), 2480 Dart_NewString("bar"),
2425 0, 2481 0,
2426 NULL); 2482 NULL);
2427 EXPECT_VALID(result); 2483 EXPECT_VALID(result);
2428 EXPECT(Dart_IsInteger(result)); 2484 EXPECT(Dart_IsInteger(result));
2429 value = 0; 2485 value = 0;
2430 EXPECT_VALID(Dart_IntegerValue(result, &value)); 2486 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
2431 EXPECT_EQ(123456, value); 2487 EXPECT_EQ(123456, value);
2432 2488
2433 // A NULL resolver is okay, but resolution will fail. 2489 // A NULL resolver is okay, but resolution will fail.
2434 result = Dart_SetNativeResolver(lib, NULL); 2490 result = Dart_SetNativeResolver(lib, NULL);
2435 EXPECT_VALID(result); 2491 EXPECT_VALID(result);
2436 2492
2437 result = Dart_InvokeStatic(lib, 2493 result = Dart_InvokeStatic(lib,
2438 Dart_NewString("Test"), 2494 Dart_NewString("Test"),
2439 Dart_NewString("baz"), 2495 Dart_NewString("baz"),
2440 0, 2496 0,
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 } 2812 }
2757 2813
2758 2814
2759 UNIT_TEST_CASE(RunLoop_Exception) { 2815 UNIT_TEST_CASE(RunLoop_Exception) {
2760 RunLoopTest(true); 2816 RunLoopTest(true);
2761 } 2817 }
2762 2818
2763 #endif // TARGET_ARCH_IA32. 2819 #endif // TARGET_ARCH_IA32.
2764 2820
2765 } // namespace dart 2821 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698