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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_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 "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); | 789 result = Dart_Invoke(lib, NewString("getNull"), 0, NULL); |
790 EXPECT_VALID(result); | 790 EXPECT_VALID(result); |
791 EXPECT(!Dart_IsNumber(result)); | 791 EXPECT(!Dart_IsNumber(result)); |
792 } | 792 } |
793 | 793 |
794 | 794 |
795 TEST_CASE(IntegerValues) { | 795 TEST_CASE(IntegerValues) { |
796 const int64_t kIntegerVal1 = 100; | 796 const int64_t kIntegerVal1 = 100; |
797 const int64_t kIntegerVal2 = 0xffffffff; | 797 const int64_t kIntegerVal2 = 0xffffffff; |
798 const char* kIntegerVal3 = "0x123456789123456789123456789"; | 798 const char* kIntegerVal3 = "0x123456789123456789123456789"; |
| 799 const uint64_t kIntegerVal4 = 0xffffffffffffffff; |
799 | 800 |
800 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); | 801 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); |
801 EXPECT(Dart_IsInteger(val1)); | 802 EXPECT(Dart_IsInteger(val1)); |
802 bool fits = false; | 803 bool fits = false; |
803 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); | 804 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); |
804 EXPECT_VALID(result); | 805 EXPECT_VALID(result); |
805 EXPECT(fits); | 806 EXPECT(fits); |
806 | 807 |
807 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2); | 808 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2); |
808 EXPECT(Dart_IsInteger(val2)); | 809 EXPECT(Dart_IsInteger(val2)); |
(...skipping 13 matching lines...) Expand all Loading... |
822 EXPECT_EQ(kIntegerVal1, out); | 823 EXPECT_EQ(kIntegerVal1, out); |
823 | 824 |
824 result = Dart_IntegerToInt64(val2, &out); | 825 result = Dart_IntegerToInt64(val2, &out); |
825 EXPECT_VALID(result); | 826 EXPECT_VALID(result); |
826 EXPECT_EQ(kIntegerVal2, out); | 827 EXPECT_EQ(kIntegerVal2, out); |
827 | 828 |
828 const char* chars = NULL; | 829 const char* chars = NULL; |
829 result = Dart_IntegerToHexCString(val3, &chars); | 830 result = Dart_IntegerToHexCString(val3, &chars); |
830 EXPECT_VALID(result); | 831 EXPECT_VALID(result); |
831 EXPECT(!strcmp(kIntegerVal3, chars)); | 832 EXPECT(!strcmp(kIntegerVal3, chars)); |
| 833 |
| 834 Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4); |
| 835 EXPECT_VALID(val4); |
| 836 uint64_t out4 = 0; |
| 837 result = Dart_IntegerToUint64(val4, &out4); |
| 838 EXPECT_VALID(result); |
| 839 EXPECT_EQ(kIntegerVal4, out4); |
| 840 |
| 841 Dart_Handle val5 = Dart_NewInteger(-1); |
| 842 EXPECT_VALID(val5); |
| 843 uint64_t out5 = 0; |
| 844 result = Dart_IntegerToUint64(val5, &out5); |
| 845 EXPECT(Dart_IsError(result)); |
832 } | 846 } |
833 | 847 |
834 | 848 |
835 TEST_CASE(IntegerFitsIntoInt64) { | 849 TEST_CASE(IntegerFitsIntoInt64) { |
836 Dart_Handle max = Dart_NewInteger(kMaxInt64); | 850 Dart_Handle max = Dart_NewInteger(kMaxInt64); |
837 EXPECT(Dart_IsInteger(max)); | 851 EXPECT(Dart_IsInteger(max)); |
838 bool fits = false; | 852 bool fits = false; |
839 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); | 853 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); |
840 EXPECT_VALID(result); | 854 EXPECT_VALID(result); |
841 EXPECT(fits); | 855 EXPECT(fits); |
842 | 856 |
843 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); | 857 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); |
844 EXPECT(Dart_IsInteger(above_max)); | 858 EXPECT(Dart_IsInteger(above_max)); |
845 fits = true; | 859 fits = true; |
846 result = Dart_IntegerFitsIntoInt64(above_max, &fits); | 860 result = Dart_IntegerFitsIntoInt64(above_max, &fits); |
847 EXPECT_VALID(result); | 861 EXPECT_VALID(result); |
848 EXPECT(!fits); | 862 EXPECT(!fits); |
849 | 863 |
850 Dart_Handle min = Dart_NewInteger(kMaxInt64); | 864 Dart_Handle min = Dart_NewInteger(kMinInt64); |
851 EXPECT(Dart_IsInteger(min)); | 865 EXPECT(Dart_IsInteger(min)); |
852 fits = false; | 866 fits = false; |
853 result = Dart_IntegerFitsIntoInt64(min, &fits); | 867 result = Dart_IntegerFitsIntoInt64(min, &fits); |
854 EXPECT_VALID(result); | 868 EXPECT_VALID(result); |
855 EXPECT(fits); | 869 EXPECT(fits); |
856 | 870 |
857 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); | 871 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); |
858 EXPECT(Dart_IsInteger(below_min)); | 872 EXPECT(Dart_IsInteger(below_min)); |
859 fits = true; | 873 fits = true; |
860 result = Dart_IntegerFitsIntoInt64(below_min, &fits); | 874 result = Dart_IntegerFitsIntoInt64(below_min, &fits); |
861 EXPECT_VALID(result); | 875 EXPECT_VALID(result); |
862 EXPECT(!fits); | 876 EXPECT(!fits); |
863 } | 877 } |
864 | 878 |
865 | 879 |
866 TEST_CASE(IntegerFitsIntoUint64) { | 880 TEST_CASE(IntegerFitsIntoUint64) { |
867 Dart_Handle max = Dart_NewIntegerFromHexCString("0xFFFFFFFFFFFFFFFF"); | 881 Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64); |
868 EXPECT(Dart_IsInteger(max)); | 882 EXPECT(Dart_IsInteger(max)); |
869 bool fits = false; | 883 bool fits = false; |
870 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits); | 884 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits); |
871 EXPECT_VALID(result); | 885 EXPECT_VALID(result); |
872 EXPECT(fits); | 886 EXPECT(fits); |
873 | 887 |
874 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); | 888 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); |
875 EXPECT(Dart_IsInteger(above_max)); | 889 EXPECT(Dart_IsInteger(above_max)); |
876 fits = true; | 890 fits = true; |
877 result = Dart_IntegerFitsIntoUint64(above_max, &fits); | 891 result = Dart_IntegerFitsIntoUint64(above_max, &fits); |
(...skipping 8127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9005 result = Dart_Invoke(lib, | 9019 result = Dart_Invoke(lib, |
9006 NewString("testView16"), | 9020 NewString("testView16"), |
9007 1, | 9021 1, |
9008 dart_args); | 9022 dart_args); |
9009 EXPECT_VALID(result); | 9023 EXPECT_VALID(result); |
9010 EXPECT(Dart_IsString(result)); | 9024 EXPECT(Dart_IsString(result)); |
9011 } | 9025 } |
9012 } | 9026 } |
9013 | 9027 |
9014 } // namespace dart | 9028 } // namespace dart |
OLD | NEW |