OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
6 #include "bin/builtin.h" | 6 #include "bin/builtin.h" |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 const uint64_t kIntegerVal4 = 0xffffffffffffffff; | 831 const uint64_t kIntegerVal4 = 0xffffffffffffffff; |
832 const int64_t kIntegerVal5 = -0x7fffffffffffffff; | 832 const int64_t kIntegerVal5 = -0x7fffffffffffffff; |
833 | 833 |
834 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); | 834 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); |
835 EXPECT(Dart_IsInteger(val1)); | 835 EXPECT(Dart_IsInteger(val1)); |
836 bool fits = false; | 836 bool fits = false; |
837 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); | 837 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); |
838 EXPECT_VALID(result); | 838 EXPECT_VALID(result); |
839 EXPECT(fits); | 839 EXPECT(fits); |
840 | 840 |
| 841 int64_t out = 0; |
| 842 result = Dart_IntegerToInt64(val1, &out); |
| 843 EXPECT_VALID(result); |
| 844 EXPECT_EQ(kIntegerVal1, out); |
| 845 |
841 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2); | 846 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2); |
842 EXPECT(Dart_IsInteger(val2)); | 847 EXPECT(Dart_IsInteger(val2)); |
843 result = Dart_IntegerFitsIntoInt64(val2, &fits); | 848 result = Dart_IntegerFitsIntoInt64(val2, &fits); |
844 EXPECT_VALID(result); | 849 EXPECT_VALID(result); |
845 EXPECT(fits); | 850 EXPECT(fits); |
846 | 851 |
| 852 result = Dart_IntegerToInt64(val2, &out); |
| 853 EXPECT_VALID(result); |
| 854 EXPECT_EQ(kIntegerVal2, out); |
| 855 |
847 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); | 856 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); |
848 if (FLAG_limit_ints_to_64_bits) { | 857 if (FLAG_limit_ints_to_64_bits) { |
849 EXPECT(Dart_IsApiError(val3)); | 858 EXPECT(Dart_IsApiError(val3)); |
850 } else { | 859 } else { |
851 EXPECT(Dart_IsInteger(val3)); | 860 EXPECT(Dart_IsInteger(val3)); |
852 result = Dart_IntegerFitsIntoInt64(val3, &fits); | 861 result = Dart_IntegerFitsIntoInt64(val3, &fits); |
853 EXPECT_VALID(result); | 862 EXPECT_VALID(result); |
854 EXPECT(!fits); | 863 EXPECT(!fits); |
| 864 |
| 865 const char* chars = NULL; |
| 866 result = Dart_IntegerToHexCString(val3, &chars); |
| 867 EXPECT_VALID(result); |
| 868 EXPECT(!strcmp(kIntegerVal3, chars)); |
855 } | 869 } |
856 | 870 |
857 int64_t out = 0; | |
858 result = Dart_IntegerToInt64(val1, &out); | |
859 EXPECT_VALID(result); | |
860 EXPECT_EQ(kIntegerVal1, out); | |
861 | |
862 result = Dart_IntegerToInt64(val2, &out); | |
863 EXPECT_VALID(result); | |
864 EXPECT_EQ(kIntegerVal2, out); | |
865 | |
866 const char* chars = NULL; | |
867 result = Dart_IntegerToHexCString(val3, &chars); | |
868 EXPECT_VALID(result); | |
869 EXPECT(!strcmp(kIntegerVal3, chars)); | |
870 | |
871 Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4); | 871 Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4); |
872 if (FLAG_limit_ints_to_64_bits) { | 872 if (FLAG_limit_ints_to_64_bits) { |
873 EXPECT(Dart_IsApiError(val4)); | 873 EXPECT(Dart_IsApiError(val4)); |
874 } else { | 874 } else { |
875 EXPECT_VALID(val4); | 875 EXPECT_VALID(val4); |
876 uint64_t out4 = 0; | 876 uint64_t out4 = 0; |
877 result = Dart_IntegerToUint64(val4, &out4); | 877 result = Dart_IntegerToUint64(val4, &out4); |
878 EXPECT_VALID(result); | 878 EXPECT_VALID(result); |
879 EXPECT_EQ(kIntegerVal4, out4); | 879 EXPECT_EQ(kIntegerVal4, out4); |
880 } | 880 } |
881 | 881 |
882 Dart_Handle val5 = Dart_NewInteger(-1); | 882 Dart_Handle val5 = Dart_NewInteger(-1); |
883 EXPECT_VALID(val5); | 883 EXPECT_VALID(val5); |
884 uint64_t out5 = 0; | 884 uint64_t out5 = 0; |
885 result = Dart_IntegerToUint64(val5, &out5); | 885 result = Dart_IntegerToUint64(val5, &out5); |
886 EXPECT(Dart_IsError(result)); | 886 EXPECT(Dart_IsError(result)); |
887 | 887 |
888 Dart_Handle val6 = Dart_NewInteger(kIntegerVal5); | 888 Dart_Handle val6 = Dart_NewInteger(kIntegerVal5); |
889 EXPECT_VALID(val6); | 889 EXPECT_VALID(val6); |
890 uint64_t out6 = 0; | 890 uint64_t out6 = 0; |
891 result = Dart_IntegerToUint64(val6, &out6); | 891 result = Dart_IntegerToUint64(val6, &out6); |
892 EXPECT(Dart_IsError(result)); | 892 EXPECT(Dart_IsError(result)); |
893 } | 893 } |
894 | 894 |
| 895 TEST_CASE(IntegerToHexCString) { |
| 896 const struct { |
| 897 int64_t i; |
| 898 const char* s; |
| 899 } kIntTestCases[] = { |
| 900 {0, "0x0"}, |
| 901 {1, "0x1"}, |
| 902 {-1, "-0x1"}, |
| 903 {0x123, "0x123"}, |
| 904 {-0xABCDEF, "-0xABCDEF"}, |
| 905 {DART_INT64_C(-0x7FFFFFFFFFFFFFFF), "-0x7FFFFFFFFFFFFFFF"}, |
| 906 {kMaxInt64, "0x7FFFFFFFFFFFFFFF"}, |
| 907 {kMinInt64, "-0x8000000000000000"}, |
| 908 }; |
| 909 |
| 910 const size_t kNumberOfIntTestCases = |
| 911 sizeof(kIntTestCases) / sizeof(kIntTestCases[0]); |
| 912 |
| 913 for (size_t i = 0; i < kNumberOfIntTestCases; ++i) { |
| 914 Dart_Handle val = Dart_NewInteger(kIntTestCases[i].i); |
| 915 EXPECT_VALID(val); |
| 916 const char* chars = NULL; |
| 917 Dart_Handle result = Dart_IntegerToHexCString(val, &chars); |
| 918 EXPECT_VALID(result); |
| 919 EXPECT_STREQ(kIntTestCases[i].s, chars); |
| 920 } |
| 921 |
| 922 if (!FLAG_limit_ints_to_64_bits) { |
| 923 const char* kStrTestCases[] = { |
| 924 "0x8000000000000000", |
| 925 "-0x8000000000000000", |
| 926 "0xFFFFFFFFFFFFFFFF", |
| 927 "-0xFFFFFFFFFFFFFFFF", |
| 928 "0xAABBCCDDEEFF00112233445566778899", |
| 929 "-0x1234567890ABCDEF1234567890ABCDEF", |
| 930 }; |
| 931 |
| 932 const size_t kNumberOfStrTestCases = |
| 933 sizeof(kStrTestCases) / sizeof(kStrTestCases[0]); |
| 934 |
| 935 for (size_t i = 0; i < kNumberOfStrTestCases; ++i) { |
| 936 Dart_Handle val = Dart_NewIntegerFromHexCString(kStrTestCases[i]); |
| 937 EXPECT_VALID(val); |
| 938 const char* chars = NULL; |
| 939 Dart_Handle result = Dart_IntegerToHexCString(val, &chars); |
| 940 EXPECT_VALID(result); |
| 941 EXPECT_STREQ(kStrTestCases[i], chars); |
| 942 } |
| 943 } |
| 944 } |
| 945 |
895 TEST_CASE(IntegerFitsIntoInt64) { | 946 TEST_CASE(IntegerFitsIntoInt64) { |
896 Dart_Handle max = Dart_NewInteger(kMaxInt64); | 947 Dart_Handle max = Dart_NewInteger(kMaxInt64); |
897 EXPECT(Dart_IsInteger(max)); | 948 EXPECT(Dart_IsInteger(max)); |
898 bool fits = false; | 949 bool fits = false; |
899 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); | 950 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); |
900 EXPECT_VALID(result); | 951 EXPECT_VALID(result); |
901 EXPECT(fits); | 952 EXPECT(fits); |
902 | 953 |
903 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); | 954 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); |
904 if (FLAG_limit_ints_to_64_bits) { | 955 if (FLAG_limit_ints_to_64_bits) { |
(...skipping 8725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9630 EXPECT_VALID(result); | 9681 EXPECT_VALID(result); |
9631 result = Dart_FinalizeLoading(false); | 9682 result = Dart_FinalizeLoading(false); |
9632 EXPECT_VALID(result); | 9683 EXPECT_VALID(result); |
9633 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9684 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
9634 EXPECT(Dart_IsError(result)); | 9685 EXPECT(Dart_IsError(result)); |
9635 } | 9686 } |
9636 | 9687 |
9637 #endif // !PRODUCT | 9688 #endif // !PRODUCT |
9638 | 9689 |
9639 } // namespace dart | 9690 } // namespace dart |
OLD | NEW |