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_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_message.h" | 10 #include "vm/dart_api_message.h" |
(...skipping 2166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2177 | 2177 |
2178 static void CheckTypedData(Dart_CObject* object, | 2178 static void CheckTypedData(Dart_CObject* object, |
2179 Dart_CObject::TypedDataType typed_data_type, | 2179 Dart_CObject::TypedDataType typed_data_type, |
2180 int len) { | 2180 int len) { |
2181 EXPECT_EQ(Dart_CObject::kTypedData, object->type); | 2181 EXPECT_EQ(Dart_CObject::kTypedData, object->type); |
2182 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); | 2182 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); |
2183 EXPECT_EQ(len, object->value.as_typed_data.length); | 2183 EXPECT_EQ(len, object->value.as_typed_data.length); |
2184 } | 2184 } |
2185 | 2185 |
2186 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { | 2186 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
2187 const int kArrayLength = 10; | |
2188 static const char* kScriptChars = | 2187 static const char* kScriptChars = |
2189 "import 'dart:typeddata';\n" | 2188 "import 'dart:typeddata';\n" |
2190 "final int kArrayLength = 10;\n" | |
2191 "getTypedDataList() {\n" | 2189 "getTypedDataList() {\n" |
2192 " var list = new List(kArrayLength);\n" | 2190 " var list = new List(10);\n" |
2193 " list[0] = new Int8List(256);\n" | 2191 " var index = 0;\n" |
2194 " list[1] = new Uint8List(256);\n" | 2192 " list[index++] = new Int8List(256);\n" |
2195 " list[2] = new Int16List(256);\n" | 2193 " list[index++] = new Uint8List(256);\n" |
2196 " list[3] = new Uint16List(256);\n" | 2194 " list[index++] = new Int16List(256);\n" |
| 2195 " list[index++] = new Uint16List(256);\n" |
| 2196 " list[index++] = new Int32List(256);\n" |
| 2197 " list[index++] = new Uint32List(256);\n" |
| 2198 " list[index++] = new Int64List(256);\n" |
| 2199 " list[index++] = new Uint64List(256);\n" |
| 2200 " list[index++] = new Float32List(256);\n" |
| 2201 " list[index++] = new Float64List(256);\n" |
2197 " return list;\n" | 2202 " return list;\n" |
2198 "}\n" | 2203 "}\n" |
2199 "getTypedDataViewList() {\n" | 2204 "getTypedDataViewList() {\n" |
2200 " var list = new List(kArrayLength);\n" | 2205 " var list = new List(30);\n" |
2201 " list[0] = new Int8List.view(new Int8List(256));\n" | 2206 " var index = 0;\n" |
2202 " list[1] = new Uint8List.view(new Uint8List(256));\n" | 2207 " list[index++] = new Int8List.view(new Int8List(256));\n" |
2203 " list[2] = new Int16List.view(new Int16List(256));\n" | 2208 " list[index++] = new Uint8List.view(new Uint8List(256));\n" |
2204 " list[3] = new Uint16List.view(new Uint16List(256));\n" | 2209 " list[index++] = new Int16List.view(new Int16List(256));\n" |
2205 " list[4] = new Int8List.view(new Int16List(256));\n" | 2210 " list[index++] = new Uint16List.view(new Uint16List(256));\n" |
2206 " list[5] = new Uint8List.view(new Uint16List(256));\n" | 2211 " list[index++] = new Int32List.view(new Int32List(256));\n" |
2207 " list[6] = new Int16List.view(new Int8List(256));\n" | 2212 " list[index++] = new Uint32List.view(new Uint32List(256));\n" |
2208 " list[7] = new Uint16List.view(new Uint8List(256));\n" | 2213 " list[index++] = new Int64List.view(new Int64List(256));\n" |
| 2214 " list[index++] = new Uint64List.view(new Uint64List(256));\n" |
| 2215 " list[index++] = new Float32List.view(new Float32List(256));\n" |
| 2216 " list[index++] = new Float64List.view(new Float64List(256));\n" |
| 2217 |
| 2218 " list[index++] = new Int8List.view(new Int16List(256));\n" |
| 2219 " list[index++] = new Uint8List.view(new Uint16List(256));\n" |
| 2220 " list[index++] = new Int8List.view(new Int32List(256));\n" |
| 2221 " list[index++] = new Uint8List.view(new Uint32List(256));\n" |
| 2222 " list[index++] = new Int8List.view(new Int64List(256));\n" |
| 2223 " list[index++] = new Uint8List.view(new Uint64List(256));\n" |
| 2224 " list[index++] = new Int8List.view(new Float32List(256));\n" |
| 2225 " list[index++] = new Uint8List.view(new Float32List(256));\n" |
| 2226 " list[index++] = new Int8List.view(new Float64List(256));\n" |
| 2227 " list[index++] = new Uint8List.view(new Float64List(256));\n" |
| 2228 |
| 2229 " list[index++] = new Int16List.view(new Int8List(256));\n" |
| 2230 " list[index++] = new Uint16List.view(new Uint8List(256));\n" |
| 2231 " list[index++] = new Int16List.view(new Int32List(256));\n" |
| 2232 " list[index++] = new Uint16List.view(new Uint32List(256));\n" |
| 2233 " list[index++] = new Int16List.view(new Int64List(256));\n" |
| 2234 " list[index++] = new Uint16List.view(new Uint64List(256));\n" |
| 2235 " list[index++] = new Int16List.view(new Float32List(256));\n" |
| 2236 " list[index++] = new Uint16List.view(new Float32List(256));\n" |
| 2237 " list[index++] = new Int16List.view(new Float64List(256));\n" |
| 2238 " list[index++] = new Uint16List.view(new Float64List(256));\n" |
| 2239 " return list;\n" |
| 2240 "}\n" |
| 2241 "getMultipleTypedDataViewList() {\n" |
| 2242 " var list = new List(10);\n" |
| 2243 " var index = 0;\n" |
| 2244 " var data = new Uint8List(256);\n" |
| 2245 " list[index++] = new Int8List.view(data);\n" |
| 2246 " list[index++] = new Uint8List.view(data);\n" |
| 2247 " list[index++] = new Int16List.view(data);\n" |
| 2248 " list[index++] = new Uint16List.view(data);\n" |
| 2249 " list[index++] = new Int32List.view(data);\n" |
| 2250 " list[index++] = new Uint32List.view(data);\n" |
| 2251 " list[index++] = new Int64List.view(data);\n" |
| 2252 " list[index++] = new Uint64List.view(data);\n" |
| 2253 " list[index++] = new Float32List.view(data);\n" |
| 2254 " list[index++] = new Float64List.view(data);\n" |
2209 " return list;\n" | 2255 " return list;\n" |
2210 "}\n"; | 2256 "}\n"; |
2211 | 2257 |
2212 TestCase::CreateTestIsolate(); | 2258 TestCase::CreateTestIsolate(); |
2213 Isolate* isolate = Isolate::Current(); | 2259 Isolate* isolate = Isolate::Current(); |
2214 EXPECT(isolate != NULL); | 2260 EXPECT(isolate != NULL); |
2215 Dart_EnterScope(); | 2261 Dart_EnterScope(); |
2216 | 2262 |
2217 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2263 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2218 EXPECT_VALID(lib); | 2264 EXPECT_VALID(lib); |
2219 | 2265 |
2220 { | 2266 { |
2221 DARTSCOPE(isolate); | 2267 DARTSCOPE(isolate); |
2222 { | 2268 { |
2223 // Generate a list of Uint8Lists from Dart code. | 2269 // Generate a list of Uint8Lists from Dart code. |
2224 ApiNativeScope scope; | 2270 ApiNativeScope scope; |
2225 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2271 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
2226 EXPECT_NOTNULL(root); | 2272 EXPECT_NOTNULL(root); |
2227 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2273 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2228 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2274 struct { |
2229 CheckTypedData(root->value.as_array.values[0], | 2275 Dart_CObject::TypedDataType type; |
2230 Dart_CObject::kInt8Array, | 2276 int size; |
2231 256); | 2277 } expected[] = { |
2232 CheckTypedData(root->value.as_array.values[1], | 2278 { Dart_CObject::kInt8Array, 256}, |
2233 Dart_CObject::kUint8Array, | 2279 { Dart_CObject::kUint8Array, 256}, |
2234 256); | 2280 { Dart_CObject::kInt16Array, 512}, |
2235 CheckTypedData(root->value.as_array.values[2], | 2281 { Dart_CObject::kUint16Array, 512}, |
2236 Dart_CObject::kInt16Array, | 2282 { Dart_CObject::kInt32Array, 1024}, |
2237 512); | 2283 { Dart_CObject::kUint32Array, 1024}, |
2238 CheckTypedData(root->value.as_array.values[3], | 2284 { Dart_CObject::kInt64Array, 2048}, |
2239 Dart_CObject::kUint16Array, | 2285 { Dart_CObject::kUint64Array, 2048}, |
2240 512); | 2286 { Dart_CObject::kFloat32Array, 1024}, |
| 2287 { Dart_CObject::kFloat64Array, 2048}, |
| 2288 { Dart_CObject::kNumberOfTypedDataTypes, -1 } |
| 2289 }; |
| 2290 |
| 2291 int i = 0; |
| 2292 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { |
| 2293 CheckTypedData(root->value.as_array.values[i], |
| 2294 expected[i].type, |
| 2295 expected[i].size); |
| 2296 i++; |
| 2297 } |
| 2298 EXPECT_EQ(i, root->value.as_array.length); |
2241 } | 2299 } |
2242 { | 2300 { |
2243 // Generate a list of Uint8List views from Dart code. | 2301 // Generate a list of Uint8List views from Dart code. |
| 2302 |
2244 ApiNativeScope scope; | 2303 ApiNativeScope scope; |
2245 Dart_CObject* root = | 2304 Dart_CObject* root = |
2246 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 2305 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
2247 EXPECT_NOTNULL(root); | 2306 EXPECT_NOTNULL(root); |
2248 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2307 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2249 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2308 struct { |
2250 CheckTypedData(root->value.as_array.values[0], | 2309 Dart_CObject::TypedDataType type; |
2251 Dart_CObject::kInt8Array, | 2310 int size; |
2252 256); | 2311 } expected[] = { |
2253 CheckTypedData(root->value.as_array.values[1], | 2312 { Dart_CObject::kInt8Array, 256}, |
2254 Dart_CObject::kUint8Array, | 2313 { Dart_CObject::kUint8Array, 256}, |
2255 256); | 2314 { Dart_CObject::kInt16Array, 512}, |
2256 CheckTypedData(root->value.as_array.values[2], | 2315 { Dart_CObject::kUint16Array, 512}, |
2257 Dart_CObject::kInt16Array, | 2316 { Dart_CObject::kInt32Array, 1024}, |
2258 512); | 2317 { Dart_CObject::kUint32Array, 1024}, |
2259 CheckTypedData(root->value.as_array.values[3], | 2318 { Dart_CObject::kInt64Array, 2048}, |
2260 Dart_CObject::kUint16Array, | 2319 { Dart_CObject::kUint64Array, 2048}, |
2261 512); | 2320 { Dart_CObject::kFloat32Array, 1024}, |
2262 CheckTypedData(root->value.as_array.values[4], | 2321 { Dart_CObject::kFloat64Array, 2048}, |
2263 Dart_CObject::kInt8Array, | 2322 |
2264 512); | 2323 { Dart_CObject::kInt8Array, 512}, |
2265 CheckTypedData(root->value.as_array.values[5], | 2324 { Dart_CObject::kUint8Array, 512}, |
2266 Dart_CObject::kUint8Array, | 2325 { Dart_CObject::kInt8Array, 1024}, |
2267 512); | 2326 { Dart_CObject::kUint8Array, 1024}, |
2268 CheckTypedData(root->value.as_array.values[6], | 2327 { Dart_CObject::kInt8Array, 2048}, |
2269 Dart_CObject::kInt16Array, | 2328 { Dart_CObject::kUint8Array, 2048}, |
2270 256); | 2329 { Dart_CObject::kInt8Array, 1024}, |
2271 CheckTypedData(root->value.as_array.values[7], | 2330 { Dart_CObject::kUint8Array, 1024}, |
2272 Dart_CObject::kUint16Array, | 2331 { Dart_CObject::kInt8Array, 2048}, |
2273 256); | 2332 { Dart_CObject::kUint8Array, 2048}, |
| 2333 |
| 2334 { Dart_CObject::kInt16Array, 256}, |
| 2335 { Dart_CObject::kUint16Array, 256}, |
| 2336 { Dart_CObject::kInt16Array, 1024}, |
| 2337 { Dart_CObject::kUint16Array, 1024}, |
| 2338 { Dart_CObject::kInt16Array, 2048}, |
| 2339 { Dart_CObject::kUint16Array, 2048}, |
| 2340 { Dart_CObject::kInt16Array, 1024}, |
| 2341 { Dart_CObject::kUint16Array, 1024}, |
| 2342 { Dart_CObject::kInt16Array, 2048}, |
| 2343 { Dart_CObject::kUint16Array, 2048}, |
| 2344 |
| 2345 { Dart_CObject::kNumberOfTypedDataTypes, -1 } |
| 2346 }; |
| 2347 |
| 2348 int i = 0; |
| 2349 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { |
| 2350 CheckTypedData(root->value.as_array.values[i], |
| 2351 expected[i].type, |
| 2352 expected[i].size); |
| 2353 i++; |
| 2354 } |
| 2355 EXPECT_EQ(i, root->value.as_array.length); |
| 2356 } |
| 2357 { |
| 2358 // Generate a list of Uint8Lists from Dart code. |
| 2359 ApiNativeScope scope; |
| 2360 Dart_CObject* root = |
| 2361 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList"); |
| 2362 EXPECT_NOTNULL(root); |
| 2363 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2364 struct { |
| 2365 Dart_CObject::TypedDataType type; |
| 2366 int size; |
| 2367 } expected[] = { |
| 2368 { Dart_CObject::kInt8Array, 256}, |
| 2369 { Dart_CObject::kUint8Array, 256}, |
| 2370 { Dart_CObject::kInt16Array, 256}, |
| 2371 { Dart_CObject::kUint16Array, 256}, |
| 2372 { Dart_CObject::kInt32Array, 256}, |
| 2373 { Dart_CObject::kUint32Array, 256}, |
| 2374 { Dart_CObject::kInt64Array, 256}, |
| 2375 { Dart_CObject::kUint64Array, 256}, |
| 2376 { Dart_CObject::kFloat32Array, 256}, |
| 2377 { Dart_CObject::kFloat64Array, 256}, |
| 2378 { Dart_CObject::kNumberOfTypedDataTypes, -1 } |
| 2379 }; |
| 2380 |
| 2381 int i = 0; |
| 2382 while (expected[i].type != Dart_CObject::kNumberOfTypedDataTypes) { |
| 2383 CheckTypedData(root->value.as_array.values[i], |
| 2384 expected[i].type, |
| 2385 expected[i].size); |
| 2386 |
| 2387 // All views point to the same data. |
| 2388 EXPECT_EQ(root->value.as_array.values[0]->value.as_typed_data.values, |
| 2389 root->value.as_array.values[i]->value.as_typed_data.values); |
| 2390 i++; |
| 2391 } |
| 2392 EXPECT_EQ(i, root->value.as_array.length); |
2274 } | 2393 } |
2275 } | 2394 } |
2276 Dart_ExitScope(); | 2395 Dart_ExitScope(); |
2277 Dart_ShutdownIsolate(); | 2396 Dart_ShutdownIsolate(); |
2278 } | 2397 } |
2279 | 2398 |
2280 | 2399 |
2281 UNIT_TEST_CASE(PostCObject) { | 2400 UNIT_TEST_CASE(PostCObject) { |
2282 // Create a native port for posting from C to Dart | 2401 // Create a native port for posting from C to Dart |
2283 TestIsolateScope __test_isolate__; | 2402 TestIsolateScope __test_isolate__; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2371 EXPECT(Dart_ErrorHasException(result)); | 2490 EXPECT(Dart_ErrorHasException(result)); |
2372 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2491 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
2373 Dart_GetError(result)); | 2492 Dart_GetError(result)); |
2374 | 2493 |
2375 Dart_ExitScope(); | 2494 Dart_ExitScope(); |
2376 } | 2495 } |
2377 | 2496 |
2378 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2497 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
2379 | 2498 |
2380 } // namespace dart | 2499 } // namespace dart |
OLD | NEW |