| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // Dart test program for testing native byte arrays. | |
| 6 | |
| 7 void testCreateByteArray() { | |
| 8 ByteArray byteArray; | |
| 9 | |
| 10 byteArray = new ByteArray(0); | |
| 11 Expect.equals(0, byteArray.length); | |
| 12 | |
| 13 byteArray = new ByteArray(10); | |
| 14 Expect.equals(10, byteArray.length); | |
| 15 for (int i = 0; i < 10; i++) { | |
| 16 Expect.equals(0, byteArray[i]); | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 void testSetRange() { | |
| 21 ByteArray byteArray = new ByteArray(3); | |
| 22 | |
| 23 List<int> list = [10, 11, 12]; | |
| 24 byteArray.setRange(0, 3, list); | |
| 25 for (int i = 0; i < 3; i++) { | |
| 26 Expect.equals(10 + i, byteArray[i]); | |
| 27 } | |
| 28 | |
| 29 byteArray[0] = 20; | |
| 30 byteArray[1] = 21; | |
| 31 byteArray[2] = 22; | |
| 32 list.setRange(0, 3, byteArray); | |
| 33 for (int i = 0; i < 3; i++) { | |
| 34 Expect.equals(20 + i, list[i]); | |
| 35 } | |
| 36 | |
| 37 byteArray.setRange(1, 2, const [8, 9]); | |
| 38 Expect.equals(20, byteArray[0]); | |
| 39 Expect.equals(8, byteArray[1]); | |
| 40 Expect.equals(9, byteArray[2]); | |
| 41 } | |
| 42 | |
| 43 void testIndexOutOfRange() { | |
| 44 ByteArray byteArray = new ByteArray(3); | |
| 45 List<int> list = const [0, 1, 2, 3]; | |
| 46 | |
| 47 Expect.throws(() { | |
| 48 byteArray.setRange(0, 4, list); | |
| 49 }); | |
| 50 | |
| 51 Expect.throws(() { | |
| 52 byteArray.setRange(3, 1, list); | |
| 53 }); | |
| 54 } | |
| 55 | |
| 56 main() { | |
| 57 for (int i = 0; i < 2000; i++) { | |
| 58 testCreateByteArray(); | |
| 59 testSetRange(); | |
| 60 testIndexOutOfRange(); | |
| 61 } | |
| 62 } | |
| OLD | NEW |