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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 12255018: Add typed data interface to Dart API, this only changes the C++ API as dicussed in a previous email… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 10 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 | « vm/dart_api_impl.cc ('k') | no next file » | 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 "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 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3); 809 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3);
810 EXPECT(Dart_IsError(result)); 810 EXPECT(Dart_IsError(result));
811 EXPECT(Dart_IsUnhandledExceptionError(result)); 811 EXPECT(Dart_IsUnhandledExceptionError(result));
812 812
813 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42)); 813 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42));
814 EXPECT(Dart_IsError(result)); 814 EXPECT(Dart_IsError(result));
815 EXPECT(Dart_IsUnhandledExceptionError(result)); 815 EXPECT(Dart_IsUnhandledExceptionError(result));
816 } 816 }
817 817
818 818
819 TEST_CASE(ByteArrayAccess) { 819 TEST_CASE(TypedDataAccess) {
820 Dart_Handle byte_array1 = Dart_NewByteArray(10); 820 EXPECT_EQ(kInvalid, Dart_GetTypeOfTypedData(Dart_True()));
821 EXPECT_EQ(kInvalid, Dart_GetTypeOfExternalTypedData(Dart_False()));
822 Dart_Handle byte_array1 = Dart_NewTypedData(kUint8, 10);
821 EXPECT_VALID(byte_array1); 823 EXPECT_VALID(byte_array1);
822 EXPECT(Dart_IsByteArray(byte_array1)); 824 EXPECT_EQ(kUint8, Dart_GetTypeOfTypedData(byte_array1));
823 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); 825 EXPECT_EQ(kInvalid, Dart_GetTypeOfExternalTypedData(byte_array1));
824 EXPECT(Dart_IsList(byte_array1)); 826 EXPECT(Dart_IsList(byte_array1));
825 827
826 intptr_t length = 0; 828 intptr_t length = 0;
827 Dart_Handle result = Dart_ListLength(byte_array1, &length); 829 Dart_Handle result = Dart_ListLength(byte_array1, &length);
828 EXPECT_VALID(result); 830 EXPECT_VALID(result);
829 EXPECT_EQ(10, length); 831 EXPECT_EQ(10, length);
830 832
831 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); 833 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1));
832 EXPECT(Dart_IsError(result)); 834 EXPECT(Dart_IsError(result));
833 835
834 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); 836 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1));
835 EXPECT(Dart_IsError(result)); 837 EXPECT(Dart_IsError(result));
836 838
837 // Set through the List API. 839 // Set through the List API.
838 for (intptr_t i = 0; i < 10; ++i) { 840 for (intptr_t i = 0; i < 10; ++i) {
839 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); 841 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1)));
840 } 842 }
841 for (intptr_t i = 0; i < 10; ++i) { 843 for (intptr_t i = 0; i < 10; ++i) {
842 // Get through the List API. 844 // Get through the List API.
843 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); 845 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i);
844 EXPECT_VALID(integer_obj); 846 EXPECT_VALID(integer_obj);
845 int64_t int64_t_value = -1; 847 int64_t int64_t_value = -1;
846 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); 848 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value));
847 EXPECT_EQ(i + 1, int64_t_value); 849 EXPECT_EQ(i + 1, int64_t_value);
848 } 850 }
849 851
850 Dart_Handle byte_array2 = Dart_NewByteArray(10); 852 Dart_Handle byte_array2 = Dart_NewTypedData(kUint8, 10);
851 bool is_equal = false; 853 bool is_equal = false;
852 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); 854 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal);
853 EXPECT(!is_equal); 855 EXPECT(!is_equal);
854 856
855 // Set through the List API. 857 // Set through the List API.
856 for (intptr_t i = 0; i < 10; ++i) { 858 for (intptr_t i = 0; i < 10; ++i) {
857 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2)); 859 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2));
858 EXPECT_VALID(result); 860 EXPECT_VALID(result);
859 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); 861 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2));
860 EXPECT_VALID(result); 862 EXPECT_VALID(result);
(...skipping 15 matching lines...) Expand all
876 for (intptr_t i = 0; i < 10; ++i) { 878 for (intptr_t i = 0; i < 10; ++i) {
877 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); 879 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i);
878 EXPECT_VALID(integer_obj); 880 EXPECT_VALID(integer_obj);
879 int64_t int64_t_value = -1; 881 int64_t int64_t_value = -1;
880 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); 882 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value));
881 EXPECT_EQ(10 - i, int64_t_value); 883 EXPECT_EQ(10 - i, int64_t_value);
882 } 884 }
883 } 885 }
884 886
885 887
886 TEST_CASE(ScalarListDirectAccess) { 888 TEST_CASE(TypedDataDirectAccess) {
887 Dart_Handle str = Dart_NewStringFromCString("junk"); 889 Dart_Handle str = Dart_NewStringFromCString("junk");
888 Dart_Handle byte_array = Dart_NewByteArray(10); 890 Dart_Handle byte_array = Dart_NewTypedData(kUint8, 10);
889 EXPECT_VALID(byte_array); 891 EXPECT_VALID(byte_array);
890 Dart_Handle result; 892 Dart_Handle result;
891 result = Dart_ScalarListAcquireData(byte_array, NULL, NULL, NULL); 893 result = Dart_TypedDataAcquireData(byte_array, NULL, NULL, NULL);
892 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'type'" 894 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'type'"
893 " to be non-null."); 895 " to be non-null.");
894 Dart_Scalar_Type type; 896 Dart_TypedData_Type type;
895 result = Dart_ScalarListAcquireData(byte_array, &type, NULL, NULL); 897 result = Dart_TypedDataAcquireData(byte_array, &type, NULL, NULL);
896 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'data'" 898 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'data'"
897 " to be non-null."); 899 " to be non-null.");
898 void* data; 900 void* data;
899 result = Dart_ScalarListAcquireData(byte_array, &type, &data, NULL); 901 result = Dart_TypedDataAcquireData(byte_array, &type, &data, NULL);
900 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'len'" 902 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'len'"
901 " to be non-null."); 903 " to be non-null.");
902 intptr_t len; 904 intptr_t len;
903 result = Dart_ScalarListAcquireData(Dart_Null(), &type, &data, &len); 905 result = Dart_TypedDataAcquireData(Dart_Null(), &type, &data, &len);
904 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" 906 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'object'"
905 " to be non-null."); 907 " to be non-null.");
906 result = Dart_ScalarListAcquireData(str, &type, &data, &len); 908 result = Dart_TypedDataAcquireData(str, &type, &data, &len);
907 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" 909 EXPECT_ERROR(result, "Dart_TypedDataAcquireData expects argument 'object'"
908 " to be of type 'scalar list'."); 910 " to be of type 'TypedData'.");
909 911
910 result = Dart_ScalarListReleaseData(Dart_Null()); 912 result = Dart_TypedDataReleaseData(Dart_Null());
911 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" 913 EXPECT_ERROR(result, "Dart_TypedDataReleaseData expects argument 'object'"
912 " to be non-null."); 914 " to be non-null.");
913 result = Dart_ScalarListReleaseData(str); 915 result = Dart_TypedDataReleaseData(str);
914 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" 916 EXPECT_ERROR(result, "Dart_TypedDataReleaseData expects argument 'object'"
915 " to be of type 'scalar list'."); 917 " to be of type 'TypedData'.");
916 } 918 }
917 919
918 920
919 static void TestDirectAccess(Dart_Handle lib, 921 static void TestDirectAccess(Dart_Handle lib,
920 Dart_Handle array, 922 Dart_Handle array,
921 Dart_Scalar_Type expected_type) { 923 Dart_TypedData_Type expected_type) {
922 // Invoke the dart function that sets initial values. 924 // Invoke the dart function that sets initial values.
923 Dart_Handle dart_args[1]; 925 Dart_Handle dart_args[1];
924 dart_args[0] = array; 926 dart_args[0] = array;
925 Dart_Invoke(lib, NewString("setMain"), 1, dart_args); 927 Dart_Invoke(lib, NewString("setMain"), 1, dart_args);
926 928
927 // Now Get a direct access to this typed array and check it's contents. 929 // Now Get a direct access to this typed data object and check it's contents.
928 const int kLength = 10; 930 const int kLength = 10;
929 Dart_Handle result; 931 Dart_Handle result;
930 Dart_Scalar_Type type; 932 Dart_TypedData_Type type;
931 void* data; 933 void* data;
932 intptr_t len; 934 intptr_t len;
933 result = Dart_ScalarListAcquireData(array, &type, &data, &len); 935 result = Dart_TypedDataAcquireData(array, &type, &data, &len);
934 EXPECT_VALID(result); 936 EXPECT_VALID(result);
935 EXPECT_EQ(expected_type, type); 937 EXPECT_EQ(expected_type, type);
936 EXPECT_EQ(kLength, len); 938 EXPECT_EQ(kLength, len);
937 int8_t* dataP = reinterpret_cast<int8_t*>(data); 939 int8_t* dataP = reinterpret_cast<int8_t*>(data);
938 for (int i = 0; i < kLength; i++) { 940 for (int i = 0; i < kLength; i++) {
939 EXPECT_EQ(i, dataP[i]); 941 EXPECT_EQ(i, dataP[i]);
940 } 942 }
941 943
942 // Now modify the values in the directly accessible array and then check 944 // Now modify the values in the directly accessible array and then check
943 // it we see the changes back in dart. 945 // it we see the changes back in dart.
944 for (int i = 0; i < kLength; i++) { 946 for (int i = 0; i < kLength; i++) {
945 dataP[i] += 10; 947 dataP[i] += 10;
946 } 948 }
947 949
948 // Release direct accesss to the typed array. 950 // Release direct accesss to the typed data object.
949 result = Dart_ScalarListReleaseData(array); 951 result = Dart_TypedDataReleaseData(array);
950 EXPECT_VALID(result); 952 EXPECT_VALID(result);
951 953
952 // Invoke the dart function in order to check the modified values. 954 // Invoke the dart function in order to check the modified values.
953 Dart_Invoke(lib, NewString("testMain"), 1, dart_args); 955 Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
954 } 956 }
955 957
956 958
957 TEST_CASE(ScalarListDirectAccess1) { 959 TEST_CASE(TypedDataDirectAccess1) {
958 const char* kScriptChars = 960 const char* kScriptChars =
959 "import 'dart:scalarlist';\n" 961 "import 'dart:scalarlist';\n"
960 "void setMain(var a) {" 962 "void setMain(var a) {"
961 " for (var i = 0; i < 10; i++) {" 963 " for (var i = 0; i < 10; i++) {"
962 " a[i] = i;" 964 " a[i] = i;"
963 " }" 965 " }"
964 "}\n" 966 "}\n"
965 "void testMain(var list) {" 967 "void testMain(var list) {"
966 " for (var i = 0; i < 10; i++) {" 968 " for (var i = 0; i < 10; i++) {"
967 " Expect.equals((10 + i), list[i]);" 969 " Expect.equals((10 + i), list[i]);"
968 " }\n" 970 " }\n"
969 "}\n" 971 "}\n"
970 "List main() {" 972 "List main() {"
971 " var a = new Int8List(10);" 973 " var a = new Int8List(10);"
972 " return a;" 974 " return a;"
973 "}\n"; 975 "}\n";
974 // Create a test library and Load up a test script in it. 976 // Create a test library and Load up a test script in it.
975 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 977 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
976 978
977 // Test with an regular typed array object. 979 // Test with an regular typed data object.
978 Dart_Handle list_access_test_obj; 980 Dart_Handle list_access_test_obj;
979 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); 981 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
980 EXPECT_VALID(list_access_test_obj); 982 EXPECT_VALID(list_access_test_obj);
981 TestDirectAccess(lib, list_access_test_obj, kInt8); 983 TestDirectAccess(lib, list_access_test_obj, kInt8);
982 984
983 // Test with an external typed array object. 985 // Test with an external typed data object.
984 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 986 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
985 intptr_t data_length = ARRAY_SIZE(data); 987 intptr_t data_length = ARRAY_SIZE(data);
986 Dart_Handle ext_list_access_test_obj; 988 Dart_Handle ext_list_access_test_obj;
987 ext_list_access_test_obj = Dart_NewExternalByteArray(data, 989 ext_list_access_test_obj = Dart_NewExternalTypedData(kUint8,
990 data,
988 data_length, 991 data_length,
989 NULL, NULL); 992 NULL, NULL);
990 EXPECT_VALID(ext_list_access_test_obj); 993 EXPECT_VALID(ext_list_access_test_obj);
991 TestDirectAccess(lib, ext_list_access_test_obj, kUint8); 994 TestDirectAccess(lib, ext_list_access_test_obj, kUint8);
992 } 995 }
993 996
994 997
995 static void ExternalByteArrayAccessTests(Dart_Handle obj, 998 static void ExternalTypedDataAccessTests(Dart_Handle obj,
999 Dart_TypedData_Type expected_type,
996 uint8_t data[], 1000 uint8_t data[],
997 intptr_t data_length) { 1001 intptr_t data_length) {
998 EXPECT_VALID(obj); 1002 EXPECT_VALID(obj);
999 EXPECT(Dart_IsByteArray(obj)); 1003 EXPECT_EQ(expected_type, Dart_GetTypeOfTypedData(obj));
1000 EXPECT(Dart_IsByteArrayExternal(obj)); 1004 EXPECT_EQ(expected_type, Dart_GetTypeOfExternalTypedData(obj));
1001 EXPECT(Dart_IsList(obj)); 1005 EXPECT(Dart_IsList(obj));
1002 1006
1003 void* raw_data = NULL; 1007 void* raw_data = NULL;
1004 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data)); 1008 intptr_t len;
1009 Dart_TypedData_Type type;
1010 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len));
1005 EXPECT(raw_data == data); 1011 EXPECT(raw_data == data);
1012 EXPECT_EQ(data_length, len);
1013 EXPECT_EQ(expected_type, type);
1014 EXPECT_VALID(Dart_TypedDataReleaseData(obj));
1006 1015
1007 void* peer = &data; // just a non-NULL value 1016 void* peer = &data; // just a non-NULL value
1008 EXPECT_VALID(Dart_ExternalByteArrayGetPeer(obj, &peer)); 1017 EXPECT_VALID(Dart_ExternalTypedDataGetPeer(obj, &peer));
1009 EXPECT(peer == NULL); 1018 EXPECT(peer == NULL);
1010 1019
1011 intptr_t list_length = 0; 1020 intptr_t list_length = 0;
1012 EXPECT_VALID(Dart_ListLength(obj, &list_length)); 1021 EXPECT_VALID(Dart_ListLength(obj, &list_length));
1013 EXPECT_EQ(data_length, list_length); 1022 EXPECT_EQ(data_length, list_length);
1014 1023
1015 // Load and check values from underlying array and API. 1024 // Load and check values from underlying array and API.
1016 for (intptr_t i = 0; i < list_length; ++i) { 1025 for (intptr_t i = 0; i < list_length; ++i) {
1017 EXPECT_EQ(11 * i, data[i]); 1026 EXPECT_EQ(11 * i, data[i]);
1018 Dart_Handle elt = Dart_ListGetAt(obj, i); 1027 Dart_Handle elt = Dart_ListGetAt(obj, i);
(...skipping 22 matching lines...) Expand all
1041 EXPECT_VALID(value); 1050 EXPECT_VALID(value);
1042 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); 1051 EXPECT_VALID(Dart_ListSetAt(obj, i, value));
1043 } 1052 }
1044 // Read them back through the underlying array. 1053 // Read them back through the underlying array.
1045 for (intptr_t i = 0; i < data_length; ++i) { 1054 for (intptr_t i = 0; i < data_length; ++i) {
1046 EXPECT_EQ(33 * i, data[i]); 1055 EXPECT_EQ(33 * i, data[i]);
1047 } 1056 }
1048 } 1057 }
1049 1058
1050 1059
1051 TEST_CASE(ExternalByteArrayAccess) { 1060 TEST_CASE(ExternalTypedDataAccess) {
1052 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1061 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1053 intptr_t data_length = ARRAY_SIZE(data); 1062 intptr_t data_length = ARRAY_SIZE(data);
1054 1063
1055 Dart_Handle obj = Dart_NewExternalByteArray(data, data_length, NULL, NULL); 1064 Dart_Handle obj = Dart_NewExternalTypedData(kUint8,
1056 ExternalByteArrayAccessTests(obj, data, data_length); 1065 data, data_length,
1066 NULL, NULL);
1067 ExternalTypedDataAccessTests(obj, kUint8, data, data_length);
1057 } 1068 }
1058 1069
1059 1070
1060 TEST_CASE(ExternalClampedByteArrayAccess) { 1071 TEST_CASE(ExternalClampedTypedDataAccess) {
1061 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1072 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1062 intptr_t data_length = ARRAY_SIZE(data); 1073 intptr_t data_length = ARRAY_SIZE(data);
1063 1074
1064 Dart_Handle obj = Dart_NewExternalClampedByteArray( 1075 Dart_Handle obj = Dart_NewExternalTypedData(kUint8Clamped,
1065 data, data_length, NULL, NULL); 1076 data, data_length,
1066 ExternalByteArrayAccessTests(obj, data, data_length); 1077 NULL, NULL);
1078 ExternalTypedDataAccessTests(obj, kUint8Clamped, data, data_length);
1067 } 1079 }
1068 1080
1069 1081
1070 TEST_CASE(ExternalUint8ClampedArrayAccess) { 1082 TEST_CASE(ExternalUint8ClampedArrayAccess) {
1071 const char* kScriptChars = 1083 const char* kScriptChars =
1072 "testClamped(List a) {\n" 1084 "testClamped(List a) {\n"
1073 " if (a[1] != 11) return false;\n" 1085 " if (a[1] != 11) return false;\n"
1074 " a[1] = 3;\n" 1086 " a[1] = 3;\n"
1075 " if (a[1] != 3) return false;\n" 1087 " if (a[1] != 3) return false;\n"
1076 " a[1] = -12;\n" 1088 " a[1] = -12;\n"
1077 " if (a[1] != 0) return false;\n" 1089 " if (a[1] != 0) return false;\n"
1078 " a[1] = 1200;\n" 1090 " a[1] = 1200;\n"
1079 " if (a[1] != 255) return false;\n" 1091 " if (a[1] != 255) return false;\n"
1080 " return true;\n" 1092 " return true;\n"
1081 "}\n"; 1093 "}\n";
1082 1094
1083 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1095 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1084 intptr_t data_length = ARRAY_SIZE(data); 1096 intptr_t data_length = ARRAY_SIZE(data);
1085 Dart_Handle obj = Dart_NewExternalClampedByteArray( 1097 Dart_Handle obj = Dart_NewExternalTypedData(kUint8Clamped,
1086 data, data_length, NULL, NULL); 1098 data, data_length,
1099 NULL, NULL);
1087 EXPECT_VALID(obj); 1100 EXPECT_VALID(obj);
1088 Dart_Handle result; 1101 Dart_Handle result;
1089 // Create a test library and Load up a test script in it. 1102 // Create a test library and Load up a test script in it.
1090 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1103 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1091 Dart_Handle args[1]; 1104 Dart_Handle args[1];
1092 args[0] = obj; 1105 args[0] = obj;
1093 result = Dart_Invoke(lib, NewString("testClamped"), 1, args); 1106 result = Dart_Invoke(lib, NewString("testClamped"), 1, args);
1094 1107
1095 // Check that result is true. 1108 // Check that result is true.
1096 EXPECT_VALID(result); 1109 EXPECT_VALID(result);
1097 EXPECT(Dart_IsBoolean(result)); 1110 EXPECT(Dart_IsBoolean(result));
1098 bool value = false; 1111 bool value = false;
1099 result = Dart_BooleanValue(result, &value); 1112 result = Dart_BooleanValue(result, &value);
1100 EXPECT_VALID(result); 1113 EXPECT_VALID(result);
1101 EXPECT(value); 1114 EXPECT(value);
1102 } 1115 }
1103 1116
1104 1117
1105 static void ExternalByteArrayCallbackFinalizer(Dart_Handle handle, void* peer) { 1118 static void ExternalTypedDataCallbackFinalizer(Dart_Handle handle,
1119 void* peer) {
1106 Dart_DeletePersistentHandle(handle); 1120 Dart_DeletePersistentHandle(handle);
1107 *static_cast<int*>(peer) = 42; 1121 *static_cast<int*>(peer) = 42;
1108 } 1122 }
1109 1123
1110 1124
1111 TEST_CASE(ExternalByteArrayCallback) { 1125 TEST_CASE(ExternalTypedDataCallback) {
1112 int peer = 0; 1126 int peer = 0;
1113 { 1127 {
1114 Dart_EnterScope(); 1128 Dart_EnterScope();
1115 uint8_t data[] = { 1, 2, 3, 4 }; 1129 uint8_t data[] = { 1, 2, 3, 4 };
1116 Dart_Handle obj = Dart_NewExternalByteArray( 1130 Dart_Handle obj = Dart_NewExternalTypedData(
1131 kUint8,
1117 data, 1132 data,
1118 ARRAY_SIZE(data), 1133 ARRAY_SIZE(data),
1119 &peer, 1134 &peer,
1120 ExternalByteArrayCallbackFinalizer); 1135 ExternalTypedDataCallbackFinalizer);
1121 EXPECT_VALID(obj); 1136 EXPECT_VALID(obj);
1122 void* api_peer = NULL; 1137 void* api_peer = NULL;
1123 EXPECT_VALID(Dart_ExternalByteArrayGetPeer(obj, &api_peer)); 1138 EXPECT_VALID(Dart_ExternalTypedDataGetPeer(obj, &api_peer));
1124 EXPECT_EQ(api_peer, &peer); 1139 EXPECT_EQ(api_peer, &peer);
1125 Dart_ExitScope(); 1140 Dart_ExitScope();
1126 } 1141 }
1127 EXPECT(peer == 0); 1142 EXPECT(peer == 0);
1128 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 1143 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1129 EXPECT(peer == 0); 1144 EXPECT(peer == 0);
1130 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 1145 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
1131 EXPECT(peer == 42); 1146 EXPECT(peer == 42);
1132 } 1147 }
1133 1148
(...skipping 6281 matching lines...) Expand 10 before | Expand all | Expand 10 after
7415 NULL); 7430 NULL);
7416 int64_t value = 0; 7431 int64_t value = 0;
7417 result = Dart_IntegerToInt64(result, &value); 7432 result = Dart_IntegerToInt64(result, &value);
7418 EXPECT_VALID(result); 7433 EXPECT_VALID(result);
7419 EXPECT_EQ(260, value); 7434 EXPECT_EQ(260, value);
7420 } 7435 }
7421 7436
7422 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7437 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7423 7438
7424 } // namespace dart 7439 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698