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 // Dart test program for testing native float arrays. | 5 // Dart test program for testing native float and int arrays. 64-bit int arrays |
| 6 // are in a separate test. |
6 | 7 |
7 // Library tag to be able to run in html test framework. | 8 // Library tag to be able to run in html test framework. |
8 library TypedArray; | 9 library TypedArray; |
9 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
11 import 'dart:typed_data'; | 12 import 'dart:typed_data'; |
12 | 13 |
13 void main() { | 14 void main() { |
14 int8_receiver(); | 15 int8_receiver(); |
15 uint8_receiver(); | 16 uint8_receiver(); |
16 int16_receiver(); | 17 int16_receiver(); |
17 uint16_receiver(); | 18 uint16_receiver(); |
18 int32_receiver(); | 19 int32_receiver(); |
19 uint32_receiver(); | 20 uint32_receiver(); |
20 int64_receiver(); | 21 // int64 and uint64 in separate test. |
21 uint64_receiver(); | |
22 float32_receiver(); | 22 float32_receiver(); |
23 float64_receiver(); | 23 float64_receiver(); |
24 } | 24 } |
25 | 25 |
26 // Int8 array. | 26 // Int8 array. |
27 Int8List initInt8() { | 27 Int8List initInt8() { |
28 var int8 = new Int8List(2); | 28 var int8 = new Int8List(2); |
29 int8[0] = 10; | 29 int8[0] = 10; |
30 int8[1] = 100; | 30 int8[1] = 100; |
31 return int8; | 31 return int8; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Expect.equals(uint32.length, len); | 208 Expect.equals(uint32.length, len); |
209 var a = new Uint32List(len); | 209 var a = new Uint32List(len); |
210 for (int i = 0; i < len; i++) { | 210 for (int i = 0; i < len; i++) { |
211 a[i] = uint32[i]; | 211 a[i] = uint32[i]; |
212 } | 212 } |
213 r.send(a); | 213 r.send(a); |
214 }); | 214 }); |
215 } | 215 } |
216 | 216 |
217 | 217 |
218 // Int64 array. | |
219 Int64List initInt64() { | |
220 var int64 = new Int64List(2); | |
221 int64[0] = 10000000; | |
222 int64[1] = 100000000; | |
223 return int64; | |
224 } | |
225 Int64List int64 = initInt64(); | |
226 | |
227 void int64_receiver() { | |
228 var sp = spawnFunction(int64_sender); | |
229 sp.call(int64.length).then((a) { | |
230 Expect.equals(int64.length, a.length); | |
231 for (int i = 0; i < a.length; i++) { | |
232 Expect.equals(int64[i], a[i]); | |
233 } | |
234 print("int64_receiver"); | |
235 }); | |
236 } | |
237 | |
238 int64_sender() { | |
239 port.receive((len, r) { | |
240 Expect.equals(int64.length, len); | |
241 var a = new Int64List(len); | |
242 for (int i = 0; i < len; i++) { | |
243 a[i] = int64[i]; | |
244 } | |
245 r.send(a); | |
246 }); | |
247 } | |
248 | |
249 | |
250 // Uint64 array. | |
251 Uint64List initUint64() { | |
252 var uint64 = new Uint64List(2); | |
253 uint64[0] = 0xffffffffffffffff; | |
254 uint64[1] = 0x7fffffffffffffff; | |
255 return uint64; | |
256 } | |
257 Uint64List uint64 = initUint64(); | |
258 | |
259 void uint64_receiver() { | |
260 var sp = spawnFunction(uint64_sender); | |
261 sp.call(uint64.length).then((a) { | |
262 Expect.equals(uint64.length, a.length); | |
263 for (int i = 0; i < a.length; i++) { | |
264 Expect.equals(uint64[i], a[i]); | |
265 } | |
266 print("uint64_receiver"); | |
267 }); | |
268 } | |
269 | |
270 uint64_sender() { | |
271 port.receive((len, r) { | |
272 Expect.equals(uint64.length, len); | |
273 var a = new Uint64List(len); | |
274 for (int i = 0; i < len; i++) { | |
275 a[i] = uint64[i]; | |
276 } | |
277 r.send(a); | |
278 }); | |
279 } | |
280 | |
281 | |
282 // Float32 Array. | 218 // Float32 Array. |
283 Float32List initFloat32() { | 219 Float32List initFloat32() { |
284 var float32 = new Float32List(2); | 220 var float32 = new Float32List(2); |
285 float32[0] = 1.0; | 221 float32[0] = 1.0; |
286 float32[1] = 2.0; | 222 float32[1] = 2.0; |
287 return float32; | 223 return float32; |
288 } | 224 } |
289 Float32List float32 = initFloat32(); | 225 Float32List float32 = initFloat32(); |
290 | 226 |
291 void float32_receiver() { | 227 void float32_receiver() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 float64_sender() { | 270 float64_sender() { |
335 port.receive((len, r) { | 271 port.receive((len, r) { |
336 Expect.equals(float64.length, len); | 272 Expect.equals(float64.length, len); |
337 var a = new Float64List(len); | 273 var a = new Float64List(len); |
338 for (int i = 0; i < len; i++) { | 274 for (int i = 0; i < len; i++) { |
339 a[i] = float64[i]; | 275 a[i] = float64[i]; |
340 } | 276 } |
341 r.send(a); | 277 r.send(a); |
342 }); | 278 }); |
343 } | 279 } |
OLD | NEW |