Chromium Code Reviews| 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'); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 list = new Float32List(10); | 71 list = new Float32List(10); |
| 72 for (int i = 0; i < list.length; i++) { | 72 for (int i = 0; i < list.length; i++) { |
| 73 list[i] = i + 10.0; | 73 list[i] = i + 10.0; |
| 74 } | 74 } |
| 75 Expect.equals(0, list.indexOf(10.0)); | 75 Expect.equals(0, list.indexOf(10.0)); |
| 76 Expect.equals(5, list.indexOf(15.0)); | 76 Expect.equals(5, list.indexOf(15.0)); |
| 77 Expect.equals(9, list.indexOf(19.0)); | 77 Expect.equals(9, list.indexOf(19.0)); |
| 78 Expect.equals(-1, list.indexOf(20.0)); | 78 Expect.equals(-1, list.indexOf(20.0)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void testSubArray() { | |
| 82 var list = new Uint8List(10); | |
| 83 var array = list.asByteArray(); | |
| 84 Expect.equals(0, array.subByteArray(0, 0).lengthInBytes()); | |
| 85 Expect.equals(0, array.subByteArray(5, 0).lengthInBytes()); | |
| 86 Expect.equals(0, array.subByteArray(10, 0).lengthInBytes()); | |
| 87 Expect.equals(0, array.subByteArray(10).lengthInBytes()); | |
| 88 Expect.equals(0, array.subByteArray(10, null).lengthInBytes()); | |
|
karlklose
2012/10/11 08:18:18
I am not sure this is what we want and since we ca
| |
| 89 Expect.equals(5, array.subByteArray(0, 5).lengthInBytes()); | |
| 90 Expect.equals(5, array.subByteArray(5, 5).lengthInBytes()); | |
| 91 Expect.equals(5, array.subByteArray(5).lengthInBytes()); | |
| 92 Expect.equals(5, array.subByteArray(5, null).lengthInBytes()); | |
| 93 Expect.equals(10, array.subByteArray(0, 10).lengthInBytes()); | |
| 94 Expect.equals(10, array.subByteArray(0).lengthInBytes()); | |
| 95 Expect.equals(10, array.subByteArray(0, null).lengthInBytes()); | |
| 96 Expect.equals(10, array.subByteArray().lengthInBytes()); | |
| 97 testThrowsIndex(function) { | |
| 98 Expect.throws(function, (e) => e is IndexOutOfRangeException); | |
| 99 } | |
| 100 testThrowsIndex(() => array.subByteArray(0, -1)); | |
| 101 testThrowsIndex(() => array.subByteArray(1, -1)); | |
| 102 testThrowsIndex(() => array.subByteArray(10, -1)); | |
| 103 testThrowsIndex(() => array.subByteArray(-1, 0)); | |
| 104 testThrowsIndex(() => array.subByteArray(-1)); | |
| 105 testThrowsIndex(() => array.subByteArray(-1, null)); | |
| 106 testThrowsIndex(() => array.subByteArray(11, 0)); | |
| 107 testThrowsIndex(() => array.subByteArray(11)); | |
| 108 testThrowsIndex(() => array.subByteArray(11, null)); | |
| 109 testThrowsIndex(() => array.subByteArray(6, 5)); | |
| 110 Expect.throws(() => array.subByteArray(0, "5"), (e) => e is ArgumentError); | |
| 111 Expect.throws(() => array.subByteArray("0", 5), (e) => e is ArgumentError); | |
| 112 Expect.throws(() => array.subByteArray("0"), (e) => e is ArgumentError); | |
| 113 Expect.throws(() => array.subByteArray(null), (e) => e is ArgumentError); | |
| 114 } | |
| 115 | |
| 81 main() { | 116 main() { |
| 82 for (int i = 0; i < 2000; i++) { | 117 for (int i = 0; i < 2000; i++) { |
| 83 testCreateByteArray(); | 118 testCreateByteArray(); |
| 84 testSetRange(); | 119 testSetRange(); |
| 85 testIndexOutOfRange(); | 120 testIndexOutOfRange(); |
| 86 testIndexOf(); | 121 testIndexOf(); |
| 122 testSubArray(); | |
| 87 } | 123 } |
| 88 } | 124 } |
| 125 | |
| OLD | NEW |