| 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 byte arrays. | 5 // Dart test program for testing native byte arrays. |
| 6 | 6 |
| 7 // Library tag to be able to run in html test framework. | 7 // Library tag to be able to run in html test framework. |
| 8 #library("ByteArrayTest.dart"); | 8 #library("ByteArrayTest.dart"); |
| 9 | 9 |
| 10 #import('dart:scalarlist'); | 10 #import('dart:scalarlist'); |
| 11 | 11 |
| 12 void testCreateByteArray() { | 12 void testCreateByteArray() { |
| 13 Uint8List byteArray; | 13 Uint8List byteArray; |
| 14 | 14 |
| 15 byteArray = new Uint8List(0); | 15 byteArray = new Uint8List(0); |
| 16 Expect.equals(0, byteArray.length); | 16 Expect.equals(0, byteArray.length); |
| 17 | 17 |
| 18 byteArray = new Uint8List(10); | 18 byteArray = new Uint8List(10); |
| 19 Expect.equals(10, byteArray.length); | 19 Expect.equals(10, byteArray.length); |
| 20 for (int i = 0; i < 10; i++) { | 20 for (int i = 0; i < 10; i++) { |
| 21 Expect.equals(0, byteArray[i]); | 21 Expect.equals(0, byteArray[i]); |
| 22 } | 22 } |
| 23 byteArray[1] = 255; |
| 24 Expect.equals(255, byteArray[1]); |
| 25 byteArray[1] = 0; |
| 26 Expect.equals(0, byteArray[1]); |
| 27 // This should eventually throw. |
| 28 byteArray[1] = 256; |
| 23 } | 29 } |
| 24 | 30 |
| 25 void testSetRange() { | 31 void testSetRange() { |
| 26 Uint8List byteArray = new Uint8List(3); | 32 Uint8List byteArray = new Uint8List(3); |
| 27 | 33 |
| 28 List<int> list = [10, 11, 12]; | 34 List<int> list = [10, 11, 12]; |
| 29 byteArray.setRange(0, 3, list); | 35 byteArray.setRange(0, 3, list); |
| 30 for (int i = 0; i < 3; i++) { | 36 for (int i = 0; i < 3; i++) { |
| 31 Expect.equals(10 + i, byteArray[i]); | 37 Expect.equals(10 + i, byteArray[i]); |
| 32 } | 38 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 85 } |
| 80 | 86 |
| 81 main() { | 87 main() { |
| 82 for (int i = 0; i < 2000; i++) { | 88 for (int i = 0; i < 2000; i++) { |
| 83 testCreateByteArray(); | 89 testCreateByteArray(); |
| 84 testSetRange(); | 90 testSetRange(); |
| 85 testIndexOutOfRange(); | 91 testIndexOutOfRange(); |
| 86 testIndexOf(); | 92 testIndexOf(); |
| 87 } | 93 } |
| 88 } | 94 } |
| OLD | NEW |