OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library('TypedArrays2Test'); |
| 6 #import('../../../../lib/unittest/unittest_html.dart'); |
| 7 #import('dart:html'); |
| 8 |
| 9 main() { |
| 10 |
| 11 forLayoutTests(); |
| 12 |
| 13 test('fromBufferTest_var', () { |
| 14 var a1 = new Uint8Array(1024); |
| 15 for (int i = 0; i < a1.length; i++) { |
| 16 a1[i] = i; // 0,1,2,...,254,255,0,1,2,... |
| 17 } |
| 18 |
| 19 var a2 = new Uint32Array.fromBuffer(a1.buffer); |
| 20 Expect.equals(1024 ~/ 4, a2.length); |
| 21 Expect.equals(0x03020100, a2[0]); |
| 22 Expect.equals(0x07060504, a2[1]); |
| 23 Expect.equals(0x0B0A0908, a2[2]); |
| 24 Expect.equals(0xCBCAC9C8, a2[50]); |
| 25 Expect.equals(0xCFCECDCC, a2[51]); |
| 26 Expect.equals(0x03020100, a2[64]); |
| 27 |
| 28 a2 = new Uint32Array.fromBuffer(a1.buffer, 200); |
| 29 Expect.equals((1024 - 200) ~/ 4, a2.length); |
| 30 Expect.equals(0xCBCAC9C8, a2[0]); |
| 31 Expect.equals(0xCFCECDCC, a2[1]); |
| 32 Expect.equals(0x03020100, a2[14]); |
| 33 |
| 34 a2 = new Uint32Array.fromBuffer(a1.buffer, 456, 20); |
| 35 Expect.equals(20, a2.length); |
| 36 Expect.equals(0xCBCAC9C8, a2[0]); |
| 37 Expect.equals(0xCFCECDCC, a2[1]); |
| 38 Expect.equals(0x03020100, a2[14]); |
| 39 |
| 40 a2 = new Uint32Array.fromBuffer(a1.buffer, length: 30, byteOffset: 456); |
| 41 Expect.equals(30, a2.length); |
| 42 Expect.equals(0xCBCAC9C8, a2[0]); |
| 43 Expect.equals(0xCFCECDCC, a2[1]); |
| 44 Expect.equals(0x03020100, a2[14]); |
| 45 }); |
| 46 |
| 47 test('fromBufferTest_typed', () { |
| 48 Uint8Array a1 = new Uint8Array(1024); |
| 49 for (int i = 0; i < a1.length; i++) { |
| 50 a1[i] = i; |
| 51 } |
| 52 |
| 53 Uint32Array a2 = new Uint32Array.fromBuffer(a1.buffer); |
| 54 Expect.equals(1024 ~/ 4, a2.length); |
| 55 Expect.equals(0x03020100, a2[0]); |
| 56 Expect.equals(0xCBCAC9C8, a2[50]); |
| 57 Expect.equals(0xCFCECDCC, a2[51]); |
| 58 Expect.equals(0x03020100, a2[64]); |
| 59 |
| 60 a2 = new Uint32Array.fromBuffer(a1.buffer, 200); |
| 61 Expect.equals((1024 - 200) ~/ 4, a2.length); |
| 62 Expect.equals(0xCBCAC9C8, a2[0]); |
| 63 Expect.equals(0xCFCECDCC, a2[1]); |
| 64 Expect.equals(0x03020100, a2[14]); |
| 65 |
| 66 a2 = new Uint32Array.fromBuffer(a1.buffer, 456, 20); |
| 67 Expect.equals(20, a2.length); |
| 68 Expect.equals(0xCBCAC9C8, a2[0]); |
| 69 Expect.equals(0xCFCECDCC, a2[1]); |
| 70 Expect.equals(0x03020100, a2[14]); |
| 71 |
| 72 a2 = new Uint32Array.fromBuffer(a1.buffer, length: 30, byteOffset: 456); |
| 73 Expect.equals(30, a2.length); |
| 74 Expect.equals(0xCBCAC9C8, a2[0]); |
| 75 Expect.equals(0xCFCECDCC, a2[1]); |
| 76 Expect.equals(0x03020100, a2[14]); |
| 77 }); |
| 78 } |
OLD | NEW |