Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: tests/standalone/byte_array_test.dart

Issue 11366071: Throwing type check errors is very slow compared to other checks (e.g., value check error in typed … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23
24 } 24 }
25 25
26 void testUnsignedByteArrayRange() { 26 void testUnsignedByteArrayRange(bool check_throws) {
27 Uint8List byteArray; 27 Uint8List byteArray;
28 byteArray = new Uint8List(10); 28 byteArray = new Uint8List(10);
29 29
30 byteArray[1] = 255; 30 byteArray[1] = 255;
31 Expect.equals(255, byteArray[1]); 31 Expect.equals(255, byteArray[1]);
32 byteArray[1] = 0; 32 byteArray[1] = 0;
33 Expect.equals(0, byteArray[1]); 33 Expect.equals(0, byteArray[1]);
34 34
35 Expect.throws(() {
36 byteArray[1] = 1.2;
37 });
38 // These should eventually throw. 35 // These should eventually throw.
39 byteArray[1] = 256; 36 byteArray[1] = 256;
40 byteArray[1] = -1; 37 byteArray[1] = -1;
41 byteArray[2] = -129; 38 byteArray[2] = -129;
39 if (check_throws) {
40 Expect.throws(() {
41 byteArray[1] = 1.2;
42 });
43 }
42 } 44 }
43 45
44 void testByteArrayRange() { 46 void testByteArrayRange(bool check_throws) {
45 Int8List byteArray; 47 Int8List byteArray;
46 byteArray = new Int8List(10); 48 byteArray = new Int8List(10);
47 byteArray[1] = 0; 49 byteArray[1] = 0;
48 Expect.equals(0, byteArray[1]); 50 Expect.equals(0, byteArray[1]);
49 byteArray[2] = -128; 51 byteArray[2] = -128;
50 Expect.equals(-128, byteArray[2]); 52 Expect.equals(-128, byteArray[2]);
51 byteArray[3] = 127; 53 byteArray[3] = 127;
52 Expect.equals(127, byteArray[3]); 54 Expect.equals(127, byteArray[3]);
53 Expect.throws(() {
54 byteArray[1] = 1.2;
55 });
56 // This should eventually throw. 55 // This should eventually throw.
57 byteArray[0] = 128; 56 byteArray[0] = 128;
58 byteArray[4] = -129; 57 byteArray[4] = -129;
58 if (check_throws) {
59 Expect.throws(() {
60 byteArray[1] = 1.2;
61 });
62 }
59 } 63 }
60 64
61 void testSetRange() { 65 void testSetRange() {
62 Uint8List byteArray = new Uint8List(3); 66 Uint8List byteArray = new Uint8List(3);
63 67
64 List<int> list = [10, 11, 12]; 68 List<int> list = [10, 11, 12];
65 byteArray.setRange(0, 3, list); 69 byteArray.setRange(0, 3, list);
66 for (int i = 0; i < 3; i++) { 70 for (int i = 0; i < 3; i++) {
67 Expect.equals(10 + i, byteArray[i]); 71 Expect.equals(10 + i, byteArray[i]);
68 } 72 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 Expect.throws(() => array.subByteArray(0, "5"), (e) => e is ArgumentError); 155 Expect.throws(() => array.subByteArray(0, "5"), (e) => e is ArgumentError);
152 Expect.throws(() => array.subByteArray("0", 5), (e) => e is ArgumentError); 156 Expect.throws(() => array.subByteArray("0", 5), (e) => e is ArgumentError);
153 Expect.throws(() => array.subByteArray("0"), (e) => e is ArgumentError); 157 Expect.throws(() => array.subByteArray("0"), (e) => e is ArgumentError);
154 } 158 }
155 Expect.throws(() => array.subByteArray(null), (e) => e is ArgumentError); 159 Expect.throws(() => array.subByteArray(null), (e) => e is ArgumentError);
156 } 160 }
157 161
158 main() { 162 main() {
159 for (int i = 0; i < 2000; i++) { 163 for (int i = 0; i < 2000; i++) {
160 testCreateByteArray(); 164 testCreateByteArray();
161 testByteArrayRange(); 165 testByteArrayRange(false);
162 testUnsignedByteArrayRange(); 166 testUnsignedByteArrayRange(false);
163 testSetRange(); 167 testSetRange();
164 testIndexOutOfRange(); 168 testIndexOutOfRange();
165 testIndexOf(); 169 testIndexOf();
166 testSubArray(); 170 testSubArray();
167 } 171 }
172 testByteArrayRange(true);
173 testUnsignedByteArrayRange(true);
168 } 174 }
169 175
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698