| 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 | 23 |
| 24 } | 24 } |
| 25 | 25 |
| 26 void testUnsignedByteArrayRange() { | 26 void testUnsignedByteArrayRange() { |
| 27 Uint8List byteArray; | 27 Uint8List byteArray; |
| 28 byteArray = new Uint8List(10); | 28 byteArray = new Uint8List(10); |
| 29 | 29 |
| 30 byteArray[1] = 255; | 30 byteArray[1] = 255; |
| 31 Expect.equals(255, byteArray[1]); | 31 Expect.equals(255, byteArray[1]); |
| 32 byteArray[1] = 0; | 32 byteArray[1] = 0; |
| 33 Expect.equals(0, byteArray[1]); | 33 Expect.equals(0, byteArray[1]); |
| 34 | 34 |
| 35 Expect.throws(() { | 35 Expect.throws(() { |
| 36 byteArray[1] = 1.2; | 36 byteArray[1] = 1.2; |
| 37 }); | 37 }); |
| 38 // These should eventually throw. | 38 // These should eventually throw. |
| 39 byteArray[1] = 256; | 39 byteArray[1] = 256; |
| 40 byteArray[1] = -1; | 40 byteArray[1] = -1; |
| 41 byteArray[2] = -129; | 41 byteArray[2] = -129; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void testByteArrayRange() { | 44 void testByteArrayRange() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 Expect.equals(0, array.subByteArray(10, null).lengthInBytes()); | 124 Expect.equals(0, array.subByteArray(10, null).lengthInBytes()); |
| 125 Expect.equals(5, array.subByteArray(0, 5).lengthInBytes()); | 125 Expect.equals(5, array.subByteArray(0, 5).lengthInBytes()); |
| 126 Expect.equals(5, array.subByteArray(5, 5).lengthInBytes()); | 126 Expect.equals(5, array.subByteArray(5, 5).lengthInBytes()); |
| 127 Expect.equals(5, array.subByteArray(5).lengthInBytes()); | 127 Expect.equals(5, array.subByteArray(5).lengthInBytes()); |
| 128 Expect.equals(5, array.subByteArray(5, null).lengthInBytes()); | 128 Expect.equals(5, array.subByteArray(5, null).lengthInBytes()); |
| 129 Expect.equals(10, array.subByteArray(0, 10).lengthInBytes()); | 129 Expect.equals(10, array.subByteArray(0, 10).lengthInBytes()); |
| 130 Expect.equals(10, array.subByteArray(0).lengthInBytes()); | 130 Expect.equals(10, array.subByteArray(0).lengthInBytes()); |
| 131 Expect.equals(10, array.subByteArray(0, null).lengthInBytes()); | 131 Expect.equals(10, array.subByteArray(0, null).lengthInBytes()); |
| 132 Expect.equals(10, array.subByteArray().lengthInBytes()); | 132 Expect.equals(10, array.subByteArray().lengthInBytes()); |
| 133 testThrowsIndex(function) { | 133 testThrowsIndex(function) { |
| 134 Expect.throws(function, (e) => e is IndexOutOfRangeException); | 134 Expect.throws(function, (e) => e is RangeError); |
| 135 } | 135 } |
| 136 testThrowsIndex(() => array.subByteArray(0, -1)); | 136 testThrowsIndex(() => array.subByteArray(0, -1)); |
| 137 testThrowsIndex(() => array.subByteArray(1, -1)); | 137 testThrowsIndex(() => array.subByteArray(1, -1)); |
| 138 testThrowsIndex(() => array.subByteArray(10, -1)); | 138 testThrowsIndex(() => array.subByteArray(10, -1)); |
| 139 testThrowsIndex(() => array.subByteArray(-1, 0)); | 139 testThrowsIndex(() => array.subByteArray(-1, 0)); |
| 140 testThrowsIndex(() => array.subByteArray(-1)); | 140 testThrowsIndex(() => array.subByteArray(-1)); |
| 141 testThrowsIndex(() => array.subByteArray(-1, null)); | 141 testThrowsIndex(() => array.subByteArray(-1, null)); |
| 142 testThrowsIndex(() => array.subByteArray(11, 0)); | 142 testThrowsIndex(() => array.subByteArray(11, 0)); |
| 143 testThrowsIndex(() => array.subByteArray(11)); | 143 testThrowsIndex(() => array.subByteArray(11)); |
| 144 testThrowsIndex(() => array.subByteArray(11, null)); | 144 testThrowsIndex(() => array.subByteArray(11, null)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 160 testCreateByteArray(); | 160 testCreateByteArray(); |
| 161 testByteArrayRange(); | 161 testByteArrayRange(); |
| 162 testUnsignedByteArrayRange(); | 162 testUnsignedByteArrayRange(); |
| 163 testSetRange(); | 163 testSetRange(); |
| 164 testIndexOutOfRange(); | 164 testIndexOutOfRange(); |
| 165 testIndexOf(); | 165 testIndexOf(); |
| 166 testSubArray(); | 166 testSubArray(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| OLD | NEW |