| Index: tests/standalone/byte_array_test.dart
|
| ===================================================================
|
| --- tests/standalone/byte_array_test.dart (revision 15794)
|
| +++ tests/standalone/byte_array_test.dart (working copy)
|
| @@ -9,10 +9,12 @@
|
|
|
| #import('dart:scalarlist');
|
|
|
| -void testCreateByteArray() {
|
| +void testCreateUint8ByteArray() {
|
| Uint8List byteArray;
|
|
|
| byteArray = new Uint8List(0);
|
| + Expect.isTrue(byteArray is Uint8List);
|
| + Expect.isFalse(byteArray is Uint8ClampedList);
|
| Expect.equals(0, byteArray.length);
|
|
|
| byteArray = new Uint8List(10);
|
| @@ -20,7 +22,21 @@
|
| for (int i = 0; i < 10; i++) {
|
| Expect.equals(0, byteArray[i]);
|
| }
|
| +}
|
|
|
| +void testCreateClampedUint8ByteArray() {
|
| + Uint8ClampedList clampedByteArray;
|
| +
|
| + clampedByteArray = new Uint8ClampedList(0);
|
| + Expect.isTrue(clampedByteArray is Uint8ClampedList);
|
| + Expect.isFalse(clampedByteArray is Uint8List);
|
| + Expect.equals(0, clampedByteArray.length);
|
| +
|
| + clampedByteArray = new Uint8ClampedList(10);
|
| + Expect.equals(10, clampedByteArray.length);
|
| + for (int i = 0; i < 10; i++) {
|
| + Expect.equals(0, clampedByteArray[i]);
|
| + }
|
| }
|
|
|
| void testUnsignedByteArrayRange(bool check_throws) {
|
| @@ -43,6 +59,22 @@
|
| }
|
| }
|
|
|
| +void testClampedUnsignedByteArrayRange(bool check_throws) {
|
| + Uint8ClampedList byteArray;
|
| + byteArray = new Uint8ClampedList(10);
|
| +
|
| + byteArray[1] = 255;
|
| + Expect.equals(255, byteArray[1]);
|
| + byteArray[1] = 0;
|
| + Expect.equals(0, byteArray[1]);
|
| +
|
| + // These should eventually throw.
|
| + byteArray[1] = 256;
|
| + byteArray[2] = -129;
|
| + Expect.equals(255, byteArray[1]);
|
| + Expect.equals(0, byteArray[2]);
|
| +}
|
| +
|
| void testByteArrayRange(bool check_throws) {
|
| Int8List byteArray;
|
| byteArray = new Int8List(10);
|
| @@ -62,9 +94,8 @@
|
| }
|
| }
|
|
|
| -void testSetRange() {
|
| - Uint8List byteArray = new Uint8List(3);
|
|
|
| +void testSetRangeHelper(byteArray) {
|
| List<int> list = [10, 11, 12];
|
| byteArray.setRange(0, 3, list);
|
| for (int i = 0; i < 3; i++) {
|
| @@ -85,8 +116,13 @@
|
| Expect.equals(9, byteArray[2]);
|
| }
|
|
|
| -void testIndexOutOfRange() {
|
| - Uint8List byteArray = new Uint8List(3);
|
| +
|
| +void testSetRange() {
|
| + testSetRangeHelper(new Uint8List(3));
|
| + testSetRangeHelper(new Uint8ClampedList(3));
|
| +}
|
| +
|
| +void testIndexOutOfRangeHelper(byteArray) {
|
| List<int> list = const [0, 1, 2, 3];
|
|
|
| Expect.throws(() {
|
| @@ -98,8 +134,12 @@
|
| });
|
| }
|
|
|
| -void testIndexOf() {
|
| - var list = new Uint8List(10);
|
| +void testIndexOutOfRange() {
|
| + testIndexOutOfRangeHelper(new Uint8List(3));
|
| + testIndexOutOfRangeHelper(new Uint8ClampedList(3));
|
| +}
|
| +
|
| +void testIndexOfHelper(list) {
|
| for (int i = 0; i < list.length; i++) {
|
| list[i] = i + 10;
|
| }
|
| @@ -118,8 +158,12 @@
|
| Expect.equals(-1, list.indexOf(20.0));
|
| }
|
|
|
| -void testSubArray() {
|
| - var list = new Uint8List(10);
|
| +void testIndexOf() {
|
| + testIndexOfHelper(new Uint8List(10));
|
| + testIndexOfHelper(new Uint8ClampedList(10));
|
| +}
|
| +
|
| +void testSubArrayHelper(list) {
|
| var array = list.asByteArray();
|
| Expect.equals(0, array.subByteArray(0, 0).lengthInBytes());
|
| Expect.equals(0, array.subByteArray(5, 0).lengthInBytes());
|
| @@ -159,11 +203,19 @@
|
| Expect.throws(() => array.subByteArray(null), (e) => e is ArgumentError);
|
| }
|
|
|
| +
|
| +void testSubArray() {
|
| + testSubArrayHelper(new Uint8List(10));
|
| + testSubArrayHelper(new Uint8ClampedList(10));
|
| +}
|
| +
|
| main() {
|
| for (int i = 0; i < 2000; i++) {
|
| - testCreateByteArray();
|
| + testCreateUint8ByteArray();
|
| + testCreateClampedUint8ByteArray();
|
| testByteArrayRange(false);
|
| testUnsignedByteArrayRange(false);
|
| + testClampedUnsignedByteArrayRange(false);
|
| testSetRange();
|
| testIndexOutOfRange();
|
| testIndexOf();
|
|
|