| 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("ByteArrayTest.dart"); | 6 #library("ByteArrayTest.dart"); |
| 7 | 7 |
| 8 #import('dart:scalarlist'); | 8 #import('dart:scalarlist'); |
| 9 | 9 |
| 10 class ByteArrayTest { | 10 class ByteArrayTest { |
| 11 static testInt8List() { | 11 static testInt8List() { |
| 12 Expect.throws(() { new Int8List(-1); }, | 12 Expect.throws(() { new Int8List(-1); }, |
| 13 (e) { return e is IllegalArgumentException; }); | 13 (e) { return e is ArgumentError; }); |
| 14 var array = new Int8List(10); | 14 var array = new Int8List(10); |
| 15 Expect.isTrue(array is List<int>); | 15 Expect.isTrue(array is List<int>); |
| 16 Expect.equals(10, array.length); | 16 Expect.equals(10, array.length); |
| 17 Expect.equals(1, array.bytesPerElement()); | 17 Expect.equals(1, array.bytesPerElement()); |
| 18 Expect.equals(10, array.lengthInBytes()); | 18 Expect.equals(10, array.lengthInBytes()); |
| 19 Expect.listEquals([0, 0, 0, 0, 0, | 19 Expect.listEquals([0, 0, 0, 0, 0, |
| 20 0, 0, 0, 0, 0], | 20 0, 0, 0, 0, 0], |
| 21 array); | 21 array); |
| 22 Expect.throws(() { array[-1] = 0; }, | 22 Expect.throws(() { array[-1] = 0; }, |
| 23 (e) { return e is IndexOutOfRangeException; }); | 23 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 Expect.isTrue(copy is Int8List); | 87 Expect.isTrue(copy is Int8List); |
| 88 Expect.equals(4, region.length); | 88 Expect.equals(4, region.length); |
| 89 Expect.listEquals([3, 4, 5, 6], region); | 89 Expect.listEquals([3, 4, 5, 6], region); |
| 90 array.setRange(3, 4, [-128, 0, 1, 127]); | 90 array.setRange(3, 4, [-128, 0, 1, 127]); |
| 91 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9], | 91 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9], |
| 92 array); | 92 array); |
| 93 } | 93 } |
| 94 | 94 |
| 95 static testUint8List() { | 95 static testUint8List() { |
| 96 Expect.throws(() { new Uint8List(-1); }, | 96 Expect.throws(() { new Uint8List(-1); }, |
| 97 (e) { return e is IllegalArgumentException; }); | 97 (e) { return e is ArgumentError; }); |
| 98 var array = new Uint8List(10); | 98 var array = new Uint8List(10); |
| 99 Expect.isTrue(array is List<int>); | 99 Expect.isTrue(array is List<int>); |
| 100 Expect.equals(10, array.length); | 100 Expect.equals(10, array.length); |
| 101 Expect.equals(1, array.bytesPerElement()); | 101 Expect.equals(1, array.bytesPerElement()); |
| 102 Expect.equals(10, array.lengthInBytes()); | 102 Expect.equals(10, array.lengthInBytes()); |
| 103 Expect.listEquals([0, 0, 0, 0, 0, | 103 Expect.listEquals([0, 0, 0, 0, 0, |
| 104 0, 0, 0, 0, 0], | 104 0, 0, 0, 0, 0], |
| 105 array); | 105 array); |
| 106 Expect.throws(() { array[-1] = 0; }, | 106 Expect.throws(() { array[-1] = 0; }, |
| 107 (e) { return e is IndexOutOfRangeException; }); | 107 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Expect.isTrue(copy is Uint8List); | 159 Expect.isTrue(copy is Uint8List); |
| 160 Expect.equals(4, region.length); | 160 Expect.equals(4, region.length); |
| 161 Expect.listEquals([3, 4, 5, 6], region); | 161 Expect.listEquals([3, 4, 5, 6], region); |
| 162 array.setRange(3, 4, [257, 0, 1, 255]); | 162 array.setRange(3, 4, [257, 0, 1, 255]); |
| 163 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9], | 163 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9], |
| 164 array); | 164 array); |
| 165 } | 165 } |
| 166 | 166 |
| 167 static testInt16List() { | 167 static testInt16List() { |
| 168 Expect.throws(() { new Int16List(-1); }, | 168 Expect.throws(() { new Int16List(-1); }, |
| 169 (e) { return e is IllegalArgumentException; }); | 169 (e) { return e is ArgumentError; }); |
| 170 var array = new Int16List(10); | 170 var array = new Int16List(10); |
| 171 Expect.isTrue(array is List<int>); | 171 Expect.isTrue(array is List<int>); |
| 172 Expect.equals(10, array.length); | 172 Expect.equals(10, array.length); |
| 173 Expect.equals(2, array.bytesPerElement()); | 173 Expect.equals(2, array.bytesPerElement()); |
| 174 Expect.equals(20, array.lengthInBytes()); | 174 Expect.equals(20, array.lengthInBytes()); |
| 175 Expect.listEquals([0, 0, 0, 0, 0, | 175 Expect.listEquals([0, 0, 0, 0, 0, |
| 176 0, 0, 0, 0, 0], | 176 0, 0, 0, 0, 0], |
| 177 array); | 177 array); |
| 178 Expect.throws(() { array[-1] = 0; }, | 178 Expect.throws(() { array[-1] = 0; }, |
| 179 (e) { return e is IndexOutOfRangeException; }); | 179 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 Expect.isTrue(copy is Int16List); | 243 Expect.isTrue(copy is Int16List); |
| 244 Expect.equals(4, region.length); | 244 Expect.equals(4, region.length); |
| 245 Expect.listEquals([3, 4, 5, 6], region); | 245 Expect.listEquals([3, 4, 5, 6], region); |
| 246 array.setRange(3, 4, [-32768, 0, 1, 32767]); | 246 array.setRange(3, 4, [-32768, 0, 1, 32767]); |
| 247 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9], | 247 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9], |
| 248 array); | 248 array); |
| 249 } | 249 } |
| 250 | 250 |
| 251 static testUint16List() { | 251 static testUint16List() { |
| 252 Expect.throws(() { new Uint16List(-1); }, | 252 Expect.throws(() { new Uint16List(-1); }, |
| 253 (e) { return e is IllegalArgumentException; }); | 253 (e) { return e is ArgumentError; }); |
| 254 var array = new Uint16List(10); | 254 var array = new Uint16List(10); |
| 255 Expect.isTrue(array is List<int>); | 255 Expect.isTrue(array is List<int>); |
| 256 Expect.equals(10, array.length); | 256 Expect.equals(10, array.length); |
| 257 Expect.equals(2, array.bytesPerElement()); | 257 Expect.equals(2, array.bytesPerElement()); |
| 258 Expect.equals(20, array.lengthInBytes()); | 258 Expect.equals(20, array.lengthInBytes()); |
| 259 Expect.listEquals([0, 0, 0, 0, 0, | 259 Expect.listEquals([0, 0, 0, 0, 0, |
| 260 0, 0, 0, 0, 0], | 260 0, 0, 0, 0, 0], |
| 261 array); | 261 array); |
| 262 Expect.throws(() { array[-1] = 0; }, | 262 Expect.throws(() { array[-1] = 0; }, |
| 263 (e) { return e is IndexOutOfRangeException; }); | 263 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 Expect.isTrue(copy is Uint16List); | 315 Expect.isTrue(copy is Uint16List); |
| 316 Expect.equals(4, region.length); | 316 Expect.equals(4, region.length); |
| 317 Expect.listEquals([3, 4, 5, 6], region); | 317 Expect.listEquals([3, 4, 5, 6], region); |
| 318 array.setRange(3, 4, [0x10001, 0, 1, 0xFFFF]); | 318 array.setRange(3, 4, [0x10001, 0, 1, 0xFFFF]); |
| 319 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9], | 319 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9], |
| 320 array); | 320 array); |
| 321 } | 321 } |
| 322 | 322 |
| 323 static testInt32List() { | 323 static testInt32List() { |
| 324 Expect.throws(() { new Int32List(-1); }, | 324 Expect.throws(() { new Int32List(-1); }, |
| 325 (e) { return e is IllegalArgumentException; }); | 325 (e) { return e is ArgumentError; }); |
| 326 var array = new Int32List(10); | 326 var array = new Int32List(10); |
| 327 Expect.isTrue(array is List<int>); | 327 Expect.isTrue(array is List<int>); |
| 328 Expect.equals(10, array.length); | 328 Expect.equals(10, array.length); |
| 329 Expect.equals(4, array.bytesPerElement()); | 329 Expect.equals(4, array.bytesPerElement()); |
| 330 Expect.equals(40, array.lengthInBytes()); | 330 Expect.equals(40, array.lengthInBytes()); |
| 331 Expect.listEquals([0, 0, 0, 0, 0, | 331 Expect.listEquals([0, 0, 0, 0, 0, |
| 332 0, 0, 0, 0, 0], | 332 0, 0, 0, 0, 0], |
| 333 array); | 333 array); |
| 334 Expect.throws(() { array[-1] = 0; }, | 334 Expect.throws(() { array[-1] = 0; }, |
| 335 (e) { return e is IndexOutOfRangeException; }); | 335 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 Expect.isTrue(copy is Int32List); | 405 Expect.isTrue(copy is Int32List); |
| 406 Expect.equals(4, region.length); | 406 Expect.equals(4, region.length); |
| 407 Expect.listEquals([3, 4, 5, 6], region); | 407 Expect.listEquals([3, 4, 5, 6], region); |
| 408 array.setRange(3, 4, [-0x80000000, 0, 1, 0x7FFFFFFF]); | 408 array.setRange(3, 4, [-0x80000000, 0, 1, 0x7FFFFFFF]); |
| 409 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9], | 409 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9], |
| 410 array); | 410 array); |
| 411 } | 411 } |
| 412 | 412 |
| 413 static testUint32List() { | 413 static testUint32List() { |
| 414 Expect.throws(() { new Uint32List(-1); }, | 414 Expect.throws(() { new Uint32List(-1); }, |
| 415 (e) { return e is IllegalArgumentException; }); | 415 (e) { return e is ArgumentError; }); |
| 416 var array = new Uint32List(10); | 416 var array = new Uint32List(10); |
| 417 Expect.isTrue(array is List<int>); | 417 Expect.isTrue(array is List<int>); |
| 418 Expect.equals(10, array.length); | 418 Expect.equals(10, array.length); |
| 419 Expect.equals(4, array.bytesPerElement()); | 419 Expect.equals(4, array.bytesPerElement()); |
| 420 Expect.equals(40, array.lengthInBytes()); | 420 Expect.equals(40, array.lengthInBytes()); |
| 421 Expect.listEquals([0, 0, 0, 0, 0, | 421 Expect.listEquals([0, 0, 0, 0, 0, |
| 422 0, 0, 0, 0, 0], | 422 0, 0, 0, 0, 0], |
| 423 array); | 423 array); |
| 424 Expect.throws(() { array[-1] = 0; }, | 424 Expect.throws(() { array[-1] = 0; }, |
| 425 (e) { return e is IndexOutOfRangeException; }); | 425 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 Expect.isTrue(copy is Uint32List); | 480 Expect.isTrue(copy is Uint32List); |
| 481 Expect.equals(4, region.length); | 481 Expect.equals(4, region.length); |
| 482 Expect.listEquals([3, 4, 5, 6], region); | 482 Expect.listEquals([3, 4, 5, 6], region); |
| 483 array.setRange(3, 4, [0x100000001, 0, 1, 0xFFFFFFFF]); | 483 array.setRange(3, 4, [0x100000001, 0, 1, 0xFFFFFFFF]); |
| 484 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9], | 484 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9], |
| 485 array); | 485 array); |
| 486 } | 486 } |
| 487 | 487 |
| 488 static testInt64List() { | 488 static testInt64List() { |
| 489 Expect.throws(() { new Int64List(-1); }, | 489 Expect.throws(() { new Int64List(-1); }, |
| 490 (e) { return e is IllegalArgumentException; }); | 490 (e) { return e is ArgumentError; }); |
| 491 var array = new Int64List(10); | 491 var array = new Int64List(10); |
| 492 Expect.isTrue(array is List<int>); | 492 Expect.isTrue(array is List<int>); |
| 493 Expect.equals(10, array.length); | 493 Expect.equals(10, array.length); |
| 494 Expect.equals(8, array.bytesPerElement()); | 494 Expect.equals(8, array.bytesPerElement()); |
| 495 Expect.equals(80, array.lengthInBytes()); | 495 Expect.equals(80, array.lengthInBytes()); |
| 496 Expect.listEquals([0, 0, 0, 0, 0, | 496 Expect.listEquals([0, 0, 0, 0, 0, |
| 497 0, 0, 0, 0, 0], | 497 0, 0, 0, 0, 0], |
| 498 array); | 498 array); |
| 499 Expect.throws(() { array[-1] = 0; }, | 499 Expect.throws(() { array[-1] = 0; }, |
| 500 (e) { return e is IndexOutOfRangeException; }); | 500 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 Expect.equals(4, region.length); | 571 Expect.equals(4, region.length); |
| 572 Expect.listEquals([3, 4, 5, 6], region); | 572 Expect.listEquals([3, 4, 5, 6], region); |
| 573 array.setRange(3, 4, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]); | 573 array.setRange(3, 4, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]); |
| 574 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0, | 574 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0, |
| 575 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9], | 575 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9], |
| 576 array); | 576 array); |
| 577 } | 577 } |
| 578 | 578 |
| 579 static testUint64List() { | 579 static testUint64List() { |
| 580 Expect.throws(() { new Uint64List(-1); }, | 580 Expect.throws(() { new Uint64List(-1); }, |
| 581 (e) { return e is IllegalArgumentException; }); | 581 (e) { return e is ArgumentError; }); |
| 582 var array = new Uint64List(10); | 582 var array = new Uint64List(10); |
| 583 Expect.isTrue(array is List<int>); | 583 Expect.isTrue(array is List<int>); |
| 584 Expect.equals(10, array.length); | 584 Expect.equals(10, array.length); |
| 585 Expect.equals(8, array.bytesPerElement()); | 585 Expect.equals(8, array.bytesPerElement()); |
| 586 Expect.equals(80, array.lengthInBytes()); | 586 Expect.equals(80, array.lengthInBytes()); |
| 587 Expect.listEquals([0, 0, 0, 0, 0, | 587 Expect.listEquals([0, 0, 0, 0, 0, |
| 588 0, 0, 0, 0, 0], | 588 0, 0, 0, 0, 0], |
| 589 array); | 589 array); |
| 590 Expect.throws(() { array[-1] = 0; }, | 590 Expect.throws(() { array[-1] = 0; }, |
| 591 (e) { return e is IndexOutOfRangeException; }); | 591 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 Expect.isTrue(copy is Uint64List); | 646 Expect.isTrue(copy is Uint64List); |
| 647 Expect.equals(4, region.length); | 647 Expect.equals(4, region.length); |
| 648 Expect.listEquals([3, 4, 5, 6], region); | 648 Expect.listEquals([3, 4, 5, 6], region); |
| 649 array.setRange(3, 4, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]); | 649 array.setRange(3, 4, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]); |
| 650 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9], | 650 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9], |
| 651 array); | 651 array); |
| 652 } | 652 } |
| 653 | 653 |
| 654 static testFloat32List() { | 654 static testFloat32List() { |
| 655 Expect.throws(() { new Float32List(-1); }, | 655 Expect.throws(() { new Float32List(-1); }, |
| 656 (e) { return e is IllegalArgumentException; }); | 656 (e) { return e is ArgumentError; }); |
| 657 var array = new Float32List(10); | 657 var array = new Float32List(10); |
| 658 Expect.isTrue(array is List<double>); | 658 Expect.isTrue(array is List<double>); |
| 659 Expect.equals(10, array.length); | 659 Expect.equals(10, array.length); |
| 660 Expect.equals(4, array.bytesPerElement()); | 660 Expect.equals(4, array.bytesPerElement()); |
| 661 Expect.equals(40, array.lengthInBytes()); | 661 Expect.equals(40, array.lengthInBytes()); |
| 662 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0, | 662 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0, |
| 663 0.0, 0.0, 0.0, 0.0, 0.0], | 663 0.0, 0.0, 0.0, 0.0, 0.0], |
| 664 array); | 664 array); |
| 665 Expect.throws(() { array[-1] = 0.0; }, | 665 Expect.throws(() { array[-1] = 0.0; }, |
| 666 (e) { return e is IndexOutOfRangeException; }); | 666 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 Expect.equals(4, region.length); | 708 Expect.equals(4, region.length); |
| 709 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); | 709 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); |
| 710 array.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); | 710 array.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); |
| 711 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0, | 711 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0, |
| 712 1.0, double.INFINITY, 7.0, 8.0, 9.0], | 712 1.0, double.INFINITY, 7.0, 8.0, 9.0], |
| 713 array); | 713 array); |
| 714 } | 714 } |
| 715 | 715 |
| 716 static testFloat64List() { | 716 static testFloat64List() { |
| 717 Expect.throws(() { new Float64List(-1); }, | 717 Expect.throws(() { new Float64List(-1); }, |
| 718 (e) { return e is IllegalArgumentException; }); | 718 (e) { return e is ArgumentError; }); |
| 719 var array = new Float64List(10); | 719 var array = new Float64List(10); |
| 720 Expect.isTrue(array is List<double>); | 720 Expect.isTrue(array is List<double>); |
| 721 Expect.equals(10, array.length); | 721 Expect.equals(10, array.length); |
| 722 Expect.equals(8, array.bytesPerElement()); | 722 Expect.equals(8, array.bytesPerElement()); |
| 723 Expect.equals(80, array.lengthInBytes()); | 723 Expect.equals(80, array.lengthInBytes()); |
| 724 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0, | 724 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0, |
| 725 0.0, 0.0, 0.0, 0.0, 0.0], | 725 0.0, 0.0, 0.0, 0.0, 0.0], |
| 726 array); | 726 array); |
| 727 Expect.throws(() { array[-1] = 0.0; }, | 727 Expect.throws(() { array[-1] = 0.0; }, |
| 728 (e) { return e is IndexOutOfRangeException; }); | 728 (e) { return e is IndexOutOfRangeException; }); |
| (...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 testInt64ListView(); | 2269 testInt64ListView(); |
| 2270 testUint64ListView(); | 2270 testUint64ListView(); |
| 2271 testFloat32ListView(); | 2271 testFloat32ListView(); |
| 2272 testFloat64ListView(); | 2272 testFloat64ListView(); |
| 2273 } | 2273 } |
| 2274 } | 2274 } |
| 2275 | 2275 |
| 2276 main() { | 2276 main() { |
| 2277 ByteArrayTest.testMain(); | 2277 ByteArrayTest.testMain(); |
| 2278 } | 2278 } |
| OLD | NEW |