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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 | 899 |
900 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, | 900 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, |
901 int arg_count) { | 901 int arg_count) { |
902 return &ByteDataNativeFunction; | 902 return &ByteDataNativeFunction; |
903 } | 903 } |
904 | 904 |
905 | 905 |
906 TEST_CASE(ByteDataAccess) { | 906 TEST_CASE(ByteDataAccess) { |
907 const char* kScriptChars = | 907 const char* kScriptChars = |
908 "import 'dart:typeddata';\n" | 908 "import 'dart:typeddata';\n" |
| 909 "class Expect {\n" |
| 910 " static equals(a, b) {\n" |
| 911 " if (a != b) {\n" |
| 912 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 913 " }\n" |
| 914 " }\n" |
| 915 "}\n" |
909 "ByteData createByteData() native 'CreateByteData';" | 916 "ByteData createByteData() native 'CreateByteData';" |
910 "ByteData main() {" | 917 "ByteData main() {" |
911 " var length = 16;" | 918 " var length = 16;" |
912 " var a = createByteData();" | 919 " var a = createByteData();" |
913 " Expect.equals(length, a.lengthInBytes);" | 920 " Expect.equals(length, a.lengthInBytes);" |
914 " for (int i = 0; i < length; i+=1) {" | 921 " for (int i = 0; i < length; i+=1) {" |
915 " a.setInt8(i, 0x42);" | 922 " a.setInt8(i, 0x42);" |
916 " }" | 923 " }" |
917 " for (int i = 0; i < length; i+=2) {" | 924 " for (int i = 0; i < length; i+=2) {" |
918 " Expect.equals(0x4242, a.getInt16(i));" | 925 " Expect.equals(0x4242, a.getInt16(i));" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 int arg_count) { | 961 int arg_count) { |
955 return &ExternalByteDataNativeFunction; | 962 return &ExternalByteDataNativeFunction; |
956 } | 963 } |
957 | 964 |
958 | 965 |
959 TEST_CASE(ExternalByteDataAccess) { | 966 TEST_CASE(ExternalByteDataAccess) { |
960 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the | 967 // TODO(asiva): Once we have getInt16LE and getInt16BE support use the |
961 // appropriate getter instead of the host endian format used now. | 968 // appropriate getter instead of the host endian format used now. |
962 const char* kScriptChars = | 969 const char* kScriptChars = |
963 "import 'dart:typeddata';\n" | 970 "import 'dart:typeddata';\n" |
| 971 "class Expect {\n" |
| 972 " static equals(a, b) {\n" |
| 973 " if (a != b) {\n" |
| 974 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 975 " }\n" |
| 976 " }\n" |
| 977 "}\n" |
964 "ByteData createExternalByteData() native 'CreateExternalByteData';" | 978 "ByteData createExternalByteData() native 'CreateExternalByteData';" |
965 "ByteData main() {" | 979 "ByteData main() {" |
966 " var length = 16;" | 980 " var length = 16;" |
967 " var a = createExternalByteData();" | 981 " var a = createExternalByteData();" |
968 " Expect.equals(length, a.lengthInBytes);" | 982 " Expect.equals(length, a.lengthInBytes);" |
969 " for (int i = 0; i < length; i+=2) {" | 983 " for (int i = 0; i < length; i+=2) {" |
970 " Expect.equals(0x4241, a.getInt16(i));" | 984 " Expect.equals(0x4241, a.getInt16(i));" |
971 " }" | 985 " }" |
972 " for (int i = 0; i < length; i+=2) {" | 986 " for (int i = 0; i < length; i+=2) {" |
973 " a.setInt8(i, 0x24);" | 987 " a.setInt8(i, 0x24);" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 | 1080 |
1067 // Invoke the dart function in order to check the modified values. | 1081 // Invoke the dart function in order to check the modified values. |
1068 result = Dart_Invoke(lib, NewString("testMain"), 1, dart_args); | 1082 result = Dart_Invoke(lib, NewString("testMain"), 1, dart_args); |
1069 EXPECT_VALID(result); | 1083 EXPECT_VALID(result); |
1070 } | 1084 } |
1071 | 1085 |
1072 | 1086 |
1073 TEST_CASE(TypedDataDirectAccess1) { | 1087 TEST_CASE(TypedDataDirectAccess1) { |
1074 const char* kScriptChars = | 1088 const char* kScriptChars = |
1075 "import 'dart:typeddata';\n" | 1089 "import 'dart:typeddata';\n" |
| 1090 "class Expect {\n" |
| 1091 " static equals(a, b) {\n" |
| 1092 " if (a != b) {\n" |
| 1093 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 1094 " }\n" |
| 1095 " }\n" |
| 1096 "}\n" |
1076 "void setMain(var a) {" | 1097 "void setMain(var a) {" |
1077 " for (var i = 0; i < 10; i++) {" | 1098 " for (var i = 0; i < 10; i++) {" |
1078 " a[i] = i;" | 1099 " a[i] = i;" |
1079 " }" | 1100 " }" |
1080 "}\n" | 1101 "}\n" |
1081 "bool testMain(var list) {" | 1102 "bool testMain(var list) {" |
1082 " for (var i = 0; i < 10; i++) {" | 1103 " for (var i = 0; i < 10; i++) {" |
1083 " Expect.equals((10 + i), list[i]);" | 1104 " Expect.equals((10 + i), list[i]);" |
1084 " }\n" | 1105 " }\n" |
1085 " return true;" | 1106 " return true;" |
(...skipping 20 matching lines...) Expand all Loading... |
1106 data_length, | 1127 data_length, |
1107 NULL, NULL); | 1128 NULL, NULL); |
1108 EXPECT_VALID(ext_list_access_test_obj); | 1129 EXPECT_VALID(ext_list_access_test_obj); |
1109 TestDirectAccess(lib, ext_list_access_test_obj, kUint8); | 1130 TestDirectAccess(lib, ext_list_access_test_obj, kUint8); |
1110 } | 1131 } |
1111 | 1132 |
1112 | 1133 |
1113 TEST_CASE(TypedDataViewDirectAccess) { | 1134 TEST_CASE(TypedDataViewDirectAccess) { |
1114 const char* kScriptChars = | 1135 const char* kScriptChars = |
1115 "import 'dart:typeddata';\n" | 1136 "import 'dart:typeddata';\n" |
| 1137 "class Expect {\n" |
| 1138 " static equals(a, b) {\n" |
| 1139 " if (a != b) {\n" |
| 1140 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 1141 " }\n" |
| 1142 " }\n" |
| 1143 "}\n" |
1116 "void setMain(var list) {" | 1144 "void setMain(var list) {" |
1117 " Expect.equals(10, list.length);" | 1145 " Expect.equals(10, list.length);" |
1118 " for (var i = 0; i < 10; i++) {" | 1146 " for (var i = 0; i < 10; i++) {" |
1119 " list[i] = i;" | 1147 " list[i] = i;" |
1120 " }" | 1148 " }" |
1121 "}\n" | 1149 "}\n" |
1122 "bool testMain(var list) {" | 1150 "bool testMain(var list) {" |
1123 " Expect.equals(10, list.length);" | 1151 " Expect.equals(10, list.length);" |
1124 " for (var i = 0; i < 10; i++) {" | 1152 " for (var i = 0; i < 10; i++) {" |
1125 " Expect.equals((10 + i), list[i]);" | 1153 " Expect.equals((10 + i), list[i]);" |
(...skipping 12 matching lines...) Expand all Loading... |
1138 Dart_Handle list_access_test_obj; | 1166 Dart_Handle list_access_test_obj; |
1139 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1167 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1140 EXPECT_VALID(list_access_test_obj); | 1168 EXPECT_VALID(list_access_test_obj); |
1141 TestDirectAccess(lib, list_access_test_obj, kInt8); | 1169 TestDirectAccess(lib, list_access_test_obj, kInt8); |
1142 } | 1170 } |
1143 | 1171 |
1144 | 1172 |
1145 TEST_CASE(ByteDataDirectAccess) { | 1173 TEST_CASE(ByteDataDirectAccess) { |
1146 const char* kScriptChars = | 1174 const char* kScriptChars = |
1147 "import 'dart:typeddata';\n" | 1175 "import 'dart:typeddata';\n" |
| 1176 "class Expect {\n" |
| 1177 " static equals(a, b) {\n" |
| 1178 " if (a != b) {\n" |
| 1179 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 1180 " }\n" |
| 1181 " }\n" |
| 1182 "}\n" |
1148 "void setMain(var list) {" | 1183 "void setMain(var list) {" |
1149 " Expect.equals(10, list.length);" | 1184 " Expect.equals(10, list.length);" |
1150 " for (var i = 0; i < 10; i++) {" | 1185 " for (var i = 0; i < 10; i++) {" |
1151 " list.setInt8(i, i);" | 1186 " list.setInt8(i, i);" |
1152 " }" | 1187 " }" |
1153 "}\n" | 1188 "}\n" |
1154 "bool testMain(var list) {" | 1189 "bool testMain(var list) {" |
1155 " Expect.equals(10, list.length);" | 1190 " Expect.equals(10, list.length);" |
1156 " for (var i = 0; i < 10; i++) {" | 1191 " for (var i = 0; i < 10; i++) {" |
1157 " Expect.equals((10 + i), list.getInt8(i));" | 1192 " Expect.equals((10 + i), list.getInt8(i));" |
(...skipping 5484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6642 " int bar31(int i) { var func = foo3; return func(i); }\n" | 6677 " int bar31(int i) { var func = foo3; return func(i); }\n" |
6643 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" | 6678 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" |
6644 " int bar41(int i) {\n" | 6679 " int bar41(int i) {\n" |
6645 " var func = foo4; return func(i); }\n" | 6680 " var func = foo4; return func(i); }\n" |
6646 " int bar42(int i, int j) {\n" | 6681 " int bar42(int i, int j) {\n" |
6647 " var func = foo4; return func(i, j); }\n" | 6682 " var func = foo4; return func(i, j); }\n" |
6648 " int bar43(int i, int j, int k) {\n" | 6683 " int bar43(int i, int j, int k) {\n" |
6649 " var func = foo4; return func(i, j, k); }\n" | 6684 " var func = foo4; return func(i, j, k); }\n" |
6650 "}\n" | 6685 "}\n" |
6651 "class Expect {\n" | 6686 "class Expect {\n" |
6652 " static void equals(x, y) {\n" | 6687 " static equals(a, b) {\n" |
6653 " if (x != y) throw new Error('not equal');\n" | 6688 " if (a != b) {\n" |
| 6689 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 6690 " }\n" |
6654 " }\n" | 6691 " }\n" |
6655 "}\n" | 6692 "}\n" |
6656 "int testMain() {\n" | 6693 "int testMain() {\n" |
6657 " Test obj = new Test();\n" | 6694 " Test obj = new Test();\n" |
6658 " Expect.equals(1, obj.foo1());\n" | 6695 " Expect.equals(1, obj.foo1());\n" |
6659 " Expect.equals(1, obj.bar1());\n" | 6696 " Expect.equals(1, obj.bar1());\n" |
6660 "\n" | 6697 "\n" |
6661 " Expect.equals(10, obj.foo2(10));\n" | 6698 " Expect.equals(10, obj.foo2(10));\n" |
6662 " Expect.equals(10, obj.bar2(10));\n" | 6699 " Expect.equals(10, obj.bar2(10));\n" |
6663 "\n" | 6700 "\n" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6785 " int bar31(int i) { var func = foo3; return func(i); }\n" | 6822 " int bar31(int i) { var func = foo3; return func(i); }\n" |
6786 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" | 6823 " int bar32(int i, int j) { var func = foo3; return func(i, j); }\n" |
6787 " int bar41(int i) {\n" | 6824 " int bar41(int i) {\n" |
6788 " var func = foo4; return func(i); }\n" | 6825 " var func = foo4; return func(i); }\n" |
6789 " int bar42(int i, int j) {\n" | 6826 " int bar42(int i, int j) {\n" |
6790 " var func = foo4; return func(i, j); }\n" | 6827 " var func = foo4; return func(i, j); }\n" |
6791 " int bar43(int i, int j, int k) {\n" | 6828 " int bar43(int i, int j, int k) {\n" |
6792 " var func = foo4; return func(i, j, k); }\n" | 6829 " var func = foo4; return func(i, j, k); }\n" |
6793 "}\n" | 6830 "}\n" |
6794 "class Expect {\n" | 6831 "class Expect {\n" |
6795 " static void equals(x, y) {\n" | 6832 " static equals(a, b) {\n" |
6796 " if (x != y) throw new Error('not equal');\n" | 6833 " if (a != b) {\n" |
| 6834 " throw new Exception('not equal. expected: $a, got: $b');\n" |
| 6835 " }\n" |
6797 " }\n" | 6836 " }\n" |
6798 "}\n" | 6837 "}\n" |
6799 "int testMain() {\n" | 6838 "int testMain() {\n" |
6800 " Test obj = new Test();\n" | 6839 " Test obj = new Test();\n" |
6801 " Expect.equals(0, Test.foo1());\n" | 6840 " Expect.equals(0, Test.foo1());\n" |
6802 " Expect.equals(0, obj.bar1());\n" | 6841 " Expect.equals(0, obj.bar1());\n" |
6803 "\n" | 6842 "\n" |
6804 " Expect.equals(10, Test.foo2(10));\n" | 6843 " Expect.equals(10, Test.foo2(10));\n" |
6805 " Expect.equals(10, obj.bar2(10));\n" | 6844 " Expect.equals(10, obj.bar2(10));\n" |
6806 "\n" | 6845 "\n" |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7549 NULL); | 7588 NULL); |
7550 int64_t value = 0; | 7589 int64_t value = 0; |
7551 result = Dart_IntegerToInt64(result, &value); | 7590 result = Dart_IntegerToInt64(result, &value); |
7552 EXPECT_VALID(result); | 7591 EXPECT_VALID(result); |
7553 EXPECT_EQ(260, value); | 7592 EXPECT_EQ(260, value); |
7554 } | 7593 } |
7555 | 7594 |
7556 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7595 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7557 | 7596 |
7558 } // namespace dart | 7597 } // namespace dart |
OLD | NEW |