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'); |
| 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 | |
| 24 } | |
| 25 | |
| 26 void testUnsignedByteArrayRange() { | |
| 27 Uint8List byteArray; | |
| 28 byteArray = new Uint8List(10); | |
| 29 | |
| 30 byteArray[1] = 255; | |
| 31 Expect.equals(255, byteArray[1]); | |
| 32 byteArray[1] = 0; | |
| 33 Expect.equals(0, byteArray[1]); | |
| 34 | |
| 35 // These should eventually throw. | |
|
srdjan
2012/10/16 17:56:01
Don't they throw?
You can use Expect.throws(...) t
| |
| 36 byteArray[1] = 256; | |
| 37 byteArray[1] = -1; | |
| 38 byteArray[2] = -129; | |
| 39 } | |
| 40 | |
| 41 void testByteArrayRange() { | |
| 42 Int8List byteArray; | |
| 43 byteArray = new Int8List(10); | |
| 44 byteArray[1] = 0; | |
| 45 Expect.equals(0, byteArray[1]); | |
| 46 byteArray[2] = -128; | |
| 47 Expect.equals(-128, byteArray[2]); | |
| 48 byteArray[3] = 127; | |
| 49 Expect.equals(127, byteArray[3]); | |
| 50 // This should eventually throw. | |
|
srdjan
2012/10/16 17:56:01
ditto
| |
| 51 byteArray[0] = 128; | |
| 52 byteArray[4] = -129; | |
| 23 } | 53 } |
| 24 | 54 |
| 25 void testSetRange() { | 55 void testSetRange() { |
| 26 Uint8List byteArray = new Uint8List(3); | 56 Uint8List byteArray = new Uint8List(3); |
| 27 | 57 |
| 28 List<int> list = [10, 11, 12]; | 58 List<int> list = [10, 11, 12]; |
| 29 byteArray.setRange(0, 3, list); | 59 byteArray.setRange(0, 3, list); |
| 30 for (int i = 0; i < 3; i++) { | 60 for (int i = 0; i < 3; i++) { |
| 31 Expect.equals(10 + i, byteArray[i]); | 61 Expect.equals(10 + i, byteArray[i]); |
| 32 } | 62 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 104 } |
| 75 Expect.equals(0, list.indexOf(10.0)); | 105 Expect.equals(0, list.indexOf(10.0)); |
| 76 Expect.equals(5, list.indexOf(15.0)); | 106 Expect.equals(5, list.indexOf(15.0)); |
| 77 Expect.equals(9, list.indexOf(19.0)); | 107 Expect.equals(9, list.indexOf(19.0)); |
| 78 Expect.equals(-1, list.indexOf(20.0)); | 108 Expect.equals(-1, list.indexOf(20.0)); |
| 79 } | 109 } |
| 80 | 110 |
| 81 main() { | 111 main() { |
| 82 for (int i = 0; i < 2000; i++) { | 112 for (int i = 0; i < 2000; i++) { |
| 83 testCreateByteArray(); | 113 testCreateByteArray(); |
| 114 testByteArrayRange(); | |
| 115 testUnsignedByteArrayRange(); | |
| 84 testSetRange(); | 116 testSetRange(); |
| 85 testIndexOutOfRange(); | 117 testIndexOutOfRange(); |
| 86 testIndexOf(); | 118 testIndexOf(); |
| 87 } | 119 } |
| 88 } | 120 } |
| OLD | NEW |