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

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

Issue 11881031: Add Dart class for _ExternalUint8ClampedArray and API to allocate it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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
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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); 1082 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value));
1083 EXPECT_EQ(1.0, double_value); 1083 EXPECT_EQ(1.0, double_value);
1084 1084
1085 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, -1.0)); 1085 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, -1.0));
1086 double_value = DBL_MAX; 1086 double_value = DBL_MAX;
1087 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); 1087 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value));
1088 EXPECT_EQ(-1.0, double_value); 1088 EXPECT_EQ(-1.0, double_value);
1089 } 1089 }
1090 1090
1091 1091
1092 TEST_CASE(ExternalByteArrayAccess) { 1092 static void ExternalByteArrayAccessTests(Dart_Handle obj,
1093 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; 1093 uint8_t data[],
1094 intptr_t data_length = ARRAY_SIZE(data); 1094 intptr_t data_length) {
1095
1096 Dart_Handle obj = Dart_NewExternalByteArray(data, data_length, NULL, NULL);
1097 EXPECT_VALID(obj); 1095 EXPECT_VALID(obj);
1098 EXPECT(Dart_IsByteArray(obj)); 1096 EXPECT(Dart_IsByteArray(obj));
1099 EXPECT(Dart_IsByteArrayExternal(obj)); 1097 EXPECT(Dart_IsByteArrayExternal(obj));
1100 EXPECT(Dart_IsList(obj)); 1098 EXPECT(Dart_IsList(obj));
1101 1099
1102 void* raw_data = NULL; 1100 void* raw_data = NULL;
1103 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data)); 1101 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data));
1104 EXPECT(raw_data == data); 1102 EXPECT(raw_data == data);
1105 1103
1106 void* peer = &data; // just a non-NULL value 1104 void* peer = &data; // just a non-NULL value
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 EXPECT_VALID(value); 1138 EXPECT_VALID(value);
1141 EXPECT_VALID(Dart_ListSetAt(obj, i, value)); 1139 EXPECT_VALID(Dart_ListSetAt(obj, i, value));
1142 } 1140 }
1143 // Read them back through the underlying array. 1141 // Read them back through the underlying array.
1144 for (intptr_t i = 0; i < data_length; ++i) { 1142 for (intptr_t i = 0; i < data_length; ++i) {
1145 EXPECT_EQ(33 * i, data[i]); 1143 EXPECT_EQ(33 * i, data[i]);
1146 } 1144 }
1147 } 1145 }
1148 1146
1149 1147
1148 TEST_CASE(ExternalByteArrayAccess) {
1149 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1150 intptr_t data_length = ARRAY_SIZE(data);
1151
1152 Dart_Handle obj = Dart_NewExternalByteArray(data, data_length, NULL, NULL);
1153 ExternalByteArrayAccessTests(obj, data, data_length);
1154 }
1155
1156
1157 TEST_CASE(ExternalClampedByteArrayAccess) {
1158 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1159 intptr_t data_length = ARRAY_SIZE(data);
1160
1161 Dart_Handle obj = Dart_NewExternalClampedByteArray(
1162 data, data_length, NULL, NULL);
1163 ExternalByteArrayAccessTests(obj, data, data_length);
1164 }
1165
1166
1167 TEST_CASE(ExternalUint8ClampedArrayAccess) {
1168 const char* kScriptChars =
1169 "testClamped(List a) {\n"
1170 " if (a[1] != 11) return false;\n"
1171 " a[1] = 3;\n"
1172 " if (a[1] != 3) return false;\n"
1173 " a[1] = -12;\n"
1174 " if (a[1] != 0) return false;\n"
1175 " a[1] = 1200;\n"
1176 " if (a[1] != 255) return false;\n"
1177 " return true;\n"
1178 "}\n";
1179
1180 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 };
1181 intptr_t data_length = ARRAY_SIZE(data);
1182 Dart_Handle obj = Dart_NewExternalClampedByteArray(
1183 data, data_length, NULL, NULL);
1184 EXPECT_VALID(obj);
1185 Dart_Handle result;
1186 // Create a test library and Load up a test script in it.
1187 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1188 Dart_Handle args[1];
1189 args[0] = obj;
1190 result = Dart_Invoke(lib, NewString("testClamped"), 1, args);
1191
1192 // Check that result is true.
1193 EXPECT_VALID(result);
1194 EXPECT(Dart_IsBoolean(result));
1195 bool value = false;
1196 result = Dart_BooleanValue(result, &value);
1197 EXPECT_VALID(result);
1198 EXPECT(value);
1199 }
1200
1201
1202
1150 static void ExternalByteArrayCallbackFinalizer(void* peer) { 1203 static void ExternalByteArrayCallbackFinalizer(void* peer) {
1151 *static_cast<int*>(peer) = 42; 1204 *static_cast<int*>(peer) = 42;
1152 } 1205 }
1153 1206
1154 1207
1155 TEST_CASE(ExternalByteArrayCallback) { 1208 TEST_CASE(ExternalByteArrayCallback) {
1156 int peer = 0; 1209 int peer = 0;
1157 { 1210 {
1158 Dart_EnterScope(); 1211 Dart_EnterScope();
1159 uint8_t data[] = { 1, 2, 3, 4 }; 1212 uint8_t data[] = { 1, 2, 3, 4 };
(...skipping 6226 matching lines...) Expand 10 before | Expand all | Expand 10 after
7386 Dart_LoadSource(TestCase::lib(), url, source); 7439 Dart_LoadSource(TestCase::lib(), url, source);
7387 7440
7388 dart_args[0] = Dart_NewInteger(1); 7441 dart_args[0] = Dart_NewInteger(1);
7389 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); 7442 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args);
7390 EXPECT_VALID(result); 7443 EXPECT_VALID(result);
7391 } 7444 }
7392 7445
7393 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7446 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7394 7447
7395 } // namespace dart 7448 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698