Chromium Code Reviews| Index: runtime/vm/dart_api_impl_test.cc |
| diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc |
| index ff2f61eec8266801d5b97fad5bff11ab7fda3917..d8c5cd85ede73f579c8276aaf811e88b3bbc0fce 100644 |
| --- a/runtime/vm/dart_api_impl_test.cc |
| +++ b/runtime/vm/dart_api_impl_test.cc |
| @@ -301,21 +301,77 @@ UNIT_TEST_CASE(IntegerValues) { |
| EXPECT(!fits); |
| int64_t out = 0; |
| - result = Dart_IntegerValue(val1, &out); |
| + result = Dart_IntegerToInt64(val1, &out); |
| EXPECT_VALID(result); |
| EXPECT_EQ(kIntegerVal1, out); |
| - result = Dart_IntegerValue(val2, &out); |
| + result = Dart_IntegerToInt64(val2, &out); |
| EXPECT_VALID(result); |
| EXPECT_EQ(kIntegerVal2, out); |
| const char* chars = NULL; |
| - result = Dart_IntegerValueHexCString(val3, &chars); |
| + result = Dart_IntegerToHexCString(val3, &chars); |
| EXPECT_VALID(result); |
| EXPECT(!strcmp(kIntegerVal3, chars)); |
| } |
| +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.
|
| + TestIsolateScope __test_isolate__; |
| + |
| + const int64_t kLongLongMax = DART_INT64_C(0x7FFFFFFFFFFFFFFF); |
| + const int64_t kLongLongMin = -kLongLongMax - 1; |
| + |
| + const char* kUnsignedLongLongMax = "0xFFFFFFFFFFFFFFFF"; |
| + const uint64_t kUnsignedLongLongMin = DART_UINT64_C(0x0); |
| + |
| + Dart_Handle long_long_min = Dart_NewInteger(kLongLongMin); |
| + EXPECT(Dart_IsInteger(long_long_min)); |
| + bool fits = false; |
| + Dart_Handle result = Dart_IntegerFitsIntoInt64(long_long_min, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| + fits = true; |
| + result = Dart_IntegerFitsIntoUint64(long_long_min, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(!fits); |
| + |
| + Dart_Handle zero = Dart_NewInteger(kUnsignedLongLongMin); |
| + EXPECT(Dart_IsInteger(zero)); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoInt64(zero, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoUint64(zero, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| + |
| + Dart_Handle long_long_max = Dart_NewInteger(kLongLongMax); |
| + EXPECT(Dart_IsInteger(long_long_max)); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoInt64(long_long_max, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoUint64(long_long_max, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| + |
| + Dart_Handle unsigned_long_long_max = |
| + Dart_NewIntegerFromHexCString(kUnsignedLongLongMax); |
| + EXPECT(Dart_IsInteger(unsigned_long_long_max)); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoInt64(unsigned_long_long_max, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(!fits); |
| + fits = false; |
| + result = Dart_IntegerFitsIntoUint64(unsigned_long_long_max, &fits); |
| + EXPECT_VALID(result); |
| + EXPECT(fits); |
| +} |
| + |
| + |
| UNIT_TEST_CASE(ArrayValues) { |
| TestIsolateScope __test_isolate__; |
| @@ -347,7 +403,7 @@ UNIT_TEST_CASE(ArrayValues) { |
| result = Dart_ListGetAt(val, i); |
| EXPECT_VALID(result); |
| int64_t value; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(i, value); |
| } |
| @@ -498,19 +554,19 @@ UNIT_TEST_CASE(ListAccess) { |
| result = Dart_ListGetAt(ListAccessTestObj, 0); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(10, value); |
| result = Dart_ListGetAt(ListAccessTestObj, 1); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(20, value); |
| result = Dart_ListGetAt(ListAccessTestObj, 2); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(30, value); |
| @@ -530,19 +586,19 @@ UNIT_TEST_CASE(ListAccess) { |
| // Now try and access these elements in the array. |
| result = Dart_ListGetAt(ListAccessTestObj, 0); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(0, value); |
| result = Dart_ListGetAt(ListAccessTestObj, 1); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(1, value); |
| result = Dart_ListGetAt(ListAccessTestObj, 2); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(2, value); |
| @@ -565,7 +621,7 @@ UNIT_TEST_CASE(ListAccess) { |
| EXPECT_EQ(30, native_array[2]); |
| result = Dart_ListGetAt(ListAccessTestObj, 2); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(30, value); |
| @@ -900,7 +956,7 @@ UNIT_TEST_CASE(FieldAccess) { |
| result = Dart_GetStaticField(cls, Dart_NewString("fld4")); |
| EXPECT_VALID(result); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(10, value); |
| result = Dart_SetStaticField(cls, |
| Dart_NewString("fld4"), |
| @@ -912,7 +968,7 @@ UNIT_TEST_CASE(FieldAccess) { |
| Dart_NewString("fld3"), |
| Dart_NewInteger(200)); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(200, value); |
| // Now access and set various instance fields of the returned object. |
| @@ -920,11 +976,11 @@ UNIT_TEST_CASE(FieldAccess) { |
| EXPECT(Dart_IsError(result)); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(10, value); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(20, value); |
| result = Dart_SetInstanceField(retobj, |
| Dart_NewString("fld2"), |
| @@ -936,7 +992,7 @@ UNIT_TEST_CASE(FieldAccess) { |
| EXPECT_VALID(result); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(40, value); |
| } |
| } |
| @@ -982,7 +1038,7 @@ UNIT_TEST_CASE(HiddenFieldAccess) { |
| result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); |
| EXPECT_VALID(result); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(10, value); |
| result = Dart_SetStaticField(cls, |
| Dart_NewString("_fld4"), |
| @@ -994,7 +1050,7 @@ UNIT_TEST_CASE(HiddenFieldAccess) { |
| Dart_NewString("_fld3"), |
| Dart_NewInteger(200)); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(200, value); |
| // Now access and set various instance fields of the returned object. |
| @@ -1002,11 +1058,11 @@ UNIT_TEST_CASE(HiddenFieldAccess) { |
| EXPECT(Dart_IsError(result)); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(10, value); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(20, value); |
| result = Dart_SetInstanceField(retobj, |
| Dart_NewString("_fld2"), |
| @@ -1018,7 +1074,7 @@ UNIT_TEST_CASE(HiddenFieldAccess) { |
| EXPECT_VALID(result); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(40, value); |
| } |
| } |
| @@ -1225,11 +1281,11 @@ static void TestNativeFields(Dart_Handle retobj) { |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(10, value); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(20, value); |
| result = Dart_SetInstanceField(retobj, |
| Dart_NewString("fld2"), |
| @@ -1241,7 +1297,7 @@ static void TestNativeFields(Dart_Handle retobj) { |
| EXPECT_VALID(result); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(40, value); |
| // Now access and set various native instance fields of the returned object. |
| @@ -1280,11 +1336,11 @@ static void TestNativeFields(Dart_Handle retobj) { |
| // to ensure that there was no corruption while setting native fields. |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(40, value); |
| result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(20, value); |
| } |
| @@ -1485,12 +1541,12 @@ UNIT_TEST_CASE(GetStaticField_RunsInitializer) { |
| result = Dart_GetStaticField(cls, Dart_NewString("fld1")); |
| EXPECT_VALID(result); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(7, value); |
| result = Dart_GetStaticField(cls, Dart_NewString("fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(11, value); |
| // Overwrite fld2 |
| @@ -1502,7 +1558,7 @@ UNIT_TEST_CASE(GetStaticField_RunsInitializer) { |
| // We now get the new value for fld2, not the initializer |
| result = Dart_GetStaticField(cls, Dart_NewString("fld2")); |
| EXPECT_VALID(result); |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(13, value); |
| } |
| } |
| @@ -1590,7 +1646,7 @@ UNIT_TEST_CASE(InvokeDynamic) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(41, value); |
| result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); |
| @@ -1654,7 +1710,7 @@ UNIT_TEST_CASE(InvokeClosure) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(51, value); |
| // Invoke closure with wrong number of args, should result in exception. |
| @@ -1749,7 +1805,7 @@ UNIT_TEST_CASE(ThrowException) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_EQ(5, value); |
| Dart_ExitScope(); // Exit the Dart API scope. |
| @@ -1798,7 +1854,7 @@ UNIT_TEST_CASE(GetNativeArgumentCount) { |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - result = Dart_IntegerValue(result, &value); |
| + result = Dart_IntegerToInt64(result, &value); |
| EXPECT_VALID(result); |
| EXPECT_EQ(3, value); |
| } |
| @@ -1997,7 +2053,7 @@ UNIT_TEST_CASE(LoadScript) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - EXPECT_VALID(Dart_IntegerValue(result, &value)); |
| + EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| EXPECT_EQ(12345, value); |
| // Further calls to LoadScript are errors. |
| @@ -2399,7 +2455,7 @@ UNIT_TEST_CASE(SetNativeResolver) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| int64_t value = 0; |
| - EXPECT_VALID(Dart_IntegerValue(result, &value)); |
| + EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| EXPECT_EQ(654321, value); |
| // A second call succeeds. |
| @@ -2415,7 +2471,7 @@ UNIT_TEST_CASE(SetNativeResolver) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| value = 0; |
| - EXPECT_VALID(Dart_IntegerValue(result, &value)); |
| + EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| EXPECT_EQ(654321, value); |
| // 'bar' has not yet been resolved so gets the new value. |
| @@ -2427,7 +2483,7 @@ UNIT_TEST_CASE(SetNativeResolver) { |
| EXPECT_VALID(result); |
| EXPECT(Dart_IsInteger(result)); |
| value = 0; |
| - EXPECT_VALID(Dart_IntegerValue(result, &value)); |
| + EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| EXPECT_EQ(123456, value); |
| // A NULL resolver is okay, but resolution will fail. |