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

Side by Side Diff: runtime/tests/vm/dart/byte_array_test.dart

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: Created 3 years, 9 months 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
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 // VMOptions=--optimization_counter_threshold=10 --disable_alloc_stubs_after_gc --no-background-compilation 4 // VMOptions=--optimization_counter_threshold=10 --disable_alloc_stubs_after_gc --no-background-compilation
5 5
6 // Library tag to be able to run in html test framework. 6 // Library tag to be able to run in html test framework.
7 library byte_array_test; 7 library byte_array_test;
8 8
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
11 11
12 class ByteArrayTest { 12 class ByteArrayTest {
13 static testInt8ListImpl(Int8List array) { 13 static testInt8ListImpl(Int8List array) {
14 Expect.isTrue(array is List<int>); 14 Expect.isTrue(array is List<int>);
15 Expect.equals(10, array.length); 15 Expect.equals(10, array.length);
16 Expect.equals(1, array.elementSizeInBytes); 16 Expect.equals(1, array.elementSizeInBytes);
17 Expect.equals(10, array.lengthInBytes); 17 Expect.equals(10, array.lengthInBytes);
18 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 18 Expect.listEquals([0, 0, 0, 0, 0,
19 Expect.throws(() { 19 0, 0, 0, 0, 0],
20 array[-1] = 0; 20 array);
21 }, (e) { 21 Expect.throws(() { array[-1] = 0; },
22 return e is RangeError; 22 (e) { return e is RangeError; });
23 }); 23 Expect.throws(() { return array[-1]; },
24 Expect.throws(() { 24 (e) { return e is RangeError; });
25 return array[-1]; 25 Expect.throws(() { array[10]; },
26 }, (e) { 26 (e) { return e is RangeError; });
27 return e is RangeError; 27 Expect.throws(() { array[10] = 0; },
28 }); 28 (e) { return e is RangeError; });
29 Expect.throws(() { 29 Expect.throws(() { array.add(0); },
30 array[10]; 30 (e) { return e is UnsupportedError; });
31 }, (e) { 31 Expect.throws(() { array.addAll([0]); },
32 return e is RangeError; 32 (e) { return e is UnsupportedError; });
33 }); 33 Expect.throws(() { array.clear(); },
34 Expect.throws(() { 34 (e) { return e is UnsupportedError; });
35 array[10] = 0; 35 Expect.throws(() { array.length = 0; },
36 }, (e) { 36 (e) { return e is UnsupportedError; });
37 return e is RangeError; 37 Expect.throws(() { array.removeLast(); },
38 }); 38 (e) { return e is UnsupportedError; });
39 Expect.throws(() { 39 Expect.throws(() { array.removeRange(0, array.length - 1); },
40 array.add(0); 40 (e) { return e is UnsupportedError; });
41 }, (e) {
42 return e is UnsupportedError;
43 });
44 Expect.throws(() {
45 array.addAll([0]);
46 }, (e) {
47 return e is UnsupportedError;
48 });
49 Expect.throws(() {
50 array.clear();
51 }, (e) {
52 return e is UnsupportedError;
53 });
54 Expect.throws(() {
55 array.length = 0;
56 }, (e) {
57 return e is UnsupportedError;
58 });
59 Expect.throws(() {
60 array.removeLast();
61 }, (e) {
62 return e is UnsupportedError;
63 });
64 Expect.throws(() {
65 array.removeRange(0, array.length - 1);
66 }, (e) {
67 return e is UnsupportedError;
68 });
69 for (int i = 0; i < array.length; ++i) { 41 for (int i = 0; i < array.length; ++i) {
70 array[i] = 1 + i; 42 array[i] = 1 + i;
71 } 43 }
72 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 44 Expect.listEquals([1, 2, 3, 4, 5,
45 6, 7, 8, 9, 10],
46 array);
73 for (int i = 0; i < array.length; ++i) { 47 for (int i = 0; i < array.length; ++i) {
74 array[i] = 0x100 + i; 48 array[i] = 0x100 + i;
75 } 49 }
76 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 50 Expect.listEquals([0, 1, 2, 3, 4,
51 5, 6, 7, 8, 9],
52 array);
77 for (int i = 0; i < array.length; ++i) { 53 for (int i = 0; i < array.length; ++i) {
78 array[i] = -10 + i; 54 array[i] = -10 + i;
79 } 55 }
80 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], array); 56 Expect.listEquals([-10, -9, -8, -7, -6,
57 -5, -4, -3, -2, -1],
58 array);
81 for (int i = 0; i < array.length; ++i) { 59 for (int i = 0; i < array.length; ++i) {
82 array[i] = 0x7F - i; 60 array[i] = 0x7F - i;
83 } 61 }
84 Expect 62 Expect.listEquals([127, 126, 125, 124, 123,
85 .listEquals([127, 126, 125, 124, 123, 122, 121, 120, 119, 118], array); 63 122, 121, 120, 119, 118],
64 array);
86 for (int i = 0; i < array.length; ++i) { 65 for (int i = 0; i < array.length; ++i) {
87 array[i] = -0x80 + i; 66 array[i] = -0x80 + i;
88 } 67 }
89 Expect.listEquals( 68 Expect.listEquals([-128, -127, -126, -125, -124,
90 [-128, -127, -126, -125, -124, -123, -122, -121, -120, -119], array); 69 -123, -122, -121, -120, -119],
70 array);
91 for (int i = 0; i < array.length; ++i) { 71 for (int i = 0; i < array.length; ++i) {
92 array[i] = i; 72 array[i] = i;
93 } 73 }
94 var copy = array.sublist(0, array.length); 74 var copy = array.sublist(0, array.length);
95 Expect.isFalse(identical(copy, array)); 75 Expect.isFalse(identical(copy, array));
96 Expect.isTrue(copy is Int8List); 76 Expect.isTrue(copy is Int8List);
97 Expect.equals(10, copy.length); 77 Expect.equals(10, copy.length);
98 Expect.listEquals(array, copy); 78 Expect.listEquals(array, copy);
99 var empty = array.sublist(array.length, array.length); 79 var empty = array.sublist(array.length, array.length);
100 Expect.equals(0, empty.length); 80 Expect.equals(0, empty.length);
101 empty = array.sublist(array.length); 81 empty = array.sublist(array.length);
102 Expect.equals(0, empty.length); 82 Expect.equals(0, empty.length);
103 83
104 var region = array.sublist(3, array.length - 3); 84 var region = array.sublist(3, array.length - 3);
105 Expect.isTrue(copy is Int8List); 85 Expect.isTrue(copy is Int8List);
106 Expect.equals(4, region.length); 86 Expect.equals(4, region.length);
107 Expect.listEquals([3, 4, 5, 6], region); 87 Expect.listEquals([3, 4, 5, 6], region);
108 array.setRange(3, 7, [-128, 0, 1, 127]); 88 array.setRange(3, 7, [-128, 0, 1, 127]);
109 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9], array); 89 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9],
90 array);
110 } 91 }
111
112 static testInt8List() { 92 static testInt8List() {
113 Expect.throws(() { 93 Expect.throws(() { new Int8List(-1); },
114 new Int8List(-1); 94 (e) { return e is ArgumentError; });
115 }, (e) {
116 return e is ArgumentError;
117 });
118 var array = new Int8List(10); 95 var array = new Int8List(10);
119 testInt8ListImpl(array); 96 testInt8ListImpl(array);
120 } 97 }
121 98
122 static testUint8ListImpl(Uint8List array) { 99 static testUint8ListImpl(Uint8List array) {
123 Expect.isTrue(array is List<int>); 100 Expect.isTrue(array is List<int>);
124 Expect.equals(10, array.length); 101 Expect.equals(10, array.length);
125 Expect.equals(1, array.elementSizeInBytes); 102 Expect.equals(1, array.elementSizeInBytes);
126 Expect.equals(10, array.lengthInBytes); 103 Expect.equals(10, array.lengthInBytes);
127 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 104 Expect.listEquals([0, 0, 0, 0, 0,
128 Expect.throws(() { 105 0, 0, 0, 0, 0],
129 array[-1] = 0; 106 array);
130 }, (e) { 107 Expect.throws(() { array[-1] = 0; },
131 return e is RangeError; 108 (e) { return e is RangeError; });
132 }); 109 Expect.throws(() { return array[-1]; },
133 Expect.throws(() { 110 (e) { return e is RangeError; });
134 return array[-1]; 111 Expect.throws(() { array[10]; },
135 }, (e) { 112 (e) { return e is RangeError; });
136 return e is RangeError; 113 Expect.throws(() { array[10] = 0; },
137 }); 114 (e) { return e is RangeError; });
138 Expect.throws(() { 115 Expect.throws(() { array.add(0); },
139 array[10]; 116 (e) { return e is UnsupportedError; });
140 }, (e) { 117 Expect.throws(() { array.addAll([0]); },
141 return e is RangeError; 118 (e) { return e is UnsupportedError; });
142 }); 119 Expect.throws(() { array.clear(); },
143 Expect.throws(() { 120 (e) { return e is UnsupportedError; });
144 array[10] = 0; 121 Expect.throws(() { array.length = 0; },
145 }, (e) { 122 (e) { return e is UnsupportedError; });
146 return e is RangeError; 123 Expect.throws(() { array.removeLast(); },
147 }); 124 (e) { return e is UnsupportedError; });
148 Expect.throws(() { 125 Expect.throws(() { array.removeRange(0, array.length - 1); },
149 array.add(0); 126 (e) { return e is UnsupportedError; });
150 }, (e) {
151 return e is UnsupportedError;
152 });
153 Expect.throws(() {
154 array.addAll([0]);
155 }, (e) {
156 return e is UnsupportedError;
157 });
158 Expect.throws(() {
159 array.clear();
160 }, (e) {
161 return e is UnsupportedError;
162 });
163 Expect.throws(() {
164 array.length = 0;
165 }, (e) {
166 return e is UnsupportedError;
167 });
168 Expect.throws(() {
169 array.removeLast();
170 }, (e) {
171 return e is UnsupportedError;
172 });
173 Expect.throws(() {
174 array.removeRange(0, array.length - 1);
175 }, (e) {
176 return e is UnsupportedError;
177 });
178 for (int i = 0; i < array.length; ++i) { 127 for (int i = 0; i < array.length; ++i) {
179 array[i] = 1 + i; 128 array[i] = 1 + i;
180 } 129 }
181 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 130 Expect.listEquals([1, 2, 3, 4, 5,
131 6, 7, 8, 9, 10],
132 array);
182 for (int i = 0; i < array.length; ++i) { 133 for (int i = 0; i < array.length; ++i) {
183 array[i] = 0x100 + i; 134 array[i] = 0x100 + i;
184 } 135 }
185 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 136 Expect.listEquals([0, 1, 2, 3, 4,
137 5, 6, 7, 8, 9],
138 array);
186 for (int i = 0; i < array.length; ++i) { 139 for (int i = 0; i < array.length; ++i) {
187 array[i] = 0xFF - i; 140 array[i] = 0xFF - i;
188 } 141 }
189 Expect.listEquals( 142 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB,
190 [0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6], array); 143 0xFA, 0xF9, 0xF8, 0xF7, 0xF6],
144 array);
191 for (int i = 0; i < array.length; ++i) { 145 for (int i = 0; i < array.length; ++i) {
192 array[i] = i; 146 array[i] = i;
193 } 147 }
194 var copy = array.sublist(0, array.length); 148 var copy = array.sublist(0, array.length);
195 Expect.isFalse(identical(copy, array)); 149 Expect.isFalse(identical(copy, array));
196 Expect.isTrue(copy is Uint8List); 150 Expect.isTrue(copy is Uint8List);
197 Expect.equals(10, copy.length); 151 Expect.equals(10, copy.length);
198 Expect.listEquals(array, copy); 152 Expect.listEquals(array, copy);
199 var empty = array.sublist(array.length, array.length); 153 var empty = array.sublist(array.length, array.length);
200 Expect.equals(0, empty.length); 154 Expect.equals(0, empty.length);
201 empty = array.sublist(array.length); 155 empty = array.sublist(array.length);
202 Expect.equals(0, empty.length); 156 Expect.equals(0, empty.length);
203 157
204 var region = array.sublist(3, array.length - 3); 158 var region = array.sublist(3, array.length - 3);
205 Expect.isTrue(copy is Uint8List); 159 Expect.isTrue(copy is Uint8List);
206 Expect.equals(4, region.length); 160 Expect.equals(4, region.length);
207 Expect.listEquals([3, 4, 5, 6], region); 161 Expect.listEquals([3, 4, 5, 6], region);
208 array.setRange(3, 7, [257, 0, 1, 255]); 162 array.setRange(3, 7, [257, 0, 1, 255]);
209 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9], array); 163 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9],
164 array);
210 } 165 }
211 166
212 static testUint8List() { 167 static testUint8List() {
213 Expect.throws(() { 168 Expect.throws(() { new Uint8List(-1); },
214 new Uint8List(-1); 169 (e) { return e is ArgumentError; });
215 }, (e) {
216 return e is ArgumentError;
217 });
218 var array = new Uint8List(10); 170 var array = new Uint8List(10);
219 testUint8ListImpl(array); 171 testUint8ListImpl(array);
220 } 172 }
221 173
222 static testUint8ClampedListImpl(Uint8ClampedList array) { 174 static testUint8ClampedListImpl(Uint8ClampedList array) {
223 Expect.isTrue(array is List<int>); 175 Expect.isTrue(array is List<int>);
224 Expect.equals(10, array.length); 176 Expect.equals(10, array.length);
225 Expect.equals(1, array.elementSizeInBytes); 177 Expect.equals(1, array.elementSizeInBytes);
226 Expect.equals(10, array.lengthInBytes); 178 Expect.equals(10, array.lengthInBytes);
227 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 179 Expect.listEquals([0, 0, 0, 0, 0,
228 Expect.throws(() { 180 0, 0, 0, 0, 0],
229 array[-1] = 0; 181 array);
230 }, (e) { 182 Expect.throws(() { array[-1] = 0; },
231 return e is RangeError; 183 (e) { return e is RangeError; });
232 }); 184 Expect.throws(() { return array[-1]; },
233 Expect.throws(() { 185 (e) { return e is RangeError; });
234 return array[-1]; 186 Expect.throws(() { array[10]; },
235 }, (e) { 187 (e) { return e is RangeError; });
236 return e is RangeError; 188 Expect.throws(() { array[10] = 0; },
237 }); 189 (e) { return e is RangeError; });
238 Expect.throws(() { 190 Expect.throws(() { array.add(0); },
239 array[10]; 191 (e) { return e is UnsupportedError; });
240 }, (e) { 192 Expect.throws(() { array.addAll([0]); },
241 return e is RangeError; 193 (e) { return e is UnsupportedError; });
242 }); 194 Expect.throws(() { array.clear(); },
243 Expect.throws(() { 195 (e) { return e is UnsupportedError; });
244 array[10] = 0; 196 Expect.throws(() { array.length = 0; },
245 }, (e) { 197 (e) { return e is UnsupportedError; });
246 return e is RangeError; 198 Expect.throws(() { array.removeLast(); },
247 }); 199 (e) { return e is UnsupportedError; });
248 Expect.throws(() { 200 Expect.throws(() { array.removeRange(0, array.length - 1); },
249 array.add(0); 201 (e) { return e is UnsupportedError; });
250 }, (e) {
251 return e is UnsupportedError;
252 });
253 Expect.throws(() {
254 array.addAll([0]);
255 }, (e) {
256 return e is UnsupportedError;
257 });
258 Expect.throws(() {
259 array.clear();
260 }, (e) {
261 return e is UnsupportedError;
262 });
263 Expect.throws(() {
264 array.length = 0;
265 }, (e) {
266 return e is UnsupportedError;
267 });
268 Expect.throws(() {
269 array.removeLast();
270 }, (e) {
271 return e is UnsupportedError;
272 });
273 Expect.throws(() {
274 array.removeRange(0, array.length - 1);
275 }, (e) {
276 return e is UnsupportedError;
277 });
278 for (int i = 0; i < array.length; ++i) { 202 for (int i = 0; i < array.length; ++i) {
279 array[i] = -1 + i; 203 array[i] = -1 + i;
280 } 204 }
281 Expect.listEquals([0, 0, 1, 2, 3, 4, 5, 6, 7, 8], array); 205 Expect.listEquals([0, 0, 1, 2, 3, 4, 5, 6, 7, 8], array);
282 for (int i = 0; i < array.length; ++i) { 206 for (int i = 0; i < array.length; ++i) {
283 array[i] = 0x100 + i; 207 array[i] = 0x100 + i;
284 } 208 }
285 Expect 209 Expect.listEquals([255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
286 .listEquals([255, 255, 255, 255, 255, 255, 255, 255, 255, 255], array); 210 array);
287 for (int i = 0; i < array.length; ++i) { 211 for (int i = 0; i < array.length; ++i) {
288 array[i] = 0xFF - i; 212 array[i] = 0xFF - i;
289 } 213 }
290 Expect.listEquals( 214 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB,
291 [0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6], array); 215 0xFA, 0xF9, 0xF8, 0xF7, 0xF6],
216 array);
292 for (int i = 0; i < array.length; ++i) { 217 for (int i = 0; i < array.length; ++i) {
293 array[i] = i; 218 array[i] = i;
294 } 219 }
295 var copy = array.sublist(0, array.length); 220 var copy = array.sublist(0, array.length);
296 Expect.isFalse(identical(copy, array)); 221 Expect.isFalse(identical(copy, array));
297 Expect.isTrue(copy is Uint8ClampedList); 222 Expect.isTrue(copy is Uint8ClampedList);
298 Expect.equals(10, copy.length); 223 Expect.equals(10, copy.length);
299 Expect.listEquals(array, copy); 224 Expect.listEquals(array, copy);
300 var empty = array.sublist(array.length, array.length); 225 var empty = array.sublist(array.length, array.length);
301 Expect.equals(0, empty.length); 226 Expect.equals(0, empty.length);
302 empty = array.sublist(array.length); 227 empty = array.sublist(array.length);
303 Expect.equals(0, empty.length); 228 Expect.equals(0, empty.length);
304 229
305 var region = array.sublist(3, array.length - 3); 230 var region = array.sublist(3, array.length - 3);
306 Expect.isTrue(copy is Uint8ClampedList); 231 Expect.isTrue(copy is Uint8ClampedList);
307 Expect.equals(4, region.length); 232 Expect.equals(4, region.length);
308 Expect.listEquals([3, 4, 5, 6], region); 233 Expect.listEquals([3, 4, 5, 6], region);
309 array.setRange(3, 7, [257, 0, 1, 255]); 234 array.setRange(3, 7, [257, 0, 1, 255]);
310 Expect.listEquals([0, 1, 2, 255, 0, 1, 255, 7, 8, 9], array); 235 Expect.listEquals([0, 1, 2, 255, 0, 1, 255, 7, 8, 9], array);
311 } 236 }
312 237
313 static testUint8ClampedList() { 238 static testUint8ClampedList() {
314 Expect.throws(() { 239 Expect.throws(() { new Uint8ClampedList(-1); },
315 new Uint8ClampedList(-1); 240 (e) { return e is ArgumentError; });
316 }, (e) {
317 return e is ArgumentError;
318 });
319 var array = new Uint8ClampedList(10); 241 var array = new Uint8ClampedList(10);
320 testUint8ClampedListImpl(array); 242 testUint8ClampedListImpl(array);
321 } 243 }
322 244
323 static testInt16ListImpl(Int16List array) { 245 static testInt16ListImpl(Int16List array) {
324 Expect.isTrue(array is List<int>); 246 Expect.isTrue(array is List<int>);
325 Expect.equals(10, array.length); 247 Expect.equals(10, array.length);
326 Expect.equals(2, array.elementSizeInBytes); 248 Expect.equals(2, array.elementSizeInBytes);
327 Expect.equals(20, array.lengthInBytes); 249 Expect.equals(20, array.lengthInBytes);
328 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 250 Expect.listEquals([0, 0, 0, 0, 0,
329 Expect.throws(() { 251 0, 0, 0, 0, 0],
330 array[-1] = 0; 252 array);
331 }, (e) { 253 Expect.throws(() { array[-1] = 0; },
332 return e is RangeError; 254 (e) { return e is RangeError; });
333 }); 255 Expect.throws(() { return array[-1]; },
334 Expect.throws(() { 256 (e) { return e is RangeError; });
335 return array[-1]; 257 Expect.throws(() { array[10]; },
336 }, (e) { 258 (e) { return e is RangeError; });
337 return e is RangeError; 259 Expect.throws(() { array[10] = 0; },
338 }); 260 (e) { return e is RangeError; });
339 Expect.throws(() { 261 Expect.throws(() { array.add(0); },
340 array[10]; 262 (e) { return e is UnsupportedError; });
341 }, (e) { 263 Expect.throws(() { array.addAll([0]); },
342 return e is RangeError; 264 (e) { return e is UnsupportedError; });
343 }); 265 Expect.throws(() { array.clear(); },
344 Expect.throws(() { 266 (e) { return e is UnsupportedError; });
345 array[10] = 0; 267 Expect.throws(() { array.length = 0; },
346 }, (e) { 268 (e) { return e is UnsupportedError; });
347 return e is RangeError; 269 Expect.throws(() { array.removeLast(); },
348 }); 270 (e) { return e is UnsupportedError; });
349 Expect.throws(() { 271 Expect.throws(() { array.removeRange(0, array.length - 1); },
350 array.add(0); 272 (e) { return e is UnsupportedError; });
351 }, (e) {
352 return e is UnsupportedError;
353 });
354 Expect.throws(() {
355 array.addAll([0]);
356 }, (e) {
357 return e is UnsupportedError;
358 });
359 Expect.throws(() {
360 array.clear();
361 }, (e) {
362 return e is UnsupportedError;
363 });
364 Expect.throws(() {
365 array.length = 0;
366 }, (e) {
367 return e is UnsupportedError;
368 });
369 Expect.throws(() {
370 array.removeLast();
371 }, (e) {
372 return e is UnsupportedError;
373 });
374 Expect.throws(() {
375 array.removeRange(0, array.length - 1);
376 }, (e) {
377 return e is UnsupportedError;
378 });
379 for (int i = 0; i < array.length; ++i) { 273 for (int i = 0; i < array.length; ++i) {
380 array[i] = 1 + i; 274 array[i] = 1 + i;
381 } 275 }
382 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 276 Expect.listEquals([1, 2, 3, 4, 5,
277 6, 7, 8, 9, 10],
278 array);
383 for (int i = 0; i < array.length; ++i) { 279 for (int i = 0; i < array.length; ++i) {
384 array[i] = 0x10000 + i; 280 array[i] = 0x10000 + i;
385 } 281 }
386 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 282 Expect.listEquals([0, 1, 2, 3, 4,
283 5, 6, 7, 8, 9],
284 array);
387 for (int i = 0; i < array.length; ++i) { 285 for (int i = 0; i < array.length; ++i) {
388 array[i] = -10 + i; 286 array[i] = -10 + i;
389 } 287 }
390 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], array); 288 Expect.listEquals([-10, -9, -8, -7, -6,
289 -5, -4, -3, -2, -1],
290 array);
391 for (int i = 0; i < array.length; ++i) { 291 for (int i = 0; i < array.length; ++i) {
392 array[i] = 0x7FFF - i; 292 array[i] = 0x7FFF - i;
393 } 293 }
394 Expect.listEquals([ 294 Expect.listEquals([0x7FFF, 0x7FFE, 0x7FFD, 0x7FFC, 0x7FFB,
395 0x7FFF, 295 0x7FFA, 0x7FF9, 0x7FF8, 0x7FF7, 0x7FF6],
396 0x7FFE, 296 array);
397 0x7FFD,
398 0x7FFC,
399 0x7FFB,
400 0x7FFA,
401 0x7FF9,
402 0x7FF8,
403 0x7FF7,
404 0x7FF6
405 ], array);
406 for (int i = 0; i < array.length; ++i) { 297 for (int i = 0; i < array.length; ++i) {
407 array[i] = -0x8000 + i; 298 array[i] = -0x8000 + i;
408 } 299 }
409 Expect.listEquals([ 300 Expect.listEquals([-0x8000, -0x7FFF, -0x7FFE, -0x7FFD, -0x7FFC,
410 -0x8000, 301 -0x7FFB, -0x7FFA, -0x7FF9, -0x7FF8, -0x7FF7],
411 -0x7FFF, 302 array);
412 -0x7FFE,
413 -0x7FFD,
414 -0x7FFC,
415 -0x7FFB,
416 -0x7FFA,
417 -0x7FF9,
418 -0x7FF8,
419 -0x7FF7
420 ], array);
421 for (int i = 0; i < array.length; ++i) { 303 for (int i = 0; i < array.length; ++i) {
422 array[i] = i; 304 array[i] = i;
423 } 305 }
424 var copy = array.sublist(0, array.length); 306 var copy = array.sublist(0, array.length);
425 Expect.isFalse(identical(copy, array)); 307 Expect.isFalse(identical(copy, array));
426 Expect.isTrue(copy is Int16List); 308 Expect.isTrue(copy is Int16List);
427 Expect.equals(10, copy.length); 309 Expect.equals(10, copy.length);
428 Expect.listEquals(array, copy); 310 Expect.listEquals(array, copy);
429 var empty = array.sublist(array.length, array.length); 311 var empty = array.sublist(array.length, array.length);
430 Expect.equals(0, empty.length); 312 Expect.equals(0, empty.length);
431 empty = array.sublist(array.length); 313 empty = array.sublist(array.length);
432 Expect.equals(0, empty.length); 314 Expect.equals(0, empty.length);
433 315
434 var region = array.sublist(3, array.length - 3); 316 var region = array.sublist(3, array.length - 3);
435 Expect.isTrue(copy is Int16List); 317 Expect.isTrue(copy is Int16List);
436 Expect.equals(4, region.length); 318 Expect.equals(4, region.length);
437 Expect.listEquals([3, 4, 5, 6], region); 319 Expect.listEquals([3, 4, 5, 6], region);
438 array.setRange(3, 7, [-32768, 0, 1, 32767]); 320 array.setRange(3, 7, [-32768, 0, 1, 32767]);
439 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9], array); 321 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9],
322 array);
440 } 323 }
441 324
442 static testInt16List() { 325 static testInt16List() {
443 Expect.throws(() { 326 Expect.throws(() { new Int16List(-1); },
444 new Int16List(-1); 327 (e) { return e is ArgumentError; });
445 }, (e) {
446 return e is ArgumentError;
447 });
448 var array = new Int16List(10); 328 var array = new Int16List(10);
449 testInt16ListImpl(array); 329 testInt16ListImpl(array);
450 } 330 }
451 331
452 static testUint16ListImpl(Uint16List array) { 332 static testUint16ListImpl(Uint16List array) {
453 Expect.isTrue(array is List<int>); 333 Expect.isTrue(array is List<int>);
454 Expect.equals(10, array.length); 334 Expect.equals(10, array.length);
455 Expect.equals(2, array.elementSizeInBytes); 335 Expect.equals(2, array.elementSizeInBytes);
456 Expect.equals(20, array.lengthInBytes); 336 Expect.equals(20, array.lengthInBytes);
457 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 337 Expect.listEquals([0, 0, 0, 0, 0,
458 Expect.throws(() { 338 0, 0, 0, 0, 0],
459 array[-1] = 0; 339 array);
460 }, (e) { 340 Expect.throws(() { array[-1] = 0; },
461 return e is RangeError; 341 (e) { return e is RangeError; });
462 }); 342 Expect.throws(() { return array[-1]; },
463 Expect.throws(() { 343 (e) { return e is RangeError; });
464 return array[-1]; 344 Expect.throws(() { array[10]; },
465 }, (e) { 345 (e) { return e is RangeError; });
466 return e is RangeError; 346 Expect.throws(() { array[10] = 0; },
467 }); 347 (e) { return e is RangeError; });
468 Expect.throws(() { 348 Expect.throws(() { array.add(0); },
469 array[10]; 349 (e) { return e is UnsupportedError; });
470 }, (e) { 350 Expect.throws(() { array.addAll([0]); },
471 return e is RangeError; 351 (e) { return e is UnsupportedError; });
472 }); 352 Expect.throws(() { array.clear(); },
473 Expect.throws(() { 353 (e) { return e is UnsupportedError; });
474 array[10] = 0; 354 Expect.throws(() { array.length = 0; },
475 }, (e) { 355 (e) { return e is UnsupportedError; });
476 return e is RangeError; 356 Expect.throws(() { array.removeLast(); },
477 }); 357 (e) { return e is UnsupportedError; });
478 Expect.throws(() { 358 Expect.throws(() { array.removeRange(0, array.length - 1); },
479 array.add(0); 359 (e) { return e is UnsupportedError; });
480 }, (e) {
481 return e is UnsupportedError;
482 });
483 Expect.throws(() {
484 array.addAll([0]);
485 }, (e) {
486 return e is UnsupportedError;
487 });
488 Expect.throws(() {
489 array.clear();
490 }, (e) {
491 return e is UnsupportedError;
492 });
493 Expect.throws(() {
494 array.length = 0;
495 }, (e) {
496 return e is UnsupportedError;
497 });
498 Expect.throws(() {
499 array.removeLast();
500 }, (e) {
501 return e is UnsupportedError;
502 });
503 Expect.throws(() {
504 array.removeRange(0, array.length - 1);
505 }, (e) {
506 return e is UnsupportedError;
507 });
508 for (int i = 0; i < array.length; ++i) { 360 for (int i = 0; i < array.length; ++i) {
509 array[i] = 1 + i; 361 array[i] = 1 + i;
510 } 362 }
511 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 363 Expect.listEquals([1, 2, 3, 4, 5,
364 6, 7, 8, 9, 10],
365 array);
512 for (int i = 0; i < array.length; ++i) { 366 for (int i = 0; i < array.length; ++i) {
513 array[i] = 0x10000 + i; 367 array[i] = 0x10000 + i;
514 } 368 }
515 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 369 Expect.listEquals([0, 1, 2, 3, 4,
370 5, 6, 7, 8, 9],
371 array);
516 for (int i = 0; i < array.length; ++i) { 372 for (int i = 0; i < array.length; ++i) {
517 array[i] = 0xFFFF - i; 373 array[i] = 0xFFFF - i;
518 } 374 }
519 Expect.listEquals([ 375 Expect.listEquals([0xFFFF, 0xFFFE, 0xFFFD, 0xFFFC, 0xFFFB,
520 0xFFFF, 376 0xFFFA, 0xFFF9, 0xFFF8, 0xFFF7, 0xFFF6],
521 0xFFFE, 377 array);
522 0xFFFD,
523 0xFFFC,
524 0xFFFB,
525 0xFFFA,
526 0xFFF9,
527 0xFFF8,
528 0xFFF7,
529 0xFFF6
530 ], array);
531 for (int i = 0; i < array.length; ++i) { 378 for (int i = 0; i < array.length; ++i) {
532 array[i] = i; 379 array[i] = i;
533 } 380 }
534 var copy = array.sublist(0, array.length); 381 var copy = array.sublist(0, array.length);
535 Expect.isFalse(identical(copy, array)); 382 Expect.isFalse(identical(copy, array));
536 Expect.isTrue(copy is Uint16List); 383 Expect.isTrue(copy is Uint16List);
537 Expect.equals(10, copy.length); 384 Expect.equals(10, copy.length);
538 Expect.listEquals(array, copy); 385 Expect.listEquals(array, copy);
539 var empty = array.sublist(array.length, array.length); 386 var empty = array.sublist(array.length, array.length);
540 Expect.equals(0, empty.length); 387 Expect.equals(0, empty.length);
541 empty = array.sublist(array.length); 388 empty = array.sublist(array.length);
542 Expect.equals(0, empty.length); 389 Expect.equals(0, empty.length);
543 390
544 var region = array.sublist(3, array.length - 3); 391 var region = array.sublist(3, array.length - 3);
545 Expect.isTrue(copy is Uint16List); 392 Expect.isTrue(copy is Uint16List);
546 Expect.equals(4, region.length); 393 Expect.equals(4, region.length);
547 Expect.listEquals([3, 4, 5, 6], region); 394 Expect.listEquals([3, 4, 5, 6], region);
548 array.setRange(3, 7, [0x10001, 0, 1, 0xFFFF]); 395 array.setRange(3, 7, [0x10001, 0, 1, 0xFFFF]);
549 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9], array); 396 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9],
397 array);
550 } 398 }
551 399
552 static testUint16List() { 400 static testUint16List() {
553 Expect.throws(() { 401 Expect.throws(() { new Uint16List(-1); },
554 new Uint16List(-1); 402 (e) { return e is ArgumentError; });
555 }, (e) {
556 return e is ArgumentError;
557 });
558 var array = new Uint16List(10); 403 var array = new Uint16List(10);
559 testUint16ListImpl(array); 404 testUint16ListImpl(array);
560 } 405 }
561 406
562 static testInt32ListImpl(Int32List array) { 407 static testInt32ListImpl(Int32List array) {
563 Expect.isTrue(array is List<int>); 408 Expect.isTrue(array is List<int>);
564 Expect.equals(10, array.length); 409 Expect.equals(10, array.length);
565 Expect.equals(4, array.elementSizeInBytes); 410 Expect.equals(4, array.elementSizeInBytes);
566 Expect.equals(40, array.lengthInBytes); 411 Expect.equals(40, array.lengthInBytes);
567 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 412 Expect.listEquals([0, 0, 0, 0, 0,
568 Expect.throws(() { 413 0, 0, 0, 0, 0],
569 array[-1] = 0; 414 array);
570 }, (e) { 415 Expect.throws(() { array[-1] = 0; },
571 return e is RangeError; 416 (e) { return e is RangeError; });
572 }); 417 Expect.throws(() { return array[-1]; },
573 Expect.throws(() { 418 (e) { return e is RangeError; });
574 return array[-1]; 419 Expect.throws(() { array[10]; },
575 }, (e) { 420 (e) { return e is RangeError; });
576 return e is RangeError; 421 Expect.throws(() { array[10] = 0; },
577 }); 422 (e) { return e is RangeError; });
578 Expect.throws(() { 423 Expect.throws(() { array.add(0); },
579 array[10]; 424 (e) { return e is UnsupportedError; });
580 }, (e) { 425 Expect.throws(() { array.addAll([0]); },
581 return e is RangeError; 426 (e) { return e is UnsupportedError; });
582 }); 427 Expect.throws(() { array.clear(); },
583 Expect.throws(() { 428 (e) { return e is UnsupportedError; });
584 array[10] = 0; 429 Expect.throws(() { array.length = 0; },
585 }, (e) { 430 (e) { return e is UnsupportedError; });
586 return e is RangeError; 431 Expect.throws(() { array.removeLast(); },
587 }); 432 (e) { return e is UnsupportedError; });
588 Expect.throws(() { 433 Expect.throws(() { array.removeRange(0, array.length - 1); },
589 array.add(0); 434 (e) { return e is UnsupportedError; });
590 }, (e) {
591 return e is UnsupportedError;
592 });
593 Expect.throws(() {
594 array.addAll([0]);
595 }, (e) {
596 return e is UnsupportedError;
597 });
598 Expect.throws(() {
599 array.clear();
600 }, (e) {
601 return e is UnsupportedError;
602 });
603 Expect.throws(() {
604 array.length = 0;
605 }, (e) {
606 return e is UnsupportedError;
607 });
608 Expect.throws(() {
609 array.removeLast();
610 }, (e) {
611 return e is UnsupportedError;
612 });
613 Expect.throws(() {
614 array.removeRange(0, array.length - 1);
615 }, (e) {
616 return e is UnsupportedError;
617 });
618 for (int i = 0; i < array.length; ++i) { 435 for (int i = 0; i < array.length; ++i) {
619 array[i] = 1 + i; 436 array[i] = 1 + i;
620 } 437 }
621 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 438 Expect.listEquals([1, 2, 3, 4, 5,
439 6, 7, 8, 9, 10],
440 array);
622 for (int i = 0; i < array.length; ++i) { 441 for (int i = 0; i < array.length; ++i) {
623 array[i] = 0x100000000 + i; 442 array[i] = 0x100000000 + i;
624 } 443 }
625 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 444 Expect.listEquals([0, 1, 2, 3, 4,
445 5, 6, 7, 8, 9],
446 array);
626 for (int i = 0; i < array.length; ++i) { 447 for (int i = 0; i < array.length; ++i) {
627 array[i] = -10 + i; 448 array[i] = -10 + i;
628 } 449 }
629 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], array); 450 Expect.listEquals([-10, -9, -8, -7, -6,
451 -5, -4, -3, -2, -1],
452 array);
630 for (int i = 0; i < array.length; ++i) { 453 for (int i = 0; i < array.length; ++i) {
631 array[i] = 0x7FFFFFFF - i; 454 array[i] = 0x7FFFFFFF - i;
632 } 455 }
633 Expect.listEquals([ 456 Expect.listEquals([0x7FFFFFFF, 0x7FFFFFFE,
634 0x7FFFFFFF, 457 0x7FFFFFFD, 0x7FFFFFFC,
635 0x7FFFFFFE, 458 0x7FFFFFFB, 0x7FFFFFFA,
636 0x7FFFFFFD, 459 0x7FFFFFF9, 0x7FFFFFF8,
637 0x7FFFFFFC, 460 0x7FFFFFF7, 0x7FFFFFF6],
638 0x7FFFFFFB, 461 array);
639 0x7FFFFFFA,
640 0x7FFFFFF9,
641 0x7FFFFFF8,
642 0x7FFFFFF7,
643 0x7FFFFFF6
644 ], array);
645 for (int i = 0; i < array.length; ++i) { 462 for (int i = 0; i < array.length; ++i) {
646 array[i] = -0x80000000 + i; 463 array[i] = -0x80000000 + i;
647 } 464 }
648 Expect.listEquals([ 465 Expect.listEquals([-0x80000000, -0x7FFFFFFF,
649 -0x80000000, 466 -0x7FFFFFFE, -0x7FFFFFFD,
650 -0x7FFFFFFF, 467 -0x7FFFFFFC, -0x7FFFFFFB,
651 -0x7FFFFFFE, 468 -0x7FFFFFFA, -0x7FFFFFF9,
652 -0x7FFFFFFD, 469 -0x7FFFFFF8, -0x7FFFFFF7],
653 -0x7FFFFFFC, 470 array);
654 -0x7FFFFFFB,
655 -0x7FFFFFFA,
656 -0x7FFFFFF9,
657 -0x7FFFFFF8,
658 -0x7FFFFFF7
659 ], array);
660 for (int i = 0; i < array.length; ++i) { 471 for (int i = 0; i < array.length; ++i) {
661 array[i] = i; 472 array[i] = i;
662 } 473 }
663 var copy = array.sublist(0, array.length); 474 var copy = array.sublist(0, array.length);
664 Expect.isFalse(identical(copy, array)); 475 Expect.isFalse(identical(copy, array));
665 Expect.isTrue(copy is Int32List); 476 Expect.isTrue(copy is Int32List);
666 Expect.equals(10, copy.length); 477 Expect.equals(10, copy.length);
667 Expect.listEquals(array, copy); 478 Expect.listEquals(array, copy);
668 var empty = array.sublist(array.length, array.length); 479 var empty = array.sublist(array.length, array.length);
669 Expect.equals(0, empty.length); 480 Expect.equals(0, empty.length);
670 empty = array.sublist(array.length); 481 empty = array.sublist(array.length);
671 Expect.equals(0, empty.length); 482 Expect.equals(0, empty.length);
672 483
673 var region = array.sublist(3, array.length - 3); 484 var region = array.sublist(3, array.length - 3);
674 Expect.isTrue(copy is Int32List); 485 Expect.isTrue(copy is Int32List);
675 Expect.equals(4, region.length); 486 Expect.equals(4, region.length);
676 Expect.listEquals([3, 4, 5, 6], region); 487 Expect.listEquals([3, 4, 5, 6], region);
677 array.setRange(3, 7, [-0x80000000, 0, 1, 0x7FFFFFFF]); 488 array.setRange(3, 7, [-0x80000000, 0, 1, 0x7FFFFFFF]);
678 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9], array); 489 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9],
490 array);
679 } 491 }
680 492
681 static testInt32List() { 493 static testInt32List() {
682 Expect.throws(() { 494 Expect.throws(() { new Int32List(-1); },
683 new Int32List(-1); 495 (e) { return e is ArgumentError; });
684 }, (e) {
685 return e is ArgumentError;
686 });
687 var array = new Int32List(10); 496 var array = new Int32List(10);
688 testInt32ListImpl(array); 497 testInt32ListImpl(array);
689 } 498 }
690 499
691 static testUint32ListImpl(Uint32List array) { 500 static testUint32ListImpl(Uint32List array) {
692 Expect.isTrue(array is List<int>); 501 Expect.isTrue(array is List<int>);
693 Expect.equals(10, array.length); 502 Expect.equals(10, array.length);
694 Expect.equals(4, array.elementSizeInBytes); 503 Expect.equals(4, array.elementSizeInBytes);
695 Expect.equals(40, array.lengthInBytes); 504 Expect.equals(40, array.lengthInBytes);
696 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 505 Expect.listEquals([0, 0, 0, 0, 0,
697 Expect.throws(() { 506 0, 0, 0, 0, 0],
698 array[-1] = 0; 507 array);
699 }, (e) { 508 Expect.throws(() { array[-1] = 0; },
700 return e is RangeError; 509 (e) { return e is RangeError; });
701 }); 510 Expect.throws(() { return array[-1]; },
702 Expect.throws(() { 511 (e) { return e is RangeError; });
703 return array[-1]; 512 Expect.throws(() { array[10]; },
704 }, (e) { 513 (e) { return e is RangeError; });
705 return e is RangeError; 514 Expect.throws(() { array[10] = 0; },
706 }); 515 (e) { return e is RangeError; });
707 Expect.throws(() { 516 Expect.throws(() { array.add(0); },
708 array[10]; 517 (e) { return e is UnsupportedError; });
709 }, (e) { 518 Expect.throws(() { array.addAll([0]); },
710 return e is RangeError; 519 (e) { return e is UnsupportedError; });
711 }); 520 Expect.throws(() { array.clear(); },
712 Expect.throws(() { 521 (e) { return e is UnsupportedError; });
713 array[10] = 0; 522 Expect.throws(() { array.length = 0; },
714 }, (e) { 523 (e) { return e is UnsupportedError; });
715 return e is RangeError; 524 Expect.throws(() { array.removeLast(); },
716 }); 525 (e) { return e is UnsupportedError; });
717 Expect.throws(() { 526 Expect.throws(() { array.removeRange(0, array.length - 1); },
718 array.add(0); 527 (e) { return e is UnsupportedError; });
719 }, (e) {
720 return e is UnsupportedError;
721 });
722 Expect.throws(() {
723 array.addAll([0]);
724 }, (e) {
725 return e is UnsupportedError;
726 });
727 Expect.throws(() {
728 array.clear();
729 }, (e) {
730 return e is UnsupportedError;
731 });
732 Expect.throws(() {
733 array.length = 0;
734 }, (e) {
735 return e is UnsupportedError;
736 });
737 Expect.throws(() {
738 array.removeLast();
739 }, (e) {
740 return e is UnsupportedError;
741 });
742 Expect.throws(() {
743 array.removeRange(0, array.length - 1);
744 }, (e) {
745 return e is UnsupportedError;
746 });
747 for (int i = 0; i < array.length; ++i) { 528 for (int i = 0; i < array.length; ++i) {
748 array[i] = 1 + i; 529 array[i] = 1 + i;
749 } 530 }
750 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 531 Expect.listEquals([1, 2, 3, 4, 5,
532 6, 7, 8, 9, 10],
533 array);
751 for (int i = 0; i < array.length; ++i) { 534 for (int i = 0; i < array.length; ++i) {
752 array[i] = 0x100000000 + i; 535 array[i] = 0x100000000 + i;
753 } 536 }
754 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 537 Expect.listEquals([0, 1, 2, 3, 4,
538 5, 6, 7, 8, 9],
539 array);
755 for (int i = 0; i < array.length; ++i) { 540 for (int i = 0; i < array.length; ++i) {
756 array[i] = 0xFFFFFFFF - i; 541 array[i] = 0xFFFFFFFF - i;
757 } 542 }
758 Expect.listEquals([ 543 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFE,
759 0xFFFFFFFF, 544 0xFFFFFFFD, 0xFFFFFFFC,
760 0xFFFFFFFE, 545 0xFFFFFFFB, 0xFFFFFFFA,
761 0xFFFFFFFD, 546 0xFFFFFFF9, 0xFFFFFFF8,
762 0xFFFFFFFC, 547 0xFFFFFFF7, 0xFFFFFFF6],
763 0xFFFFFFFB, 548 array);
764 0xFFFFFFFA,
765 0xFFFFFFF9,
766 0xFFFFFFF8,
767 0xFFFFFFF7,
768 0xFFFFFFF6
769 ], array);
770 for (int i = 0; i < array.length; ++i) { 549 for (int i = 0; i < array.length; ++i) {
771 array[i] = i; 550 array[i] = i;
772 } 551 }
773 var copy = array.sublist(0, array.length); 552 var copy = array.sublist(0, array.length);
774 Expect.isFalse(identical(copy, array)); 553 Expect.isFalse(identical(copy, array));
775 Expect.isTrue(copy is Uint32List); 554 Expect.isTrue(copy is Uint32List);
776 Expect.equals(10, copy.length); 555 Expect.equals(10, copy.length);
777 Expect.listEquals(array, copy); 556 Expect.listEquals(array, copy);
778 var empty = array.sublist(array.length, array.length); 557 var empty = array.sublist(array.length, array.length);
779 Expect.equals(0, empty.length); 558 Expect.equals(0, empty.length);
780 empty = array.sublist(array.length); 559 empty = array.sublist(array.length);
781 Expect.equals(0, empty.length); 560 Expect.equals(0, empty.length);
782 561
783 var region = array.sublist(3, array.length - 3); 562 var region = array.sublist(3, array.length - 3);
784 Expect.isTrue(copy is Uint32List); 563 Expect.isTrue(copy is Uint32List);
785 Expect.equals(4, region.length); 564 Expect.equals(4, region.length);
786 Expect.listEquals([3, 4, 5, 6], region); 565 Expect.listEquals([3, 4, 5, 6], region);
787 array.setRange(3, 7, [0x100000001, 0, 1, 0xFFFFFFFF]); 566 array.setRange(3, 7, [0x100000001, 0, 1, 0xFFFFFFFF]);
788 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9], array); 567 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9],
568 array);
789 } 569 }
790 570
791 static testUint32List() { 571 static testUint32List() {
792 Expect.throws(() { 572 Expect.throws(() { new Uint32List(-1); },
793 new Uint32List(-1); 573 (e) { return e is ArgumentError; });
794 }, (e) { 574 Expect.throws(() { new Uint32List(-1); },
795 return e is ArgumentError; 575 (e) { return e is ArgumentError; });
796 });
797 Expect.throws(() {
798 new Uint32List(-1);
799 }, (e) {
800 return e is ArgumentError;
801 });
802 var array = new Uint32List(10); 576 var array = new Uint32List(10);
803 testUint32ListImpl(array); 577 testUint32ListImpl(array);
578
804 } 579 }
805 580
806 static testInt64ListImpl(Int64List array) { 581 static testInt64ListImpl(Int64List array) {
807 Expect.isTrue(array is List<int>); 582 Expect.isTrue(array is List<int>);
808 Expect.equals(10, array.length); 583 Expect.equals(10, array.length);
809 Expect.equals(8, array.elementSizeInBytes); 584 Expect.equals(8, array.elementSizeInBytes);
810 Expect.equals(80, array.lengthInBytes); 585 Expect.equals(80, array.lengthInBytes);
811 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 586 Expect.listEquals([0, 0, 0, 0, 0,
812 Expect.throws(() { 587 0, 0, 0, 0, 0],
813 array[-1] = 0; 588 array);
814 }, (e) { 589 Expect.throws(() { array[-1] = 0; },
815 return e is RangeError; 590 (e) { return e is RangeError; });
816 }); 591 Expect.throws(() { return array[-1]; },
817 Expect.throws(() { 592 (e) { return e is RangeError; });
818 return array[-1]; 593 Expect.throws(() { array[10]; },
819 }, (e) { 594 (e) { return e is RangeError; });
820 return e is RangeError; 595 Expect.throws(() { array[10] = 0; },
821 }); 596 (e) { return e is RangeError; });
822 Expect.throws(() { 597 Expect.throws(() { array.add(0); },
823 array[10]; 598 (e) { return e is UnsupportedError; });
824 }, (e) { 599 Expect.throws(() { array.addAll([0]); },
825 return e is RangeError; 600 (e) { return e is UnsupportedError; });
826 }); 601 Expect.throws(() { array.clear(); },
827 Expect.throws(() { 602 (e) { return e is UnsupportedError; });
828 array[10] = 0; 603 Expect.throws(() { array.length = 0; },
829 }, (e) { 604 (e) { return e is UnsupportedError; });
830 return e is RangeError; 605 Expect.throws(() { array.removeLast(); },
831 }); 606 (e) { return e is UnsupportedError; });
832 Expect.throws(() { 607 Expect.throws(() { array.removeRange(0, array.length - 1); },
833 array.add(0); 608 (e) { return e is UnsupportedError; });
834 }, (e) {
835 return e is UnsupportedError;
836 });
837 Expect.throws(() {
838 array.addAll([0]);
839 }, (e) {
840 return e is UnsupportedError;
841 });
842 Expect.throws(() {
843 array.clear();
844 }, (e) {
845 return e is UnsupportedError;
846 });
847 Expect.throws(() {
848 array.length = 0;
849 }, (e) {
850 return e is UnsupportedError;
851 });
852 Expect.throws(() {
853 array.removeLast();
854 }, (e) {
855 return e is UnsupportedError;
856 });
857 Expect.throws(() {
858 array.removeRange(0, array.length - 1);
859 }, (e) {
860 return e is UnsupportedError;
861 });
862 for (int i = 0; i < array.length; ++i) { 609 for (int i = 0; i < array.length; ++i) {
863 array[i] = 1 + i; 610 array[i] = 1 + i;
864 } 611 }
865 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 612 Expect.listEquals([1, 2, 3, 4, 5,
613 6, 7, 8, 9, 10],
614 array);
866 for (int i = 0; i < array.length; ++i) { 615 for (int i = 0; i < array.length; ++i) {
867 array[i] = 0x10000000000000000 + i; 616 array[i] = 0x10000000000000000 + i;
868 } 617 }
869 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 618 Expect.listEquals([0, 1, 2, 3, 4,
619 5, 6, 7, 8, 9],
620 array);
870 for (int i = 0; i < array.length; ++i) { 621 for (int i = 0; i < array.length; ++i) {
871 array[i] = -10 + i; 622 array[i] = -10 + i;
872 } 623 }
873 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], array); 624 Expect.listEquals([-10, -9, -8, -7, -6,
625 -5, -4, -3, -2, -1],
626 array);
874 for (int i = 0; i < array.length; ++i) { 627 for (int i = 0; i < array.length; ++i) {
875 array[i] = 0x7FFFFFFFFFFFFFFF - i; 628 array[i] = 0x7FFFFFFFFFFFFFFF - i;
876 } 629 }
877 Expect.listEquals([ 630 Expect.listEquals([0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFE,
878 0x7FFFFFFFFFFFFFFF, 631 0x7FFFFFFFFFFFFFFD, 0x7FFFFFFFFFFFFFFC,
879 0x7FFFFFFFFFFFFFFE, 632 0x7FFFFFFFFFFFFFFB, 0x7FFFFFFFFFFFFFFA,
880 0x7FFFFFFFFFFFFFFD, 633 0x7FFFFFFFFFFFFFF9, 0x7FFFFFFFFFFFFFF8,
881 0x7FFFFFFFFFFFFFFC, 634 0x7FFFFFFFFFFFFFF7, 0x7FFFFFFFFFFFFFF6],
882 0x7FFFFFFFFFFFFFFB, 635 array);
883 0x7FFFFFFFFFFFFFFA,
884 0x7FFFFFFFFFFFFFF9,
885 0x7FFFFFFFFFFFFFF8,
886 0x7FFFFFFFFFFFFFF7,
887 0x7FFFFFFFFFFFFFF6
888 ], array);
889 for (int i = 0; i < array.length; ++i) { 636 for (int i = 0; i < array.length; ++i) {
890 array[i] = -0x8000000000000000 + i; 637 array[i] = -0x8000000000000000 + i;
891 } 638 }
892 Expect.listEquals([ 639 Expect.listEquals([-0x8000000000000000, -0x7FFFFFFFFFFFFFFF,
893 -0x8000000000000000, 640 -0x7FFFFFFFFFFFFFFE, -0x7FFFFFFFFFFFFFFD,
894 -0x7FFFFFFFFFFFFFFF, 641 -0x7FFFFFFFFFFFFFFC, -0x7FFFFFFFFFFFFFFB,
895 -0x7FFFFFFFFFFFFFFE, 642 -0x7FFFFFFFFFFFFFFA, -0x7FFFFFFFFFFFFFF9,
896 -0x7FFFFFFFFFFFFFFD, 643 -0x7FFFFFFFFFFFFFF8, -0x7FFFFFFFFFFFFFF7],
897 -0x7FFFFFFFFFFFFFFC, 644 array);
898 -0x7FFFFFFFFFFFFFFB,
899 -0x7FFFFFFFFFFFFFFA,
900 -0x7FFFFFFFFFFFFFF9,
901 -0x7FFFFFFFFFFFFFF8,
902 -0x7FFFFFFFFFFFFFF7
903 ], array);
904 for (int i = 0; i < array.length; ++i) { 645 for (int i = 0; i < array.length; ++i) {
905 array[i] = i; 646 array[i] = i;
906 } 647 }
907 var copy = array.sublist(0, array.length); 648 var copy = array.sublist(0, array.length);
908 Expect.isFalse(identical(copy, array)); 649 Expect.isFalse(identical(copy, array));
909 Expect.isTrue(copy is Int64List); 650 Expect.isTrue(copy is Int64List);
910 Expect.equals(10, copy.length); 651 Expect.equals(10, copy.length);
911 Expect.listEquals(array, copy); 652 Expect.listEquals(array, copy);
912 var empty = array.sublist(array.length, array.length); 653 var empty = array.sublist(array.length, array.length);
913 Expect.equals(0, empty.length); 654 Expect.equals(0, empty.length);
914 empty = array.sublist(array.length); 655 empty = array.sublist(array.length);
915 Expect.equals(0, empty.length); 656 Expect.equals(0, empty.length);
916 657
917 var region = array.sublist(3, array.length - 3); 658 var region = array.sublist(3, array.length - 3);
918 Expect.isTrue(copy is Int64List); 659 Expect.isTrue(copy is Int64List);
919 Expect.equals(4, region.length); 660 Expect.equals(4, region.length);
920 Expect.listEquals([3, 4, 5, 6], region); 661 Expect.listEquals([3, 4, 5, 6], region);
921 array.setRange(3, 7, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]); 662 array.setRange(3, 7, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]);
922 Expect.listEquals( 663 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0,
923 [0, 1, 2, -0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9], 664 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9],
924 array); 665 array);
925 } 666 }
926 667
927 static testInt64List() { 668 static testInt64List() {
928 Expect.throws(() { 669 Expect.throws(() { new Int64List(-1); },
929 new Int64List(-1); 670 (e) { return e is ArgumentError; });
930 }, (e) {
931 return e is ArgumentError;
932 });
933 var array = new Int64List(10); 671 var array = new Int64List(10);
934 testInt64ListImpl(array); 672 testInt64ListImpl(array);
935 } 673 }
936 674
937 static testUint64ListImpl(Uint64List array) { 675 static testUint64ListImpl(Uint64List array) {
938 Expect.isTrue(array is List<int>); 676 Expect.isTrue(array is List<int>);
939 Expect.equals(10, array.length); 677 Expect.equals(10, array.length);
940 Expect.equals(8, array.elementSizeInBytes); 678 Expect.equals(8, array.elementSizeInBytes);
941 Expect.equals(80, array.lengthInBytes); 679 Expect.equals(80, array.lengthInBytes);
942 Expect.listEquals([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], array); 680 Expect.listEquals([0, 0, 0, 0, 0,
943 Expect.throws(() { 681 0, 0, 0, 0, 0],
944 array[-1] = 0; 682 array);
945 }, (e) { 683 Expect.throws(() { array[-1] = 0; },
946 return e is RangeError; 684 (e) { return e is RangeError; });
947 }); 685 Expect.throws(() { return array[-1]; },
948 Expect.throws(() { 686 (e) { return e is RangeError; });
949 return array[-1]; 687 Expect.throws(() { array[10]; },
950 }, (e) { 688 (e) { return e is RangeError; });
951 return e is RangeError; 689 Expect.throws(() { array[10] = 0; },
952 }); 690 (e) { return e is RangeError; });
953 Expect.throws(() { 691 Expect.throws(() { array.add(0); },
954 array[10]; 692 (e) { return e is UnsupportedError; });
955 }, (e) { 693 Expect.throws(() { array.addAll([0]); },
956 return e is RangeError; 694 (e) { return e is UnsupportedError; });
957 }); 695 Expect.throws(() { array.clear(); },
958 Expect.throws(() { 696 (e) { return e is UnsupportedError; });
959 array[10] = 0; 697 Expect.throws(() { array.length = 0; },
960 }, (e) { 698 (e) { return e is UnsupportedError; });
961 return e is RangeError; 699 Expect.throws(() { array.removeLast(); },
962 }); 700 (e) { return e is UnsupportedError; });
963 Expect.throws(() { 701 Expect.throws(() { array.removeRange(0, array.length - 1); },
964 array.add(0); 702 (e) { return e is UnsupportedError; });
965 }, (e) {
966 return e is UnsupportedError;
967 });
968 Expect.throws(() {
969 array.addAll([0]);
970 }, (e) {
971 return e is UnsupportedError;
972 });
973 Expect.throws(() {
974 array.clear();
975 }, (e) {
976 return e is UnsupportedError;
977 });
978 Expect.throws(() {
979 array.length = 0;
980 }, (e) {
981 return e is UnsupportedError;
982 });
983 Expect.throws(() {
984 array.removeLast();
985 }, (e) {
986 return e is UnsupportedError;
987 });
988 Expect.throws(() {
989 array.removeRange(0, array.length - 1);
990 }, (e) {
991 return e is UnsupportedError;
992 });
993 for (int i = 0; i < array.length; ++i) { 703 for (int i = 0; i < array.length; ++i) {
994 array[i] = 1 + i; 704 array[i] = 1 + i;
995 } 705 }
996 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], array); 706 Expect.listEquals([1, 2, 3, 4, 5,
707 6, 7, 8, 9, 10],
708 array);
997 for (int i = 0; i < array.length; ++i) { 709 for (int i = 0; i < array.length; ++i) {
998 array[i] = 0x10000000000000000 + i; 710 array[i] = 0x10000000000000000 + i;
999 } 711 }
1000 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], array); 712 Expect.listEquals([0, 1, 2, 3, 4,
713 5, 6, 7, 8, 9],
714 array);
1001 for (int i = 0; i < array.length; ++i) { 715 for (int i = 0; i < array.length; ++i) {
1002 array[i] = 0xFFFFFFFFFFFFFFFF - i; 716 array[i] = 0xFFFFFFFFFFFFFFFF - i;
1003 } 717 }
1004 Expect.listEquals([ 718 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFE,
1005 0xFFFFFFFFFFFFFFFF, 719 0xFFFFFFFFFFFFFFFD, 0xFFFFFFFFFFFFFFFC,
1006 0xFFFFFFFFFFFFFFFE, 720 0xFFFFFFFFFFFFFFFB, 0xFFFFFFFFFFFFFFFA,
1007 0xFFFFFFFFFFFFFFFD, 721 0xFFFFFFFFFFFFFFF9, 0xFFFFFFFFFFFFFFF8,
1008 0xFFFFFFFFFFFFFFFC, 722 0xFFFFFFFFFFFFFFF7, 0xFFFFFFFFFFFFFFF6],
1009 0xFFFFFFFFFFFFFFFB, 723 array);
1010 0xFFFFFFFFFFFFFFFA,
1011 0xFFFFFFFFFFFFFFF9,
1012 0xFFFFFFFFFFFFFFF8,
1013 0xFFFFFFFFFFFFFFF7,
1014 0xFFFFFFFFFFFFFFF6
1015 ], array);
1016 for (int i = 0; i < array.length; ++i) { 724 for (int i = 0; i < array.length; ++i) {
1017 array[i] = i; 725 array[i] = i;
1018 } 726 }
1019 var copy = array.sublist(0, array.length); 727 var copy = array.sublist(0, array.length);
1020 Expect.isFalse(identical(copy, array)); 728 Expect.isFalse(identical(copy, array));
1021 Expect.isTrue(copy is Uint64List); 729 Expect.isTrue(copy is Uint64List);
1022 Expect.equals(10, copy.length); 730 Expect.equals(10, copy.length);
1023 Expect.listEquals(array, copy); 731 Expect.listEquals(array, copy);
1024 var empty = array.sublist(array.length, array.length); 732 var empty = array.sublist(array.length, array.length);
1025 Expect.equals(0, empty.length); 733 Expect.equals(0, empty.length);
1026 empty = array.sublist(array.length); 734 empty = array.sublist(array.length);
1027 Expect.equals(0, empty.length); 735 Expect.equals(0, empty.length);
1028 736
1029 var region = array.sublist(3, array.length - 3); 737 var region = array.sublist(3, array.length - 3);
1030 Expect.isTrue(copy is Uint64List); 738 Expect.isTrue(copy is Uint64List);
1031 Expect.equals(4, region.length); 739 Expect.equals(4, region.length);
1032 Expect.listEquals([3, 4, 5, 6], region); 740 Expect.listEquals([3, 4, 5, 6], region);
1033 array.setRange(3, 7, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]); 741 array.setRange(3, 7, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]);
1034 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9], array); 742 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9],
743 array);
1035 } 744 }
1036 745
1037 static testUint64List() { 746 static testUint64List() {
1038 Expect.throws(() { 747 Expect.throws(() { new Uint64List(-1); },
1039 new Uint64List(-1); 748 (e) { return e is ArgumentError; });
1040 }, (e) {
1041 return e is ArgumentError;
1042 });
1043 var array = new Uint64List(10); 749 var array = new Uint64List(10);
1044 testUint64ListImpl(array); 750 testUint64ListImpl(array);
1045 } 751 }
1046 752
1047 static testFloat32ListImpl(Float32List array) { 753 static testFloat32ListImpl(Float32List array) {
1048 Expect.isTrue(array is List<double>); 754 Expect.isTrue(array is List<double>);
1049 Expect.equals(10, array.length); 755 Expect.equals(10, array.length);
1050 Expect.equals(4, array.elementSizeInBytes); 756 Expect.equals(4, array.elementSizeInBytes);
1051 Expect.equals(40, array.lengthInBytes); 757 Expect.equals(40, array.lengthInBytes);
1052 Expect 758 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0,
1053 .listEquals([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], array); 759 0.0, 0.0, 0.0, 0.0, 0.0],
1054 Expect.throws(() { 760 array);
1055 array[-1] = 0.0; 761 Expect.throws(() { array[-1] = 0.0; },
1056 }, (e) { 762 (e) { return e is RangeError; });
1057 return e is RangeError; 763 Expect.throws(() { return array[-1]; },
1058 }); 764 (e) { return e is RangeError; });
1059 Expect.throws(() { 765 Expect.throws(() { array[10]; },
1060 return array[-1]; 766 (e) { return e is RangeError; });
1061 }, (e) { 767 Expect.throws(() { array[10] = 0.0; },
1062 return e is RangeError; 768 (e) { return e is RangeError; });
1063 }); 769 Expect.throws(() { array.add(0.0); },
1064 Expect.throws(() { 770 (e) { return e is UnsupportedError; });
1065 array[10]; 771 Expect.throws(() { array.addAll([0]); },
1066 }, (e) { 772 (e) { return e is UnsupportedError; });
1067 return e is RangeError; 773 Expect.throws(() { array.clear(); },
1068 }); 774 (e) { return e is UnsupportedError; });
1069 Expect.throws(() { 775 Expect.throws(() { array.length = 0; },
1070 array[10] = 0.0; 776 (e) { return e is UnsupportedError; });
1071 }, (e) { 777 Expect.throws(() { array.removeLast(); },
1072 return e is RangeError; 778 (e) { return e is UnsupportedError; });
1073 }); 779 Expect.throws(() { array.removeRange(0, array.length - 1); },
1074 Expect.throws(() { 780 (e) { return e is UnsupportedError; });
1075 array.add(0.0);
1076 }, (e) {
1077 return e is UnsupportedError;
1078 });
1079 Expect.throws(() {
1080 array.addAll([0]);
1081 }, (e) {
1082 return e is UnsupportedError;
1083 });
1084 Expect.throws(() {
1085 array.clear();
1086 }, (e) {
1087 return e is UnsupportedError;
1088 });
1089 Expect.throws(() {
1090 array.length = 0;
1091 }, (e) {
1092 return e is UnsupportedError;
1093 });
1094 Expect.throws(() {
1095 array.removeLast();
1096 }, (e) {
1097 return e is UnsupportedError;
1098 });
1099 Expect.throws(() {
1100 array.removeRange(0, array.length - 1);
1101 }, (e) {
1102 return e is UnsupportedError;
1103 });
1104 for (int i = 0; i < array.length; ++i) { 781 for (int i = 0; i < array.length; ++i) {
1105 array[i] = 1.0 + i; 782 array[i] = 1.0 + i;
1106 } 783 }
1107 Expect 784 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
1108 .listEquals([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], array); 785 6.0, 7.0, 8.0, 9.0, 10.0],
786 array);
1109 // TODO: min, max, and round 787 // TODO: min, max, and round
1110 for (int i = 0; i < array.length; ++i) { 788 for (int i = 0; i < array.length; ++i) {
1111 array[i] = i * 1.0; 789 array[i] = i * 1.0;
1112 } 790 }
1113 var copy = array.sublist(0, array.length); 791 var copy = array.sublist(0, array.length);
1114 Expect.isFalse(identical(copy, array)); 792 Expect.isFalse(identical(copy, array));
1115 Expect.isTrue(copy is Float32List); 793 Expect.isTrue(copy is Float32List);
1116 Expect.equals(10, copy.length); 794 Expect.equals(10, copy.length);
1117 Expect.listEquals(array, copy); 795 Expect.listEquals(array, copy);
1118 var empty = array.sublist(array.length, array.length); 796 var empty = array.sublist(array.length, array.length);
1119 Expect.equals(0, empty.length); 797 Expect.equals(0, empty.length);
1120 empty = array.sublist(array.length); 798 empty = array.sublist(array.length);
1121 Expect.equals(0, empty.length); 799 Expect.equals(0, empty.length);
1122 800
1123 var region = array.sublist(3, array.length - 3); 801 var region = array.sublist(3, array.length - 3);
1124 Expect.isTrue(copy is Float32List); 802 Expect.isTrue(copy is Float32List);
1125 Expect.equals(4, region.length); 803 Expect.equals(4, region.length);
1126 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); 804 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
1127 array.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); 805 array.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
1128 Expect.listEquals([ 806 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
1129 0.0, 807 1.0, double.INFINITY, 7.0, 8.0, 9.0],
1130 1.0, 808 array);
1131 2.0,
1132 double.NEGATIVE_INFINITY,
1133 0.0,
1134 1.0,
1135 double.INFINITY,
1136 7.0,
1137 8.0,
1138 9.0
1139 ], array);
1140 } 809 }
1141 810
1142 static testFloat32List() { 811 static testFloat32List() {
1143 Expect.throws(() { 812 Expect.throws(() { new Float32List(-1); },
1144 new Float32List(-1); 813 (e) { return e is ArgumentError; });
1145 }, (e) {
1146 return e is ArgumentError;
1147 });
1148 var array = new Float32List(10); 814 var array = new Float32List(10);
1149 testFloat32ListImpl(array); 815 testFloat32ListImpl(array);
1150 } 816 }
1151 817
1152 static testFloat64ListImpl(Float64List array) { 818 static testFloat64ListImpl(Float64List array) {
1153 Expect.isTrue(array is List<double>); 819 Expect.isTrue(array is List<double>);
1154 Expect.equals(10, array.length); 820 Expect.equals(10, array.length);
1155 Expect.equals(8, array.elementSizeInBytes); 821 Expect.equals(8, array.elementSizeInBytes);
1156 Expect.equals(80, array.lengthInBytes); 822 Expect.equals(80, array.lengthInBytes);
1157 Expect 823 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0,
1158 .listEquals([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], array); 824 0.0, 0.0, 0.0, 0.0, 0.0],
1159 Expect.throws(() { 825 array);
1160 array[-1] = 0.0; 826 Expect.throws(() { array[-1] = 0.0; },
1161 }, (e) { 827 (e) { return e is RangeError; });
1162 return e is RangeError; 828 Expect.throws(() { return array[-1]; },
1163 }); 829 (e) { return e is RangeError; });
1164 Expect.throws(() { 830 Expect.throws(() { array[10]; },
1165 return array[-1]; 831 (e) { return e is RangeError; });
1166 }, (e) { 832 Expect.throws(() { array[10] = 0.0; },
1167 return e is RangeError; 833 (e) { return e is RangeError; });
1168 }); 834 Expect.throws(() { array.add(0.0); },
1169 Expect.throws(() { 835 (e) { return e is UnsupportedError; });
1170 array[10]; 836 Expect.throws(() { array.addAll([0]); },
1171 }, (e) { 837 (e) { return e is UnsupportedError; });
1172 return e is RangeError; 838 Expect.throws(() { array.clear(); },
1173 }); 839 (e) { return e is UnsupportedError; });
1174 Expect.throws(() { 840 Expect.throws(() { array.length = 0; },
1175 array[10] = 0.0; 841 (e) { return e is UnsupportedError; });
1176 }, (e) { 842 Expect.throws(() { array.removeLast(); },
1177 return e is RangeError; 843 (e) { return e is UnsupportedError; });
1178 }); 844 Expect.throws(() { array.removeRange(0, array.length - 1); },
1179 Expect.throws(() { 845 (e) { return e is UnsupportedError; });
1180 array.add(0.0);
1181 }, (e) {
1182 return e is UnsupportedError;
1183 });
1184 Expect.throws(() {
1185 array.addAll([0]);
1186 }, (e) {
1187 return e is UnsupportedError;
1188 });
1189 Expect.throws(() {
1190 array.clear();
1191 }, (e) {
1192 return e is UnsupportedError;
1193 });
1194 Expect.throws(() {
1195 array.length = 0;
1196 }, (e) {
1197 return e is UnsupportedError;
1198 });
1199 Expect.throws(() {
1200 array.removeLast();
1201 }, (e) {
1202 return e is UnsupportedError;
1203 });
1204 Expect.throws(() {
1205 array.removeRange(0, array.length - 1);
1206 }, (e) {
1207 return e is UnsupportedError;
1208 });
1209 for (int i = 0; i < array.length; ++i) { 846 for (int i = 0; i < array.length; ++i) {
1210 array[i] = 1.0 + i; 847 array[i] = 1.0 + i;
1211 } 848 }
1212 Expect 849 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
1213 .listEquals([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], array); 850 6.0, 7.0, 8.0, 9.0, 10.0],
851 array);
1214 // TODO: min, max 852 // TODO: min, max
1215 for (int i = 0; i < array.length; ++i) { 853 for (int i = 0; i < array.length; ++i) {
1216 array[i] = i * 1.0; 854 array[i] = i * 1.0;
1217 } 855 }
1218 var copy = array.sublist(0, array.length); 856 var copy = array.sublist(0, array.length);
1219 Expect.isFalse(identical(copy, array)); 857 Expect.isFalse(identical(copy, array));
1220 Expect.isTrue(copy is Float64List); 858 Expect.isTrue(copy is Float64List);
1221 Expect.equals(10, copy.length); 859 Expect.equals(10, copy.length);
1222 Expect.listEquals(array, copy); 860 Expect.listEquals(array, copy);
1223 var empty = array.sublist(array.length, array.length); 861 var empty = array.sublist(array.length, array.length);
1224 Expect.equals(0, empty.length); 862 Expect.equals(0, empty.length);
1225 empty = array.sublist(array.length); 863 empty = array.sublist(array.length);
1226 Expect.equals(0, empty.length); 864 Expect.equals(0, empty.length);
1227 865
1228 var region = array.sublist(3, array.length - 3); 866 var region = array.sublist(3, array.length - 3);
1229 Expect.isTrue(copy is Float64List); 867 Expect.isTrue(copy is Float64List);
1230 Expect.equals(4, region.length); 868 Expect.equals(4, region.length);
1231 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); 869 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
1232 array.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); 870 array.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
1233 Expect.listEquals([ 871 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
1234 0.0, 872 1.0, double.INFINITY, 7.0, 8.0, 9.0],
1235 1.0, 873 array);
1236 2.0,
1237 double.NEGATIVE_INFINITY,
1238 0.0,
1239 1.0,
1240 double.INFINITY,
1241 7.0,
1242 8.0,
1243 9.0
1244 ], array);
1245 } 874 }
1246 875
1247 static testFloat64List() { 876 static testFloat64List() {
1248 Expect.throws(() { 877 Expect.throws(() { new Float64List(-1); },
1249 new Float64List(-1); 878 (e) { return e is ArgumentError; });
1250 }, (e) {
1251 return e is ArgumentError;
1252 });
1253 var array = new Float64List(10); 879 var array = new Float64List(10);
1254 testFloat64ListImpl(array); 880 testFloat64ListImpl(array);
1255 } 881 }
1256 882
1257 static testByteList() { 883 static testByteList() {
1258 var array = new Uint8List(8); 884 var array = new Uint8List(8);
1259 Expect.equals(8, array.length); 885 Expect.equals(8, array.length);
1260 Expect.equals(8, array.lengthInBytes); 886 Expect.equals(8, array.lengthInBytes);
1261 var byte_array = new ByteData.view(array.buffer); 887 var byte_array = new ByteData.view(array.buffer);
1262 Expect.equals(8, byte_array.lengthInBytes); 888 Expect.equals(8, byte_array.lengthInBytes);
1263 Expect.throws(() { 889 Expect.throws(() { byte_array.getInt8(-1); },
1264 byte_array.getInt8(-1); 890 (e) { return e is RangeError; });
1265 }, (e) { 891 Expect.throws(() { byte_array.getUint8(-1); },
1266 return e is RangeError; 892 (e) { return e is RangeError; });
1267 }); 893 Expect.throws(() { byte_array.getInt16(-1); },
1268 Expect.throws(() { 894 (e) { return e is RangeError; });
1269 byte_array.getUint8(-1); 895 Expect.throws(() { byte_array.getUint16(-1); },
1270 }, (e) { 896 (e) { return e is RangeError; });
1271 return e is RangeError; 897 Expect.throws(() { byte_array.getInt32(-1); },
1272 }); 898 (e) { return e is RangeError; });
1273 Expect.throws(() { 899 Expect.throws(() { byte_array.getUint32(-1); },
1274 byte_array.getInt16(-1); 900 (e) { return e is RangeError; });
1275 }, (e) { 901 Expect.throws(() { byte_array.getInt64(-1); },
1276 return e is RangeError; 902 (e) { return e is RangeError; });
1277 }); 903 Expect.throws(() { byte_array.getUint64(-1); },
1278 Expect.throws(() { 904 (e) { return e is RangeError; });
1279 byte_array.getUint16(-1); 905 Expect.throws(() { byte_array.getFloat32(-1); },
1280 }, (e) { 906 (e) { return e is RangeError; });
1281 return e is RangeError; 907 Expect.throws(() { byte_array.getFloat64(-1); },
1282 }); 908 (e) { return e is RangeError; });
1283 Expect.throws(() { 909 Expect.throws(() { byte_array.setInt8(-1, 0); },
1284 byte_array.getInt32(-1); 910 (e) { return e is RangeError; });
1285 }, (e) { 911 Expect.throws(() { byte_array.setUint8(-1, 0); },
1286 return e is RangeError; 912 (e) { return e is RangeError; });
1287 }); 913 Expect.throws(() { byte_array.setInt16(-1, 0); },
1288 Expect.throws(() { 914 (e) { return e is RangeError; });
1289 byte_array.getUint32(-1); 915 Expect.throws(() { byte_array.setUint16(-1, 0); },
1290 }, (e) { 916 (e) { return e is RangeError; });
1291 return e is RangeError; 917 Expect.throws(() { byte_array.setInt32(-1, 0); },
1292 }); 918 (e) { return e is RangeError; });
1293 Expect.throws(() { 919 Expect.throws(() { byte_array.setUint32(-1, 0); },
1294 byte_array.getInt64(-1); 920 (e) { return e is RangeError; });
1295 }, (e) { 921 Expect.throws(() { byte_array.setInt64(-1, 0); },
1296 return e is RangeError; 922 (e) { return e is RangeError; });
1297 }); 923 Expect.throws(() { byte_array.setUint64(-1, 0); },
1298 Expect.throws(() { 924 (e) { return e is RangeError; });
1299 byte_array.getUint64(-1); 925 Expect.throws(() { byte_array.setFloat32(-1, 0.0); },
1300 }, (e) { 926 (e) { return e is RangeError; });
1301 return e is RangeError; 927 Expect.throws(() { byte_array.setFloat64(-1, 0.0); },
1302 }); 928 (e) { return e is RangeError; });
1303 Expect.throws(() { 929 Expect.throws(() { byte_array.getInt8(8); },
1304 byte_array.getFloat32(-1); 930 (e) { return e is RangeError; });
1305 }, (e) { 931 Expect.throws(() { byte_array.getUint8(8); },
1306 return e is RangeError; 932 (e) { return e is RangeError; });
1307 }); 933 Expect.throws(() { byte_array.getInt16(8); },
1308 Expect.throws(() { 934 (e) { return e is RangeError; });
1309 byte_array.getFloat64(-1); 935 Expect.throws(() { byte_array.getUint16(8); },
1310 }, (e) { 936 (e) { return e is RangeError; });
1311 return e is RangeError; 937 Expect.throws(() { byte_array.getInt32(8); },
1312 }); 938 (e) { return e is RangeError; });
1313 Expect.throws(() { 939 Expect.throws(() { byte_array.getUint32(8); },
1314 byte_array.setInt8(-1, 0); 940 (e) { return e is RangeError; });
1315 }, (e) { 941 Expect.throws(() { byte_array.getInt64(8); },
1316 return e is RangeError; 942 (e) { return e is RangeError; });
1317 }); 943 Expect.throws(() { byte_array.getUint64(8); },
1318 Expect.throws(() { 944 (e) { return e is RangeError; });
1319 byte_array.setUint8(-1, 0); 945 Expect.throws(() { byte_array.getFloat32(8); },
1320 }, (e) { 946 (e) { return e is RangeError; });
1321 return e is RangeError; 947 Expect.throws(() { byte_array.getFloat64(8); },
1322 }); 948 (e) { return e is RangeError; });
1323 Expect.throws(() { 949 Expect.throws(() { byte_array.setInt8(8, 0); },
1324 byte_array.setInt16(-1, 0); 950 (e) { return e is RangeError; });
1325 }, (e) { 951 Expect.throws(() { byte_array.setUint8(8, 0); },
1326 return e is RangeError; 952 (e) { return e is RangeError; });
1327 }); 953 Expect.throws(() { byte_array.setInt16(8, 0); },
1328 Expect.throws(() { 954 (e) { return e is RangeError; });
1329 byte_array.setUint16(-1, 0); 955 Expect.throws(() { byte_array.setUint16(8, 0); },
1330 }, (e) { 956 (e) { return e is RangeError; });
1331 return e is RangeError; 957 Expect.throws(() { byte_array.setInt32(8, 0); },
1332 }); 958 (e) { return e is RangeError; });
1333 Expect.throws(() { 959 Expect.throws(() { byte_array.setUint32(8, 0); },
1334 byte_array.setInt32(-1, 0); 960 (e) { return e is RangeError; });
1335 }, (e) { 961 Expect.throws(() { byte_array.setInt64(8, 0); },
1336 return e is RangeError; 962 (e) { return e is RangeError; });
1337 }); 963 Expect.throws(() { byte_array.setUint64(8, 0); },
1338 Expect.throws(() { 964 (e) { return e is RangeError; });
1339 byte_array.setUint32(-1, 0); 965 Expect.throws(() { byte_array.setFloat32(8, 0.0); },
1340 }, (e) { 966 (e) { return e is RangeError; });
1341 return e is RangeError; 967 Expect.throws(() { byte_array.setFloat64(8, 0.0); },
1342 }); 968 (e) { return e is RangeError; });
1343 Expect.throws(() {
1344 byte_array.setInt64(-1, 0);
1345 }, (e) {
1346 return e is RangeError;
1347 });
1348 Expect.throws(() {
1349 byte_array.setUint64(-1, 0);
1350 }, (e) {
1351 return e is RangeError;
1352 });
1353 Expect.throws(() {
1354 byte_array.setFloat32(-1, 0.0);
1355 }, (e) {
1356 return e is RangeError;
1357 });
1358 Expect.throws(() {
1359 byte_array.setFloat64(-1, 0.0);
1360 }, (e) {
1361 return e is RangeError;
1362 });
1363 Expect.throws(() {
1364 byte_array.getInt8(8);
1365 }, (e) {
1366 return e is RangeError;
1367 });
1368 Expect.throws(() {
1369 byte_array.getUint8(8);
1370 }, (e) {
1371 return e is RangeError;
1372 });
1373 Expect.throws(() {
1374 byte_array.getInt16(8);
1375 }, (e) {
1376 return e is RangeError;
1377 });
1378 Expect.throws(() {
1379 byte_array.getUint16(8);
1380 }, (e) {
1381 return e is RangeError;
1382 });
1383 Expect.throws(() {
1384 byte_array.getInt32(8);
1385 }, (e) {
1386 return e is RangeError;
1387 });
1388 Expect.throws(() {
1389 byte_array.getUint32(8);
1390 }, (e) {
1391 return e is RangeError;
1392 });
1393 Expect.throws(() {
1394 byte_array.getInt64(8);
1395 }, (e) {
1396 return e is RangeError;
1397 });
1398 Expect.throws(() {
1399 byte_array.getUint64(8);
1400 }, (e) {
1401 return e is RangeError;
1402 });
1403 Expect.throws(() {
1404 byte_array.getFloat32(8);
1405 }, (e) {
1406 return e is RangeError;
1407 });
1408 Expect.throws(() {
1409 byte_array.getFloat64(8);
1410 }, (e) {
1411 return e is RangeError;
1412 });
1413 Expect.throws(() {
1414 byte_array.setInt8(8, 0);
1415 }, (e) {
1416 return e is RangeError;
1417 });
1418 Expect.throws(() {
1419 byte_array.setUint8(8, 0);
1420 }, (e) {
1421 return e is RangeError;
1422 });
1423 Expect.throws(() {
1424 byte_array.setInt16(8, 0);
1425 }, (e) {
1426 return e is RangeError;
1427 });
1428 Expect.throws(() {
1429 byte_array.setUint16(8, 0);
1430 }, (e) {
1431 return e is RangeError;
1432 });
1433 Expect.throws(() {
1434 byte_array.setInt32(8, 0);
1435 }, (e) {
1436 return e is RangeError;
1437 });
1438 Expect.throws(() {
1439 byte_array.setUint32(8, 0);
1440 }, (e) {
1441 return e is RangeError;
1442 });
1443 Expect.throws(() {
1444 byte_array.setInt64(8, 0);
1445 }, (e) {
1446 return e is RangeError;
1447 });
1448 Expect.throws(() {
1449 byte_array.setUint64(8, 0);
1450 }, (e) {
1451 return e is RangeError;
1452 });
1453 Expect.throws(() {
1454 byte_array.setFloat32(8, 0.0);
1455 }, (e) {
1456 return e is RangeError;
1457 });
1458 Expect.throws(() {
1459 byte_array.setFloat64(8, 0.0);
1460 }, (e) {
1461 return e is RangeError;
1462 });
1463 Expect.equals(0, byte_array.getInt8(0)); 969 Expect.equals(0, byte_array.getInt8(0));
1464 Expect.equals(0, byte_array.getUint8(0)); 970 Expect.equals(0, byte_array.getUint8(0));
1465 Expect.equals(0, byte_array.getInt16(0)); 971 Expect.equals(0, byte_array.getInt16(0));
1466 Expect.equals(0, byte_array.getUint16(0)); 972 Expect.equals(0, byte_array.getUint16(0));
1467 Expect.equals(0, byte_array.getInt32(0)); 973 Expect.equals(0, byte_array.getInt32(0));
1468 Expect.equals(0, byte_array.getUint32(0)); 974 Expect.equals(0, byte_array.getUint32(0));
1469 Expect.equals(0, byte_array.getInt64(0)); 975 Expect.equals(0, byte_array.getInt64(0));
1470 Expect.equals(0, byte_array.getUint64(0)); 976 Expect.equals(0, byte_array.getUint64(0));
1471 Expect.equals(0.0, byte_array.getFloat32(0)); 977 Expect.equals(0.0, byte_array.getFloat32(0));
1472 Expect.equals(0.0, byte_array.getFloat64(0)); 978 Expect.equals(0.0, byte_array.getFloat64(0));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 Expect.equals(0xF9, byte_array.getUint8(6)); 1010 Expect.equals(0xF9, byte_array.getUint8(6));
1505 Expect.equals(0xF8, byte_array.getUint8(7)); 1011 Expect.equals(0xF8, byte_array.getUint8(7));
1506 Expect.equals(0, byte_array.getInt16(0)); 1012 Expect.equals(0, byte_array.getInt16(0));
1507 Expect.equals(-16512, byte_array.getInt16(2, Endianness.LITTLE_ENDIAN)); 1013 Expect.equals(-16512, byte_array.getInt16(2, Endianness.LITTLE_ENDIAN));
1508 Expect.equals(-1285, byte_array.getInt16(4, Endianness.LITTLE_ENDIAN)); 1014 Expect.equals(-1285, byte_array.getInt16(4, Endianness.LITTLE_ENDIAN));
1509 Expect.equals(-1799, byte_array.getInt16(6, Endianness.LITTLE_ENDIAN)); 1015 Expect.equals(-1799, byte_array.getInt16(6, Endianness.LITTLE_ENDIAN));
1510 Expect.equals(0x0000, byte_array.getUint16(0, Endianness.LITTLE_ENDIAN)); 1016 Expect.equals(0x0000, byte_array.getUint16(0, Endianness.LITTLE_ENDIAN));
1511 Expect.equals(0xBF80, byte_array.getUint16(2, Endianness.LITTLE_ENDIAN)); 1017 Expect.equals(0xBF80, byte_array.getUint16(2, Endianness.LITTLE_ENDIAN));
1512 Expect.equals(0xFAFB, byte_array.getUint16(4, Endianness.LITTLE_ENDIAN)); 1018 Expect.equals(0xFAFB, byte_array.getUint16(4, Endianness.LITTLE_ENDIAN));
1513 Expect.equals(0xF8F9, byte_array.getUint16(6, Endianness.LITTLE_ENDIAN)); 1019 Expect.equals(0xF8F9, byte_array.getUint16(6, Endianness.LITTLE_ENDIAN));
1514 Expect.equals( 1020 Expect.equals(-1082130432,
1515 -1082130432, byte_array.getInt32(0, Endianness.LITTLE_ENDIAN)); 1021 byte_array.getInt32(0, Endianness.LITTLE_ENDIAN));
1516 Expect.equals( 1022 Expect.equals(0xBF800000,
1517 0xBF800000, byte_array.getUint32(0, Endianness.LITTLE_ENDIAN)); 1023 byte_array.getUint32(0, Endianness.LITTLE_ENDIAN));
1518 Expect.equals( 1024 Expect.equals(-506097523945897984,
1519 -506097523945897984, byte_array.getInt64(0, Endianness.LITTLE_ENDIAN)); 1025 byte_array.getInt64(0, Endianness.LITTLE_ENDIAN));
1520 Expect.equals( 1026 Expect.equals(0xF8F9FAFBBF800000,
1521 0xF8F9FAFBBF800000, byte_array.getUint64(0, Endianness.LITTLE_ENDIAN)); 1027 byte_array.getUint64(0, Endianness.LITTLE_ENDIAN));
1522 Expect.equals(-1.0, byte_array.getFloat32(0, Endianness.LITTLE_ENDIAN)); 1028 Expect.equals(-1.0, byte_array.getFloat32(0, Endianness.LITTLE_ENDIAN));
1523 // TODO: byte_array.getFloat64(0) 1029 // TODO: byte_array.getFloat64(0)
1524 } 1030 }
1525 1031
1526 static testInt8ListViewImpl(var array) { 1032 static testInt8ListViewImpl(var array) {
1527 Expect.equals(12, array.length); 1033 Expect.equals(12, array.length);
1528 Expect.equals(1, array.elementSizeInBytes); 1034 Expect.equals(1, array.elementSizeInBytes);
1529 Expect.equals(12, array.lengthInBytes); 1035 Expect.equals(12, array.lengthInBytes);
1530 for (int i = 0; i < array.length; ++i) { 1036 for (int i = 0; i < array.length; ++i) {
1531 array[i] = 0xFF; 1037 array[i] = 0xFF;
1532 } 1038 }
1533 Expect.throws(() { 1039 Expect.throws(() { new Int8List.view(array.buffer, -1); },
1534 new Int8List.view(array.buffer, -1); 1040 (e) { return e is RangeError; });
1535 }, (e) { 1041 Expect.throws(() { new Int8List.view(array.buffer, 0, -1); },
1536 return e is RangeError; 1042 (e) { return e is RangeError; });
1537 }); 1043 Expect.throws(() { new Int8List.view(array.buffer,
1538 Expect.throws(() { 1044 array.lengthInBytes + 1); },
1539 new Int8List.view(array.buffer, 0, -1); 1045 (e) { return e is RangeError; });
1540 }, (e) { 1046 Expect.throws(() { new Int8List.view(array.buffer,
1541 return e is RangeError; 1047 0, array.length + 1); },
1542 }); 1048 (e) { return e is RangeError; });
1543 Expect.throws(() { 1049 Expect.throws(() { new Int8List.view(array.buffer,
1544 new Int8List.view(array.buffer, array.lengthInBytes + 1); 1050 array.length - 1, 2); },
1545 }, (e) { 1051 (e) { return e is RangeError; });
1546 return e is RangeError; 1052 var empty = new Int8List.view(array.buffer,
1547 }); 1053 array.lengthInBytes);
1548 Expect.throws(() {
1549 new Int8List.view(array.buffer, 0, array.length + 1);
1550 }, (e) {
1551 return e is RangeError;
1552 });
1553 Expect.throws(() {
1554 new Int8List.view(array.buffer, array.length - 1, 2);
1555 }, (e) {
1556 return e is RangeError;
1557 });
1558 var empty = new Int8List.view(array.buffer, array.lengthInBytes);
1559 Expect.isTrue(empty is List<int>); 1054 Expect.isTrue(empty is List<int>);
1560 Expect.isTrue(empty is Int8List); 1055 Expect.isTrue(empty is Int8List);
1561 Expect.equals(0, empty.length); 1056 Expect.equals(0, empty.length);
1562 var whole = new Int8List.view(array.buffer); 1057 var whole = new Int8List.view(array.buffer);
1563 Expect.isTrue(whole is List<int>); 1058 Expect.isTrue(whole is List<int>);
1564 Expect.isTrue(whole is Int8List); 1059 Expect.isTrue(whole is Int8List);
1565 Expect.equals(12, whole.length); 1060 Expect.equals(12, whole.length);
1566 var view = new Int8List.view(array.buffer, 1, array.length - 2); 1061 var view = new Int8List.view(array.buffer, 1, array.length - 2);
1567 Expect.isTrue(view is List<int>); 1062 Expect.isTrue(view is List<int>);
1568 Expect.isTrue(view is Int8List); 1063 Expect.isTrue(view is Int8List);
1569 Expect.equals(10, view.length); 1064 Expect.equals(10, view.length);
1570 Expect.equals(1, view.elementSizeInBytes); 1065 Expect.equals(1, view.elementSizeInBytes);
1571 Expect.equals(10, view.lengthInBytes); 1066 Expect.equals(10, view.lengthInBytes);
1572 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], view); 1067 Expect.listEquals([-1, -1, -1, -1, -1,
1573 Expect.throws(() { 1068 -1, -1, -1, -1, -1],
1574 view[-1] = 0; 1069 view);
1575 }, (e) { 1070 Expect.throws(() { view[-1] = 0; },
1576 return e is RangeError; 1071 (e) { return e is RangeError; });
1577 }); 1072 Expect.throws(() { return view[-1]; },
1578 Expect.throws(() { 1073 (e) { return e is RangeError; });
1579 return view[-1]; 1074 Expect.throws(() { view[view.length]; },
1580 }, (e) { 1075 (e) { return e is RangeError; });
1581 return e is RangeError; 1076 Expect.throws(() { view[10] = 0; },
1582 }); 1077 (e) { return e is RangeError; });
1583 Expect.throws(() { 1078 Expect.throws(() { view.add(0); },
1584 view[view.length]; 1079 (e) { return e is UnsupportedError; });
1585 }, (e) { 1080 Expect.throws(() { view.addAll([0]); },
1586 return e is RangeError; 1081 (e) { return e is UnsupportedError; });
1587 }); 1082 Expect.throws(() { view.clear(); },
1588 Expect.throws(() { 1083 (e) { return e is UnsupportedError; });
1589 view[10] = 0; 1084 Expect.throws(() { view.length = 0; },
1590 }, (e) { 1085 (e) { return e is UnsupportedError; });
1591 return e is RangeError; 1086 Expect.throws(() { view.removeLast(); },
1592 }); 1087 (e) { return e is UnsupportedError; });
1593 Expect.throws(() { 1088 Expect.throws(() { view.removeRange(0, view.length - 1); },
1594 view.add(0); 1089 (e) { return e is UnsupportedError; });
1595 }, (e) {
1596 return e is UnsupportedError;
1597 });
1598 Expect.throws(() {
1599 view.addAll([0]);
1600 }, (e) {
1601 return e is UnsupportedError;
1602 });
1603 Expect.throws(() {
1604 view.clear();
1605 }, (e) {
1606 return e is UnsupportedError;
1607 });
1608 Expect.throws(() {
1609 view.length = 0;
1610 }, (e) {
1611 return e is UnsupportedError;
1612 });
1613 Expect.throws(() {
1614 view.removeLast();
1615 }, (e) {
1616 return e is UnsupportedError;
1617 });
1618 Expect.throws(() {
1619 view.removeRange(0, view.length - 1);
1620 }, (e) {
1621 return e is UnsupportedError;
1622 });
1623 for (int i = 0; i < view.length; ++i) { 1090 for (int i = 0; i < view.length; ++i) {
1624 view[i] = 1 + i; 1091 view[i] = 1 + i;
1625 } 1092 }
1626 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1093 Expect.listEquals([1, 2, 3, 4, 5,
1627 Expect.listEquals([0xFF, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0xFF], array); 1094 6, 7, 8, 9, 10],
1095 view);
1096 Expect.listEquals([0xFF, 1, 2, 3, 4, 5,
1097 6, 7, 8, 9, 10, 0xFF],
1098 array);
1628 for (int i = 0; i < view.length; ++i) { 1099 for (int i = 0; i < view.length; ++i) {
1629 view[i] = 0x100 + i; 1100 view[i] = 0x100 + i;
1630 } 1101 }
1631 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1102 Expect.listEquals([0, 1, 2, 3, 4,
1632 Expect.listEquals([0xFF, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xFF], array); 1103 5, 6, 7, 8, 9],
1104 view);
1105 Expect.listEquals([0xFF, 0, 1, 2, 3, 4,
1106 5, 6, 7, 8, 9, 0xFF],
1107 array);
1633 for (int i = 0; i < view.length; ++i) { 1108 for (int i = 0; i < view.length; ++i) {
1634 view[i] = -10 + i; 1109 view[i] = -10 + i;
1635 } 1110 }
1636 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], view); 1111 Expect.listEquals([-10, -9, -8, -7, -6,
1637 Expect.listEquals([ 1112 -5, -4, -3, -2, -1],
1638 0xFF, 1113 view);
1639 0xF6, 1114 Expect.listEquals([0xFF, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
1640 0xF7, 1115 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0xFF],
1641 0xF8, 1116 array);
1642 0xF9,
1643 0xFA,
1644 0xFB,
1645 0xFC,
1646 0xFD,
1647 0xFE,
1648 0xFF,
1649 0xFF
1650 ], array);
1651 for (int i = 0; i < view.length; ++i) { 1117 for (int i = 0; i < view.length; ++i) {
1652 view[i] = 0x7F - i; 1118 view[i] = 0x7F - i;
1653 } 1119 }
1654 Expect.listEquals([127, 126, 125, 124, 123, 122, 121, 120, 119, 118], view); 1120 Expect.listEquals([127, 126, 125, 124, 123,
1655 Expect.listEquals( 1121 122, 121, 120, 119, 118],
1656 [0xFF, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 0xFF], array); 1122 view);
1123 Expect.listEquals([0xFF, 127, 126, 125, 124, 123,
1124 122, 121, 120, 119, 118, 0xFF],
1125 array);
1657 for (int i = 0; i < view.length; ++i) { 1126 for (int i = 0; i < view.length; ++i) {
1658 view[i] = -0x80 + i; 1127 view[i] = -0x80 + i;
1659 } 1128 }
1660 Expect.listEquals( 1129 Expect.listEquals([-128, -127, -126, -125, -124,
1661 [-128, -127, -126, -125, -124, -123, -122, -121, -120, -119], view); 1130 -123, -122, -121, -120, -119],
1662 Expect.listEquals([ 1131 view);
1663 0xFF, 1132 Expect.listEquals([0xFF, 0x80, 0x81, 0x82, 0x83, 0x84,
1664 0x80, 1133 0x85, 0x86, 0x87, 0x88, 0x89, 0xFF],
1665 0x81, 1134 array);
1666 0x82,
1667 0x83,
1668 0x84,
1669 0x85,
1670 0x86,
1671 0x87,
1672 0x88,
1673 0x89,
1674 0xFF
1675 ], array);
1676 for (int i = 0; i < view.length; ++i) { 1135 for (int i = 0; i < view.length; ++i) {
1677 view[i] = i; 1136 view[i] = i;
1678 } 1137 }
1679 var copy = view.sublist(0, view.length); 1138 var copy = view.sublist(0, view.length);
1680 Expect.isFalse(identical(copy, view)); 1139 Expect.isFalse(identical(copy, view));
1681 Expect.isTrue(copy is Int8List); 1140 Expect.isTrue(copy is Int8List);
1682 Expect.equals(10, copy.length); 1141 Expect.equals(10, copy.length);
1683 Expect.listEquals(view, copy); 1142 Expect.listEquals(view, copy);
1684 var region = view.sublist(3, view.length - 3); 1143 var region = view.sublist(3, view.length - 3);
1685 Expect.isTrue(copy is Int8List); 1144 Expect.isTrue(copy is Int8List);
1686 Expect.equals(4, region.length); 1145 Expect.equals(4, region.length);
1687 Expect.listEquals([3, 4, 5, 6], region); 1146 Expect.listEquals([3, 4, 5, 6], region);
1688 view.setRange(3, 7, [-128, 0, 1, 127]); 1147 view.setRange(3, 7, [-128, 0, 1, 127]);
1689 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9], view); 1148 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9],
1690 Expect.listEquals([0xFF, 0, 1, 2, 128, 0, 1, 127, 7, 8, 9, 0xFF], array); 1149 view);
1150 Expect.listEquals([0xFF, 0, 1, 2, 128, 0, 1, 127, 7, 8, 9, 0xFF],
1151 array);
1691 } 1152 }
1692
1693 static testInt8ListView() { 1153 static testInt8ListView() {
1694 var array = new Uint8List(12); 1154 var array = new Uint8List(12);
1695 testInt8ListViewImpl(array); 1155 testInt8ListViewImpl(array);
1696 } 1156 }
1697 1157
1698 static testUint8ListViewImpl(var array) { 1158 static testUint8ListViewImpl(var array) {
1699 Expect.isTrue(array is List<int>); 1159 Expect.isTrue(array is List<int>);
1700 Expect.equals(12, array.length); 1160 Expect.equals(12, array.length);
1701 Expect.equals(1, array.elementSizeInBytes); 1161 Expect.equals(1, array.elementSizeInBytes);
1702 Expect.equals(12, array.lengthInBytes); 1162 Expect.equals(12, array.lengthInBytes);
1703 for (int i = 0; i < array.length; ++i) { 1163 for (int i = 0; i < array.length; ++i) {
1704 array[i] = -1; 1164 array[i] = -1;
1705 } 1165 }
1706 Expect.throws(() { 1166 Expect.throws(() { new Uint8List.view(array.buffer, -1); },
1707 new Uint8List.view(array.buffer, -1); 1167 (e) { return e is RangeError; });
1708 }, (e) { 1168 Expect.throws(() { new Uint8List.view(array.buffer, 0, -1); },
1709 return e is RangeError; 1169 (e) { return e is RangeError; });
1710 }); 1170 Expect.throws(() { new Uint8List.view(array.buffer,
1711 Expect.throws(() { 1171 array.lengthInBytes + 1); },
1712 new Uint8List.view(array.buffer, 0, -1); 1172 (e) { return e is RangeError; });
1713 }, (e) { 1173 Expect.throws(() { new Uint8List.view(array.buffer,
1714 return e is RangeError; 1174 0, array.length + 1); },
1715 }); 1175 (e) { return e is RangeError; });
1716 Expect.throws(() { 1176 Expect.throws(() { new Uint8List.view(array.buffer,
1717 new Uint8List.view(array.buffer, array.lengthInBytes + 1); 1177 array.length - 1, 2); },
1718 }, (e) { 1178 (e) { return e is RangeError; });
1719 return e is RangeError; 1179 var empty = new Uint8List.view(array.buffer,
1720 }); 1180 array.lengthInBytes);
1721 Expect.throws(() {
1722 new Uint8List.view(array.buffer, 0, array.length + 1);
1723 }, (e) {
1724 return e is RangeError;
1725 });
1726 Expect.throws(() {
1727 new Uint8List.view(array.buffer, array.length - 1, 2);
1728 }, (e) {
1729 return e is RangeError;
1730 });
1731 var empty = new Uint8List.view(array.buffer, array.lengthInBytes);
1732 Expect.isTrue(empty is List<int>); 1181 Expect.isTrue(empty is List<int>);
1733 Expect.isTrue(empty is Uint8List); 1182 Expect.isTrue(empty is Uint8List);
1734 Expect.equals(0, empty.length); 1183 Expect.equals(0, empty.length);
1735 var whole = new Uint8List.view(array.buffer); 1184 var whole = new Uint8List.view(array.buffer);
1736 Expect.isTrue(whole is List<int>); 1185 Expect.isTrue(whole is List<int>);
1737 Expect.isTrue(whole is Uint8List); 1186 Expect.isTrue(whole is Uint8List);
1738 Expect.equals(12, whole.length); 1187 Expect.equals(12, whole.length);
1739 var view = new Uint8List.view(array.buffer, 1, array.length - 2); 1188 var view = new Uint8List.view(array.buffer, 1, array.length - 2);
1740 Expect.isTrue(view is List<int>); 1189 Expect.isTrue(view is List<int>);
1741 Expect.isTrue(view is Uint8List); 1190 Expect.isTrue(view is Uint8List);
1742 Expect.equals(10, view.length); 1191 Expect.equals(10, view.length);
1743 Expect.equals(1, view.elementSizeInBytes); 1192 Expect.equals(1, view.elementSizeInBytes);
1744 Expect.equals(10, view.lengthInBytes); 1193 Expect.equals(10, view.lengthInBytes);
1745 Expect.listEquals( 1194 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1746 [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], view); 1195 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1747 Expect.throws(() { 1196 view);
1748 view[-1] = 0; 1197 Expect.throws(() { view[-1] = 0; },
1749 }, (e) { 1198 (e) { return e is RangeError; });
1750 return e is RangeError; 1199 Expect.throws(() { return view[-1]; },
1751 }); 1200 (e) { return e is RangeError; });
1752 Expect.throws(() { 1201 Expect.throws(() { view[view.length]; },
1753 return view[-1]; 1202 (e) { return e is RangeError; });
1754 }, (e) { 1203 Expect.throws(() { view[view.length] = 0; },
1755 return e is RangeError; 1204 (e) { return e is RangeError; });
1756 }); 1205 Expect.throws(() { view.add(0); },
1757 Expect.throws(() { 1206 (e) { return e is UnsupportedError; });
1758 view[view.length]; 1207 Expect.throws(() { view.addAll([0]); },
1759 }, (e) { 1208 (e) { return e is UnsupportedError; });
1760 return e is RangeError; 1209 Expect.throws(() { view.clear(); },
1761 }); 1210 (e) { return e is UnsupportedError; });
1762 Expect.throws(() { 1211 Expect.throws(() { view.length = 0; },
1763 view[view.length] = 0; 1212 (e) { return e is UnsupportedError; });
1764 }, (e) { 1213 Expect.throws(() { view.removeLast(); },
1765 return e is RangeError; 1214 (e) { return e is UnsupportedError; });
1766 }); 1215 Expect.throws(() { view.removeRange(0, view.length - 1); },
1767 Expect.throws(() { 1216 (e) { return e is UnsupportedError; });
1768 view.add(0);
1769 }, (e) {
1770 return e is UnsupportedError;
1771 });
1772 Expect.throws(() {
1773 view.addAll([0]);
1774 }, (e) {
1775 return e is UnsupportedError;
1776 });
1777 Expect.throws(() {
1778 view.clear();
1779 }, (e) {
1780 return e is UnsupportedError;
1781 });
1782 Expect.throws(() {
1783 view.length = 0;
1784 }, (e) {
1785 return e is UnsupportedError;
1786 });
1787 Expect.throws(() {
1788 view.removeLast();
1789 }, (e) {
1790 return e is UnsupportedError;
1791 });
1792 Expect.throws(() {
1793 view.removeRange(0, view.length - 1);
1794 }, (e) {
1795 return e is UnsupportedError;
1796 });
1797 for (int i = 0; i < view.length; ++i) { 1217 for (int i = 0; i < view.length; ++i) {
1798 view[i] = 1 + i; 1218 view[i] = 1 + i;
1799 } 1219 }
1800 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1220 Expect.listEquals([1, 2, 3, 4, 5,
1801 Expect.listEquals([-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1], array); 1221 6, 7, 8, 9, 10],
1222 view);
1223 Expect.listEquals([-1, 1, 2, 3, 4, 5,
1224 6, 7, 8, 9, 10, -1],
1225 array);
1802 for (int i = 0; i < view.length; ++i) { 1226 for (int i = 0; i < view.length; ++i) {
1803 view[i] = 0x100 + i; 1227 view[i] = 0x100 + i;
1804 } 1228 }
1805 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1229 Expect.listEquals([0, 1, 2, 3, 4,
1806 Expect.listEquals([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1], array); 1230 5, 6, 7, 8, 9],
1231 view);
1232 Expect.listEquals([-1, 0, 1, 2, 3, 4,
1233 5, 6, 7, 8, 9, -1],
1234 array);
1807 for (int i = 0; i < view.length; ++i) { 1235 for (int i = 0; i < view.length; ++i) {
1808 view[i] = 0xFF - i; 1236 view[i] = 0xFF - i;
1809 } 1237 }
1810 Expect.listEquals( 1238 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB,
1811 [0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6], view); 1239 0xFA, 0xF9, 0xF8, 0xF7, 0xF6],
1812 Expect.listEquals([-1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1], array); 1240 view);
1241 Expect.listEquals([-1, -1, -2, -3, -4, -5,
1242 -6, -7, -8, -9, -10, -1],
1243 array);
1813 for (int i = 0; i < view.length; ++i) { 1244 for (int i = 0; i < view.length; ++i) {
1814 view[i] = i; 1245 view[i] = i;
1815 } 1246 }
1816 var copy = view.sublist(0, view.length); 1247 var copy = view.sublist(0, view.length);
1817 Expect.isFalse(identical(copy, view)); 1248 Expect.isFalse(identical(copy, view));
1818 Expect.isTrue(copy is Uint8List); 1249 Expect.isTrue(copy is Uint8List);
1819 Expect.equals(10, copy.length); 1250 Expect.equals(10, copy.length);
1820 Expect.listEquals(view, copy); 1251 Expect.listEquals(view, copy);
1821 var region = view.sublist(3, view.length - 3); 1252 var region = view.sublist(3, view.length - 3);
1822 Expect.isTrue(copy is Uint8List); 1253 Expect.isTrue(copy is Uint8List);
1823 Expect.equals(4, region.length); 1254 Expect.equals(4, region.length);
1824 Expect.listEquals([3, 4, 5, 6], region); 1255 Expect.listEquals([3, 4, 5, 6], region);
1825 view.setRange(3, 7, [257, 0, 1, 255]); 1256 view.setRange(3, 7, [257, 0, 1, 255]);
1826 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9], view); 1257 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9],
1258 view);
1827 } 1259 }
1828 1260
1829 static testUint8ListView() { 1261 static testUint8ListView() {
1830 var array = new Int8List(12); 1262 var array = new Int8List(12);
1831 testUint8ListViewImpl(array); 1263 testUint8ListViewImpl(array);
1832 } 1264 }
1833 1265
1834 static testInt16ListViewImpl(var array) { 1266 static testInt16ListViewImpl(var array) {
1835 Expect.equals(24, array.length); 1267 Expect.equals(24, array.length);
1836 Expect.equals(1, array.elementSizeInBytes); 1268 Expect.equals(1, array.elementSizeInBytes);
1837 Expect.equals(24, array.lengthInBytes); 1269 Expect.equals(24, array.lengthInBytes);
1838 for (int i = 0; i < array.length; ++i) { 1270 for (int i = 0; i < array.length; ++i) {
1839 array[i] = 0xFF; 1271 array[i] = 0xFF;
1840 } 1272 }
1841 Expect.throws(() { 1273 Expect.throws(() { new Int16List.view(array.buffer, -1); },
1842 new Int16List.view(array.buffer, -1); 1274 (e) { return e is RangeError; });
1843 }, (e) { 1275 Expect.throws(() { new Int16List.view(array.buffer, 0, -1); },
1844 return e is RangeError; 1276 (e) { return e is RangeError; });
1845 }); 1277 Expect.throws(() { new Int16List.view(array.buffer,
1846 Expect.throws(() { 1278 array.lengthInBytes + 1); },
1847 new Int16List.view(array.buffer, 0, -1); 1279 (e) { return e is RangeError; });
1848 }, (e) { 1280 Expect.throws(() { new Int16List.view(array.buffer,
1849 return e is RangeError; 1281 0, array.length + 1); },
1850 }); 1282 (e) { return e is RangeError; });
1851 Expect.throws(() { 1283 Expect.throws(() { new Int16List.view(array.buffer,
1852 new Int16List.view(array.buffer, array.lengthInBytes + 1); 1284 array.length - 1, 2); },
1853 }, (e) { 1285 (e) { return e is RangeError; });
1854 return e is RangeError; 1286 var empty = new Int16List.view(array.buffer,
1855 }); 1287 array.lengthInBytes);
1856 Expect.throws(() {
1857 new Int16List.view(array.buffer, 0, array.length + 1);
1858 }, (e) {
1859 return e is RangeError;
1860 });
1861 Expect.throws(() {
1862 new Int16List.view(array.buffer, array.length - 1, 2);
1863 }, (e) {
1864 return e is RangeError;
1865 });
1866 var empty = new Int16List.view(array.buffer, array.lengthInBytes);
1867 Expect.isTrue(empty is List<int>); 1288 Expect.isTrue(empty is List<int>);
1868 Expect.isTrue(empty is Int16List); 1289 Expect.isTrue(empty is Int16List);
1869 Expect.equals(0, empty.length); 1290 Expect.equals(0, empty.length);
1870 var whole = new Int16List.view(array.buffer); 1291 var whole = new Int16List.view(array.buffer);
1871 Expect.isTrue(whole is List<int>); 1292 Expect.isTrue(whole is List<int>);
1872 Expect.isTrue(whole is Int16List); 1293 Expect.isTrue(whole is Int16List);
1873 Expect.equals(12, whole.length); 1294 Expect.equals(12, whole.length);
1874 var view = new Int16List.view(array.buffer, 2, 10); 1295 var view = new Int16List.view(array.buffer, 2, 10);
1875 Expect.isTrue(view is List<int>); 1296 Expect.isTrue(view is List<int>);
1876 Expect.isTrue(view is Int16List); 1297 Expect.isTrue(view is Int16List);
1877 Expect.equals(10, view.length); 1298 Expect.equals(10, view.length);
1878 Expect.equals(2, view.elementSizeInBytes); 1299 Expect.equals(2, view.elementSizeInBytes);
1879 Expect.equals(20, view.lengthInBytes); 1300 Expect.equals(20, view.lengthInBytes);
1880 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], view); 1301 Expect.listEquals([-1, -1, -1, -1, -1,
1881 Expect.throws(() { 1302 -1, -1, -1, -1, -1],
1882 view[-1] = 0; 1303 view);
1883 }, (e) { 1304 Expect.throws(() { view[-1] = 0; },
1884 return e is RangeError; 1305 (e) { return e is RangeError; });
1885 }); 1306 Expect.throws(() { return view[-1]; },
1886 Expect.throws(() { 1307 (e) { return e is RangeError; });
1887 return view[-1]; 1308 Expect.throws(() { view[view.length]; },
1888 }, (e) { 1309 (e) { return e is RangeError; });
1889 return e is RangeError; 1310 Expect.throws(() { view[10] = 0; },
1890 }); 1311 (e) { return e is RangeError; });
1891 Expect.throws(() { 1312 Expect.throws(() { view.add(0); },
1892 view[view.length]; 1313 (e) { return e is UnsupportedError; });
1893 }, (e) { 1314 Expect.throws(() { view.addAll([0]); },
1894 return e is RangeError; 1315 (e) { return e is UnsupportedError; });
1895 }); 1316 Expect.throws(() { view.clear(); },
1896 Expect.throws(() { 1317 (e) { return e is UnsupportedError; });
1897 view[10] = 0; 1318 Expect.throws(() { view.length = 0; },
1898 }, (e) { 1319 (e) { return e is UnsupportedError; });
1899 return e is RangeError; 1320 Expect.throws(() { view.removeLast(); },
1900 }); 1321 (e) { return e is UnsupportedError; });
1901 Expect.throws(() { 1322 Expect.throws(() { view.removeRange(0, view.length - 1); },
1902 view.add(0); 1323 (e) { return e is UnsupportedError; });
1903 }, (e) {
1904 return e is UnsupportedError;
1905 });
1906 Expect.throws(() {
1907 view.addAll([0]);
1908 }, (e) {
1909 return e is UnsupportedError;
1910 });
1911 Expect.throws(() {
1912 view.clear();
1913 }, (e) {
1914 return e is UnsupportedError;
1915 });
1916 Expect.throws(() {
1917 view.length = 0;
1918 }, (e) {
1919 return e is UnsupportedError;
1920 });
1921 Expect.throws(() {
1922 view.removeLast();
1923 }, (e) {
1924 return e is UnsupportedError;
1925 });
1926 Expect.throws(() {
1927 view.removeRange(0, view.length - 1);
1928 }, (e) {
1929 return e is UnsupportedError;
1930 });
1931 for (int i = 0; i < view.length; ++i) { 1324 for (int i = 0; i < view.length; ++i) {
1932 view[i] = 1 + i; 1325 view[i] = 1 + i;
1933 } 1326 }
1934 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1327 Expect.listEquals([1, 2, 3, 4, 5,
1935 Expect.listEquals([ 1328 6, 7, 8, 9, 10],
1936 0xFF, 1329 view);
1937 0xFF, 1330 Expect.listEquals([0xFF, 0xFF, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
1938 0x01, 1331 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00,
1939 0x00, 1332 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0xFF, 0xFF],
1940 0x02, 1333 array);
1941 0x00,
1942 0x03,
1943 0x00,
1944 0x04,
1945 0x00,
1946 0x05,
1947 0x00,
1948 0x06,
1949 0x00,
1950 0x07,
1951 0x00,
1952 0x08,
1953 0x00,
1954 0x09,
1955 0x00,
1956 0x0A,
1957 0x00,
1958 0xFF,
1959 0xFF
1960 ], array);
1961 for (int i = 0; i < view.length; ++i) { 1334 for (int i = 0; i < view.length; ++i) {
1962 view[i] = 0x10000 + i; 1335 view[i] = 0x10000 + i;
1963 } 1336 }
1964 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1337 Expect.listEquals([0, 1, 2, 3, 4,
1965 Expect.listEquals([ 1338 5, 6, 7, 8, 9],
1966 0xFF, 1339 view);
1967 0xFF, 1340 Expect.listEquals([0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
1968 0x00, 1341 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00,
1969 0x00, 1342 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0xFF, 0xFF],
1970 0x01, 1343 array);
1971 0x00,
1972 0x02,
1973 0x00,
1974 0x03,
1975 0x00,
1976 0x04,
1977 0x00,
1978 0x05,
1979 0x00,
1980 0x06,
1981 0x00,
1982 0x07,
1983 0x00,
1984 0x08,
1985 0x00,
1986 0x09,
1987 0x00,
1988 0xFF,
1989 0xFF
1990 ], array);
1991 for (int i = 0; i < view.length; ++i) { 1344 for (int i = 0; i < view.length; ++i) {
1992 view[i] = -10 + i; 1345 view[i] = -10 + i;
1993 } 1346 }
1994 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], view); 1347 Expect.listEquals([-10, -9, -8, -7, -6,
1995 Expect.listEquals([ 1348 -5, -4, -3, -2, -1],
1996 0xFF, 1349 view);
1997 0xFF, 1350 Expect.listEquals([0xFF, 0xFF, 0xF6, 0xFF, 0xF7, 0xFF, 0xF8, 0xFF,
1998 0xF6, 1351 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF,
1999 0xFF, 1352 0xFD, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
2000 0xF7, 1353 array);
2001 0xFF,
2002 0xF8,
2003 0xFF,
2004 0xF9,
2005 0xFF,
2006 0xFA,
2007 0xFF,
2008 0xFB,
2009 0xFF,
2010 0xFC,
2011 0xFF,
2012 0xFD,
2013 0xFF,
2014 0xFE,
2015 0xFF,
2016 0xFF,
2017 0xFF,
2018 0xFF,
2019 0xFF
2020 ], array);
2021 for (int i = 0; i < view.length; ++i) { 1354 for (int i = 0; i < view.length; ++i) {
2022 view[i] = 0x7FFF - i; 1355 view[i] = 0x7FFF - i;
2023 } 1356 }
2024 Expect.listEquals([ 1357 Expect.listEquals([0x7FFF, 0x7FFE, 0x7FFD, 0x7FFC, 0x7FFB,
2025 0x7FFF, 1358 0x7FFA, 0x7FF9, 0x7FF8, 0x7FF7, 0x7FF6],
2026 0x7FFE, 1359 view);
2027 0x7FFD, 1360 Expect.listEquals([0xFF, 0xFF, 0xFF, 0x7F, 0xFE, 0x7F, 0xFD, 0x7F,
2028 0x7FFC, 1361 0xFC, 0x7F, 0xFB, 0x7F, 0xFA, 0x7F, 0xF9, 0x7F,
2029 0x7FFB, 1362 0xF8, 0x7F, 0xF7, 0x7F, 0xF6, 0x7F, 0xFF, 0xFF],
2030 0x7FFA, 1363 array);
2031 0x7FF9,
2032 0x7FF8,
2033 0x7FF7,
2034 0x7FF6
2035 ], view);
2036 Expect.listEquals([
2037 0xFF,
2038 0xFF,
2039 0xFF,
2040 0x7F,
2041 0xFE,
2042 0x7F,
2043 0xFD,
2044 0x7F,
2045 0xFC,
2046 0x7F,
2047 0xFB,
2048 0x7F,
2049 0xFA,
2050 0x7F,
2051 0xF9,
2052 0x7F,
2053 0xF8,
2054 0x7F,
2055 0xF7,
2056 0x7F,
2057 0xF6,
2058 0x7F,
2059 0xFF,
2060 0xFF
2061 ], array);
2062 for (int i = 0; i < view.length; ++i) { 1364 for (int i = 0; i < view.length; ++i) {
2063 view[i] = -0x8000 + i; 1365 view[i] = -0x8000 + i;
2064 } 1366 }
2065 Expect.listEquals([ 1367 Expect.listEquals([-0x8000, -0x7FFF, -0x7FFE, -0x7FFD, -0x7FFC,
2066 -0x8000, 1368 -0x7FFB, -0x7FFA, -0x7FF9, -0x7FF8, -0x7FF7],
2067 -0x7FFF, 1369 view);
2068 -0x7FFE, 1370 Expect.listEquals([0xFF, 0xFF, 0x00, 0x80, 0x01, 0x80, 0x02, 0x80,
2069 -0x7FFD, 1371 0x03, 0x80, 0x04, 0x80, 0x05, 0x80, 0x06, 0x80,
2070 -0x7FFC, 1372 0x07, 0x80, 0x08, 0x80, 0x09, 0x80, 0xFF, 0xFF],
2071 -0x7FFB, 1373 array);
2072 -0x7FFA,
2073 -0x7FF9,
2074 -0x7FF8,
2075 -0x7FF7
2076 ], view);
2077 Expect.listEquals([
2078 0xFF,
2079 0xFF,
2080 0x00,
2081 0x80,
2082 0x01,
2083 0x80,
2084 0x02,
2085 0x80,
2086 0x03,
2087 0x80,
2088 0x04,
2089 0x80,
2090 0x05,
2091 0x80,
2092 0x06,
2093 0x80,
2094 0x07,
2095 0x80,
2096 0x08,
2097 0x80,
2098 0x09,
2099 0x80,
2100 0xFF,
2101 0xFF
2102 ], array);
2103 for (int i = 0; i < view.length; ++i) { 1374 for (int i = 0; i < view.length; ++i) {
2104 view[i] = i; 1375 view[i] = i;
2105 } 1376 }
2106 var copy = view.sublist(0, view.length); 1377 var copy = view.sublist(0, view.length);
2107 Expect.isFalse(identical(copy, view)); 1378 Expect.isFalse(identical(copy, view));
2108 Expect.isTrue(copy is Int16List); 1379 Expect.isTrue(copy is Int16List);
2109 Expect.equals(10, copy.length); 1380 Expect.equals(10, copy.length);
2110 Expect.listEquals(view, copy); 1381 Expect.listEquals(view, copy);
2111 var region = view.sublist(3, view.length - 3); 1382 var region = view.sublist(3, view.length - 3);
2112 Expect.isTrue(copy is Int16List); 1383 Expect.isTrue(copy is Int16List);
2113 Expect.equals(4, region.length); 1384 Expect.equals(4, region.length);
2114 Expect.listEquals([3, 4, 5, 6], region); 1385 Expect.listEquals([3, 4, 5, 6], region);
2115 view.setRange(3, 7, [-32768, 0, 1, 32767]); 1386 view.setRange(3, 7, [-32768, 0, 1, 32767]);
2116 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9], view); 1387 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9],
2117 Expect.listEquals([ 1388 view);
2118 0xFF, 1389 Expect.listEquals([0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
2119 0xFF, 1390 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0xFF, 0x7F,
2120 0x00, 1391 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0xFF, 0xFF],
2121 0x00, 1392 array);
2122 0x01,
2123 0x00,
2124 0x02,
2125 0x00,
2126 0x00,
2127 0x80,
2128 0x00,
2129 0x00,
2130 0x01,
2131 0x00,
2132 0xFF,
2133 0x7F,
2134 0x07,
2135 0x00,
2136 0x08,
2137 0x00,
2138 0x09,
2139 0x00,
2140 0xFF,
2141 0xFF
2142 ], array);
2143 } 1393 }
2144 1394
2145 static testInt16ListView() { 1395 static testInt16ListView() {
2146 var array = new Uint8List(24); 1396 var array = new Uint8List(24);
2147 testInt16ListViewImpl(array); 1397 testInt16ListViewImpl(array);
2148 } 1398 }
2149 1399
2150 static testUint16ListViewImpl(var array) { 1400 static testUint16ListViewImpl(var array) {
2151 Expect.isTrue(array is List<int>); 1401 Expect.isTrue(array is List<int>);
2152 Expect.equals(24, array.length); 1402 Expect.equals(24, array.length);
2153 Expect.equals(1, array.elementSizeInBytes); 1403 Expect.equals(1, array.elementSizeInBytes);
2154 Expect.equals(24, array.lengthInBytes); 1404 Expect.equals(24, array.lengthInBytes);
2155 for (int i = 0; i < array.length; ++i) { 1405 for (int i = 0; i < array.length; ++i) {
2156 array[i] = -1; 1406 array[i] = -1;
2157 } 1407 }
2158 Expect.throws(() { 1408 Expect.throws(() { new Uint16List.view(array.buffer, -1); },
2159 new Uint16List.view(array.buffer, -1); 1409 (e) { return e is RangeError; });
2160 }, (e) { 1410 Expect.throws(() { new Uint16List.view(array.buffer, 0, -1); },
2161 return e is RangeError; 1411 (e) { return e is RangeError; });
2162 }); 1412 Expect.throws(() { new Uint16List.view(array.buffer,
2163 Expect.throws(() { 1413 array.lengthInBytes + 1); },
2164 new Uint16List.view(array.buffer, 0, -1); 1414 (e) { return e is RangeError; });
2165 }, (e) { 1415 Expect.throws(() { new Uint16List.view(array.buffer,
2166 return e is RangeError; 1416 0, array.length + 1); },
2167 }); 1417 (e) { return e is RangeError; });
2168 Expect.throws(() { 1418 Expect.throws(() { new Uint16List.view(array.buffer,
2169 new Uint16List.view(array.buffer, array.lengthInBytes + 1); 1419 array.length - 1, 2); },
2170 }, (e) { 1420 (e) { return e is RangeError; });
2171 return e is RangeError; 1421 var empty = new Uint16List.view(array.buffer,
2172 }); 1422 array.lengthInBytes);
2173 Expect.throws(() {
2174 new Uint16List.view(array.buffer, 0, array.length + 1);
2175 }, (e) {
2176 return e is RangeError;
2177 });
2178 Expect.throws(() {
2179 new Uint16List.view(array.buffer, array.length - 1, 2);
2180 }, (e) {
2181 return e is RangeError;
2182 });
2183 var empty = new Uint16List.view(array.buffer, array.lengthInBytes);
2184 Expect.isTrue(empty is List<int>); 1423 Expect.isTrue(empty is List<int>);
2185 Expect.isTrue(empty is Uint16List); 1424 Expect.isTrue(empty is Uint16List);
2186 Expect.equals(0, empty.length); 1425 Expect.equals(0, empty.length);
2187 var whole = new Uint16List.view(array.buffer); 1426 var whole = new Uint16List.view(array.buffer);
2188 Expect.isTrue(whole is List<int>); 1427 Expect.isTrue(whole is List<int>);
2189 Expect.isTrue(whole is Uint16List); 1428 Expect.isTrue(whole is Uint16List);
2190 Expect.equals(12, whole.length); 1429 Expect.equals(12, whole.length);
2191 var view = new Uint16List.view(array.buffer, 2, 10); 1430 var view = new Uint16List.view(array.buffer, 2, 10);
2192 Expect.isTrue(view is List<int>); 1431 Expect.isTrue(view is List<int>);
2193 Expect.isTrue(view is Uint16List); 1432 Expect.isTrue(view is Uint16List);
2194 Expect.equals(10, view.length); 1433 Expect.equals(10, view.length);
2195 Expect.equals(2, view.elementSizeInBytes); 1434 Expect.equals(2, view.elementSizeInBytes);
2196 Expect.equals(20, view.lengthInBytes); 1435 Expect.equals(20, view.lengthInBytes);
2197 Expect.listEquals([ 1436 Expect.listEquals([0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
2198 0xFFFF, 1437 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF],
2199 0xFFFF, 1438 view);
2200 0xFFFF, 1439 Expect.throws(() { view[-1] = 0; },
2201 0xFFFF, 1440 (e) { return e is RangeError; });
2202 0xFFFF, 1441 Expect.throws(() { return view[-1]; },
2203 0xFFFF, 1442 (e) { return e is RangeError; });
2204 0xFFFF, 1443 Expect.throws(() { view[view.length]; },
2205 0xFFFF, 1444 (e) { return e is RangeError; });
2206 0xFFFF, 1445 Expect.throws(() { view[view.length] = 0; },
2207 0xFFFF 1446 (e) { return e is RangeError; });
2208 ], view); 1447 Expect.throws(() { view.add(0); },
2209 Expect.throws(() { 1448 (e) { return e is UnsupportedError; });
2210 view[-1] = 0; 1449 Expect.throws(() { view.addAll([0]); },
2211 }, (e) { 1450 (e) { return e is UnsupportedError; });
2212 return e is RangeError; 1451 Expect.throws(() { view.clear(); },
2213 }); 1452 (e) { return e is UnsupportedError; });
2214 Expect.throws(() { 1453 Expect.throws(() { view.length = 0; },
2215 return view[-1]; 1454 (e) { return e is UnsupportedError; });
2216 }, (e) { 1455 Expect.throws(() { view.removeLast(); },
2217 return e is RangeError; 1456 (e) { return e is UnsupportedError; });
2218 }); 1457 Expect.throws(() { view.removeRange(0, view.length - 1); },
2219 Expect.throws(() { 1458 (e) { return e is UnsupportedError; });
2220 view[view.length];
2221 }, (e) {
2222 return e is RangeError;
2223 });
2224 Expect.throws(() {
2225 view[view.length] = 0;
2226 }, (e) {
2227 return e is RangeError;
2228 });
2229 Expect.throws(() {
2230 view.add(0);
2231 }, (e) {
2232 return e is UnsupportedError;
2233 });
2234 Expect.throws(() {
2235 view.addAll([0]);
2236 }, (e) {
2237 return e is UnsupportedError;
2238 });
2239 Expect.throws(() {
2240 view.clear();
2241 }, (e) {
2242 return e is UnsupportedError;
2243 });
2244 Expect.throws(() {
2245 view.length = 0;
2246 }, (e) {
2247 return e is UnsupportedError;
2248 });
2249 Expect.throws(() {
2250 view.removeLast();
2251 }, (e) {
2252 return e is UnsupportedError;
2253 });
2254 Expect.throws(() {
2255 view.removeRange(0, view.length - 1);
2256 }, (e) {
2257 return e is UnsupportedError;
2258 });
2259 for (int i = 0; i < view.length; ++i) { 1459 for (int i = 0; i < view.length; ++i) {
2260 view[i] = 1 + i; 1460 view[i] = 1 + i;
2261 } 1461 }
2262 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1462 Expect.listEquals([1, 2, 3, 4, 5,
2263 Expect.listEquals([ 1463 6, 7, 8, 9, 10],
2264 -1, 1464 view);
2265 -1, 1465 Expect.listEquals([-1, -1, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0,
2266 1, 1466 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, -1, -1],
2267 0, 1467 array);
2268 2,
2269 0,
2270 3,
2271 0,
2272 4,
2273 0,
2274 5,
2275 0,
2276 6,
2277 0,
2278 7,
2279 0,
2280 8,
2281 0,
2282 9,
2283 0,
2284 10,
2285 0,
2286 -1,
2287 -1
2288 ], array);
2289 for (int i = 0; i < view.length; ++i) { 1468 for (int i = 0; i < view.length; ++i) {
2290 view[i] = 0x10000 + i; 1469 view[i] = 0x10000 + i;
2291 } 1470 }
2292 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1471 Expect.listEquals([0, 1, 2, 3, 4,
2293 Expect.listEquals([ 1472 5, 6, 7, 8, 9],
2294 -1, 1473 view);
2295 -1, 1474 Expect.listEquals([-1, -1, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0,
2296 0, 1475 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, -1, -1],
2297 0, 1476 array);
2298 1,
2299 0,
2300 2,
2301 0,
2302 3,
2303 0,
2304 4,
2305 0,
2306 5,
2307 0,
2308 6,
2309 0,
2310 7,
2311 0,
2312 8,
2313 0,
2314 9,
2315 0,
2316 -1,
2317 -1
2318 ], array);
2319 for (int i = 0; i < view.length; ++i) { 1477 for (int i = 0; i < view.length; ++i) {
2320 view[i] = 0xFFFF - i; 1478 view[i] = 0xFFFF - i;
2321 } 1479 }
2322 Expect.listEquals([ 1480 Expect.listEquals([0xFFFF, 0xFFFE, 0xFFFD, 0xFFFC, 0xFFFB,
2323 0xFFFF, 1481 0xFFFA, 0xFFF9, 0xFFF8, 0xFFF7, 0xFFF6],
2324 0xFFFE, 1482 view);
2325 0xFFFD, 1483 Expect.listEquals([-1, -1, -1, -1, -2, -1, -3, -1,
2326 0xFFFC, 1484 -4, -1, -5, -1, -6, -1, -7, -1,
2327 0xFFFB, 1485 -8, -1, -9, -1, -10, -1, -1, -1],
2328 0xFFFA, 1486 array);
2329 0xFFF9,
2330 0xFFF8,
2331 0xFFF7,
2332 0xFFF6
2333 ], view);
2334 Expect.listEquals([
2335 -1,
2336 -1,
2337 -1,
2338 -1,
2339 -2,
2340 -1,
2341 -3,
2342 -1,
2343 -4,
2344 -1,
2345 -5,
2346 -1,
2347 -6,
2348 -1,
2349 -7,
2350 -1,
2351 -8,
2352 -1,
2353 -9,
2354 -1,
2355 -10,
2356 -1,
2357 -1,
2358 -1
2359 ], array);
2360 for (int i = 0; i < view.length; ++i) { 1487 for (int i = 0; i < view.length; ++i) {
2361 view[i] = i; 1488 view[i] = i;
2362 } 1489 }
2363 var copy = view.sublist(0, view.length); 1490 var copy = view.sublist(0, view.length);
2364 Expect.isFalse(identical(copy, view)); 1491 Expect.isFalse(identical(copy, view));
2365 Expect.isTrue(copy is Uint16List); 1492 Expect.isTrue(copy is Uint16List);
2366 Expect.equals(10, copy.length); 1493 Expect.equals(10, copy.length);
2367 Expect.listEquals(view, copy); 1494 Expect.listEquals(view, copy);
2368 var region = view.sublist(3, view.length - 3); 1495 var region = view.sublist(3, view.length - 3);
2369 Expect.isTrue(copy is Uint16List); 1496 Expect.isTrue(copy is Uint16List);
2370 Expect.equals(4, region.length); 1497 Expect.equals(4, region.length);
2371 Expect.listEquals([3, 4, 5, 6], region); 1498 Expect.listEquals([3, 4, 5, 6], region);
2372 view.setRange(3, 7, [0x10001, 0, 1, 0xFFFF]); 1499 view.setRange(3, 7, [0x10001, 0, 1, 0xFFFF]);
2373 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9], view); 1500 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9],
2374 Expect.listEquals([ 1501 view);
2375 -1, 1502 Expect.listEquals([-1, -1, 0, 0, 1, 0, 2, 0,
2376 -1, 1503 1, 0, 0, 0, 1, 0, -1, -1,
2377 0, 1504 7, 0, 8, 0, 9, 0, -1, -1],
2378 0, 1505 array);
2379 1,
2380 0,
2381 2,
2382 0,
2383 1,
2384 0,
2385 0,
2386 0,
2387 1,
2388 0,
2389 -1,
2390 -1,
2391 7,
2392 0,
2393 8,
2394 0,
2395 9,
2396 0,
2397 -1,
2398 -1
2399 ], array);
2400 } 1506 }
2401 1507
2402 static testUint16ListView() { 1508 static testUint16ListView() {
2403 var array = new Int8List(24); 1509 var array = new Int8List(24);
2404 testUint16ListViewImpl(array); 1510 testUint16ListViewImpl(array);
2405 } 1511 }
2406 1512
2407 static testInt32ListView() { 1513 static testInt32ListView() {
2408 var array = new Uint8List(48); 1514 var array = new Uint8List(48);
2409 Expect.equals(48, array.length); 1515 Expect.equals(48, array.length);
2410 Expect.equals(1, array.elementSizeInBytes); 1516 Expect.equals(1, array.elementSizeInBytes);
2411 Expect.equals(48, array.lengthInBytes); 1517 Expect.equals(48, array.lengthInBytes);
2412 for (int i = 0; i < array.length; ++i) { 1518 for (int i = 0; i < array.length; ++i) {
2413 array[i] = 0xFF; 1519 array[i] = 0xFF;
2414 } 1520 }
2415 Expect.throws(() { 1521 Expect.throws(() { new Int32List.view(array.buffer, -1); },
2416 new Int32List.view(array.buffer, -1); 1522 (e) { return e is RangeError; });
2417 }, (e) { 1523 Expect.throws(() { new Int32List.view(array.buffer, 0, -1); },
2418 return e is RangeError; 1524 (e) { return e is RangeError; });
2419 }); 1525 Expect.throws(() { new Int32List.view(array.buffer,
2420 Expect.throws(() { 1526 array.lengthInBytes + 1); },
2421 new Int32List.view(array.buffer, 0, -1); 1527 (e) { return e is RangeError; });
2422 }, (e) { 1528 Expect.throws(() { new Int32List.view(array.buffer,
2423 return e is RangeError; 1529 0, array.length + 1); },
2424 }); 1530 (e) { return e is RangeError; });
2425 Expect.throws(() { 1531 Expect.throws(() { new Int32List.view(array.buffer,
2426 new Int32List.view(array.buffer, array.lengthInBytes + 1); 1532 array.length - 1, 2); },
2427 }, (e) { 1533 (e) { return e is RangeError; });
2428 return e is RangeError; 1534 var empty = new Int32List.view(array.buffer,
2429 }); 1535 array.lengthInBytes);
2430 Expect.throws(() {
2431 new Int32List.view(array.buffer, 0, array.length + 1);
2432 }, (e) {
2433 return e is RangeError;
2434 });
2435 Expect.throws(() {
2436 new Int32List.view(array.buffer, array.length - 1, 2);
2437 }, (e) {
2438 return e is RangeError;
2439 });
2440 var empty = new Int32List.view(array.buffer, array.lengthInBytes);
2441 Expect.isTrue(empty is List<int>); 1536 Expect.isTrue(empty is List<int>);
2442 Expect.isTrue(empty is Int32List); 1537 Expect.isTrue(empty is Int32List);
2443 Expect.equals(0, empty.length); 1538 Expect.equals(0, empty.length);
2444 var whole = new Int32List.view(array.buffer); 1539 var whole = new Int32List.view(array.buffer);
2445 Expect.isTrue(whole is List<int>); 1540 Expect.isTrue(whole is List<int>);
2446 Expect.isTrue(whole is Int32List); 1541 Expect.isTrue(whole is Int32List);
2447 Expect.equals(12, whole.length); 1542 Expect.equals(12, whole.length);
2448 var view = new Int32List.view(array.buffer, 4, 10); 1543 var view = new Int32List.view(array.buffer, 4, 10);
2449 Expect.isTrue(view is List<int>); 1544 Expect.isTrue(view is List<int>);
2450 Expect.isTrue(view is Int32List); 1545 Expect.isTrue(view is Int32List);
2451 Expect.equals(10, view.length); 1546 Expect.equals(10, view.length);
2452 Expect.equals(4, view.elementSizeInBytes); 1547 Expect.equals(4, view.elementSizeInBytes);
2453 Expect.equals(40, view.lengthInBytes); 1548 Expect.equals(40, view.lengthInBytes);
2454 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], view); 1549 Expect.listEquals([-1, -1, -1, -1, -1,
2455 Expect.throws(() { 1550 -1, -1, -1, -1, -1],
2456 view[-1] = 0; 1551 view);
2457 }, (e) { 1552 Expect.throws(() { view[-1] = 0; },
2458 return e is RangeError; 1553 (e) { return e is RangeError; });
2459 }); 1554 Expect.throws(() { return view[-1]; },
2460 Expect.throws(() { 1555 (e) { return e is RangeError; });
2461 return view[-1]; 1556 Expect.throws(() { view[view.length]; },
2462 }, (e) { 1557 (e) { return e is RangeError; });
2463 return e is RangeError; 1558 Expect.throws(() { view[10] = 0; },
2464 }); 1559 (e) { return e is RangeError; });
2465 Expect.throws(() { 1560 Expect.throws(() { view.add(0); },
2466 view[view.length]; 1561 (e) { return e is UnsupportedError; });
2467 }, (e) { 1562 Expect.throws(() { view.addAll([0]); },
2468 return e is RangeError; 1563 (e) { return e is UnsupportedError; });
2469 }); 1564 Expect.throws(() { view.clear(); },
2470 Expect.throws(() { 1565 (e) { return e is UnsupportedError; });
2471 view[10] = 0; 1566 Expect.throws(() { view.length = 0; },
2472 }, (e) { 1567 (e) { return e is UnsupportedError; });
2473 return e is RangeError; 1568 Expect.throws(() { view.removeLast(); },
2474 }); 1569 (e) { return e is UnsupportedError; });
2475 Expect.throws(() { 1570 Expect.throws(() { view.removeRange(0, view.length - 1); },
2476 view.add(0); 1571 (e) { return e is UnsupportedError; });
2477 }, (e) {
2478 return e is UnsupportedError;
2479 });
2480 Expect.throws(() {
2481 view.addAll([0]);
2482 }, (e) {
2483 return e is UnsupportedError;
2484 });
2485 Expect.throws(() {
2486 view.clear();
2487 }, (e) {
2488 return e is UnsupportedError;
2489 });
2490 Expect.throws(() {
2491 view.length = 0;
2492 }, (e) {
2493 return e is UnsupportedError;
2494 });
2495 Expect.throws(() {
2496 view.removeLast();
2497 }, (e) {
2498 return e is UnsupportedError;
2499 });
2500 Expect.throws(() {
2501 view.removeRange(0, view.length - 1);
2502 }, (e) {
2503 return e is UnsupportedError;
2504 });
2505 for (int i = 0; i < view.length; ++i) { 1572 for (int i = 0; i < view.length; ++i) {
2506 view[i] = 1 + i; 1573 view[i] = 1 + i;
2507 } 1574 }
2508 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1575 Expect.listEquals([1, 2, 3, 4, 5,
2509 Expect.listEquals([ 1576 6, 7, 8, 9, 10],
2510 0xFF, 1577 view);
2511 0xFF, 1578 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00,
2512 0xFF, 1579 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
2513 0xFF, 1580 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
2514 0x01, 1581 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
2515 0x00, 1582 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
2516 0x00, 1583 0x0A, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
2517 0x00, 1584 array);
2518 0x02,
2519 0x00,
2520 0x00,
2521 0x00,
2522 0x03,
2523 0x00,
2524 0x00,
2525 0x00,
2526 0x04,
2527 0x00,
2528 0x00,
2529 0x00,
2530 0x05,
2531 0x00,
2532 0x00,
2533 0x00,
2534 0x06,
2535 0x00,
2536 0x00,
2537 0x00,
2538 0x07,
2539 0x00,
2540 0x00,
2541 0x00,
2542 0x08,
2543 0x00,
2544 0x00,
2545 0x00,
2546 0x09,
2547 0x00,
2548 0x00,
2549 0x00,
2550 0x0A,
2551 0x00,
2552 0x00,
2553 0x00,
2554 0xFF,
2555 0xFF,
2556 0xFF,
2557 0xFF
2558 ], array);
2559 for (int i = 0; i < view.length; ++i) { 1585 for (int i = 0; i < view.length; ++i) {
2560 view[i] = 0x100000000 + i; 1586 view[i] = 0x100000000 + i;
2561 } 1587 }
2562 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1588 Expect.listEquals([0, 1, 2, 3, 4,
2563 Expect.listEquals([ 1589 5, 6, 7, 8, 9],
2564 0xFF, 1590 view);
2565 0xFF, 1591 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
2566 0xFF, 1592 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
2567 0xFF, 1593 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
2568 0x00, 1594 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
2569 0x00, 1595 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
2570 0x00, 1596 0x09, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
2571 0x00, 1597 array);
2572 0x01,
2573 0x00,
2574 0x00,
2575 0x00,
2576 0x02,
2577 0x00,
2578 0x00,
2579 0x00,
2580 0x03,
2581 0x00,
2582 0x00,
2583 0x00,
2584 0x04,
2585 0x00,
2586 0x00,
2587 0x00,
2588 0x05,
2589 0x00,
2590 0x00,
2591 0x00,
2592 0x06,
2593 0x00,
2594 0x00,
2595 0x00,
2596 0x07,
2597 0x00,
2598 0x00,
2599 0x00,
2600 0x08,
2601 0x00,
2602 0x00,
2603 0x00,
2604 0x09,
2605 0x00,
2606 0x00,
2607 0x00,
2608 0xFF,
2609 0xFF,
2610 0xFF,
2611 0xFF
2612 ], array);
2613 for (int i = 0; i < view.length; ++i) { 1598 for (int i = 0; i < view.length; ++i) {
2614 view[i] = -10 + i; 1599 view[i] = -10 + i;
2615 } 1600 }
2616 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], view); 1601 Expect.listEquals([-10, -9, -8, -7, -6,
2617 Expect.listEquals([ 1602 -5, -4, -3, -2, -1],
2618 0xFF, 1603 view);
2619 0xFF, 1604 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xF6, 0xFF, 0xFF, 0xFF,
2620 0xFF, 1605 0xF7, 0xFF, 0xFF, 0xFF, 0xF8, 0xFF, 0xFF, 0xFF,
2621 0xFF, 1606 0xF9, 0xFF, 0xFF, 0xFF, 0xFA, 0xFF, 0xFF, 0xFF,
2622 0xF6, 1607 0xFB, 0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF,
2623 0xFF, 1608 0xFD, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF,
2624 0xFF, 1609 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
2625 0xFF, 1610 array);
2626 0xF7,
2627 0xFF,
2628 0xFF,
2629 0xFF,
2630 0xF8,
2631 0xFF,
2632 0xFF,
2633 0xFF,
2634 0xF9,
2635 0xFF,
2636 0xFF,
2637 0xFF,
2638 0xFA,
2639 0xFF,
2640 0xFF,
2641 0xFF,
2642 0xFB,
2643 0xFF,
2644 0xFF,
2645 0xFF,
2646 0xFC,
2647 0xFF,
2648 0xFF,
2649 0xFF,
2650 0xFD,
2651 0xFF,
2652 0xFF,
2653 0xFF,
2654 0xFE,
2655 0xFF,
2656 0xFF,
2657 0xFF,
2658 0xFF,
2659 0xFF,
2660 0xFF,
2661 0xFF,
2662 0xFF,
2663 0xFF,
2664 0xFF,
2665 0xFF
2666 ], array);
2667 for (int i = 0; i < view.length; ++i) { 1611 for (int i = 0; i < view.length; ++i) {
2668 view[i] = 0x7FFFFFFF - i; 1612 view[i] = 0x7FFFFFFF - i;
2669 } 1613 }
2670 Expect.listEquals([ 1614 Expect.listEquals([0x7FFFFFFF, 0x7FFFFFFE,
2671 0x7FFFFFFF, 1615 0x7FFFFFFD, 0x7FFFFFFC,
2672 0x7FFFFFFE, 1616 0x7FFFFFFB, 0x7FFFFFFA,
2673 0x7FFFFFFD, 1617 0x7FFFFFF9, 0x7FFFFFF8,
2674 0x7FFFFFFC, 1618 0x7FFFFFF7, 0x7FFFFFF6],
2675 0x7FFFFFFB, 1619 view);
2676 0x7FFFFFFA, 1620 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
2677 0x7FFFFFF9, 1621 0xFE, 0xFF, 0xFF, 0x7F, 0xFD, 0xFF, 0xFF, 0x7F,
2678 0x7FFFFFF8, 1622 0xFC, 0xFF, 0xFF, 0x7F, 0xFB, 0xFF, 0xFF, 0x7F,
2679 0x7FFFFFF7, 1623 0xFA, 0xFF, 0xFF, 0x7F, 0xF9, 0xFF, 0xFF, 0x7F,
2680 0x7FFFFFF6 1624 0xF8, 0xFF, 0xFF, 0x7F, 0xF7, 0xFF, 0xFF, 0x7F,
2681 ], view); 1625 0xF6, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF],
2682 Expect.listEquals([ 1626 array);
2683 0xFF,
2684 0xFF,
2685 0xFF,
2686 0xFF,
2687 0xFF,
2688 0xFF,
2689 0xFF,
2690 0x7F,
2691 0xFE,
2692 0xFF,
2693 0xFF,
2694 0x7F,
2695 0xFD,
2696 0xFF,
2697 0xFF,
2698 0x7F,
2699 0xFC,
2700 0xFF,
2701 0xFF,
2702 0x7F,
2703 0xFB,
2704 0xFF,
2705 0xFF,
2706 0x7F,
2707 0xFA,
2708 0xFF,
2709 0xFF,
2710 0x7F,
2711 0xF9,
2712 0xFF,
2713 0xFF,
2714 0x7F,
2715 0xF8,
2716 0xFF,
2717 0xFF,
2718 0x7F,
2719 0xF7,
2720 0xFF,
2721 0xFF,
2722 0x7F,
2723 0xF6,
2724 0xFF,
2725 0xFF,
2726 0x7F,
2727 0xFF,
2728 0xFF,
2729 0xFF,
2730 0xFF
2731 ], array);
2732 for (int i = 0; i < view.length; ++i) { 1627 for (int i = 0; i < view.length; ++i) {
2733 view[i] = -0x80000000 + i; 1628 view[i] = -0x80000000 + i;
2734 } 1629 }
2735 Expect.listEquals([ 1630 Expect.listEquals([-0x80000000, -0x7FFFFFFF,
2736 -0x80000000, 1631 -0x7FFFFFFE, -0x7FFFFFFD,
2737 -0x7FFFFFFF, 1632 -0x7FFFFFFC, -0x7FFFFFFB,
2738 -0x7FFFFFFE, 1633 -0x7FFFFFFA, -0x7FFFFFF9,
2739 -0x7FFFFFFD, 1634 -0x7FFFFFF8, -0x7FFFFFF7],
2740 -0x7FFFFFFC, 1635 view);
2741 -0x7FFFFFFB, 1636 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80,
2742 -0x7FFFFFFA, 1637 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80,
2743 -0x7FFFFFF9, 1638 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80,
2744 -0x7FFFFFF8, 1639 0x05, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x80,
2745 -0x7FFFFFF7 1640 0x07, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x80,
2746 ], view); 1641 0x09, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF],
2747 Expect.listEquals([ 1642 array);
2748 0xFF,
2749 0xFF,
2750 0xFF,
2751 0xFF,
2752 0x00,
2753 0x00,
2754 0x00,
2755 0x80,
2756 0x01,
2757 0x00,
2758 0x00,
2759 0x80,
2760 0x02,
2761 0x00,
2762 0x00,
2763 0x80,
2764 0x03,
2765 0x00,
2766 0x00,
2767 0x80,
2768 0x04,
2769 0x00,
2770 0x00,
2771 0x80,
2772 0x05,
2773 0x00,
2774 0x00,
2775 0x80,
2776 0x06,
2777 0x00,
2778 0x00,
2779 0x80,
2780 0x07,
2781 0x00,
2782 0x00,
2783 0x80,
2784 0x08,
2785 0x00,
2786 0x00,
2787 0x80,
2788 0x09,
2789 0x00,
2790 0x00,
2791 0x80,
2792 0xFF,
2793 0xFF,
2794 0xFF,
2795 0xFF
2796 ], array);
2797 for (int i = 0; i < view.length; ++i) { 1643 for (int i = 0; i < view.length; ++i) {
2798 view[i] = i; 1644 view[i] = i;
2799 } 1645 }
2800 var copy = view.sublist(0, view.length); 1646 var copy = view.sublist(0, view.length);
2801 Expect.isFalse(identical(copy, view)); 1647 Expect.isFalse(identical(copy, view));
2802 Expect.isTrue(copy is Int32List); 1648 Expect.isTrue(copy is Int32List);
2803 Expect.equals(10, copy.length); 1649 Expect.equals(10, copy.length);
2804 Expect.listEquals(view, copy); 1650 Expect.listEquals(view, copy);
2805 var region = view.sublist(3, view.length - 3); 1651 var region = view.sublist(3, view.length - 3);
2806 Expect.isTrue(copy is Int32List); 1652 Expect.isTrue(copy is Int32List);
2807 Expect.equals(4, region.length); 1653 Expect.equals(4, region.length);
2808 Expect.listEquals([3, 4, 5, 6], region); 1654 Expect.listEquals([3, 4, 5, 6], region);
2809 view.setRange(3, 7, [-0x80000000, 0, 1, 0x7FFFFFFF]); 1655 view.setRange(3, 7, [-0x80000000, 0, 1, 0x7FFFFFFF]);
2810 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9], view); 1656 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9],
2811 Expect.listEquals([ 1657 view);
2812 0xFF, 1658 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
2813 0xFF, 1659 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
2814 0xFF, 1660 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
2815 0xFF, 1661 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x7F,
2816 0x00, 1662 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
2817 0x00, 1663 0x09, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
2818 0x00, 1664 array);
2819 0x00,
2820 0x01,
2821 0x00,
2822 0x00,
2823 0x00,
2824 0x02,
2825 0x00,
2826 0x00,
2827 0x00,
2828 0x00,
2829 0x00,
2830 0x00,
2831 0x80,
2832 0x00,
2833 0x00,
2834 0x00,
2835 0x00,
2836 0x01,
2837 0x00,
2838 0x00,
2839 0x00,
2840 0xFF,
2841 0xFF,
2842 0xFF,
2843 0x7F,
2844 0x07,
2845 0x00,
2846 0x00,
2847 0x00,
2848 0x08,
2849 0x00,
2850 0x00,
2851 0x00,
2852 0x09,
2853 0x00,
2854 0x00,
2855 0x00,
2856 0xFF,
2857 0xFF,
2858 0xFF,
2859 0xFF
2860 ], array);
2861 } 1665 }
2862 1666
2863 static testUint32ListViewImpl(var array) { 1667 static testUint32ListViewImpl(var array) {
2864 Expect.isTrue(array is List<int>); 1668 Expect.isTrue(array is List<int>);
2865 Expect.equals(48, array.length); 1669 Expect.equals(48, array.length);
2866 Expect.equals(1, array.elementSizeInBytes); 1670 Expect.equals(1, array.elementSizeInBytes);
2867 Expect.equals(48, array.lengthInBytes); 1671 Expect.equals(48, array.lengthInBytes);
2868 for (int i = 0; i < array.length; ++i) { 1672 for (int i = 0; i < array.length; ++i) {
2869 array[i] = -1; 1673 array[i] = -1;
2870 } 1674 }
2871 Expect.throws(() { 1675 Expect.throws(() { new Uint32List.view(array.buffer, -1); },
2872 new Uint32List.view(array.buffer, -1); 1676 (e) { return e is RangeError; });
2873 }, (e) { 1677 Expect.throws(() { new Uint32List.view(array.buffer, 0, -1); },
2874 return e is RangeError; 1678 (e) { return e is RangeError; });
2875 }); 1679 Expect.throws(() { new Uint32List.view(array.buffer,
2876 Expect.throws(() { 1680 array.lengthInBytes + 1); },
2877 new Uint32List.view(array.buffer, 0, -1); 1681 (e) { return e is RangeError; });
2878 }, (e) { 1682 Expect.throws(() { new Uint32List.view(array.buffer,
2879 return e is RangeError; 1683 0, array.length + 1); },
2880 }); 1684 (e) { return e is RangeError; });
2881 Expect.throws(() { 1685 Expect.throws(() { new Uint32List.view(array.buffer,
2882 new Uint32List.view(array.buffer, array.lengthInBytes + 1); 1686 array.length - 1, 2); },
2883 }, (e) { 1687 (e) { return e is RangeError; });
2884 return e is RangeError; 1688 var empty = new Uint32List.view(array.buffer,
2885 }); 1689 array.lengthInBytes);
2886 Expect.throws(() {
2887 new Uint32List.view(array.buffer, 0, array.length + 1);
2888 }, (e) {
2889 return e is RangeError;
2890 });
2891 Expect.throws(() {
2892 new Uint32List.view(array.buffer, array.length - 1, 2);
2893 }, (e) {
2894 return e is RangeError;
2895 });
2896 var empty = new Uint32List.view(array.buffer, array.lengthInBytes);
2897 Expect.isTrue(empty is List<int>); 1690 Expect.isTrue(empty is List<int>);
2898 Expect.isTrue(empty is Uint32List); 1691 Expect.isTrue(empty is Uint32List);
2899 Expect.equals(0, empty.length); 1692 Expect.equals(0, empty.length);
2900 var whole = new Uint32List.view(array.buffer); 1693 var whole = new Uint32List.view(array.buffer);
2901 Expect.isTrue(whole is List<int>); 1694 Expect.isTrue(whole is List<int>);
2902 Expect.isTrue(whole is Uint32List); 1695 Expect.isTrue(whole is Uint32List);
2903 Expect.equals(12, whole.length); 1696 Expect.equals(12, whole.length);
2904 var view = new Uint32List.view(array.buffer, 4, 10); 1697 var view = new Uint32List.view(array.buffer, 4, 10);
2905 Expect.isTrue(view is List<int>); 1698 Expect.isTrue(view is List<int>);
2906 Expect.isTrue(view is Uint32List); 1699 Expect.isTrue(view is Uint32List);
2907 Expect.equals(10, view.length); 1700 Expect.equals(10, view.length);
2908 Expect.equals(4, view.elementSizeInBytes); 1701 Expect.equals(4, view.elementSizeInBytes);
2909 Expect.equals(40, view.lengthInBytes); 1702 Expect.equals(40, view.lengthInBytes);
2910 Expect.listEquals([ 1703 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF F,
2911 0xFFFFFFFF, 1704 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF F],
2912 0xFFFFFFFF, 1705 view);
2913 0xFFFFFFFF, 1706 Expect.throws(() { view[-1] = 0; },
2914 0xFFFFFFFF, 1707 (e) { return e is RangeError; });
2915 0xFFFFFFFF, 1708 Expect.throws(() { return view[-1]; },
2916 0xFFFFFFFF, 1709 (e) { return e is RangeError; });
2917 0xFFFFFFFF, 1710 Expect.throws(() { view[view.length]; },
2918 0xFFFFFFFF, 1711 (e) { return e is RangeError; });
2919 0xFFFFFFFF, 1712 Expect.throws(() { view[view.length] = 0; },
2920 0xFFFFFFFF 1713 (e) { return e is RangeError; });
2921 ], view); 1714 Expect.throws(() { view.add(0); },
2922 Expect.throws(() { 1715 (e) { return e is UnsupportedError; });
2923 view[-1] = 0; 1716 Expect.throws(() { view.addAll([0]); },
2924 }, (e) { 1717 (e) { return e is UnsupportedError; });
2925 return e is RangeError; 1718 Expect.throws(() { view.clear(); },
2926 }); 1719 (e) { return e is UnsupportedError; });
2927 Expect.throws(() { 1720 Expect.throws(() { view.length = 0; },
2928 return view[-1]; 1721 (e) { return e is UnsupportedError; });
2929 }, (e) { 1722 Expect.throws(() { view.removeLast(); },
2930 return e is RangeError; 1723 (e) { return e is UnsupportedError; });
2931 }); 1724 Expect.throws(() { view.removeRange(0, view.length - 1); },
2932 Expect.throws(() { 1725 (e) { return e is UnsupportedError; });
2933 view[view.length];
2934 }, (e) {
2935 return e is RangeError;
2936 });
2937 Expect.throws(() {
2938 view[view.length] = 0;
2939 }, (e) {
2940 return e is RangeError;
2941 });
2942 Expect.throws(() {
2943 view.add(0);
2944 }, (e) {
2945 return e is UnsupportedError;
2946 });
2947 Expect.throws(() {
2948 view.addAll([0]);
2949 }, (e) {
2950 return e is UnsupportedError;
2951 });
2952 Expect.throws(() {
2953 view.clear();
2954 }, (e) {
2955 return e is UnsupportedError;
2956 });
2957 Expect.throws(() {
2958 view.length = 0;
2959 }, (e) {
2960 return e is UnsupportedError;
2961 });
2962 Expect.throws(() {
2963 view.removeLast();
2964 }, (e) {
2965 return e is UnsupportedError;
2966 });
2967 Expect.throws(() {
2968 view.removeRange(0, view.length - 1);
2969 }, (e) {
2970 return e is UnsupportedError;
2971 });
2972 for (int i = 0; i < view.length; ++i) { 1726 for (int i = 0; i < view.length; ++i) {
2973 view[i] = 1 + i; 1727 view[i] = 1 + i;
2974 } 1728 }
2975 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1729 Expect.listEquals([1, 2, 3, 4, 5,
2976 Expect.listEquals([ 1730 6, 7, 8, 9, 10],
2977 -1, 1731 view);
2978 -1, 1732 Expect.listEquals([-1, -1, -1, -1, 1, 0, 0, 0,
2979 -1, 1733 2, 0, 0, 0, 3, 0, 0, 0,
2980 -1, 1734 4, 0, 0, 0, 5, 0, 0, 0,
2981 1, 1735 6, 0, 0, 0, 7, 0, 0, 0,
2982 0, 1736 8, 0, 0, 0, 9, 0, 0, 0,
2983 0, 1737 10, 0, 0, 0, -1, -1, -1, -1],
2984 0, 1738 array);
2985 2,
2986 0,
2987 0,
2988 0,
2989 3,
2990 0,
2991 0,
2992 0,
2993 4,
2994 0,
2995 0,
2996 0,
2997 5,
2998 0,
2999 0,
3000 0,
3001 6,
3002 0,
3003 0,
3004 0,
3005 7,
3006 0,
3007 0,
3008 0,
3009 8,
3010 0,
3011 0,
3012 0,
3013 9,
3014 0,
3015 0,
3016 0,
3017 10,
3018 0,
3019 0,
3020 0,
3021 -1,
3022 -1,
3023 -1,
3024 -1
3025 ], array);
3026 for (int i = 0; i < view.length; ++i) { 1739 for (int i = 0; i < view.length; ++i) {
3027 view[i] = 0x100000000 + i; 1740 view[i] = 0x100000000 + i;
3028 } 1741 }
3029 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1742 Expect.listEquals([0, 1, 2, 3, 4,
3030 Expect.listEquals([ 1743 5, 6, 7, 8, 9],
3031 -1, 1744 view);
3032 -1, 1745 Expect.listEquals([-1, -1, -1, -1, 0, 0, 0, 0,
3033 -1, 1746 1, 0, 0, 0, 2, 0, 0, 0,
3034 -1, 1747 3, 0, 0, 0, 4, 0, 0, 0,
3035 0, 1748 5, 0, 0, 0, 6, 0, 0, 0,
3036 0, 1749 7, 0, 0, 0, 8, 0, 0, 0,
3037 0, 1750 9, 0, 0, 0, -1, -1, -1, -1],
3038 0, 1751 array);
3039 1,
3040 0,
3041 0,
3042 0,
3043 2,
3044 0,
3045 0,
3046 0,
3047 3,
3048 0,
3049 0,
3050 0,
3051 4,
3052 0,
3053 0,
3054 0,
3055 5,
3056 0,
3057 0,
3058 0,
3059 6,
3060 0,
3061 0,
3062 0,
3063 7,
3064 0,
3065 0,
3066 0,
3067 8,
3068 0,
3069 0,
3070 0,
3071 9,
3072 0,
3073 0,
3074 0,
3075 -1,
3076 -1,
3077 -1,
3078 -1
3079 ], array);
3080 for (int i = 0; i < view.length; ++i) { 1752 for (int i = 0; i < view.length; ++i) {
3081 view[i] = 0xFFFFFFFF - i; 1753 view[i] = 0xFFFFFFFF - i;
3082 } 1754 }
3083 Expect.listEquals([ 1755 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFE,
3084 0xFFFFFFFF, 1756 0xFFFFFFFD, 0xFFFFFFFC,
3085 0xFFFFFFFE, 1757 0xFFFFFFFB, 0xFFFFFFFA,
3086 0xFFFFFFFD, 1758 0xFFFFFFF9, 0xFFFFFFF8,
3087 0xFFFFFFFC, 1759 0xFFFFFFF7, 0xFFFFFFF6],
3088 0xFFFFFFFB, 1760 view);
3089 0xFFFFFFFA, 1761 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
3090 0xFFFFFFF9, 1762 -2, -1, -1, -1, -3, -1, -1, -1,
3091 0xFFFFFFF8, 1763 -4, -1, -1, -1, -5, -1, -1, -1,
3092 0xFFFFFFF7, 1764 -6, -1, -1, -1, -7, -1, -1, -1,
3093 0xFFFFFFF6 1765 -8, -1, -1, -1, -9, -1, -1, -1,
3094 ], view); 1766 -10, -1, -1, -1, -1, -1, -1, -1],
3095 Expect.listEquals([ 1767 array);
3096 -1,
3097 -1,
3098 -1,
3099 -1,
3100 -1,
3101 -1,
3102 -1,
3103 -1,
3104 -2,
3105 -1,
3106 -1,
3107 -1,
3108 -3,
3109 -1,
3110 -1,
3111 -1,
3112 -4,
3113 -1,
3114 -1,
3115 -1,
3116 -5,
3117 -1,
3118 -1,
3119 -1,
3120 -6,
3121 -1,
3122 -1,
3123 -1,
3124 -7,
3125 -1,
3126 -1,
3127 -1,
3128 -8,
3129 -1,
3130 -1,
3131 -1,
3132 -9,
3133 -1,
3134 -1,
3135 -1,
3136 -10,
3137 -1,
3138 -1,
3139 -1,
3140 -1,
3141 -1,
3142 -1,
3143 -1
3144 ], array);
3145 for (int i = 0; i < view.length; ++i) { 1768 for (int i = 0; i < view.length; ++i) {
3146 view[i] = i; 1769 view[i] = i;
3147 } 1770 }
3148 var copy = view.sublist(0, view.length); 1771 var copy = view.sublist(0, view.length);
3149 Expect.isFalse(identical(copy, view)); 1772 Expect.isFalse(identical(copy, view));
3150 Expect.isTrue(copy is Uint32List); 1773 Expect.isTrue(copy is Uint32List);
3151 Expect.equals(10, copy.length); 1774 Expect.equals(10, copy.length);
3152 Expect.listEquals(view, copy); 1775 Expect.listEquals(view, copy);
3153 var region = view.sublist(3, view.length - 3); 1776 var region = view.sublist(3, view.length - 3);
3154 Expect.isTrue(copy is Uint32List); 1777 Expect.isTrue(copy is Uint32List);
3155 Expect.equals(4, region.length); 1778 Expect.equals(4, region.length);
3156 Expect.listEquals([3, 4, 5, 6], region); 1779 Expect.listEquals([3, 4, 5, 6], region);
3157 view.setRange(3, 7, [0x100000001, 0, 1, 0xFFFFFFFF]); 1780 view.setRange(3, 7, [0x100000001, 0, 1, 0xFFFFFFFF]);
3158 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9], view); 1781 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9],
3159 Expect.listEquals([ 1782 view);
3160 -1, 1783 Expect.listEquals([-1, -1, -1, -1, 0, 0, 0, 0,
3161 -1, 1784 1, 0, 0, 0, 2, 0, 0, 0,
3162 -1, 1785 1, 0, 0, 0, 0, 0, 0, 0,
3163 -1, 1786 1, 0, 0, 0, -1, -1, -1, -1,
3164 0, 1787 7, 0, 0, 0, 8, 0, 0, 0,
3165 0, 1788 9, 0, 0, 0, -1, -1, -1, -1],
3166 0, 1789 array);
3167 0,
3168 1,
3169 0,
3170 0,
3171 0,
3172 2,
3173 0,
3174 0,
3175 0,
3176 1,
3177 0,
3178 0,
3179 0,
3180 0,
3181 0,
3182 0,
3183 0,
3184 1,
3185 0,
3186 0,
3187 0,
3188 -1,
3189 -1,
3190 -1,
3191 -1,
3192 7,
3193 0,
3194 0,
3195 0,
3196 8,
3197 0,
3198 0,
3199 0,
3200 9,
3201 0,
3202 0,
3203 0,
3204 -1,
3205 -1,
3206 -1,
3207 -1
3208 ], array);
3209 } 1790 }
3210 1791
3211 static testUint32ListView() { 1792 static testUint32ListView() {
3212 var array = new Int8List(48); 1793 var array = new Int8List(48);
3213 testUint32ListViewImpl(array); 1794 testUint32ListViewImpl(array);
3214 } 1795 }
3215 1796
3216 static testInt64ListViewImpl(var array) { 1797 static testInt64ListViewImpl(var array) {
3217 Expect.equals(96, array.length); 1798 Expect.equals(96, array.length);
3218 Expect.equals(1, array.elementSizeInBytes); 1799 Expect.equals(1, array.elementSizeInBytes);
3219 Expect.equals(96, array.lengthInBytes); 1800 Expect.equals(96, array.lengthInBytes);
3220 for (int i = 0; i < array.length; ++i) { 1801 for (int i = 0; i < array.length; ++i) {
3221 array[i] = 0xFF; 1802 array[i] = 0xFF;
3222 } 1803 }
3223 Expect.throws(() { 1804 Expect.throws(() { new Int64List.view(array.buffer, -1); },
3224 new Int64List.view(array.buffer, -1); 1805 (e) { return e is RangeError; });
3225 }, (e) { 1806 Expect.throws(() { new Int64List.view(array.buffer, 0, -1); },
3226 return e is RangeError; 1807 (e) { return e is RangeError; });
3227 }); 1808 Expect.throws(() { new Int64List.view(array.buffer,
3228 Expect.throws(() { 1809 array.lengthInBytes + 1); },
3229 new Int64List.view(array.buffer, 0, -1); 1810 (e) { return e is RangeError; });
3230 }, (e) { 1811 Expect.throws(() { new Int64List.view(array.buffer,
3231 return e is RangeError; 1812 0, array.length + 1); },
3232 }); 1813 (e) { return e is RangeError; });
3233 Expect.throws(() { 1814 Expect.throws(() { new Int64List.view(array.buffer,
3234 new Int64List.view(array.buffer, array.lengthInBytes + 1); 1815 array.length - 1, 2); },
3235 }, (e) { 1816 (e) { return e is RangeError; });
3236 return e is RangeError; 1817 var empty = new Int64List.view(array.buffer,
3237 }); 1818 array.lengthInBytes);
3238 Expect.throws(() {
3239 new Int64List.view(array.buffer, 0, array.length + 1);
3240 }, (e) {
3241 return e is RangeError;
3242 });
3243 Expect.throws(() {
3244 new Int64List.view(array.buffer, array.length - 1, 2);
3245 }, (e) {
3246 return e is RangeError;
3247 });
3248 var empty = new Int64List.view(array.buffer, array.lengthInBytes);
3249 Expect.isTrue(empty is List<int>); 1819 Expect.isTrue(empty is List<int>);
3250 Expect.isTrue(empty is Int64List); 1820 Expect.isTrue(empty is Int64List);
3251 Expect.equals(0, empty.length); 1821 Expect.equals(0, empty.length);
3252 var whole = new Int64List.view(array.buffer); 1822 var whole = new Int64List.view(array.buffer);
3253 Expect.isTrue(whole is List<int>); 1823 Expect.isTrue(whole is List<int>);
3254 Expect.isTrue(whole is Int64List); 1824 Expect.isTrue(whole is Int64List);
3255 Expect.equals(12, whole.length); 1825 Expect.equals(12, whole.length);
3256 var view = new Int64List.view(array.buffer, 8, 10); 1826 var view = new Int64List.view(array.buffer, 8, 10);
3257 Expect.isTrue(view is List<int>); 1827 Expect.isTrue(view is List<int>);
3258 Expect.isTrue(view is Int64List); 1828 Expect.isTrue(view is Int64List);
3259 Expect.equals(10, view.length); 1829 Expect.equals(10, view.length);
3260 Expect.equals(8, view.elementSizeInBytes); 1830 Expect.equals(8, view.elementSizeInBytes);
3261 Expect.equals(80, view.lengthInBytes); 1831 Expect.equals(80, view.lengthInBytes);
3262 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], view); 1832 Expect.listEquals([-1, -1, -1, -1, -1,
3263 Expect.throws(() { 1833 -1, -1, -1, -1, -1],
3264 view[-1] = 0; 1834 view);
3265 }, (e) { 1835 Expect.throws(() { view[-1] = 0; },
3266 return e is RangeError; 1836 (e) { return e is RangeError; });
3267 }); 1837 Expect.throws(() { return view[-1]; },
3268 Expect.throws(() { 1838 (e) { return e is RangeError; });
3269 return view[-1]; 1839 Expect.throws(() { view[view.length]; },
3270 }, (e) { 1840 (e) { return e is RangeError; });
3271 return e is RangeError; 1841 Expect.throws(() { view[10] = 0; },
3272 }); 1842 (e) { return e is RangeError; });
3273 Expect.throws(() { 1843 Expect.throws(() { view.add(0); },
3274 view[view.length]; 1844 (e) { return e is UnsupportedError; });
3275 }, (e) { 1845 Expect.throws(() { view.addAll([0]); },
3276 return e is RangeError; 1846 (e) { return e is UnsupportedError; });
3277 }); 1847 Expect.throws(() { view.clear(); },
3278 Expect.throws(() { 1848 (e) { return e is UnsupportedError; });
3279 view[10] = 0; 1849 Expect.throws(() { view.length = 0; },
3280 }, (e) { 1850 (e) { return e is UnsupportedError; });
3281 return e is RangeError; 1851 Expect.throws(() { view.removeLast(); },
3282 }); 1852 (e) { return e is UnsupportedError; });
3283 Expect.throws(() { 1853 Expect.throws(() { view.removeRange(0, view.length - 1); },
3284 view.add(0); 1854 (e) { return e is UnsupportedError; });
3285 }, (e) {
3286 return e is UnsupportedError;
3287 });
3288 Expect.throws(() {
3289 view.addAll([0]);
3290 }, (e) {
3291 return e is UnsupportedError;
3292 });
3293 Expect.throws(() {
3294 view.clear();
3295 }, (e) {
3296 return e is UnsupportedError;
3297 });
3298 Expect.throws(() {
3299 view.length = 0;
3300 }, (e) {
3301 return e is UnsupportedError;
3302 });
3303 Expect.throws(() {
3304 view.removeLast();
3305 }, (e) {
3306 return e is UnsupportedError;
3307 });
3308 Expect.throws(() {
3309 view.removeRange(0, view.length - 1);
3310 }, (e) {
3311 return e is UnsupportedError;
3312 });
3313 for (int i = 0; i < view.length; ++i) { 1855 for (int i = 0; i < view.length; ++i) {
3314 view[i] = 1 + i; 1856 view[i] = 1 + i;
3315 } 1857 }
3316 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 1858 Expect.listEquals([1, 2, 3, 4, 5,
3317 Expect.listEquals([ 1859 6, 7, 8, 9, 10],
3318 0xFF, 1860 view);
3319 0xFF, 1861 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3320 0xFF, 1862 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3321 0xFF, 1863 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3322 0xFF, 1864 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3323 0xFF, 1865 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3324 0xFF, 1866 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3325 0xFF, 1867 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3326 0x01, 1868 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3327 0x00, 1869 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3328 0x00, 1870 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3329 0x00, 1871 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3330 0x00, 1872 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3331 0x00, 1873 array);
3332 0x00,
3333 0x00,
3334 0x02,
3335 0x00,
3336 0x00,
3337 0x00,
3338 0x00,
3339 0x00,
3340 0x00,
3341 0x00,
3342 0x03,
3343 0x00,
3344 0x00,
3345 0x00,
3346 0x00,
3347 0x00,
3348 0x00,
3349 0x00,
3350 0x04,
3351 0x00,
3352 0x00,
3353 0x00,
3354 0x00,
3355 0x00,
3356 0x00,
3357 0x00,
3358 0x05,
3359 0x00,
3360 0x00,
3361 0x00,
3362 0x00,
3363 0x00,
3364 0x00,
3365 0x00,
3366 0x06,
3367 0x00,
3368 0x00,
3369 0x00,
3370 0x00,
3371 0x00,
3372 0x00,
3373 0x00,
3374 0x07,
3375 0x00,
3376 0x00,
3377 0x00,
3378 0x00,
3379 0x00,
3380 0x00,
3381 0x00,
3382 0x08,
3383 0x00,
3384 0x00,
3385 0x00,
3386 0x00,
3387 0x00,
3388 0x00,
3389 0x00,
3390 0x09,
3391 0x00,
3392 0x00,
3393 0x00,
3394 0x00,
3395 0x00,
3396 0x00,
3397 0x00,
3398 0x0A,
3399 0x00,
3400 0x00,
3401 0x00,
3402 0x00,
3403 0x00,
3404 0x00,
3405 0x00,
3406 0xFF,
3407 0xFF,
3408 0xFF,
3409 0xFF,
3410 0xFF,
3411 0xFF,
3412 0xFF,
3413 0xFF
3414 ], array);
3415 for (int i = 0; i < view.length; ++i) { 1874 for (int i = 0; i < view.length; ++i) {
3416 view[i] = 0x10000000000000000 + i; 1875 view[i] = 0x10000000000000000 + i;
3417 } 1876 }
3418 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 1877 Expect.listEquals([0, 1, 2, 3, 4,
3419 Expect.listEquals([ 1878 5, 6, 7, 8, 9],
3420 0xFF, 1879 view);
3421 0xFF, 1880 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3422 0xFF, 1881 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3423 0xFF, 1882 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3424 0xFF, 1883 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3425 0xFF, 1884 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3426 0xFF, 1885 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3427 0xFF, 1886 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3428 0x00, 1887 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3429 0x00, 1888 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3430 0x00, 1889 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3431 0x00, 1890 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3432 0x00, 1891 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3433 0x00, 1892 array);
3434 0x00,
3435 0x00,
3436 0x01,
3437 0x00,
3438 0x00,
3439 0x00,
3440 0x00,
3441 0x00,
3442 0x00,
3443 0x00,
3444 0x02,
3445 0x00,
3446 0x00,
3447 0x00,
3448 0x00,
3449 0x00,
3450 0x00,
3451 0x00,
3452 0x03,
3453 0x00,
3454 0x00,
3455 0x00,
3456 0x00,
3457 0x00,
3458 0x00,
3459 0x00,
3460 0x04,
3461 0x00,
3462 0x00,
3463 0x00,
3464 0x00,
3465 0x00,
3466 0x00,
3467 0x00,
3468 0x05,
3469 0x00,
3470 0x00,
3471 0x00,
3472 0x00,
3473 0x00,
3474 0x00,
3475 0x00,
3476 0x06,
3477 0x00,
3478 0x00,
3479 0x00,
3480 0x00,
3481 0x00,
3482 0x00,
3483 0x00,
3484 0x07,
3485 0x00,
3486 0x00,
3487 0x00,
3488 0x00,
3489 0x00,
3490 0x00,
3491 0x00,
3492 0x08,
3493 0x00,
3494 0x00,
3495 0x00,
3496 0x00,
3497 0x00,
3498 0x00,
3499 0x00,
3500 0x09,
3501 0x00,
3502 0x00,
3503 0x00,
3504 0x00,
3505 0x00,
3506 0x00,
3507 0x00,
3508 0xFF,
3509 0xFF,
3510 0xFF,
3511 0xFF,
3512 0xFF,
3513 0xFF,
3514 0xFF,
3515 0xFF
3516 ], array);
3517 for (int i = 0; i < view.length; ++i) { 1893 for (int i = 0; i < view.length; ++i) {
3518 view[i] = -10 + i; 1894 view[i] = -10 + i;
3519 } 1895 }
3520 Expect.listEquals([-10, -9, -8, -7, -6, -5, -4, -3, -2, -1], view); 1896 Expect.listEquals([-10, -9, -8, -7, -6,
3521 Expect.listEquals([ 1897 -5, -4, -3, -2, -1],
3522 0xFF, 1898 view);
3523 0xFF, 1899 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3524 0xFF, 1900 0xF6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3525 0xFF, 1901 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3526 0xFF, 1902 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3527 0xFF, 1903 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3528 0xFF, 1904 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3529 0xFF, 1905 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3530 0xF6, 1906 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3531 0xFF, 1907 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3532 0xFF, 1908 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3533 0xFF, 1909 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3534 0xFF, 1910 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3535 0xFF, 1911 array);
3536 0xFF,
3537 0xFF,
3538 0xF7,
3539 0xFF,
3540 0xFF,
3541 0xFF,
3542 0xFF,
3543 0xFF,
3544 0xFF,
3545 0xFF,
3546 0xF8,
3547 0xFF,
3548 0xFF,
3549 0xFF,
3550 0xFF,
3551 0xFF,
3552 0xFF,
3553 0xFF,
3554 0xF9,
3555 0xFF,
3556 0xFF,
3557 0xFF,
3558 0xFF,
3559 0xFF,
3560 0xFF,
3561 0xFF,
3562 0xFA,
3563 0xFF,
3564 0xFF,
3565 0xFF,
3566 0xFF,
3567 0xFF,
3568 0xFF,
3569 0xFF,
3570 0xFB,
3571 0xFF,
3572 0xFF,
3573 0xFF,
3574 0xFF,
3575 0xFF,
3576 0xFF,
3577 0xFF,
3578 0xFC,
3579 0xFF,
3580 0xFF,
3581 0xFF,
3582 0xFF,
3583 0xFF,
3584 0xFF,
3585 0xFF,
3586 0xFD,
3587 0xFF,
3588 0xFF,
3589 0xFF,
3590 0xFF,
3591 0xFF,
3592 0xFF,
3593 0xFF,
3594 0xFE,
3595 0xFF,
3596 0xFF,
3597 0xFF,
3598 0xFF,
3599 0xFF,
3600 0xFF,
3601 0xFF,
3602 0xFF,
3603 0xFF,
3604 0xFF,
3605 0xFF,
3606 0xFF,
3607 0xFF,
3608 0xFF,
3609 0xFF,
3610 0xFF,
3611 0xFF,
3612 0xFF,
3613 0xFF,
3614 0xFF,
3615 0xFF,
3616 0xFF,
3617 0xFF
3618 ], array);
3619 for (int i = 0; i < view.length; ++i) { 1912 for (int i = 0; i < view.length; ++i) {
3620 view[i] = 0x7FFFFFFFFFFFFFFF - i; 1913 view[i] = 0x7FFFFFFFFFFFFFFF - i;
3621 } 1914 }
3622 Expect.listEquals([ 1915 Expect.listEquals([0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFE,
3623 0x7FFFFFFFFFFFFFFF, 1916 0x7FFFFFFFFFFFFFFD, 0x7FFFFFFFFFFFFFFC,
3624 0x7FFFFFFFFFFFFFFE, 1917 0x7FFFFFFFFFFFFFFB, 0x7FFFFFFFFFFFFFFA,
3625 0x7FFFFFFFFFFFFFFD, 1918 0x7FFFFFFFFFFFFFF9, 0x7FFFFFFFFFFFFFF8,
3626 0x7FFFFFFFFFFFFFFC, 1919 0x7FFFFFFFFFFFFFF7, 0x7FFFFFFFFFFFFFF6],
3627 0x7FFFFFFFFFFFFFFB, 1920 view);
3628 0x7FFFFFFFFFFFFFFA, 1921 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3629 0x7FFFFFFFFFFFFFF9, 1922 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3630 0x7FFFFFFFFFFFFFF8, 1923 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3631 0x7FFFFFFFFFFFFFF7, 1924 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3632 0x7FFFFFFFFFFFFFF6 1925 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3633 ], view); 1926 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3634 Expect.listEquals([ 1927 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3635 0xFF, 1928 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3636 0xFF, 1929 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3637 0xFF, 1930 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3638 0xFF, 1931 0xF6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3639 0xFF, 1932 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3640 0xFF, 1933 array);
3641 0xFF,
3642 0xFF,
3643 0xFF,
3644 0xFF,
3645 0xFF,
3646 0xFF,
3647 0xFF,
3648 0xFF,
3649 0xFF,
3650 0x7F,
3651 0xFE,
3652 0xFF,
3653 0xFF,
3654 0xFF,
3655 0xFF,
3656 0xFF,
3657 0xFF,
3658 0x7F,
3659 0xFD,
3660 0xFF,
3661 0xFF,
3662 0xFF,
3663 0xFF,
3664 0xFF,
3665 0xFF,
3666 0x7F,
3667 0xFC,
3668 0xFF,
3669 0xFF,
3670 0xFF,
3671 0xFF,
3672 0xFF,
3673 0xFF,
3674 0x7F,
3675 0xFB,
3676 0xFF,
3677 0xFF,
3678 0xFF,
3679 0xFF,
3680 0xFF,
3681 0xFF,
3682 0x7F,
3683 0xFA,
3684 0xFF,
3685 0xFF,
3686 0xFF,
3687 0xFF,
3688 0xFF,
3689 0xFF,
3690 0x7F,
3691 0xF9,
3692 0xFF,
3693 0xFF,
3694 0xFF,
3695 0xFF,
3696 0xFF,
3697 0xFF,
3698 0x7F,
3699 0xF8,
3700 0xFF,
3701 0xFF,
3702 0xFF,
3703 0xFF,
3704 0xFF,
3705 0xFF,
3706 0x7F,
3707 0xF7,
3708 0xFF,
3709 0xFF,
3710 0xFF,
3711 0xFF,
3712 0xFF,
3713 0xFF,
3714 0x7F,
3715 0xF6,
3716 0xFF,
3717 0xFF,
3718 0xFF,
3719 0xFF,
3720 0xFF,
3721 0xFF,
3722 0x7F,
3723 0xFF,
3724 0xFF,
3725 0xFF,
3726 0xFF,
3727 0xFF,
3728 0xFF,
3729 0xFF,
3730 0xFF
3731 ], array);
3732 for (int i = 0; i < view.length; ++i) { 1934 for (int i = 0; i < view.length; ++i) {
3733 view[i] = -0x8000000000000000 + i; 1935 view[i] = -0x8000000000000000 + i;
3734 } 1936 }
3735 Expect.listEquals([ 1937 Expect.listEquals([-0x8000000000000000, -0x7FFFFFFFFFFFFFFF,
3736 -0x8000000000000000, 1938 -0x7FFFFFFFFFFFFFFE, -0x7FFFFFFFFFFFFFFD,
3737 -0x7FFFFFFFFFFFFFFF, 1939 -0x7FFFFFFFFFFFFFFC, -0x7FFFFFFFFFFFFFFB,
3738 -0x7FFFFFFFFFFFFFFE, 1940 -0x7FFFFFFFFFFFFFFA, -0x7FFFFFFFFFFFFFF9,
3739 -0x7FFFFFFFFFFFFFFD, 1941 -0x7FFFFFFFFFFFFFF8, -0x7FFFFFFFFFFFFFF7],
3740 -0x7FFFFFFFFFFFFFFC, 1942 view);
3741 -0x7FFFFFFFFFFFFFFB, 1943 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3742 -0x7FFFFFFFFFFFFFFA, 1944 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3743 -0x7FFFFFFFFFFFFFF9, 1945 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3744 -0x7FFFFFFFFFFFFFF8, 1946 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3745 -0x7FFFFFFFFFFFFFF7 1947 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3746 ], view); 1948 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3747 Expect.listEquals([ 1949 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3748 0xFF, 1950 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3749 0xFF, 1951 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3750 0xFF, 1952 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3751 0xFF, 1953 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3752 0xFF, 1954 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3753 0xFF, 1955 array);
3754 0xFF,
3755 0xFF,
3756 0x00,
3757 0x00,
3758 0x00,
3759 0x00,
3760 0x00,
3761 0x00,
3762 0x00,
3763 0x80,
3764 0x01,
3765 0x00,
3766 0x00,
3767 0x00,
3768 0x00,
3769 0x00,
3770 0x00,
3771 0x80,
3772 0x02,
3773 0x00,
3774 0x00,
3775 0x00,
3776 0x00,
3777 0x00,
3778 0x00,
3779 0x80,
3780 0x03,
3781 0x00,
3782 0x00,
3783 0x00,
3784 0x00,
3785 0x00,
3786 0x00,
3787 0x80,
3788 0x04,
3789 0x00,
3790 0x00,
3791 0x00,
3792 0x00,
3793 0x00,
3794 0x00,
3795 0x80,
3796 0x05,
3797 0x00,
3798 0x00,
3799 0x00,
3800 0x00,
3801 0x00,
3802 0x00,
3803 0x80,
3804 0x06,
3805 0x00,
3806 0x00,
3807 0x00,
3808 0x00,
3809 0x00,
3810 0x00,
3811 0x80,
3812 0x07,
3813 0x00,
3814 0x00,
3815 0x00,
3816 0x00,
3817 0x00,
3818 0x00,
3819 0x80,
3820 0x08,
3821 0x00,
3822 0x00,
3823 0x00,
3824 0x00,
3825 0x00,
3826 0x00,
3827 0x80,
3828 0x09,
3829 0x00,
3830 0x00,
3831 0x00,
3832 0x00,
3833 0x00,
3834 0x00,
3835 0x80,
3836 0xFF,
3837 0xFF,
3838 0xFF,
3839 0xFF,
3840 0xFF,
3841 0xFF,
3842 0xFF,
3843 0xFF
3844 ], array);
3845 for (int i = 0; i < view.length; ++i) { 1956 for (int i = 0; i < view.length; ++i) {
3846 view[i] = i; 1957 view[i] = i;
3847 } 1958 }
3848 var copy = view.sublist(0, view.length); 1959 var copy = view.sublist(0, view.length);
3849 Expect.isFalse(identical(copy, view)); 1960 Expect.isFalse(identical(copy, view));
3850 Expect.isTrue(copy is Int64List); 1961 Expect.isTrue(copy is Int64List);
3851 Expect.equals(10, copy.length); 1962 Expect.equals(10, copy.length);
3852 Expect.listEquals(view, copy); 1963 Expect.listEquals(view, copy);
3853 var region = view.sublist(3, view.length - 3); 1964 var region = view.sublist(3, view.length - 3);
3854 Expect.isTrue(copy is Int64List); 1965 Expect.isTrue(copy is Int64List);
3855 Expect.equals(4, region.length); 1966 Expect.equals(4, region.length);
3856 Expect.listEquals([3, 4, 5, 6], region); 1967 Expect.listEquals([3, 4, 5, 6], region);
3857 view.setRange(3, 7, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]); 1968 view.setRange(3, 7, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]);
3858 Expect.listEquals( 1969 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0,
3859 [0, 1, 2, -0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9], 1970 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9],
3860 view); 1971 view);
3861 Expect.listEquals([ 1972 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3862 0xFF, 1973 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3863 0xFF, 1974 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3864 0xFF, 1975 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3865 0xFF, 1976 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
3866 0xFF, 1977 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3867 0xFF, 1978 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3868 0xFF, 1979 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
3869 0xFF, 1980 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3870 0x00, 1981 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3871 0x00, 1982 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3872 0x00, 1983 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
3873 0x00, 1984 array);
3874 0x00,
3875 0x00,
3876 0x00,
3877 0x00,
3878 0x01,
3879 0x00,
3880 0x00,
3881 0x00,
3882 0x00,
3883 0x00,
3884 0x00,
3885 0x00,
3886 0x02,
3887 0x00,
3888 0x00,
3889 0x00,
3890 0x00,
3891 0x00,
3892 0x00,
3893 0x00,
3894 0x00,
3895 0x00,
3896 0x00,
3897 0x00,
3898 0x00,
3899 0x00,
3900 0x00,
3901 0x80,
3902 0x00,
3903 0x00,
3904 0x00,
3905 0x00,
3906 0x00,
3907 0x00,
3908 0x00,
3909 0x00,
3910 0x01,
3911 0x00,
3912 0x00,
3913 0x00,
3914 0x00,
3915 0x00,
3916 0x00,
3917 0x00,
3918 0xFF,
3919 0xFF,
3920 0xFF,
3921 0xFF,
3922 0xFF,
3923 0xFF,
3924 0xFF,
3925 0x7F,
3926 0x07,
3927 0x00,
3928 0x00,
3929 0x00,
3930 0x00,
3931 0x00,
3932 0x00,
3933 0x00,
3934 0x08,
3935 0x00,
3936 0x00,
3937 0x00,
3938 0x00,
3939 0x00,
3940 0x00,
3941 0x00,
3942 0x09,
3943 0x00,
3944 0x00,
3945 0x00,
3946 0x00,
3947 0x00,
3948 0x00,
3949 0x00,
3950 0xFF,
3951 0xFF,
3952 0xFF,
3953 0xFF,
3954 0xFF,
3955 0xFF,
3956 0xFF,
3957 0xFF
3958 ], array);
3959 } 1985 }
3960 1986
3961 static testInt64ListView() { 1987 static testInt64ListView() {
3962 var array = new Uint8List(96); 1988 var array = new Uint8List(96);
3963 testInt64ListViewImpl(array); 1989 testInt64ListViewImpl(array);
3964 } 1990 }
3965 1991
3966 static testUint64ListViewImpl(var array) { 1992 static testUint64ListViewImpl(var array) {
3967 Expect.isTrue(array is List<int>); 1993 Expect.isTrue(array is List<int>);
3968 Expect.equals(96, array.length); 1994 Expect.equals(96, array.length);
3969 Expect.equals(1, array.elementSizeInBytes); 1995 Expect.equals(1, array.elementSizeInBytes);
3970 Expect.equals(96, array.lengthInBytes); 1996 Expect.equals(96, array.lengthInBytes);
3971 for (int i = 0; i < array.length; ++i) { 1997 for (int i = 0; i < array.length; ++i) {
3972 array[i] = -1; 1998 array[i] = -1;
3973 } 1999 }
3974 Expect.throws(() { 2000 Expect.throws(() { new Uint64List.view(array.buffer, -1); },
3975 new Uint64List.view(array.buffer, -1); 2001 (e) { return e is RangeError; });
3976 }, (e) { 2002 Expect.throws(() { new Uint64List.view(array.buffer, 0, -1); },
3977 return e is RangeError; 2003 (e) { return e is RangeError; });
3978 }); 2004 Expect.throws(() { new Uint64List.view(array.buffer,
3979 Expect.throws(() { 2005 array.lengthInBytes + 1); },
3980 new Uint64List.view(array.buffer, 0, -1); 2006 (e) { return e is RangeError; });
3981 }, (e) { 2007 Expect.throws(() { new Uint64List.view(array.buffer,
3982 return e is RangeError; 2008 0, array.length + 1); },
3983 }); 2009 (e) { return e is RangeError; });
3984 Expect.throws(() { 2010 Expect.throws(() { new Uint64List.view(array.buffer,
3985 new Uint64List.view(array.buffer, array.lengthInBytes + 1); 2011 array.length - 1, 2); },
3986 }, (e) { 2012 (e) { return e is RangeError; });
3987 return e is RangeError; 2013 var empty = new Uint64List.view(array.buffer,
3988 }); 2014 array.lengthInBytes);
3989 Expect.throws(() {
3990 new Uint64List.view(array.buffer, 0, array.length + 1);
3991 }, (e) {
3992 return e is RangeError;
3993 });
3994 Expect.throws(() {
3995 new Uint64List.view(array.buffer, array.length - 1, 2);
3996 }, (e) {
3997 return e is RangeError;
3998 });
3999 var empty = new Uint64List.view(array.buffer, array.lengthInBytes);
4000 Expect.isTrue(empty is List<int>); 2015 Expect.isTrue(empty is List<int>);
4001 Expect.isTrue(empty is Uint64List); 2016 Expect.isTrue(empty is Uint64List);
4002 Expect.equals(0, empty.length); 2017 Expect.equals(0, empty.length);
4003 var whole = new Uint64List.view(array.buffer); 2018 var whole = new Uint64List.view(array.buffer);
4004 Expect.isTrue(whole is List<int>); 2019 Expect.isTrue(whole is List<int>);
4005 Expect.isTrue(whole is Uint64List); 2020 Expect.isTrue(whole is Uint64List);
4006 Expect.equals(12, whole.length); 2021 Expect.equals(12, whole.length);
4007 var view = new Uint64List.view(array.buffer, 8, 10); 2022 var view = new Uint64List.view(array.buffer, 8, 10);
4008 Expect.isTrue(view is List<int>); 2023 Expect.isTrue(view is List<int>);
4009 Expect.isTrue(view is Uint64List); 2024 Expect.isTrue(view is Uint64List);
4010 Expect.equals(10, view.length); 2025 Expect.equals(10, view.length);
4011 Expect.equals(8, view.elementSizeInBytes); 2026 Expect.equals(8, view.elementSizeInBytes);
4012 Expect.equals(80, view.lengthInBytes); 2027 Expect.equals(80, view.lengthInBytes);
4013 Expect.listEquals([ 2028 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
4014 0xFFFFFFFFFFFFFFFF, 2029 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
4015 0xFFFFFFFFFFFFFFFF, 2030 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
4016 0xFFFFFFFFFFFFFFFF, 2031 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
4017 0xFFFFFFFFFFFFFFFF, 2032 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF],
4018 0xFFFFFFFFFFFFFFFF, 2033 view);
4019 0xFFFFFFFFFFFFFFFF, 2034 Expect.throws(() { view[-1] = 0; },
4020 0xFFFFFFFFFFFFFFFF, 2035 (e) { return e is RangeError; });
4021 0xFFFFFFFFFFFFFFFF, 2036 Expect.throws(() { return view[-1]; },
4022 0xFFFFFFFFFFFFFFFF, 2037 (e) { return e is RangeError; });
4023 0xFFFFFFFFFFFFFFFF 2038 Expect.throws(() { view[view.length]; },
4024 ], view); 2039 (e) { return e is RangeError; });
4025 Expect.throws(() { 2040 Expect.throws(() { view[view.length] = 0; },
4026 view[-1] = 0; 2041 (e) { return e is RangeError; });
4027 }, (e) { 2042 Expect.throws(() { view.add(0); },
4028 return e is RangeError; 2043 (e) { return e is UnsupportedError; });
4029 }); 2044 Expect.throws(() { view.addAll([0]); },
4030 Expect.throws(() { 2045 (e) { return e is UnsupportedError; });
4031 return view[-1]; 2046 Expect.throws(() { view.clear(); },
4032 }, (e) { 2047 (e) { return e is UnsupportedError; });
4033 return e is RangeError; 2048 Expect.throws(() { view.length = 0; },
4034 }); 2049 (e) { return e is UnsupportedError; });
4035 Expect.throws(() { 2050 Expect.throws(() { view.removeLast(); },
4036 view[view.length]; 2051 (e) { return e is UnsupportedError; });
4037 }, (e) { 2052 Expect.throws(() { view.removeRange(0, view.length - 1); },
4038 return e is RangeError; 2053 (e) { return e is UnsupportedError; });
4039 });
4040 Expect.throws(() {
4041 view[view.length] = 0;
4042 }, (e) {
4043 return e is RangeError;
4044 });
4045 Expect.throws(() {
4046 view.add(0);
4047 }, (e) {
4048 return e is UnsupportedError;
4049 });
4050 Expect.throws(() {
4051 view.addAll([0]);
4052 }, (e) {
4053 return e is UnsupportedError;
4054 });
4055 Expect.throws(() {
4056 view.clear();
4057 }, (e) {
4058 return e is UnsupportedError;
4059 });
4060 Expect.throws(() {
4061 view.length = 0;
4062 }, (e) {
4063 return e is UnsupportedError;
4064 });
4065 Expect.throws(() {
4066 view.removeLast();
4067 }, (e) {
4068 return e is UnsupportedError;
4069 });
4070 Expect.throws(() {
4071 view.removeRange(0, view.length - 1);
4072 }, (e) {
4073 return e is UnsupportedError;
4074 });
4075 for (int i = 0; i < view.length; ++i) { 2054 for (int i = 0; i < view.length; ++i) {
4076 view[i] = 1 + i; 2055 view[i] = 1 + i;
4077 } 2056 }
4078 Expect.listEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], view); 2057 Expect.listEquals([1, 2, 3, 4, 5,
4079 Expect.listEquals([ 2058 6, 7, 8, 9, 10],
4080 -1, 2059 view);
4081 -1, 2060 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
4082 -1, 2061 1, 0, 0, 0, 0, 0, 0, 0,
4083 -1, 2062 2, 0, 0, 0, 0, 0, 0, 0,
4084 -1, 2063 3, 0, 0, 0, 0, 0, 0, 0,
4085 -1, 2064 4, 0, 0, 0, 0, 0, 0, 0,
4086 -1, 2065 5, 0, 0, 0, 0, 0, 0, 0,
4087 -1, 2066 6, 0, 0, 0, 0, 0, 0, 0,
4088 1, 2067 7, 0, 0, 0, 0, 0, 0, 0,
4089 0, 2068 8, 0, 0, 0, 0, 0, 0, 0,
4090 0, 2069 9, 0, 0, 0, 0, 0, 0, 0,
4091 0, 2070 10, 0, 0, 0, 0, 0, 0, 0,
4092 0, 2071 -1, -1, -1, -1, -1, -1, -1, -1],
4093 0, 2072 array);
4094 0,
4095 0,
4096 2,
4097 0,
4098 0,
4099 0,
4100 0,
4101 0,
4102 0,
4103 0,
4104 3,
4105 0,
4106 0,
4107 0,
4108 0,
4109 0,
4110 0,
4111 0,
4112 4,
4113 0,
4114 0,
4115 0,
4116 0,
4117 0,
4118 0,
4119 0,
4120 5,
4121 0,
4122 0,
4123 0,
4124 0,
4125 0,
4126 0,
4127 0,
4128 6,
4129 0,
4130 0,
4131 0,
4132 0,
4133 0,
4134 0,
4135 0,
4136 7,
4137 0,
4138 0,
4139 0,
4140 0,
4141 0,
4142 0,
4143 0,
4144 8,
4145 0,
4146 0,
4147 0,
4148 0,
4149 0,
4150 0,
4151 0,
4152 9,
4153 0,
4154 0,
4155 0,
4156 0,
4157 0,
4158 0,
4159 0,
4160 10,
4161 0,
4162 0,
4163 0,
4164 0,
4165 0,
4166 0,
4167 0,
4168 -1,
4169 -1,
4170 -1,
4171 -1,
4172 -1,
4173 -1,
4174 -1,
4175 -1
4176 ], array);
4177 for (int i = 0; i < view.length; ++i) { 2073 for (int i = 0; i < view.length; ++i) {
4178 view[i] = 0x10000000000000000 + i; 2074 view[i] = 0x10000000000000000 + i;
4179 } 2075 }
4180 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], view); 2076 Expect.listEquals([0, 1, 2, 3, 4,
4181 Expect.listEquals([ 2077 5, 6, 7, 8, 9],
4182 -1, 2078 view);
4183 -1, 2079 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
4184 -1, 2080 0, 0, 0, 0, 0, 0, 0, 0,
4185 -1, 2081 1, 0, 0, 0, 0, 0, 0, 0,
4186 -1, 2082 2, 0, 0, 0, 0, 0, 0, 0,
4187 -1, 2083 3, 0, 0, 0, 0, 0, 0, 0,
4188 -1, 2084 4, 0, 0, 0, 0, 0, 0, 0,
4189 -1, 2085 5, 0, 0, 0, 0, 0, 0, 0,
4190 0, 2086 6, 0, 0, 0, 0, 0, 0, 0,
4191 0, 2087 7, 0, 0, 0, 0, 0, 0, 0,
4192 0, 2088 8, 0, 0, 0, 0, 0, 0, 0,
4193 0, 2089 9, 0, 0, 0, 0, 0, 0, 0,
4194 0, 2090 -1, -1, -1, -1, -1, -1, -1, -1],
4195 0, 2091 array);
4196 0,
4197 0,
4198 1,
4199 0,
4200 0,
4201 0,
4202 0,
4203 0,
4204 0,
4205 0,
4206 2,
4207 0,
4208 0,
4209 0,
4210 0,
4211 0,
4212 0,
4213 0,
4214 3,
4215 0,
4216 0,
4217 0,
4218 0,
4219 0,
4220 0,
4221 0,
4222 4,
4223 0,
4224 0,
4225 0,
4226 0,
4227 0,
4228 0,
4229 0,
4230 5,
4231 0,
4232 0,
4233 0,
4234 0,
4235 0,
4236 0,
4237 0,
4238 6,
4239 0,
4240 0,
4241 0,
4242 0,
4243 0,
4244 0,
4245 0,
4246 7,
4247 0,
4248 0,
4249 0,
4250 0,
4251 0,
4252 0,
4253 0,
4254 8,
4255 0,
4256 0,
4257 0,
4258 0,
4259 0,
4260 0,
4261 0,
4262 9,
4263 0,
4264 0,
4265 0,
4266 0,
4267 0,
4268 0,
4269 0,
4270 -1,
4271 -1,
4272 -1,
4273 -1,
4274 -1,
4275 -1,
4276 -1,
4277 -1
4278 ], array);
4279 for (int i = 0; i < view.length; ++i) { 2092 for (int i = 0; i < view.length; ++i) {
4280 view[i] = 0xFFFFFFFFFFFFFFFF - i; 2093 view[i] = 0xFFFFFFFFFFFFFFFF - i;
4281 } 2094 }
4282 Expect.listEquals([ 2095 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFE,
4283 0xFFFFFFFFFFFFFFFF, 2096 0xFFFFFFFFFFFFFFFD, 0xFFFFFFFFFFFFFFFC,
4284 0xFFFFFFFFFFFFFFFE, 2097 0xFFFFFFFFFFFFFFFB, 0xFFFFFFFFFFFFFFFA,
4285 0xFFFFFFFFFFFFFFFD, 2098 0xFFFFFFFFFFFFFFF9, 0xFFFFFFFFFFFFFFF8,
4286 0xFFFFFFFFFFFFFFFC, 2099 0xFFFFFFFFFFFFFFF7, 0xFFFFFFFFFFFFFFF6],
4287 0xFFFFFFFFFFFFFFFB, 2100 view);
4288 0xFFFFFFFFFFFFFFFA, 2101 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
4289 0xFFFFFFFFFFFFFFF9, 2102 -1, -1, -1, -1, -1, -1, -1, -1,
4290 0xFFFFFFFFFFFFFFF8, 2103 -2, -1, -1, -1, -1, -1, -1, -1,
4291 0xFFFFFFFFFFFFFFF7, 2104 -3, -1, -1, -1, -1, -1, -1, -1,
4292 0xFFFFFFFFFFFFFFF6 2105 -4, -1, -1, -1, -1, -1, -1, -1,
4293 ], view); 2106 -5, -1, -1, -1, -1, -1, -1, -1,
4294 Expect.listEquals([ 2107 -6, -1, -1, -1, -1, -1, -1, -1,
4295 -1, 2108 -7, -1, -1, -1, -1, -1, -1, -1,
4296 -1, 2109 -8, -1, -1, -1, -1, -1, -1, -1,
4297 -1, 2110 -9, -1, -1, -1, -1, -1, -1, -1,
4298 -1, 2111 -10, -1, -1, -1, -1, -1, -1, -1,
4299 -1, 2112 -1, -1, -1, -1, -1, -1, -1, -1],
4300 -1, 2113 array);
4301 -1,
4302 -1,
4303 -1,
4304 -1,
4305 -1,
4306 -1,
4307 -1,
4308 -1,
4309 -1,
4310 -1,
4311 -2,
4312 -1,
4313 -1,
4314 -1,
4315 -1,
4316 -1,
4317 -1,
4318 -1,
4319 -3,
4320 -1,
4321 -1,
4322 -1,
4323 -1,
4324 -1,
4325 -1,
4326 -1,
4327 -4,
4328 -1,
4329 -1,
4330 -1,
4331 -1,
4332 -1,
4333 -1,
4334 -1,
4335 -5,
4336 -1,
4337 -1,
4338 -1,
4339 -1,
4340 -1,
4341 -1,
4342 -1,
4343 -6,
4344 -1,
4345 -1,
4346 -1,
4347 -1,
4348 -1,
4349 -1,
4350 -1,
4351 -7,
4352 -1,
4353 -1,
4354 -1,
4355 -1,
4356 -1,
4357 -1,
4358 -1,
4359 -8,
4360 -1,
4361 -1,
4362 -1,
4363 -1,
4364 -1,
4365 -1,
4366 -1,
4367 -9,
4368 -1,
4369 -1,
4370 -1,
4371 -1,
4372 -1,
4373 -1,
4374 -1,
4375 -10,
4376 -1,
4377 -1,
4378 -1,
4379 -1,
4380 -1,
4381 -1,
4382 -1,
4383 -1,
4384 -1,
4385 -1,
4386 -1,
4387 -1,
4388 -1,
4389 -1,
4390 -1
4391 ], array);
4392 for (int i = 0; i < view.length; ++i) { 2114 for (int i = 0; i < view.length; ++i) {
4393 view[i] = i; 2115 view[i] = i;
4394 } 2116 }
4395 var copy = view.sublist(0, view.length); 2117 var copy = view.sublist(0, view.length);
4396 Expect.isFalse(identical(copy, view)); 2118 Expect.isFalse(identical(copy, view));
4397 Expect.isTrue(copy is Uint64List); 2119 Expect.isTrue(copy is Uint64List);
4398 Expect.equals(10, copy.length); 2120 Expect.equals(10, copy.length);
4399 Expect.listEquals(view, copy); 2121 Expect.listEquals(view, copy);
4400 var region = view.sublist(3, view.length - 3); 2122 var region = view.sublist(3, view.length - 3);
4401 Expect.isTrue(copy is Uint64List); 2123 Expect.isTrue(copy is Uint64List);
4402 Expect.equals(4, region.length); 2124 Expect.equals(4, region.length);
4403 Expect.listEquals([3, 4, 5, 6], region); 2125 Expect.listEquals([3, 4, 5, 6], region);
4404 view.setRange(3, 7, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]); 2126 view.setRange(3, 7, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]);
4405 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9], view); 2127 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9],
4406 Expect.listEquals([ 2128 view);
4407 -1, 2129 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
4408 -1, 2130 0, 0, 0, 0, 0, 0, 0, 0,
4409 -1, 2131 1, 0, 0, 0, 0, 0, 0, 0,
4410 -1, 2132 2, 0, 0, 0, 0, 0, 0, 0,
4411 -1, 2133 1, 0, 0, 0, 0, 0, 0, 0,
4412 -1, 2134 0, 0, 0, 0, 0, 0, 0, 0,
4413 -1, 2135 1, 0, 0, 0, 0, 0, 0, 0,
4414 -1, 2136 -1, -1, -1, -1, -1, -1, -1, -1,
4415 0, 2137 7, 0, 0, 0, 0, 0, 0, 0,
4416 0, 2138 8, 0, 0, 0, 0, 0, 0, 0,
4417 0, 2139 9, 0, 0, 0, 0, 0, 0, 0,
4418 0, 2140 -1, -1, -1, -1, -1, -1, -1, -1],
4419 0, 2141 array);
4420 0,
4421 0,
4422 0,
4423 1,
4424 0,
4425 0,
4426 0,
4427 0,
4428 0,
4429 0,
4430 0,
4431 2,
4432 0,
4433 0,
4434 0,
4435 0,
4436 0,
4437 0,
4438 0,
4439 1,
4440 0,
4441 0,
4442 0,
4443 0,
4444 0,
4445 0,
4446 0,
4447 0,
4448 0,
4449 0,
4450 0,
4451 0,
4452 0,
4453 0,
4454 0,
4455 1,
4456 0,
4457 0,
4458 0,
4459 0,
4460 0,
4461 0,
4462 0,
4463 -1,
4464 -1,
4465 -1,
4466 -1,
4467 -1,
4468 -1,
4469 -1,
4470 -1,
4471 7,
4472 0,
4473 0,
4474 0,
4475 0,
4476 0,
4477 0,
4478 0,
4479 8,
4480 0,
4481 0,
4482 0,
4483 0,
4484 0,
4485 0,
4486 0,
4487 9,
4488 0,
4489 0,
4490 0,
4491 0,
4492 0,
4493 0,
4494 0,
4495 -1,
4496 -1,
4497 -1,
4498 -1,
4499 -1,
4500 -1,
4501 -1,
4502 -1
4503 ], array);
4504 } 2142 }
4505 2143
4506 static testUint64ListView() { 2144 static testUint64ListView() {
4507 var array = new Int8List(96); 2145 var array = new Int8List(96);
4508 testUint64ListViewImpl(array); 2146 testUint64ListViewImpl(array);
4509 } 2147 }
4510 2148
4511 static testFloat32ListViewImpl(var array) { 2149 static testFloat32ListViewImpl(var array) {
4512 Expect.isTrue(array is List<int>); 2150 Expect.isTrue(array is List<int>);
4513 Expect.equals(12, array.length); 2151 Expect.equals(12, array.length);
4514 Expect.equals(4, array.elementSizeInBytes); 2152 Expect.equals(4, array.elementSizeInBytes);
4515 Expect.equals(48, array.lengthInBytes); 2153 Expect.equals(48, array.lengthInBytes);
4516 for (int i = 0; i < array.length; ++i) { 2154 for (int i = 0; i < array.length; ++i) {
4517 array[i] = 0xBF800000; 2155 array[i] = 0xBF800000;
4518 } 2156 }
4519 Expect.throws(() { 2157 Expect.throws(() { new Float32List.view(array.buffer, -1); },
4520 new Float32List.view(array.buffer, -1); 2158 (e) { return e is RangeError; });
4521 }, (e) { 2159 Expect.throws(() { new Float32List.view(array.buffer, 0, -1); },
4522 return e is RangeError; 2160 (e) { return e is RangeError; });
4523 }); 2161 Expect.throws(() { new Float32List.view(array.buffer,
4524 Expect.throws(() { 2162 array.lengthInBytes + 1); },
4525 new Float32List.view(array.buffer, 0, -1); 2163 (e) { return e is RangeError; });
4526 }, (e) { 2164 Expect.throws(() { new Float32List.view(array.buffer,
4527 return e is RangeError; 2165 0, array.lengthInBytes + 1); },
4528 }); 2166 (e) { return e is RangeError; });
4529 Expect.throws(() { 2167 Expect.throws(() { new Float32List.view(array.buffer,
4530 new Float32List.view(array.buffer, array.lengthInBytes + 1); 2168 array.lengthInBytes - 1, 2); },
4531 }, (e) { 2169 (e) { return e is RangeError; });
4532 return e is RangeError; 2170 var empty = new Float32List.view(array.buffer,
4533 }); 2171 array.lengthInBytes);
4534 Expect.throws(() {
4535 new Float32List.view(array.buffer, 0, array.lengthInBytes + 1);
4536 }, (e) {
4537 return e is RangeError;
4538 });
4539 Expect.throws(() {
4540 new Float32List.view(array.buffer, array.lengthInBytes - 1, 2);
4541 }, (e) {
4542 return e is RangeError;
4543 });
4544 var empty = new Float32List.view(array.buffer, array.lengthInBytes);
4545 Expect.isTrue(empty is List<double>); 2172 Expect.isTrue(empty is List<double>);
4546 Expect.isTrue(empty is Float32List); 2173 Expect.isTrue(empty is Float32List);
4547 Expect.equals(0, empty.length); 2174 Expect.equals(0, empty.length);
4548 var whole = new Float32List.view(array.buffer); 2175 var whole = new Float32List.view(array.buffer);
4549 Expect.isTrue(whole is List<double>); 2176 Expect.isTrue(whole is List<double>);
4550 Expect.isTrue(whole is Float32List); 2177 Expect.isTrue(whole is Float32List);
4551 Expect.equals(12, whole.length); 2178 Expect.equals(12, whole.length);
4552 var view = new Float32List.view(array.buffer, 4, 10); 2179 var view = new Float32List.view(array.buffer, 4, 10);
4553 Expect.isTrue(view is List<double>); 2180 Expect.isTrue(view is List<double>);
4554 Expect.isTrue(view is Float32List); 2181 Expect.isTrue(view is Float32List);
4555 Expect.equals(10, view.length); 2182 Expect.equals(10, view.length);
4556 Expect.equals(4, view.elementSizeInBytes); 2183 Expect.equals(4, view.elementSizeInBytes);
4557 Expect.equals(40, view.lengthInBytes); 2184 Expect.equals(40, view.lengthInBytes);
4558 Expect.listEquals( 2185 Expect.listEquals([-1.0, -1.0, -1.0, -1.0, -1.0,
4559 [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0], view); 2186 -1.0, -1.0, -1.0, -1.0, -1.0],
4560 Expect.throws(() { 2187 view);
4561 view[-1] = 0.0; 2188 Expect.throws(() { view[-1] = 0.0; },
4562 }, (e) { 2189 (e) { return e is RangeError; });
4563 return e is RangeError; 2190 Expect.throws(() { return view[-1]; },
4564 }); 2191 (e) { return e is RangeError; });
4565 Expect.throws(() { 2192 Expect.throws(() { view[10]; },
4566 return view[-1]; 2193 (e) { return e is RangeError; });
4567 }, (e) { 2194 Expect.throws(() { view[10] = 0.0; },
4568 return e is RangeError; 2195 (e) { return e is RangeError; });
4569 }); 2196 Expect.throws(() { array.add(0.0); },
4570 Expect.throws(() { 2197 (e) { return e is UnsupportedError; });
4571 view[10]; 2198 Expect.throws(() { array.addAll([0]); },
4572 }, (e) { 2199 (e) { return e is UnsupportedError; });
4573 return e is RangeError; 2200 Expect.throws(() { array.clear(); },
4574 }); 2201 (e) { return e is UnsupportedError; });
4575 Expect.throws(() { 2202 Expect.throws(() { array.length = 0; },
4576 view[10] = 0.0; 2203 (e) { return e is UnsupportedError; });
4577 }, (e) { 2204 Expect.throws(() { array.removeLast(); },
4578 return e is RangeError; 2205 (e) { return e is UnsupportedError; });
4579 }); 2206 Expect.throws(() { array.removeRange(0, array.length - 1); },
4580 Expect.throws(() { 2207 (e) { return e is UnsupportedError; });
4581 array.add(0.0);
4582 }, (e) {
4583 return e is UnsupportedError;
4584 });
4585 Expect.throws(() {
4586 array.addAll([0]);
4587 }, (e) {
4588 return e is UnsupportedError;
4589 });
4590 Expect.throws(() {
4591 array.clear();
4592 }, (e) {
4593 return e is UnsupportedError;
4594 });
4595 Expect.throws(() {
4596 array.length = 0;
4597 }, (e) {
4598 return e is UnsupportedError;
4599 });
4600 Expect.throws(() {
4601 array.removeLast();
4602 }, (e) {
4603 return e is UnsupportedError;
4604 });
4605 Expect.throws(() {
4606 array.removeRange(0, array.length - 1);
4607 }, (e) {
4608 return e is UnsupportedError;
4609 });
4610 for (int i = 0; i < view.length; ++i) { 2208 for (int i = 0; i < view.length; ++i) {
4611 view[i] = 1.0 + i; 2209 view[i] = 1.0 + i;
4612 } 2210 }
4613 Expect 2211 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
4614 .listEquals([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], view); 2212 6.0, 7.0, 8.0, 9.0, 10.0],
4615 Expect.listEquals([ 2213 view);
4616 0xBF800000, 2214 Expect.listEquals([0xBF800000, 0x3F800000,
4617 0x3F800000, 2215 0x40000000, 0x40400000,
4618 0x40000000, 2216 0x40800000, 0x40A00000,
4619 0x40400000, 2217 0x40C00000, 0x40E00000,
4620 0x40800000, 2218 0x41000000, 0x41100000,
4621 0x40A00000, 2219 0x41200000, 0xBF800000],
4622 0x40C00000, 2220 array);
4623 0x40E00000,
4624 0x41000000,
4625 0x41100000,
4626 0x41200000,
4627 0xBF800000
4628 ], array);
4629 // TODO: min, max, and round 2221 // TODO: min, max, and round
4630 for (int i = 0; i < view.length; ++i) { 2222 for (int i = 0; i < view.length; ++i) {
4631 view[i] = i * 1.0; 2223 view[i] = i * 1.0;
4632 } 2224 }
4633 var copy = view.sublist(0, view.length); 2225 var copy = view.sublist(0, view.length);
4634 Expect.isFalse(identical(copy, view)); 2226 Expect.isFalse(identical(copy, view));
4635 Expect.isTrue(copy is Float32List); 2227 Expect.isTrue(copy is Float32List);
4636 Expect.equals(10, copy.length); 2228 Expect.equals(10, copy.length);
4637 Expect.listEquals(view, copy); 2229 Expect.listEquals(view, copy);
4638 var region = view.sublist(3, view.length - 3); 2230 var region = view.sublist(3, view.length - 3);
4639 Expect.isTrue(copy is Float32List); 2231 Expect.isTrue(copy is Float32List);
4640 Expect.equals(4, region.length); 2232 Expect.equals(4, region.length);
4641 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); 2233 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
4642 view.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); 2234 view.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
4643 Expect.listEquals([ 2235 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
4644 0.0, 2236 1.0, double.INFINITY, 7.0, 8.0, 9.0],
4645 1.0, 2237 view);
4646 2.0, 2238 Expect.listEquals([0xBF800000, 0x00000000,
4647 double.NEGATIVE_INFINITY, 2239 0x3F800000, 0x40000000,
4648 0.0, 2240 0xFF800000, 0x00000000,
4649 1.0, 2241 0x3F800000, 0x7F800000,
4650 double.INFINITY, 2242 0x40E00000, 0x41000000,
4651 7.0, 2243 0x41100000, 0xBF800000],
4652 8.0, 2244 array);
4653 9.0
4654 ], view);
4655 Expect.listEquals([
4656 0xBF800000,
4657 0x00000000,
4658 0x3F800000,
4659 0x40000000,
4660 0xFF800000,
4661 0x00000000,
4662 0x3F800000,
4663 0x7F800000,
4664 0x40E00000,
4665 0x41000000,
4666 0x41100000,
4667 0xBF800000
4668 ], array);
4669 } 2245 }
4670 2246
4671 static testFloat32ListView() { 2247 static testFloat32ListView() {
4672 var array = new Uint32List(12); 2248 var array = new Uint32List(12);
4673 testFloat32ListViewImpl(array); 2249 testFloat32ListViewImpl(array);
4674 } 2250 }
4675 2251
4676 static testFloat64ListViewImpl(var array) { 2252 static testFloat64ListViewImpl(var array) {
4677 Expect.isTrue(array is List<int>); 2253 Expect.isTrue(array is List<int>);
4678 Expect.equals(12, array.length); 2254 Expect.equals(12, array.length);
4679 Expect.equals(8, array.elementSizeInBytes); 2255 Expect.equals(8, array.elementSizeInBytes);
4680 Expect.equals(96, array.lengthInBytes); 2256 Expect.equals(96, array.lengthInBytes);
4681 for (int i = 0; i < array.length; ++i) { 2257 for (int i = 0; i < array.length; ++i) {
4682 array[i] = 0xBFF0000000000000; 2258 array[i] = 0xBFF0000000000000;
4683 } 2259 }
4684 Expect.throws(() { 2260 Expect.throws(() { new Float64List.view(array.buffer, -1); },
4685 new Float64List.view(array.buffer, -1); 2261 (e) { return e is RangeError; });
4686 }, (e) { 2262 Expect.throws(() { new Float64List.view(array.buffer, 0, -1); },
4687 return e is RangeError; 2263 (e) { return e is RangeError; });
4688 }); 2264 Expect.throws(() { new Float64List.view(array.buffer,
4689 Expect.throws(() { 2265 array.lengthInBytes + 1); },
4690 new Float64List.view(array.buffer, 0, -1); 2266 (e) { return e is RangeError; });
4691 }, (e) { 2267 Expect.throws(() { new Float64List.view(array.buffer,
4692 return e is RangeError; 2268 0, array.lengthInBytes + 1); },
4693 }); 2269 (e) { return e is RangeError; });
4694 Expect.throws(() { 2270 Expect.throws(() { new Float64List.view(array.buffer,
4695 new Float64List.view(array.buffer, array.lengthInBytes + 1); 2271 array.lengthInBytes - 1, 2); },
4696 }, (e) { 2272 (e) { return e is RangeError; });
4697 return e is RangeError; 2273 var empty = new Float64List.view(array.buffer,
4698 }); 2274 array.lengthInBytes);
4699 Expect.throws(() {
4700 new Float64List.view(array.buffer, 0, array.lengthInBytes + 1);
4701 }, (e) {
4702 return e is RangeError;
4703 });
4704 Expect.throws(() {
4705 new Float64List.view(array.buffer, array.lengthInBytes - 1, 2);
4706 }, (e) {
4707 return e is RangeError;
4708 });
4709 var empty = new Float64List.view(array.buffer, array.lengthInBytes);
4710 Expect.isTrue(empty is List<double>); 2275 Expect.isTrue(empty is List<double>);
4711 Expect.isTrue(empty is Float64List); 2276 Expect.isTrue(empty is Float64List);
4712 Expect.equals(0, empty.length); 2277 Expect.equals(0, empty.length);
4713 var whole = new Float64List.view(array.buffer); 2278 var whole = new Float64List.view(array.buffer);
4714 Expect.isTrue(whole is List<double>); 2279 Expect.isTrue(whole is List<double>);
4715 Expect.isTrue(whole is Float64List); 2280 Expect.isTrue(whole is Float64List);
4716 Expect.equals(12, whole.length); 2281 Expect.equals(12, whole.length);
4717 var view = new Float64List.view(array.buffer, 8, 10); 2282 var view = new Float64List.view(array.buffer, 8, 10);
4718 Expect.isTrue(view is List<double>); 2283 Expect.isTrue(view is List<double>);
4719 Expect.isTrue(view is Float64List); 2284 Expect.isTrue(view is Float64List);
4720 Expect.equals(10, view.length); 2285 Expect.equals(10, view.length);
4721 Expect.equals(8, view.elementSizeInBytes); 2286 Expect.equals(8, view.elementSizeInBytes);
4722 Expect.equals(80, view.lengthInBytes); 2287 Expect.equals(80, view.lengthInBytes);
4723 Expect.listEquals( 2288 Expect.listEquals([-1.0, -1.0, -1.0, -1.0, -1.0,
4724 [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0], view); 2289 -1.0, -1.0, -1.0, -1.0, -1.0],
4725 Expect.throws(() { 2290 view);
4726 view[-1] = 0.0; 2291 Expect.throws(() { view[-1] = 0.0; },
4727 }, (e) { 2292 (e) { return e is RangeError; });
4728 return e is RangeError; 2293 Expect.throws(() { return view[-1]; },
4729 }); 2294 (e) { return e is RangeError; });
4730 Expect.throws(() { 2295 Expect.throws(() { view[10]; },
4731 return view[-1]; 2296 (e) { return e is RangeError; });
4732 }, (e) { 2297 Expect.throws(() { view[10] = 0.0; },
4733 return e is RangeError; 2298 (e) { return e is RangeError; });
4734 }); 2299 Expect.throws(() { array.add(0.0); },
4735 Expect.throws(() { 2300 (e) { return e is UnsupportedError; });
4736 view[10]; 2301 Expect.throws(() { array.addAll([0]); },
4737 }, (e) { 2302 (e) { return e is UnsupportedError; });
4738 return e is RangeError; 2303 Expect.throws(() { array.clear(); },
4739 }); 2304 (e) { return e is UnsupportedError; });
4740 Expect.throws(() { 2305 Expect.throws(() { array.length = 0; },
4741 view[10] = 0.0; 2306 (e) { return e is UnsupportedError; });
4742 }, (e) { 2307 Expect.throws(() { array.removeLast(); },
4743 return e is RangeError; 2308 (e) { return e is UnsupportedError; });
4744 }); 2309 Expect.throws(() { array.removeRange(0, array.length - 1); },
4745 Expect.throws(() { 2310 (e) { return e is UnsupportedError; });
4746 array.add(0.0);
4747 }, (e) {
4748 return e is UnsupportedError;
4749 });
4750 Expect.throws(() {
4751 array.addAll([0]);
4752 }, (e) {
4753 return e is UnsupportedError;
4754 });
4755 Expect.throws(() {
4756 array.clear();
4757 }, (e) {
4758 return e is UnsupportedError;
4759 });
4760 Expect.throws(() {
4761 array.length = 0;
4762 }, (e) {
4763 return e is UnsupportedError;
4764 });
4765 Expect.throws(() {
4766 array.removeLast();
4767 }, (e) {
4768 return e is UnsupportedError;
4769 });
4770 Expect.throws(() {
4771 array.removeRange(0, array.length - 1);
4772 }, (e) {
4773 return e is UnsupportedError;
4774 });
4775 for (int i = 0; i < view.length; ++i) { 2311 for (int i = 0; i < view.length; ++i) {
4776 view[i] = 1.0 + i; 2312 view[i] = 1.0 + i;
4777 } 2313 }
4778 Expect 2314 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
4779 .listEquals([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], view); 2315 6.0, 7.0, 8.0, 9.0, 10.0],
4780 Expect.listEquals([ 2316 view);
4781 0xBFF0000000000000, 2317 Expect.listEquals([0xBFF0000000000000, 0x3FF0000000000000,
4782 0x3FF0000000000000, 2318 0x4000000000000000, 0x4008000000000000,
4783 0x4000000000000000, 2319 0x4010000000000000, 0x4014000000000000,
4784 0x4008000000000000, 2320 0x4018000000000000, 0x401C000000000000,
4785 0x4010000000000000, 2321 0x4020000000000000, 0x4022000000000000,
4786 0x4014000000000000, 2322 0x4024000000000000, 0xBFF0000000000000],
4787 0x4018000000000000, 2323 array);
4788 0x401C000000000000,
4789 0x4020000000000000,
4790 0x4022000000000000,
4791 0x4024000000000000,
4792 0xBFF0000000000000
4793 ], array);
4794 // TODO: min, max 2324 // TODO: min, max
4795 for (int i = 0; i < view.length; ++i) { 2325 for (int i = 0; i < view.length; ++i) {
4796 view[i] = i * 1.0; 2326 view[i] = i * 1.0;
4797 } 2327 }
4798 var copy = view.sublist(0, view.length); 2328 var copy = view.sublist(0, view.length);
4799 Expect.isFalse(identical(copy, view)); 2329 Expect.isFalse(identical(copy, view));
4800 Expect.isTrue(copy is Float64List); 2330 Expect.isTrue(copy is Float64List);
4801 Expect.equals(10, copy.length); 2331 Expect.equals(10, copy.length);
4802 Expect.listEquals(view, copy); 2332 Expect.listEquals(view, copy);
4803 var region = view.sublist(3, view.length - 3); 2333 var region = view.sublist(3, view.length - 3);
4804 Expect.isTrue(copy is Float64List); 2334 Expect.isTrue(copy is Float64List);
4805 Expect.equals(4, region.length); 2335 Expect.equals(4, region.length);
4806 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region); 2336 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
4807 view.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]); 2337 view.setRange(3, 7, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
4808 Expect.listEquals([ 2338 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
4809 0.0, 2339 1.0, double.INFINITY, 7.0, 8.0, 9.0],
4810 1.0, 2340 view);
4811 2.0, 2341 Expect.listEquals([0xBFF0000000000000, 0x0000000000000000,
4812 double.NEGATIVE_INFINITY, 2342 0x3FF0000000000000, 0x4000000000000000,
4813 0.0, 2343 0xFFF0000000000000, 0x0000000000000000,
4814 1.0, 2344 0x3FF0000000000000, 0x7FF0000000000000,
4815 double.INFINITY, 2345 0x401C000000000000, 0x4020000000000000,
4816 7.0, 2346 0x4022000000000000, 0xBFF0000000000000],
4817 8.0, 2347 array);
4818 9.0
4819 ], view);
4820 Expect.listEquals([
4821 0xBFF0000000000000,
4822 0x0000000000000000,
4823 0x3FF0000000000000,
4824 0x4000000000000000,
4825 0xFFF0000000000000,
4826 0x0000000000000000,
4827 0x3FF0000000000000,
4828 0x7FF0000000000000,
4829 0x401C000000000000,
4830 0x4020000000000000,
4831 0x4022000000000000,
4832 0xBFF0000000000000
4833 ], array);
4834 } 2348 }
4835 2349
4836 static testFloat64ListView() { 2350 static testFloat64ListView() {
4837 var array = new Uint64List(12); 2351 var array = new Uint64List(12);
4838 testFloat64ListViewImpl(array); 2352 testFloat64ListViewImpl(array);
4839 } 2353 }
4840 2354
4841 static testMain() { 2355 static testMain() {
4842 testInt8List(); 2356 testInt8List();
4843 testUint8List(); 2357 testUint8List();
(...skipping 16 matching lines...) Expand all
4860 testInt64ListView(); 2374 testInt64ListView();
4861 testUint64ListView(); 2375 testUint64ListView();
4862 testFloat32ListView(); 2376 testFloat32ListView();
4863 testFloat64ListView(); 2377 testFloat64ListView();
4864 2378
4865 testByteList(); 2379 testByteList();
4866 } 2380 }
4867 } 2381 }
4868 2382
4869 main() { 2383 main() {
4870 for (var i = 0; i < 20; i++) { 2384 for (var i=0; i<20; i++) {
4871 ByteArrayTest.testMain(); 2385 ByteArrayTest.testMain();
4872 } 2386 }
4873 } 2387 }
OLDNEW
« no previous file with comments | « runtime/tests/vm/dart/byte_array_optimized_test.dart ('k') | runtime/tests/vm/dart/data_uri_spawn_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698