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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 15689013: - Modify dart_api.h to be a proper C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_api_message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "bin/builtin.h" 6 #include "bin/builtin.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/json.h" 8 #include "platform/json.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 EXPECT(Dart_IsError(result)); 793 EXPECT(Dart_IsError(result));
794 EXPECT(Dart_IsUnhandledExceptionError(result)); 794 EXPECT(Dart_IsUnhandledExceptionError(result));
795 795
796 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42)); 796 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42));
797 EXPECT(Dart_IsError(result)); 797 EXPECT(Dart_IsError(result));
798 EXPECT(Dart_IsUnhandledExceptionError(result)); 798 EXPECT(Dart_IsUnhandledExceptionError(result));
799 } 799 }
800 800
801 801
802 TEST_CASE(TypedDataAccess) { 802 TEST_CASE(TypedDataAccess) {
803 EXPECT_EQ(kInvalid, Dart_GetTypeOfTypedData(Dart_True())); 803 EXPECT_EQ(Dart_TypedData_kInvalid,
804 EXPECT_EQ(kInvalid, Dart_GetTypeOfExternalTypedData(Dart_False())); 804 Dart_GetTypeOfTypedData(Dart_True()));
805 Dart_Handle byte_array1 = Dart_NewTypedData(kUint8, 10); 805 EXPECT_EQ(Dart_TypedData_kInvalid,
806 Dart_GetTypeOfExternalTypedData(Dart_False()));
807 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10);
806 EXPECT_VALID(byte_array1); 808 EXPECT_VALID(byte_array1);
807 EXPECT_EQ(kUint8, Dart_GetTypeOfTypedData(byte_array1)); 809 EXPECT_EQ(Dart_TypedData_kUint8,
808 EXPECT_EQ(kInvalid, Dart_GetTypeOfExternalTypedData(byte_array1)); 810 Dart_GetTypeOfTypedData(byte_array1));
811 EXPECT_EQ(Dart_TypedData_kInvalid,
812 Dart_GetTypeOfExternalTypedData(byte_array1));
809 EXPECT(Dart_IsList(byte_array1)); 813 EXPECT(Dart_IsList(byte_array1));
810 814
811 intptr_t length = 0; 815 intptr_t length = 0;
812 Dart_Handle result = Dart_ListLength(byte_array1, &length); 816 Dart_Handle result = Dart_ListLength(byte_array1, &length);
813 EXPECT_VALID(result); 817 EXPECT_VALID(result);
814 EXPECT_EQ(10, length); 818 EXPECT_EQ(10, length);
815 819
816 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); 820 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1));
817 EXPECT(Dart_IsError(result)); 821 EXPECT(Dart_IsError(result));
818 822
819 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); 823 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1));
820 EXPECT(Dart_IsError(result)); 824 EXPECT(Dart_IsError(result));
821 825
822 // Set through the List API. 826 // Set through the List API.
823 for (intptr_t i = 0; i < 10; ++i) { 827 for (intptr_t i = 0; i < 10; ++i) {
824 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); 828 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1)));
825 } 829 }
826 for (intptr_t i = 0; i < 10; ++i) { 830 for (intptr_t i = 0; i < 10; ++i) {
827 // Get through the List API. 831 // Get through the List API.
828 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); 832 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i);
829 EXPECT_VALID(integer_obj); 833 EXPECT_VALID(integer_obj);
830 int64_t int64_t_value = -1; 834 int64_t int64_t_value = -1;
831 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); 835 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value));
832 EXPECT_EQ(i + 1, int64_t_value); 836 EXPECT_EQ(i + 1, int64_t_value);
833 } 837 }
834 838
835 Dart_Handle byte_array2 = Dart_NewTypedData(kUint8, 10); 839 Dart_Handle byte_array2 = Dart_NewTypedData(Dart_TypedData_kUint8, 10);
836 bool is_equal = false; 840 bool is_equal = false;
837 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); 841 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal);
838 EXPECT(!is_equal); 842 EXPECT(!is_equal);
839 843
840 // Set through the List API. 844 // Set through the List API.
841 for (intptr_t i = 0; i < 10; ++i) { 845 for (intptr_t i = 0; i < 10; ++i) {
842 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2)); 846 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2));
843 EXPECT_VALID(result); 847 EXPECT_VALID(result);
844 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); 848 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2));
845 EXPECT_VALID(result); 849 EXPECT_VALID(result);
(...skipping 19 matching lines...) Expand all
865 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); 869 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value));
866 EXPECT_EQ(10 - i, int64_t_value); 870 EXPECT_EQ(10 - i, int64_t_value);
867 } 871 }
868 } 872 }
869 873
870 874
871 static int kLength = 16; 875 static int kLength = 16;
872 876
873 static void ByteDataNativeFunction(Dart_NativeArguments args) { 877 static void ByteDataNativeFunction(Dart_NativeArguments args) {
874 Dart_EnterScope(); 878 Dart_EnterScope();
875 Dart_Handle byte_data = Dart_NewTypedData(kByteData, kLength); 879 Dart_Handle byte_data = Dart_NewTypedData(Dart_TypedData_kByteData, kLength);
876 EXPECT_VALID(byte_data); 880 EXPECT_VALID(byte_data);
877 EXPECT_EQ(kByteData, Dart_GetTypeOfTypedData(byte_data)); 881 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data));
878 Dart_SetReturnValue(args, byte_data); 882 Dart_SetReturnValue(args, byte_data);
879 Dart_ExitScope(); 883 Dart_ExitScope();
880 } 884 }
881 885
882 886
883 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name, 887 static Dart_NativeFunction ByteDataNativeResolver(Dart_Handle name,
884 int arg_count) { 888 int arg_count) {
885 return &ByteDataNativeFunction; 889 return &ByteDataNativeFunction;
886 } 890 }
887 891
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 926
923 927
924 static const intptr_t kExtLength = 16; 928 static const intptr_t kExtLength = 16;
925 static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42, 929 static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42,
926 0x41, 0x42, 0x41, 0x42, 930 0x41, 0x42, 0x41, 0x42,
927 0x41, 0x42, 0x41, 0x42, 931 0x41, 0x42, 0x41, 0x42,
928 0x41, 0x42, 0x41, 0x42, }; 932 0x41, 0x42, 0x41, 0x42, };
929 933
930 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) { 934 static void ExternalByteDataNativeFunction(Dart_NativeArguments args) {
931 Dart_EnterScope(); 935 Dart_EnterScope();
932 Dart_Handle external_byte_data = Dart_NewExternalTypedData(kByteData, 936 Dart_Handle external_byte_data = Dart_NewExternalTypedData(
933 data, 937 Dart_TypedData_kByteData, data, 16);
934 16);
935 EXPECT_VALID(external_byte_data); 938 EXPECT_VALID(external_byte_data);
936 EXPECT_EQ(kByteData, Dart_GetTypeOfTypedData(external_byte_data)); 939 EXPECT_EQ(Dart_TypedData_kByteData,
940 Dart_GetTypeOfTypedData(external_byte_data));
937 Dart_SetReturnValue(args, external_byte_data); 941 Dart_SetReturnValue(args, external_byte_data);
938 Dart_ExitScope(); 942 Dart_ExitScope();
939 } 943 }
940 944
941 945
942 static Dart_NativeFunction ExternalByteDataNativeResolver(Dart_Handle name, 946 static Dart_NativeFunction ExternalByteDataNativeResolver(Dart_Handle name,
943 int arg_count) { 947 int arg_count) {
944 return &ExternalByteDataNativeFunction; 948 return &ExternalByteDataNativeFunction;
945 } 949 }
946 950
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 991
988 for (intptr_t i = 0; i < kExtLength; i+=2) { 992 for (intptr_t i = 0; i < kExtLength; i+=2) {
989 EXPECT_EQ(0x24, data[i]); 993 EXPECT_EQ(0x24, data[i]);
990 EXPECT_EQ(0x28, data[i+1]); 994 EXPECT_EQ(0x28, data[i+1]);
991 } 995 }
992 } 996 }
993 997
994 998
995 TEST_CASE(TypedDataDirectAccess) { 999 TEST_CASE(TypedDataDirectAccess) {
996 Dart_Handle str = Dart_NewStringFromCString("junk"); 1000 Dart_Handle str = Dart_NewStringFromCString("junk");
997 Dart_Handle byte_array = Dart_NewTypedData(kUint8, 10); 1001 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10);
998 EXPECT_VALID(byte_array); 1002 EXPECT_VALID(byte_array);
999 Dart_Handle result; 1003 Dart_Handle result;
1000 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL); 1004 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL);
1001 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'type'" 1005 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'type'"
1002 " to be non-null."); 1006 " to be non-null.");
1003 Dart_TypedData_Type type; 1007 Dart_TypedData_Type type;
1004 result = Dart_TypedDataAcquireData(byte_array, &type, NULL, NULL); 1008 result = Dart_TypedDataAcquireData(byte_array, &type, NULL, NULL);
1005 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'data'" 1009 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'data'"
1006 " to be non-null."); 1010 " to be non-null.");
1007 void* data; 1011 void* data;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 " var a = new Int8List(10);" 1095 " var a = new Int8List(10);"
1092 " return a;" 1096 " return a;"
1093 "}\n"; 1097 "}\n";
1094 // Create a test library and Load up a test script in it. 1098 // Create a test library and Load up a test script in it.
1095 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1099 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1096 1100
1097 // Test with an regular typed data object. 1101 // Test with an regular typed data object.
1098 Dart_Handle list_access_test_obj; 1102 Dart_Handle list_access_test_obj;
1099 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); 1103 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
1100 EXPECT_VALID(list_access_test_obj); 1104 EXPECT_VALID(list_access_test_obj);
1101 TestDirectAccess(lib, list_access_test_obj, kInt8); 1105 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8);
1102 1106
1103 // Test with an external typed data object. 1107 // Test with an external typed data object.
1104 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1108 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1105 intptr_t data_length = ARRAY_SIZE(data); 1109 intptr_t data_length = ARRAY_SIZE(data);
1106 Dart_Handle ext_list_access_test_obj; 1110 Dart_Handle ext_list_access_test_obj;
1107 ext_list_access_test_obj = Dart_NewExternalTypedData(kUint8, 1111 ext_list_access_test_obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8,
1108 data, data_length); 1112 data, data_length);
1109 EXPECT_VALID(ext_list_access_test_obj); 1113 EXPECT_VALID(ext_list_access_test_obj);
1110 TestDirectAccess(lib, ext_list_access_test_obj, kUint8); 1114 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8);
1111 } 1115 }
1112 1116
1113 1117
1114 TEST_CASE(TypedDataViewDirectAccess) { 1118 TEST_CASE(TypedDataViewDirectAccess) {
1115 const char* kScriptChars = 1119 const char* kScriptChars =
1116 "import 'dart:typed_data';\n" 1120 "import 'dart:typed_data';\n"
1117 "class Expect {\n" 1121 "class Expect {\n"
1118 " static equals(a, b) {\n" 1122 " static equals(a, b) {\n"
1119 " if (a != b) {\n" 1123 " if (a != b) {\n"
1120 " throw 'not equal. expected: $a, got: $b';\n" 1124 " throw 'not equal. expected: $a, got: $b';\n"
(...skipping 18 matching lines...) Expand all
1139 " var view = new Int8List.view(a.buffer, 50, 10);" 1143 " var view = new Int8List.view(a.buffer, 50, 10);"
1140 " return view;" 1144 " return view;"
1141 "}\n"; 1145 "}\n";
1142 // Create a test library and Load up a test script in it. 1146 // Create a test library and Load up a test script in it.
1143 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1147 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1144 1148
1145 // Test with a typed data view object. 1149 // Test with a typed data view object.
1146 Dart_Handle list_access_test_obj; 1150 Dart_Handle list_access_test_obj;
1147 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); 1151 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
1148 EXPECT_VALID(list_access_test_obj); 1152 EXPECT_VALID(list_access_test_obj);
1149 TestDirectAccess(lib, list_access_test_obj, kInt8); 1153 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8);
1150 } 1154 }
1151 1155
1152 1156
1153 TEST_CASE(ByteDataDirectAccess) { 1157 TEST_CASE(ByteDataDirectAccess) {
1154 const char* kScriptChars = 1158 const char* kScriptChars =
1155 "import 'dart:typed_data';\n" 1159 "import 'dart:typed_data';\n"
1156 "class Expect {\n" 1160 "class Expect {\n"
1157 " static equals(a, b) {\n" 1161 " static equals(a, b) {\n"
1158 " if (a != b) {\n" 1162 " if (a != b) {\n"
1159 " throw 'not equal. expected: $a, got: $b';\n" 1163 " throw 'not equal. expected: $a, got: $b';\n"
(...skipping 18 matching lines...) Expand all
1178 " var view = new ByteData.view(a.buffer, 50, 10);" 1182 " var view = new ByteData.view(a.buffer, 50, 10);"
1179 " return view;" 1183 " return view;"
1180 "}\n"; 1184 "}\n";
1181 // Create a test library and Load up a test script in it. 1185 // Create a test library and Load up a test script in it.
1182 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1186 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1183 1187
1184 // Test with a typed data view object. 1188 // Test with a typed data view object.
1185 Dart_Handle list_access_test_obj; 1189 Dart_Handle list_access_test_obj;
1186 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); 1190 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
1187 EXPECT_VALID(list_access_test_obj); 1191 EXPECT_VALID(list_access_test_obj);
1188 TestDirectAccess(lib, list_access_test_obj, kByteData); 1192 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData);
1189 } 1193 }
1190 1194
1191 1195
1192 static void ExternalTypedDataAccessTests(Dart_Handle obj, 1196 static void ExternalTypedDataAccessTests(Dart_Handle obj,
1193 Dart_TypedData_Type expected_type, 1197 Dart_TypedData_Type expected_type,
1194 uint8_t data[], 1198 uint8_t data[],
1195 intptr_t data_length) { 1199 intptr_t data_length) {
1196 EXPECT_VALID(obj); 1200 EXPECT_VALID(obj);
1197 EXPECT_EQ(expected_type, Dart_GetTypeOfExternalTypedData(obj)); 1201 EXPECT_EQ(expected_type, Dart_GetTypeOfExternalTypedData(obj));
1198 EXPECT(Dart_IsList(obj)); 1202 EXPECT(Dart_IsList(obj));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 for (intptr_t i = 0; i < data_length; ++i) { 1247 for (intptr_t i = 0; i < data_length; ++i) {
1244 EXPECT_EQ(33 * i, data[i]); 1248 EXPECT_EQ(33 * i, data[i]);
1245 } 1249 }
1246 } 1250 }
1247 1251
1248 1252
1249 TEST_CASE(ExternalTypedDataAccess) { 1253 TEST_CASE(ExternalTypedDataAccess) {
1250 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1254 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1251 intptr_t data_length = ARRAY_SIZE(data); 1255 intptr_t data_length = ARRAY_SIZE(data);
1252 1256
1253 Dart_Handle obj = Dart_NewExternalTypedData(kUint8, data, data_length); 1257 Dart_Handle obj = Dart_NewExternalTypedData(
1254 ExternalTypedDataAccessTests(obj, kUint8, data, data_length); 1258 Dart_TypedData_kUint8, data, data_length);
1259 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8, data, data_length);
1255 } 1260 }
1256 1261
1257 1262
1258 TEST_CASE(ExternalClampedTypedDataAccess) { 1263 TEST_CASE(ExternalClampedTypedDataAccess) {
1259 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1264 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1260 intptr_t data_length = ARRAY_SIZE(data); 1265 intptr_t data_length = ARRAY_SIZE(data);
1261 1266
1262 Dart_Handle obj = Dart_NewExternalTypedData(kUint8Clamped, data, data_length); 1267 Dart_Handle obj = Dart_NewExternalTypedData(
1263 ExternalTypedDataAccessTests(obj, kUint8Clamped, data, data_length); 1268 Dart_TypedData_kUint8Clamped, data, data_length);
1269 ExternalTypedDataAccessTests(obj, Dart_TypedData_kUint8Clamped,
1270 data, data_length);
1264 } 1271 }
1265 1272
1266 1273
1267 TEST_CASE(ExternalUint8ClampedArrayAccess) { 1274 TEST_CASE(ExternalUint8ClampedArrayAccess) {
1268 const char* kScriptChars = 1275 const char* kScriptChars =
1269 "testClamped(List a) {\n" 1276 "testClamped(List a) {\n"
1270 " if (a[1] != 11) return false;\n" 1277 " if (a[1] != 11) return false;\n"
1271 " a[1] = 3;\n" 1278 " a[1] = 3;\n"
1272 " if (a[1] != 3) return false;\n" 1279 " if (a[1] != 3) return false;\n"
1273 " a[1] = -12;\n" 1280 " a[1] = -12;\n"
1274 " if (a[1] != 0) return false;\n" 1281 " if (a[1] != 0) return false;\n"
1275 " a[1] = 1200;\n" 1282 " a[1] = 1200;\n"
1276 " if (a[1] != 255) return false;\n" 1283 " if (a[1] != 255) return false;\n"
1277 " return true;\n" 1284 " return true;\n"
1278 "}\n"; 1285 "}\n";
1279 1286
1280 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1287 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1281 intptr_t data_length = ARRAY_SIZE(data); 1288 intptr_t data_length = ARRAY_SIZE(data);
1282 Dart_Handle obj = Dart_NewExternalTypedData(kUint8Clamped, 1289 Dart_Handle obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8Clamped,
1283 data, data_length); 1290 data, data_length);
1284 EXPECT_VALID(obj); 1291 EXPECT_VALID(obj);
1285 Dart_Handle result; 1292 Dart_Handle result;
1286 // Create a test library and Load up a test script in it. 1293 // Create a test library and Load up a test script in it.
1287 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1294 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1288 Dart_Handle args[1]; 1295 Dart_Handle args[1];
1289 args[0] = obj; 1296 args[0] = obj;
1290 result = Dart_Invoke(lib, NewString("testClamped"), 1, args); 1297 result = Dart_Invoke(lib, NewString("testClamped"), 1, args);
1291 1298
1292 // Check that result is true. 1299 // Check that result is true.
(...skipping 12 matching lines...) Expand all
1305 *static_cast<int*>(peer) = 42; 1312 *static_cast<int*>(peer) = 42;
1306 } 1313 }
1307 1314
1308 1315
1309 TEST_CASE(ExternalTypedDataCallback) { 1316 TEST_CASE(ExternalTypedDataCallback) {
1310 int peer = 0; 1317 int peer = 0;
1311 { 1318 {
1312 Dart_EnterScope(); 1319 Dart_EnterScope();
1313 uint8_t data[] = { 1, 2, 3, 4 }; 1320 uint8_t data[] = { 1, 2, 3, 4 };
1314 Dart_Handle obj = Dart_NewExternalTypedData( 1321 Dart_Handle obj = Dart_NewExternalTypedData(
1315 kUint8, 1322 Dart_TypedData_kUint8,
1316 data, 1323 data,
1317 ARRAY_SIZE(data)); 1324 ARRAY_SIZE(data));
1318 Dart_NewWeakPersistentHandle(obj, &peer, ExternalTypedDataFinalizer); 1325 Dart_NewWeakPersistentHandle(obj, &peer, ExternalTypedDataFinalizer);
1319 EXPECT_VALID(obj); 1326 EXPECT_VALID(obj);
1320 Dart_ExitScope(); 1327 Dart_ExitScope();
1321 } 1328 }
1322 EXPECT(peer == 0); 1329 EXPECT(peer == 0);
1323 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 1330 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1324 EXPECT(peer == 0); 1331 EXPECT(peer == 0);
1325 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 1332 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
1326 EXPECT(peer == 42); 1333 EXPECT(peer == 42);
1327 } 1334 }
1328 1335
1329 1336
1330 static void CheckFloat32x4Data(Dart_Handle obj) { 1337 static void CheckFloat32x4Data(Dart_Handle obj) {
1331 void* raw_data = NULL; 1338 void* raw_data = NULL;
1332 intptr_t len; 1339 intptr_t len;
1333 Dart_TypedData_Type type; 1340 Dart_TypedData_Type type;
1334 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); 1341 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len));
1335 EXPECT_EQ(kFloat32x4, type); 1342 EXPECT_EQ(Dart_TypedData_kFloat32x4, type);
1336 EXPECT_EQ(len, 10); 1343 EXPECT_EQ(len, 10);
1337 float* float_data = reinterpret_cast<float*>(raw_data); 1344 float* float_data = reinterpret_cast<float*>(raw_data);
1338 for (int i = 0; i < len * 4; i++) { 1345 for (int i = 0; i < len * 4; i++) {
1339 EXPECT_EQ(0.0, float_data[i]); 1346 EXPECT_EQ(0.0, float_data[i]);
1340 } 1347 }
1341 EXPECT_VALID(Dart_TypedDataReleaseData(obj)); 1348 EXPECT_VALID(Dart_TypedDataReleaseData(obj));
1342 } 1349 }
1343 1350
1344 1351
1345 TEST_CASE(Float32x4List) { 1352 TEST_CASE(Float32x4List) {
1346 const char* kScriptChars = 1353 const char* kScriptChars =
1347 "import 'dart:typed_data';\n" 1354 "import 'dart:typed_data';\n"
1348 "Float32x4List float32x4() {\n" 1355 "Float32x4List float32x4() {\n"
1349 " return new Float32x4List(10);\n" 1356 " return new Float32x4List(10);\n"
1350 "}\n"; 1357 "}\n";
1351 // Create a test library and Load up a test script in it. 1358 // Create a test library and Load up a test script in it.
1352 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1359 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1353 1360
1354 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL); 1361 Dart_Handle obj = Dart_Invoke(lib, NewString("float32x4"), 0, NULL);
1355 EXPECT_VALID(obj); 1362 EXPECT_VALID(obj);
1356 CheckFloat32x4Data(obj); 1363 CheckFloat32x4Data(obj);
1357 1364
1358 obj = Dart_NewTypedData(kFloat32x4, 10); 1365 obj = Dart_NewTypedData(Dart_TypedData_kFloat32x4, 10);
1359 EXPECT_VALID(obj); 1366 EXPECT_VALID(obj);
1360 CheckFloat32x4Data(obj); 1367 CheckFloat32x4Data(obj);
1361 1368
1362 int peer = 0; 1369 int peer = 0;
1363 float data[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1370 float data[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1364 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1371 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1365 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1372 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1366 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; 1373 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1367 // Push a scope so that we can collect the local handle created as part of 1374 // Push a scope so that we can collect the local handle created as part of
1368 // Dart_NewExternalTypedData. 1375 // Dart_NewExternalTypedData.
1369 Dart_EnterScope(); 1376 Dart_EnterScope();
1370 { 1377 {
1371 Dart_Handle lcl = Dart_NewExternalTypedData(kFloat32x4, data, 10); 1378 Dart_Handle lcl = Dart_NewExternalTypedData(
1379 Dart_TypedData_kFloat32x4, data, 10);
1372 Dart_NewWeakPersistentHandle(lcl, &peer, ExternalTypedDataFinalizer); 1380 Dart_NewWeakPersistentHandle(lcl, &peer, ExternalTypedDataFinalizer);
1373 CheckFloat32x4Data(lcl); 1381 CheckFloat32x4Data(lcl);
1374 } 1382 }
1375 Dart_ExitScope(); 1383 Dart_ExitScope();
1376 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 1384 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
1377 EXPECT(peer == 42); 1385 EXPECT(peer == 42);
1378 } 1386 }
1379 1387
1380 1388
1381 // Unit test for entering a scope, creating a local handle and exiting 1389 // Unit test for entering a scope, creating a local handle and exiting
(...skipping 3879 matching lines...) Expand 10 before | Expand all | Expand 10 after
5261 5269
5262 // Check that error is returned if null is passed as a class argument. 5270 // Check that error is returned if null is passed as a class argument.
5263 result = Dart_ObjectIsType(null, null, &is_instance); 5271 result = Dart_ObjectIsType(null, null, &is_instance);
5264 EXPECT(Dart_IsError(result)); 5272 EXPECT(Dart_IsError(result));
5265 } 5273 }
5266 5274
5267 5275
5268 static Dart_Handle library_handler(Dart_LibraryTag tag, 5276 static Dart_Handle library_handler(Dart_LibraryTag tag,
5269 Dart_Handle library, 5277 Dart_Handle library,
5270 Dart_Handle url) { 5278 Dart_Handle url) {
5271 if (tag == kCanonicalizeUrl) { 5279 if (tag == Dart_kCanonicalizeUrl) {
5272 return url; 5280 return url;
5273 } 5281 }
5274 return Api::Success(); 5282 return Api::Success();
5275 } 5283 }
5276 5284
5277 5285
5278 TEST_CASE(LoadScript) { 5286 TEST_CASE(LoadScript) {
5279 const char* kScriptChars = 5287 const char* kScriptChars =
5280 "main() {" 5288 "main() {"
5281 " return 12345;" 5289 " return 12345;"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5361 EXPECT_STREQ(TestCase::url(), name_cstr); 5369 EXPECT_STREQ(TestCase::url(), name_cstr);
5362 } 5370 }
5363 5371
5364 5372
5365 static int index = 0; 5373 static int index = 0;
5366 5374
5367 5375
5368 static Dart_Handle import_library_handler(Dart_LibraryTag tag, 5376 static Dart_Handle import_library_handler(Dart_LibraryTag tag,
5369 Dart_Handle library, 5377 Dart_Handle library,
5370 Dart_Handle url) { 5378 Dart_Handle url) {
5371 if (tag == kCanonicalizeUrl) { 5379 if (tag == Dart_kCanonicalizeUrl) {
5372 return url; 5380 return url;
5373 } 5381 }
5374 EXPECT(Dart_IsString(url)); 5382 EXPECT(Dart_IsString(url));
5375 const char* cstr = NULL; 5383 const char* cstr = NULL;
5376 EXPECT_VALID(Dart_StringToCString(url, &cstr)); 5384 EXPECT_VALID(Dart_StringToCString(url, &cstr));
5377 switch (index) { 5385 switch (index) {
5378 case 0: 5386 case 0:
5379 EXPECT_STREQ("./weird.dart", cstr); 5387 EXPECT_STREQ("./weird.dart", cstr);
5380 break; 5388 break;
5381 case 1: 5389 case 1:
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
6420 result = Dart_Invoke(result, NewString("main"), 0, NULL); 6428 result = Dart_Invoke(result, NewString("main"), 0, NULL);
6421 EXPECT_VALID(result); 6429 EXPECT_VALID(result);
6422 } 6430 }
6423 6431
6424 6432
6425 void NewNativePort_send123(Dart_Port dest_port_id, 6433 void NewNativePort_send123(Dart_Port dest_port_id,
6426 Dart_Port reply_port_id, 6434 Dart_Port reply_port_id,
6427 Dart_CObject *message) { 6435 Dart_CObject *message) {
6428 // Gets a null message. 6436 // Gets a null message.
6429 EXPECT_NOTNULL(message); 6437 EXPECT_NOTNULL(message);
6430 EXPECT_EQ(Dart_CObject::kNull, message->type); 6438 EXPECT_EQ(Dart_CObject_kNull, message->type);
6431 6439
6432 // Post integer value. 6440 // Post integer value.
6433 Dart_CObject* response = 6441 Dart_CObject* response =
6434 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); 6442 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject)));
6435 response->type = Dart_CObject::kInt32; 6443 response->type = Dart_CObject_kInt32;
6436 response->value.as_int32 = 123; 6444 response->value.as_int32 = 123;
6437 Dart_PostCObject(reply_port_id, response); 6445 Dart_PostCObject(reply_port_id, response);
6438 } 6446 }
6439 6447
6440 6448
6441 void NewNativePort_send321(Dart_Port dest_port_id, 6449 void NewNativePort_send321(Dart_Port dest_port_id,
6442 Dart_Port reply_port_id, 6450 Dart_Port reply_port_id,
6443 Dart_CObject* message) { 6451 Dart_CObject* message) {
6444 // Gets a null message. 6452 // Gets a null message.
6445 EXPECT_NOTNULL(message); 6453 EXPECT_NOTNULL(message);
6446 EXPECT_EQ(Dart_CObject::kNull, message->type); 6454 EXPECT_EQ(Dart_CObject_kNull, message->type);
6447 6455
6448 // Post integer value. 6456 // Post integer value.
6449 Dart_CObject* response = 6457 Dart_CObject* response =
6450 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); 6458 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject)));
6451 response->type = Dart_CObject::kInt32; 6459 response->type = Dart_CObject_kInt32;
6452 response->value.as_int32 = 321; 6460 response->value.as_int32 = 321;
6453 Dart_PostCObject(reply_port_id, response); 6461 Dart_PostCObject(reply_port_id, response);
6454 } 6462 }
6455 6463
6456 6464
6457 UNIT_TEST_CASE(NewNativePort) { 6465 UNIT_TEST_CASE(NewNativePort) {
6458 // Create a port with a bogus handler. 6466 // Create a port with a bogus handler.
6459 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); 6467 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true);
6460 EXPECT_EQ(ILLEGAL_PORT, error_port); 6468 EXPECT_EQ(ILLEGAL_PORT, error_port);
6461 6469
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
7883 NewString("main"), 7891 NewString("main"),
7884 0, 7892 0,
7885 NULL); 7893 NULL);
7886 int64_t value = 0; 7894 int64_t value = 0;
7887 result = Dart_IntegerToInt64(result, &value); 7895 result = Dart_IntegerToInt64(result, &value);
7888 EXPECT_VALID(result); 7896 EXPECT_VALID(result);
7889 EXPECT_EQ(8, value); 7897 EXPECT_EQ(8, value);
7890 } 7898 }
7891 7899
7892 } // namespace dart 7900 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_api_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698