| 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 // Library tag to be able to run in html test framework. | 5 // Library tag to be able to run in html test framework. |
| 6 library byte_array_test; | 6 library byte_array_test; |
| 7 | 7 |
| 8 import 'dart:scalarlist'; | 8 import 'dart:scalarlist'; |
| 9 | 9 |
| 10 class ByteArrayTest { | 10 class ByteArrayTest { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 Expect.throws(() { new Uint8List(-1); }, | 172 Expect.throws(() { new Uint8List(-1); }, |
| 173 (e) { return e is ArgumentError; }); | 173 (e) { return e is ArgumentError; }); |
| 174 Expect.throws(() { new Uint8List.transferable(-1); }, | 174 Expect.throws(() { new Uint8List.transferable(-1); }, |
| 175 (e) { return e is ArgumentError; }); | 175 (e) { return e is ArgumentError; }); |
| 176 var array = new Uint8List(10); | 176 var array = new Uint8List(10); |
| 177 testUint8ListImpl(array); | 177 testUint8ListImpl(array); |
| 178 array = new Uint8List.transferable(10); | 178 array = new Uint8List.transferable(10); |
| 179 testUint8ListImpl(array); | 179 testUint8ListImpl(array); |
| 180 } | 180 } |
| 181 | 181 |
| 182 static testUint8ClampedListImpl(Uint8ClampedList array) { |
| 183 Expect.isTrue(array is List<int>); |
| 184 Expect.equals(10, array.length); |
| 185 Expect.equals(1, array.bytesPerElement()); |
| 186 Expect.equals(10, array.lengthInBytes()); |
| 187 Expect.listEquals([0, 0, 0, 0, 0, |
| 188 0, 0, 0, 0, 0], |
| 189 array); |
| 190 Expect.throws(() { array[-1] = 0; }, |
| 191 (e) { return e is RangeError; }); |
| 192 Expect.throws(() { return array[-1]; }, |
| 193 (e) { return e is RangeError; }); |
| 194 Expect.throws(() { array[10]; }, |
| 195 (e) { return e is RangeError; }); |
| 196 Expect.throws(() { array[10] = 0; }, |
| 197 (e) { return e is RangeError; }); |
| 198 Expect.throws(() { array.add(0); }, |
| 199 (e) { return e is UnsupportedError; }); |
| 200 Expect.throws(() { array.addAll([0]); }, |
| 201 (e) { return e is UnsupportedError; }); |
| 202 Expect.throws(() { array.addLast(0); }, |
| 203 (e) { return e is UnsupportedError; }); |
| 204 Expect.throws(() { array.clear(); }, |
| 205 (e) { return e is UnsupportedError; }); |
| 206 Expect.throws(() { array.insertRange(0, array.length, 0); }, |
| 207 (e) { return e is UnsupportedError; }); |
| 208 Expect.throws(() { array.length = 0; }, |
| 209 (e) { return e is UnsupportedError; }); |
| 210 Expect.throws(() { array.removeLast(); }, |
| 211 (e) { return e is UnsupportedError; }); |
| 212 Expect.throws(() { array.removeRange(0, array.length - 1); }, |
| 213 (e) { return e is UnsupportedError; }); |
| 214 for (int i = 0; i < array.length; ++i) { |
| 215 array[i] = -1 + i; |
| 216 } |
| 217 Expect.listEquals([0, 0, 1, 2, 3, 4, 5, 6, 7, 8], array); |
| 218 for (int i = 0; i < array.length; ++i) { |
| 219 array[i] = 0x100 + i; |
| 220 } |
| 221 Expect.listEquals([255, 255, 255, 255, 255, 255, 255, 255, 255, 255], |
| 222 array); |
| 223 for (int i = 0; i < array.length; ++i) { |
| 224 array[i] = 0xFF - i; |
| 225 } |
| 226 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB, |
| 227 0xFA, 0xF9, 0xF8, 0xF7, 0xF6], |
| 228 array); |
| 229 for (int i = 0; i < array.length; ++i) { |
| 230 array[i] = i; |
| 231 } |
| 232 var copy = array.getRange(0, array.length); |
| 233 Expect.isFalse(copy === array); |
| 234 Expect.isTrue(copy is Uint8ClampedList); |
| 235 Expect.equals(10, copy.length); |
| 236 Expect.listEquals(array, copy); |
| 237 var empty = array.getRange(array.length, 0); |
| 238 Expect.equals(0, empty.length); |
| 239 var region = array.getRange(3, array.length - 6); |
| 240 Expect.isTrue(copy is Uint8ClampedList); |
| 241 Expect.equals(4, region.length); |
| 242 Expect.listEquals([3, 4, 5, 6], region); |
| 243 array.setRange(3, 4, [257, 0, 1, 255]); |
| 244 Expect.listEquals([0, 1, 2, 255, 0, 1, 255, 7, 8, 9], array); |
| 245 } |
| 246 |
| 247 static testUint8ClampedList() { |
| 248 Expect.throws(() { new Uint8ClampedList(-1); }, |
| 249 (e) { return e is ArgumentError; }); |
| 250 Expect.throws(() { new Uint8ClampedList.transferable(-1); }, |
| 251 (e) { return e is ArgumentError; }); |
| 252 var array = new Uint8ClampedList(10); |
| 253 testUint8ClampedListImpl(array); |
| 254 array = new Uint8ClampedList.transferable(10); |
| 255 testUint8ClampedListImpl(array); |
| 256 } |
| 257 |
| 182 static testInt16ListImpl(Int16List array) { | 258 static testInt16ListImpl(Int16List array) { |
| 183 Expect.isTrue(array is List<int>); | 259 Expect.isTrue(array is List<int>); |
| 184 Expect.equals(10, array.length); | 260 Expect.equals(10, array.length); |
| 185 Expect.equals(2, array.bytesPerElement()); | 261 Expect.equals(2, array.bytesPerElement()); |
| 186 Expect.equals(20, array.lengthInBytes()); | 262 Expect.equals(20, array.lengthInBytes()); |
| 187 Expect.listEquals([0, 0, 0, 0, 0, | 263 Expect.listEquals([0, 0, 0, 0, 0, |
| 188 0, 0, 0, 0, 0], | 264 0, 0, 0, 0, 0], |
| 189 array); | 265 array); |
| 190 Expect.throws(() { array[-1] = 0; }, | 266 Expect.throws(() { array[-1] = 0; }, |
| 191 (e) { return e is RangeError; }); | 267 (e) { return e is RangeError; }); |
| (...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2375 static testFloat64ListView() { | 2451 static testFloat64ListView() { |
| 2376 var array = new Uint64List(12); | 2452 var array = new Uint64List(12); |
| 2377 testFloat64ListViewImpl(array); | 2453 testFloat64ListViewImpl(array); |
| 2378 array = new Uint64List.transferable(12); | 2454 array = new Uint64List.transferable(12); |
| 2379 testFloat64ListViewImpl(array); | 2455 testFloat64ListViewImpl(array); |
| 2380 } | 2456 } |
| 2381 | 2457 |
| 2382 static testMain() { | 2458 static testMain() { |
| 2383 testInt8List(); | 2459 testInt8List(); |
| 2384 testUint8List(); | 2460 testUint8List(); |
| 2461 testUint8ClampedList(); |
| 2385 testInt16List(); | 2462 testInt16List(); |
| 2386 testUint16List(); | 2463 testUint16List(); |
| 2387 testInt32List(); | 2464 testInt32List(); |
| 2388 testUint32List(); | 2465 testUint32List(); |
| 2389 testInt64List(); | 2466 testInt64List(); |
| 2390 testUint64List(); | 2467 testUint64List(); |
| 2391 testFloat32List(); | 2468 testFloat32List(); |
| 2392 testFloat64List(); | 2469 testFloat64List(); |
| 2393 testByteList(); | 2470 testByteList(); |
| 2394 testInt8ListView(); | 2471 testInt8ListView(); |
| 2395 testUint8ListView(); | 2472 testUint8ListView(); |
| 2396 testInt16ListView(); | 2473 testInt16ListView(); |
| 2397 testUint16ListView(); | 2474 testUint16ListView(); |
| 2398 testInt32ListView(); | 2475 testInt32ListView(); |
| 2399 testUint32ListView(); | 2476 testUint32ListView(); |
| 2400 testInt64ListView(); | 2477 testInt64ListView(); |
| 2401 testUint64ListView(); | 2478 testUint64ListView(); |
| 2402 testFloat32ListView(); | 2479 testFloat32ListView(); |
| 2403 testFloat64ListView(); | 2480 testFloat64ListView(); |
| 2404 } | 2481 } |
| 2405 } | 2482 } |
| 2406 | 2483 |
| 2407 main() { | 2484 main() { |
| 2408 for (var i=0; i<1000; i++) { | 2485 for (var i=0; i<1000; i++) { |
| 2409 ByteArrayTest.testMain(); | 2486 ByteArrayTest.testMain(); |
| 2410 } | 2487 } |
| 2411 } | 2488 } |
| OLD | NEW |