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 library TypedArrays3Test; | 5 library TypedArrays3Test; |
| 6 |
6 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 8 import 'package:unittest/html_config.dart'; |
8 import 'dart:html'; | 9 import 'dart:html'; |
9 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
10 | 11 |
11 main() { | 12 main() { |
12 useHtmlConfiguration(); | 13 useHtmlConfiguration(); |
13 | 14 |
14 // Only perform tests if ArrayBuffer is supported. | 15 // Only perform tests if ArrayBuffer is supported. |
15 if (!Platform.supportsTypedData) { | 16 if (!Platform.supportsTypedData) { |
16 return; | 17 return; |
17 } | 18 } |
18 | 19 |
19 test('setElementsTest_dynamic', () { | 20 test('setElementsTest_dynamic', () { |
20 var a1 = new Int8List(1024); | 21 var a1 = new Int8List(1024); |
21 | 22 |
22 a1.setRange(4, 7, [0x50,0x60,0x70]); | 23 a1.setRange(4, 7, [0x50, 0x60, 0x70]); |
23 | 24 |
24 var a2 = new Uint32List.view(a1.buffer); | 25 var a2 = new Uint32List.view(a1.buffer); |
25 expect(a2[0], 0x00000000); | 26 expect(a2[0], 0x00000000); |
26 expect(a2[1], 0x00706050); | 27 expect(a2[1], 0x00706050); |
27 | 28 |
28 a2.setRange(2, 3, [0x01020304]); | 29 a2.setRange(2, 3, [0x01020304]); |
29 expect(a1[8], 0x04); | 30 expect(a1[8], 0x04); |
30 expect(a1[11], 0x01); | 31 expect(a1[11], 0x01); |
31 }); | 32 }); |
32 | 33 |
33 test('setElementsTest_typed', () { | 34 test('setElementsTest_typed', () { |
34 Int8List a1 = new Int8List(1024); | 35 Int8List a1 = new Int8List(1024); |
35 | 36 |
36 a1.setRange(4, 7, [0x50,0x60,0x70]); | 37 a1.setRange(4, 7, [0x50, 0x60, 0x70]); |
37 | 38 |
38 Uint32List a2 = new Uint32List.view(a1.buffer); | 39 Uint32List a2 = new Uint32List.view(a1.buffer); |
39 expect(a2[0], 0x00000000); | 40 expect(a2[0], 0x00000000); |
40 expect(a2[1], 0x00706050); | 41 expect(a2[1], 0x00706050); |
41 | 42 |
42 a2.setRange(2, 3, [0x01020304]); | 43 a2.setRange(2, 3, [0x01020304]); |
43 expect(a1[8], 0x04); | 44 expect(a1[8], 0x04); |
44 expect(a1[11], 0x01); | 45 expect(a1[11], 0x01); |
45 }); | 46 }); |
46 } | 47 } |
OLD | NEW |