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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 2987183002: [vm] Revise Dart_IntegerToHexCString to avoid dependency on Bigint (Closed)
Patch Set: Virtual methods grouped together Created 3 years, 5 months 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 side-by-side diff with in-line comments
Download patch
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 5b50d6eb731862bd9805aed1ac272462e7b3894f..946f53ffa709d4bae16101d9200405f24ed61cc9 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -838,12 +838,21 @@ TEST_CASE(IntegerValues) {
EXPECT_VALID(result);
EXPECT(fits);
+ int64_t out = 0;
+ result = Dart_IntegerToInt64(val1, &out);
+ EXPECT_VALID(result);
+ EXPECT_EQ(kIntegerVal1, out);
+
Dart_Handle val2 = Dart_NewInteger(kIntegerVal2);
EXPECT(Dart_IsInteger(val2));
result = Dart_IntegerFitsIntoInt64(val2, &fits);
EXPECT_VALID(result);
EXPECT(fits);
+ result = Dart_IntegerToInt64(val2, &out);
+ EXPECT_VALID(result);
+ EXPECT_EQ(kIntegerVal2, out);
+
Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3);
if (FLAG_limit_ints_to_64_bits) {
EXPECT(Dart_IsApiError(val3));
@@ -852,21 +861,12 @@ TEST_CASE(IntegerValues) {
result = Dart_IntegerFitsIntoInt64(val3, &fits);
EXPECT_VALID(result);
EXPECT(!fits);
- }
-
- int64_t out = 0;
- result = Dart_IntegerToInt64(val1, &out);
- EXPECT_VALID(result);
- EXPECT_EQ(kIntegerVal1, out);
-
- result = Dart_IntegerToInt64(val2, &out);
- EXPECT_VALID(result);
- EXPECT_EQ(kIntegerVal2, out);
- const char* chars = NULL;
- result = Dart_IntegerToHexCString(val3, &chars);
- EXPECT_VALID(result);
- EXPECT(!strcmp(kIntegerVal3, chars));
+ const char* chars = NULL;
+ result = Dart_IntegerToHexCString(val3, &chars);
+ EXPECT_VALID(result);
+ EXPECT(!strcmp(kIntegerVal3, chars));
+ }
Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4);
if (FLAG_limit_ints_to_64_bits) {
@@ -892,6 +892,57 @@ TEST_CASE(IntegerValues) {
EXPECT(Dart_IsError(result));
}
+TEST_CASE(IntegerToHexCString) {
+ const struct {
+ int64_t i;
+ const char* s;
+ } kIntTestCases[] = {
+ {0, "0x0"},
+ {1, "0x1"},
+ {-1, "-0x1"},
+ {0x123, "0x123"},
+ {-0xABCDEF, "-0xABCDEF"},
+ {DART_INT64_C(-0x7FFFFFFFFFFFFFFF), "-0x7FFFFFFFFFFFFFFF"},
+ {kMaxInt64, "0x7FFFFFFFFFFFFFFF"},
+ {kMinInt64, "-0x8000000000000000"},
+ };
+
+ const size_t kNumberOfIntTestCases =
+ sizeof(kIntTestCases) / sizeof(kIntTestCases[0]);
+
+ for (size_t i = 0; i < kNumberOfIntTestCases; ++i) {
+ Dart_Handle val = Dart_NewInteger(kIntTestCases[i].i);
+ EXPECT_VALID(val);
+ const char* chars = NULL;
+ Dart_Handle result = Dart_IntegerToHexCString(val, &chars);
+ EXPECT_VALID(result);
+ EXPECT_STREQ(kIntTestCases[i].s, chars);
+ }
+
+ if (!FLAG_limit_ints_to_64_bits) {
+ const char* kStrTestCases[] = {
+ "0x8000000000000000",
+ "-0x8000000000000000",
+ "0xFFFFFFFFFFFFFFFF",
+ "-0xFFFFFFFFFFFFFFFF",
+ "0xAABBCCDDEEFF00112233445566778899",
+ "-0x1234567890ABCDEF1234567890ABCDEF",
+ };
+
+ const size_t kNumberOfStrTestCases =
+ sizeof(kStrTestCases) / sizeof(kStrTestCases[0]);
+
+ for (size_t i = 0; i < kNumberOfStrTestCases; ++i) {
+ Dart_Handle val = Dart_NewIntegerFromHexCString(kStrTestCases[i]);
+ EXPECT_VALID(val);
+ const char* chars = NULL;
+ Dart_Handle result = Dart_IntegerToHexCString(val, &chars);
+ EXPECT_VALID(result);
+ EXPECT_STREQ(kStrTestCases[i], chars);
+ }
+ }
+}
+
TEST_CASE(IntegerFitsIntoInt64) {
Dart_Handle max = Dart_NewInteger(kMaxInt64);
EXPECT(Dart_IsInteger(max));
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698