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

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

Issue 10379018: Revert "Revert "Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 class ByteArrayTest {
2 static testInt8List() {
3 Expect.throws(() { new Int8List(-1); },
4 (e) { return e is IllegalArgumentException; });
5 var array = new Int8List(10);
6 Expect.isTrue(array is List<int>);
7 Expect.equals(10, array.length);
8 Expect.equals(1, array.bytesPerElement());
9 Expect.equals(10, array.lengthInBytes());
10 Expect.listEquals([0, 0, 0, 0, 0,
11 0, 0, 0, 0, 0],
12 array);
13 Expect.throws(() { array[-1] = 0; },
14 (e) { return e is IndexOutOfRangeException; });
15 Expect.throws(() { return array[-1]; },
16 (e) { return e is IndexOutOfRangeException; });
17 Expect.throws(() { array[10]; },
18 (e) { return e is IndexOutOfRangeException; });
19 Expect.throws(() { array[10] = 0; },
20 (e) { return e is IndexOutOfRangeException; });
21 Expect.throws(() { array.add(0); },
22 (e) { return e is UnsupportedOperationException; });
23 Expect.throws(() { array.addAll([0]); },
24 (e) { return e is UnsupportedOperationException; });
25 Expect.throws(() { array.addLast(0); },
26 (e) { return e is UnsupportedOperationException; });
27 Expect.throws(() { array.clear(); },
28 (e) { return e is UnsupportedOperationException; });
29 Expect.throws(() { array.insertRange(0, array.length, 0); },
30 (e) { return e is UnsupportedOperationException; });
31 Expect.throws(() { array.length = 0; },
32 (e) { return e is UnsupportedOperationException; });
33 Expect.throws(() { array.removeLast(); },
34 (e) { return e is UnsupportedOperationException; });
35 Expect.throws(() { array.removeRange(0, array.length - 1); },
36 (e) { return e is UnsupportedOperationException; });
37 for (int i = 0; i < array.length; ++i) {
38 array[i] = 1 + i;
39 }
40 Expect.listEquals([1, 2, 3, 4, 5,
41 6, 7, 8, 9, 10],
42 array);
43 for (int i = 0; i < array.length; ++i) {
44 array[i] = 0x100 + i;
45 }
46 Expect.listEquals([0, 1, 2, 3, 4,
47 5, 6, 7, 8, 9],
48 array);
49 for (int i = 0; i < array.length; ++i) {
50 array[i] = -10 + i;
51 }
52 Expect.listEquals([-10, -9, -8, -7, -6,
53 -5, -4, -3, -2, -1],
54 array);
55 for (int i = 0; i < array.length; ++i) {
56 array[i] = 0x7F - i;
57 }
58 Expect.listEquals([127, 126, 125, 124, 123,
59 122, 121, 120, 119, 118],
60 array);
61 for (int i = 0; i < array.length; ++i) {
62 array[i] = -0x80 + i;
63 }
64 Expect.listEquals([-128, -127, -126, -125, -124,
65 -123, -122, -121, -120, -119],
66 array);
67 for (int i = 0; i < array.length; ++i) {
68 array[i] = i;
69 }
70 var copy = array.getRange(0, array.length);
71 Expect.isFalse(copy === array);
72 Expect.isTrue(copy is Int8List);
73 Expect.equals(10, copy.length);
74 Expect.listEquals(array, copy);
75 var empty = array.getRange(array.length, 0);
76 Expect.equals(0, empty.length);
77 var region = array.getRange(3, array.length - 6);
78 Expect.isTrue(copy is Int8List);
79 Expect.equals(4, region.length);
80 Expect.listEquals([3, 4, 5, 6], region);
81 array.setRange(3, 4, [-128, 0, 1, 127]);
82 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9],
83 array);
84 }
85
86 static testUint8List() {
87 Expect.throws(() { new Uint8List(-1); },
88 (e) { return e is IllegalArgumentException; });
89 var array = new Uint8List(10);
90 Expect.isTrue(array is List<int>);
91 Expect.equals(10, array.length);
92 Expect.equals(1, array.bytesPerElement());
93 Expect.equals(10, array.lengthInBytes());
94 Expect.listEquals([0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0],
96 array);
97 Expect.throws(() { array[-1] = 0; },
98 (e) { return e is IndexOutOfRangeException; });
99 Expect.throws(() { return array[-1]; },
100 (e) { return e is IndexOutOfRangeException; });
101 Expect.throws(() { array[10]; },
102 (e) { return e is IndexOutOfRangeException; });
103 Expect.throws(() { array[10] = 0; },
104 (e) { return e is IndexOutOfRangeException; });
105 Expect.throws(() { array.add(0); },
106 (e) { return e is UnsupportedOperationException; });
107 Expect.throws(() { array.addAll([0]); },
108 (e) { return e is UnsupportedOperationException; });
109 Expect.throws(() { array.addLast(0); },
110 (e) { return e is UnsupportedOperationException; });
111 Expect.throws(() { array.clear(); },
112 (e) { return e is UnsupportedOperationException; });
113 Expect.throws(() { array.insertRange(0, array.length, 0); },
114 (e) { return e is UnsupportedOperationException; });
115 Expect.throws(() { array.length = 0; },
116 (e) { return e is UnsupportedOperationException; });
117 Expect.throws(() { array.removeLast(); },
118 (e) { return e is UnsupportedOperationException; });
119 Expect.throws(() { array.removeRange(0, array.length - 1); },
120 (e) { return e is UnsupportedOperationException; });
121 for (int i = 0; i < array.length; ++i) {
122 array[i] = 1 + i;
123 }
124 Expect.listEquals([1, 2, 3, 4, 5,
125 6, 7, 8, 9, 10],
126 array);
127 for (int i = 0; i < array.length; ++i) {
128 array[i] = 0x100 + i;
129 }
130 Expect.listEquals([0, 1, 2, 3, 4,
131 5, 6, 7, 8, 9],
132 array);
133 for (int i = 0; i < array.length; ++i) {
134 array[i] = 0xFF - i;
135 }
136 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB,
137 0xFA, 0xF9, 0xF8, 0xF7, 0xF6],
138 array);
139 for (int i = 0; i < array.length; ++i) {
140 array[i] = i;
141 }
142 var copy = array.getRange(0, array.length);
143 Expect.isFalse(copy === array);
144 Expect.isTrue(copy is Uint8List);
145 Expect.equals(10, copy.length);
146 Expect.listEquals(array, copy);
147 var empty = array.getRange(array.length, 0);
148 Expect.equals(0, empty.length);
149 var region = array.getRange(3, array.length - 6);
150 Expect.isTrue(copy is Uint8List);
151 Expect.equals(4, region.length);
152 Expect.listEquals([3, 4, 5, 6], region);
153 array.setRange(3, 4, [257, 0, 1, 255]);
154 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9],
155 array);
156 }
157
158 static testInt16List() {
159 Expect.throws(() { new Int16List(-1); },
160 (e) { return e is IllegalArgumentException; });
161 var array = new Int16List(10);
162 Expect.isTrue(array is List<int>);
163 Expect.equals(10, array.length);
164 Expect.equals(2, array.bytesPerElement());
165 Expect.equals(20, array.lengthInBytes());
166 Expect.listEquals([0, 0, 0, 0, 0,
167 0, 0, 0, 0, 0],
168 array);
169 Expect.throws(() { array[-1] = 0; },
170 (e) { return e is IndexOutOfRangeException; });
171 Expect.throws(() { return array[-1]; },
172 (e) { return e is IndexOutOfRangeException; });
173 Expect.throws(() { array[10]; },
174 (e) { return e is IndexOutOfRangeException; });
175 Expect.throws(() { array[10] = 0; },
176 (e) { return e is IndexOutOfRangeException; });
177 Expect.throws(() { array.add(0); },
178 (e) { return e is UnsupportedOperationException; });
179 Expect.throws(() { array.addAll([0]); },
180 (e) { return e is UnsupportedOperationException; });
181 Expect.throws(() { array.addLast(0); },
182 (e) { return e is UnsupportedOperationException; });
183 Expect.throws(() { array.clear(); },
184 (e) { return e is UnsupportedOperationException; });
185 Expect.throws(() { array.insertRange(0, array.length, 0); },
186 (e) { return e is UnsupportedOperationException; });
187 Expect.throws(() { array.length = 0; },
188 (e) { return e is UnsupportedOperationException; });
189 Expect.throws(() { array.removeLast(); },
190 (e) { return e is UnsupportedOperationException; });
191 Expect.throws(() { array.removeRange(0, array.length - 1); },
192 (e) { return e is UnsupportedOperationException; });
193 for (int i = 0; i < array.length; ++i) {
194 array[i] = 1 + i;
195 }
196 Expect.listEquals([1, 2, 3, 4, 5,
197 6, 7, 8, 9, 10],
198 array);
199 for (int i = 0; i < array.length; ++i) {
200 array[i] = 0x10000 + i;
201 }
202 Expect.listEquals([0, 1, 2, 3, 4,
203 5, 6, 7, 8, 9],
204 array);
205 for (int i = 0; i < array.length; ++i) {
206 array[i] = -10 + i;
207 }
208 Expect.listEquals([-10, -9, -8, -7, -6,
209 -5, -4, -3, -2, -1],
210 array);
211 for (int i = 0; i < array.length; ++i) {
212 array[i] = 0x7FFF - i;
213 }
214 Expect.listEquals([0x7FFF, 0x7FFE, 0x7FFD, 0x7FFC, 0x7FFB,
215 0x7FFA, 0x7FF9, 0x7FF8, 0x7FF7, 0x7FF6],
216 array);
217 for (int i = 0; i < array.length; ++i) {
218 array[i] = -0x8000 + i;
219 }
220 Expect.listEquals([-0x8000, -0x7FFF, -0x7FFE, -0x7FFD, -0x7FFC,
221 -0x7FFB, -0x7FFA, -0x7FF9, -0x7FF8, -0x7FF7],
222 array);
223 for (int i = 0; i < array.length; ++i) {
224 array[i] = i;
225 }
226 var copy = array.getRange(0, array.length);
227 Expect.isFalse(copy === array);
228 Expect.isTrue(copy is Int16List);
229 Expect.equals(10, copy.length);
230 Expect.listEquals(array, copy);
231 var empty = array.getRange(array.length, 0);
232 Expect.equals(0, empty.length);
233 var region = array.getRange(3, array.length - 6);
234 Expect.isTrue(copy is Int16List);
235 Expect.equals(4, region.length);
236 Expect.listEquals([3, 4, 5, 6], region);
237 array.setRange(3, 4, [-32768, 0, 1, 32767]);
238 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9],
239 array);
240 }
241
242 static testUint16List() {
243 Expect.throws(() { new Uint16List(-1); },
244 (e) { return e is IllegalArgumentException; });
245 var array = new Uint16List(10);
246 Expect.isTrue(array is List<int>);
247 Expect.equals(10, array.length);
248 Expect.equals(2, array.bytesPerElement());
249 Expect.equals(20, array.lengthInBytes());
250 Expect.listEquals([0, 0, 0, 0, 0,
251 0, 0, 0, 0, 0],
252 array);
253 Expect.throws(() { array[-1] = 0; },
254 (e) { return e is IndexOutOfRangeException; });
255 Expect.throws(() { return array[-1]; },
256 (e) { return e is IndexOutOfRangeException; });
257 Expect.throws(() { array[10]; },
258 (e) { return e is IndexOutOfRangeException; });
259 Expect.throws(() { array[10] = 0; },
260 (e) { return e is IndexOutOfRangeException; });
261 Expect.throws(() { array.add(0); },
262 (e) { return e is UnsupportedOperationException; });
263 Expect.throws(() { array.addAll([0]); },
264 (e) { return e is UnsupportedOperationException; });
265 Expect.throws(() { array.addLast(0); },
266 (e) { return e is UnsupportedOperationException; });
267 Expect.throws(() { array.clear(); },
268 (e) { return e is UnsupportedOperationException; });
269 Expect.throws(() { array.insertRange(0, array.length, 0); },
270 (e) { return e is UnsupportedOperationException; });
271 Expect.throws(() { array.length = 0; },
272 (e) { return e is UnsupportedOperationException; });
273 Expect.throws(() { array.removeLast(); },
274 (e) { return e is UnsupportedOperationException; });
275 Expect.throws(() { array.removeRange(0, array.length - 1); },
276 (e) { return e is UnsupportedOperationException; });
277 for (int i = 0; i < array.length; ++i) {
278 array[i] = 1 + i;
279 }
280 Expect.listEquals([1, 2, 3, 4, 5,
281 6, 7, 8, 9, 10],
282 array);
283 for (int i = 0; i < array.length; ++i) {
284 array[i] = 0x10000 + i;
285 }
286 Expect.listEquals([0, 1, 2, 3, 4,
287 5, 6, 7, 8, 9],
288 array);
289 for (int i = 0; i < array.length; ++i) {
290 array[i] = 0xFFFF - i;
291 }
292 Expect.listEquals([0xFFFF, 0xFFFE, 0xFFFD, 0xFFFC, 0xFFFB,
293 0xFFFA, 0xFFF9, 0xFFF8, 0xFFF7, 0xFFF6],
294 array);
295 for (int i = 0; i < array.length; ++i) {
296 array[i] = i;
297 }
298 var copy = array.getRange(0, array.length);
299 Expect.isFalse(copy === array);
300 Expect.isTrue(copy is Uint16List);
301 Expect.equals(10, copy.length);
302 Expect.listEquals(array, copy);
303 var empty = array.getRange(array.length, 0);
304 Expect.equals(0, empty.length);
305 var region = array.getRange(3, array.length - 6);
306 Expect.isTrue(copy is Uint16List);
307 Expect.equals(4, region.length);
308 Expect.listEquals([3, 4, 5, 6], region);
309 array.setRange(3, 4, [0x10001, 0, 1, 0xFFFF]);
310 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9],
311 array);
312 }
313
314 static testInt32List() {
315 Expect.throws(() { new Int32List(-1); },
316 (e) { return e is IllegalArgumentException; });
317 var array = new Int32List(10);
318 Expect.isTrue(array is List<int>);
319 Expect.equals(10, array.length);
320 Expect.equals(4, array.bytesPerElement());
321 Expect.equals(40, array.lengthInBytes());
322 Expect.listEquals([0, 0, 0, 0, 0,
323 0, 0, 0, 0, 0],
324 array);
325 Expect.throws(() { array[-1] = 0; },
326 (e) { return e is IndexOutOfRangeException; });
327 Expect.throws(() { return array[-1]; },
328 (e) { return e is IndexOutOfRangeException; });
329 Expect.throws(() { array[10]; },
330 (e) { return e is IndexOutOfRangeException; });
331 Expect.throws(() { array[10] = 0; },
332 (e) { return e is IndexOutOfRangeException; });
333 Expect.throws(() { array.add(0); },
334 (e) { return e is UnsupportedOperationException; });
335 Expect.throws(() { array.addAll([0]); },
336 (e) { return e is UnsupportedOperationException; });
337 Expect.throws(() { array.addLast(0); },
338 (e) { return e is UnsupportedOperationException; });
339 Expect.throws(() { array.clear(); },
340 (e) { return e is UnsupportedOperationException; });
341 Expect.throws(() { array.insertRange(0, array.length, 0); },
342 (e) { return e is UnsupportedOperationException; });
343 Expect.throws(() { array.length = 0; },
344 (e) { return e is UnsupportedOperationException; });
345 Expect.throws(() { array.removeLast(); },
346 (e) { return e is UnsupportedOperationException; });
347 Expect.throws(() { array.removeRange(0, array.length - 1); },
348 (e) { return e is UnsupportedOperationException; });
349 for (int i = 0; i < array.length; ++i) {
350 array[i] = 1 + i;
351 }
352 Expect.listEquals([1, 2, 3, 4, 5,
353 6, 7, 8, 9, 10],
354 array);
355 for (int i = 0; i < array.length; ++i) {
356 array[i] = 0x100000000 + i;
357 }
358 Expect.listEquals([0, 1, 2, 3, 4,
359 5, 6, 7, 8, 9],
360 array);
361 for (int i = 0; i < array.length; ++i) {
362 array[i] = -10 + i;
363 }
364 Expect.listEquals([-10, -9, -8, -7, -6,
365 -5, -4, -3, -2, -1],
366 array);
367 for (int i = 0; i < array.length; ++i) {
368 array[i] = 0x7FFFFFFF - i;
369 }
370 Expect.listEquals([0x7FFFFFFF, 0x7FFFFFFE,
371 0x7FFFFFFD, 0x7FFFFFFC,
372 0x7FFFFFFB, 0x7FFFFFFA,
373 0x7FFFFFF9, 0x7FFFFFF8,
374 0x7FFFFFF7, 0x7FFFFFF6],
375 array);
376 for (int i = 0; i < array.length; ++i) {
377 array[i] = -0x80000000 + i;
378 }
379 Expect.listEquals([-0x80000000, -0x7FFFFFFF,
380 -0x7FFFFFFE, -0x7FFFFFFD,
381 -0x7FFFFFFC, -0x7FFFFFFB,
382 -0x7FFFFFFA, -0x7FFFFFF9,
383 -0x7FFFFFF8, -0x7FFFFFF7],
384 array);
385 for (int i = 0; i < array.length; ++i) {
386 array[i] = i;
387 }
388 var copy = array.getRange(0, array.length);
389 Expect.isFalse(copy === array);
390 Expect.isTrue(copy is Int32List);
391 Expect.equals(10, copy.length);
392 Expect.listEquals(array, copy);
393 var empty = array.getRange(array.length, 0);
394 Expect.equals(0, empty.length);
395 var region = array.getRange(3, array.length - 6);
396 Expect.isTrue(copy is Int32List);
397 Expect.equals(4, region.length);
398 Expect.listEquals([3, 4, 5, 6], region);
399 array.setRange(3, 4, [-0x80000000, 0, 1, 0x7FFFFFFF]);
400 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9],
401 array);
402 }
403
404 static testUint32List() {
405 Expect.throws(() { new Uint32List(-1); },
406 (e) { return e is IllegalArgumentException; });
407 var array = new Uint32List(10);
408 Expect.isTrue(array is List<int>);
409 Expect.equals(10, array.length);
410 Expect.equals(4, array.bytesPerElement());
411 Expect.equals(40, array.lengthInBytes());
412 Expect.listEquals([0, 0, 0, 0, 0,
413 0, 0, 0, 0, 0],
414 array);
415 Expect.throws(() { array[-1] = 0; },
416 (e) { return e is IndexOutOfRangeException; });
417 Expect.throws(() { return array[-1]; },
418 (e) { return e is IndexOutOfRangeException; });
419 Expect.throws(() { array[10]; },
420 (e) { return e is IndexOutOfRangeException; });
421 Expect.throws(() { array[10] = 0; },
422 (e) { return e is IndexOutOfRangeException; });
423 Expect.throws(() { array.add(0); },
424 (e) { return e is UnsupportedOperationException; });
425 Expect.throws(() { array.addAll([0]); },
426 (e) { return e is UnsupportedOperationException; });
427 Expect.throws(() { array.addLast(0); },
428 (e) { return e is UnsupportedOperationException; });
429 Expect.throws(() { array.clear(); },
430 (e) { return e is UnsupportedOperationException; });
431 Expect.throws(() { array.insertRange(0, array.length, 0); },
432 (e) { return e is UnsupportedOperationException; });
433 Expect.throws(() { array.length = 0; },
434 (e) { return e is UnsupportedOperationException; });
435 Expect.throws(() { array.removeLast(); },
436 (e) { return e is UnsupportedOperationException; });
437 Expect.throws(() { array.removeRange(0, array.length - 1); },
438 (e) { return e is UnsupportedOperationException; });
439 for (int i = 0; i < array.length; ++i) {
440 array[i] = 1 + i;
441 }
442 Expect.listEquals([1, 2, 3, 4, 5,
443 6, 7, 8, 9, 10],
444 array);
445 for (int i = 0; i < array.length; ++i) {
446 array[i] = 0x100000000 + i;
447 }
448 Expect.listEquals([0, 1, 2, 3, 4,
449 5, 6, 7, 8, 9],
450 array);
451 for (int i = 0; i < array.length; ++i) {
452 array[i] = 0xFFFFFFFF - i;
453 }
454 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFE,
455 0xFFFFFFFD, 0xFFFFFFFC,
456 0xFFFFFFFB, 0xFFFFFFFA,
457 0xFFFFFFF9, 0xFFFFFFF8,
458 0xFFFFFFF7, 0xFFFFFFF6],
459 array);
460 for (int i = 0; i < array.length; ++i) {
461 array[i] = i;
462 }
463 var copy = array.getRange(0, array.length);
464 Expect.isFalse(copy === array);
465 Expect.isTrue(copy is Uint32List);
466 Expect.equals(10, copy.length);
467 Expect.listEquals(array, copy);
468 var empty = array.getRange(array.length, 0);
469 Expect.equals(0, empty.length);
470 var region = array.getRange(3, array.length - 6);
471 Expect.isTrue(copy is Uint32List);
472 Expect.equals(4, region.length);
473 Expect.listEquals([3, 4, 5, 6], region);
474 array.setRange(3, 4, [0x100000001, 0, 1, 0xFFFFFFFF]);
475 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9],
476 array);
477 }
478
479 static testInt64List() {
480 Expect.throws(() { new Int64List(-1); },
481 (e) { return e is IllegalArgumentException; });
482 var array = new Int64List(10);
483 Expect.isTrue(array is List<int>);
484 Expect.equals(10, array.length);
485 Expect.equals(8, array.bytesPerElement());
486 Expect.equals(80, array.lengthInBytes());
487 Expect.listEquals([0, 0, 0, 0, 0,
488 0, 0, 0, 0, 0],
489 array);
490 Expect.throws(() { array[-1] = 0; },
491 (e) { return e is IndexOutOfRangeException; });
492 Expect.throws(() { return array[-1]; },
493 (e) { return e is IndexOutOfRangeException; });
494 Expect.throws(() { array[10]; },
495 (e) { return e is IndexOutOfRangeException; });
496 Expect.throws(() { array[10] = 0; },
497 (e) { return e is IndexOutOfRangeException; });
498 Expect.throws(() { array.add(0); },
499 (e) { return e is UnsupportedOperationException; });
500 Expect.throws(() { array.addAll([0]); },
501 (e) { return e is UnsupportedOperationException; });
502 Expect.throws(() { array.addLast(0); },
503 (e) { return e is UnsupportedOperationException; });
504 Expect.throws(() { array.clear(); },
505 (e) { return e is UnsupportedOperationException; });
506 Expect.throws(() { array.insertRange(0, array.length, 0); },
507 (e) { return e is UnsupportedOperationException; });
508 Expect.throws(() { array.length = 0; },
509 (e) { return e is UnsupportedOperationException; });
510 Expect.throws(() { array.removeLast(); },
511 (e) { return e is UnsupportedOperationException; });
512 Expect.throws(() { array.removeRange(0, array.length - 1); },
513 (e) { return e is UnsupportedOperationException; });
514 for (int i = 0; i < array.length; ++i) {
515 array[i] = 1 + i;
516 }
517 Expect.listEquals([1, 2, 3, 4, 5,
518 6, 7, 8, 9, 10],
519 array);
520 for (int i = 0; i < array.length; ++i) {
521 array[i] = 0x10000000000000000 + i;
522 }
523 Expect.listEquals([0, 1, 2, 3, 4,
524 5, 6, 7, 8, 9],
525 array);
526 for (int i = 0; i < array.length; ++i) {
527 array[i] = -10 + i;
528 }
529 Expect.listEquals([-10, -9, -8, -7, -6,
530 -5, -4, -3, -2, -1],
531 array);
532 for (int i = 0; i < array.length; ++i) {
533 array[i] = 0x7FFFFFFFFFFFFFFF - i;
534 }
535 Expect.listEquals([0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFE,
536 0x7FFFFFFFFFFFFFFD, 0x7FFFFFFFFFFFFFFC,
537 0x7FFFFFFFFFFFFFFB, 0x7FFFFFFFFFFFFFFA,
538 0x7FFFFFFFFFFFFFF9, 0x7FFFFFFFFFFFFFF8,
539 0x7FFFFFFFFFFFFFF7, 0x7FFFFFFFFFFFFFF6],
540 array);
541 for (int i = 0; i < array.length; ++i) {
542 array[i] = -0x8000000000000000 + i;
543 }
544 Expect.listEquals([-0x8000000000000000, -0x7FFFFFFFFFFFFFFF,
545 -0x7FFFFFFFFFFFFFFE, -0x7FFFFFFFFFFFFFFD,
546 -0x7FFFFFFFFFFFFFFC, -0x7FFFFFFFFFFFFFFB,
547 -0x7FFFFFFFFFFFFFFA, -0x7FFFFFFFFFFFFFF9,
548 -0x7FFFFFFFFFFFFFF8, -0x7FFFFFFFFFFFFFF7],
549 array);
550 for (int i = 0; i < array.length; ++i) {
551 array[i] = i;
552 }
553 var copy = array.getRange(0, array.length);
554 Expect.isFalse(copy === array);
555 Expect.isTrue(copy is Int64List);
556 Expect.equals(10, copy.length);
557 Expect.listEquals(array, copy);
558 var empty = array.getRange(array.length, 0);
559 Expect.equals(0, empty.length);
560 var region = array.getRange(3, array.length - 6);
561 Expect.isTrue(copy is Int64List);
562 Expect.equals(4, region.length);
563 Expect.listEquals([3, 4, 5, 6], region);
564 array.setRange(3, 4, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]);
565 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0,
566 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9],
567 array);
568 }
569
570 static testUint64List() {
571 Expect.throws(() { new Uint64List(-1); },
572 (e) { return e is IllegalArgumentException; });
573 var array = new Uint64List(10);
574 Expect.isTrue(array is List<int>);
575 Expect.equals(10, array.length);
576 Expect.equals(8, array.bytesPerElement());
577 Expect.equals(80, array.lengthInBytes());
578 Expect.listEquals([0, 0, 0, 0, 0,
579 0, 0, 0, 0, 0],
580 array);
581 Expect.throws(() { array[-1] = 0; },
582 (e) { return e is IndexOutOfRangeException; });
583 Expect.throws(() { return array[-1]; },
584 (e) { return e is IndexOutOfRangeException; });
585 Expect.throws(() { array[10]; },
586 (e) { return e is IndexOutOfRangeException; });
587 Expect.throws(() { array[10] = 0; },
588 (e) { return e is IndexOutOfRangeException; });
589 Expect.throws(() { array.add(0); },
590 (e) { return e is UnsupportedOperationException; });
591 Expect.throws(() { array.addAll([0]); },
592 (e) { return e is UnsupportedOperationException; });
593 Expect.throws(() { array.addLast(0); },
594 (e) { return e is UnsupportedOperationException; });
595 Expect.throws(() { array.clear(); },
596 (e) { return e is UnsupportedOperationException; });
597 Expect.throws(() { array.insertRange(0, array.length, 0); },
598 (e) { return e is UnsupportedOperationException; });
599 Expect.throws(() { array.length = 0; },
600 (e) { return e is UnsupportedOperationException; });
601 Expect.throws(() { array.removeLast(); },
602 (e) { return e is UnsupportedOperationException; });
603 Expect.throws(() { array.removeRange(0, array.length - 1); },
604 (e) { return e is UnsupportedOperationException; });
605 for (int i = 0; i < array.length; ++i) {
606 array[i] = 1 + i;
607 }
608 Expect.listEquals([1, 2, 3, 4, 5,
609 6, 7, 8, 9, 10],
610 array);
611 for (int i = 0; i < array.length; ++i) {
612 array[i] = 0x10000000000000000 + i;
613 }
614 Expect.listEquals([0, 1, 2, 3, 4,
615 5, 6, 7, 8, 9],
616 array);
617 for (int i = 0; i < array.length; ++i) {
618 array[i] = 0xFFFFFFFFFFFFFFFF - i;
619 }
620 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFE,
621 0xFFFFFFFFFFFFFFFD, 0xFFFFFFFFFFFFFFFC,
622 0xFFFFFFFFFFFFFFFB, 0xFFFFFFFFFFFFFFFA,
623 0xFFFFFFFFFFFFFFF9, 0xFFFFFFFFFFFFFFF8,
624 0xFFFFFFFFFFFFFFF7, 0xFFFFFFFFFFFFFFF6],
625 array);
626 for (int i = 0; i < array.length; ++i) {
627 array[i] = i;
628 }
629 var copy = array.getRange(0, array.length);
630 Expect.isFalse(copy === array);
631 Expect.isTrue(copy is Uint64List);
632 Expect.equals(10, copy.length);
633 Expect.listEquals(array, copy);
634 var empty = array.getRange(array.length, 0);
635 Expect.equals(0, empty.length);
636 var region = array.getRange(3, array.length - 6);
637 Expect.isTrue(copy is Uint64List);
638 Expect.equals(4, region.length);
639 Expect.listEquals([3, 4, 5, 6], region);
640 array.setRange(3, 4, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]);
641 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9],
642 array);
643 }
644
645 static testFloat32List() {
646 Expect.throws(() { new Float32List(-1); },
647 (e) { return e is IllegalArgumentException; });
648 var array = new Float32List(10);
649 Expect.isTrue(array is List<double>);
650 Expect.equals(10, array.length);
651 Expect.equals(4, array.bytesPerElement());
652 Expect.equals(40, array.lengthInBytes());
653 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0,
654 0.0, 0.0, 0.0, 0.0, 0.0],
655 array);
656 Expect.throws(() { array[-1] = 0.0; },
657 (e) { return e is IndexOutOfRangeException; });
658 Expect.throws(() { return array[-1]; },
659 (e) { return e is IndexOutOfRangeException; });
660 Expect.throws(() { array[10]; },
661 (e) { return e is IndexOutOfRangeException; });
662 Expect.throws(() { array[10] = 0.0; },
663 (e) { return e is IndexOutOfRangeException; });
664 Expect.throws(() { array.add(0.0); },
665 (e) { return e is UnsupportedOperationException; });
666 Expect.throws(() { array.addAll([0]); },
667 (e) { return e is UnsupportedOperationException; });
668 Expect.throws(() { array.addLast(0.0); },
669 (e) { return e is UnsupportedOperationException; });
670 Expect.throws(() { array.clear(); },
671 (e) { return e is UnsupportedOperationException; });
672 Expect.throws(() { array.insertRange(0, array.length, 0.0); },
673 (e) { return e is UnsupportedOperationException; });
674 Expect.throws(() { array.length = 0; },
675 (e) { return e is UnsupportedOperationException; });
676 Expect.throws(() { array.removeLast(); },
677 (e) { return e is UnsupportedOperationException; });
678 Expect.throws(() { array.removeRange(0, array.length - 1); },
679 (e) { return e is UnsupportedOperationException; });
680 for (int i = 0; i < array.length; ++i) {
681 array[i] = 1.0 + i;
682 }
683 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
684 6.0, 7.0, 8.0, 9.0, 10.0],
685 array);
686 // TODO: min, max, and round
687 for (int i = 0; i < array.length; ++i) {
688 array[i] = i * 1.0;
689 }
690 var copy = array.getRange(0, array.length);
691 Expect.isFalse(copy === array);
692 Expect.isTrue(copy is Float32List);
693 Expect.equals(10, copy.length);
694 Expect.listEquals(array, copy);
695 var empty = array.getRange(array.length, 0);
696 Expect.equals(0, empty.length);
697 var region = array.getRange(3, array.length - 6);
698 Expect.isTrue(copy is Float32List);
699 Expect.equals(4, region.length);
700 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
701 array.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
702 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
703 1.0, double.INFINITY, 7.0, 8.0, 9.0],
704 array);
705 }
706
707 static testFloat64List() {
708 Expect.throws(() { new Float64List(-1); },
709 (e) { return e is IllegalArgumentException; });
710 var array = new Float64List(10);
711 Expect.isTrue(array is List<double>);
712 Expect.equals(10, array.length);
713 Expect.equals(8, array.bytesPerElement());
714 Expect.equals(80, array.lengthInBytes());
715 Expect.listEquals([0.0, 0.0, 0.0, 0.0, 0.0,
716 0.0, 0.0, 0.0, 0.0, 0.0],
717 array);
718 Expect.throws(() { array[-1] = 0.0; },
719 (e) { return e is IndexOutOfRangeException; });
720 Expect.throws(() { return array[-1]; },
721 (e) { return e is IndexOutOfRangeException; });
722 Expect.throws(() { array[10]; },
723 (e) { return e is IndexOutOfRangeException; });
724 Expect.throws(() { array[10] = 0.0; },
725 (e) { return e is IndexOutOfRangeException; });
726 Expect.throws(() { array.add(0.0); },
727 (e) { return e is UnsupportedOperationException; });
728 Expect.throws(() { array.addAll([0]); },
729 (e) { return e is UnsupportedOperationException; });
730 Expect.throws(() { array.addLast(0.0); },
731 (e) { return e is UnsupportedOperationException; });
732 Expect.throws(() { array.clear(); },
733 (e) { return e is UnsupportedOperationException; });
734 Expect.throws(() { array.insertRange(0, array.length, 0.0); },
735 (e) { return e is UnsupportedOperationException; });
736 Expect.throws(() { array.length = 0; },
737 (e) { return e is UnsupportedOperationException; });
738 Expect.throws(() { array.removeLast(); },
739 (e) { return e is UnsupportedOperationException; });
740 Expect.throws(() { array.removeRange(0, array.length - 1); },
741 (e) { return e is UnsupportedOperationException; });
742 for (int i = 0; i < array.length; ++i) {
743 array[i] = 1.0 + i;
744 }
745 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
746 6.0, 7.0, 8.0, 9.0, 10.0],
747 array);
748 // TODO: min, max
749 for (int i = 0; i < array.length; ++i) {
750 array[i] = i * 1.0;
751 }
752 var copy = array.getRange(0, array.length);
753 Expect.isFalse(copy === array);
754 Expect.isTrue(copy is Float64List);
755 Expect.equals(10, copy.length);
756 Expect.listEquals(array, copy);
757 var empty = array.getRange(array.length, 0);
758 Expect.equals(0, empty.length);
759 var region = array.getRange(3, array.length - 6);
760 Expect.isTrue(copy is Float64List);
761 Expect.equals(4, region.length);
762 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
763 array.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
764 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
765 1.0, double.INFINITY, 7.0, 8.0, 9.0],
766 array);
767 }
768
769 static testByteList() {
770 var array = new Uint8List(8);
771 Expect.equals(8, array.length);
772 Expect.equals(8, array.lengthInBytes());
773 var byte_array = array.asByteArray(0, array.lengthInBytes());
774 Expect.equals(8, byte_array.lengthInBytes());
775 Expect.throws(() { byte_array.getInt8(-1); },
776 (e) { return e is IndexOutOfRangeException; });
777 Expect.throws(() { byte_array.getUint8(-1); },
778 (e) { return e is IndexOutOfRangeException; });
779 Expect.throws(() { byte_array.getInt16(-1); },
780 (e) { return e is IndexOutOfRangeException; });
781 Expect.throws(() { byte_array.getUint16(-1); },
782 (e) { return e is IndexOutOfRangeException; });
783 Expect.throws(() { byte_array.getInt32(-1); },
784 (e) { return e is IndexOutOfRangeException; });
785 Expect.throws(() { byte_array.getUint32(-1); },
786 (e) { return e is IndexOutOfRangeException; });
787 Expect.throws(() { byte_array.getInt64(-1); },
788 (e) { return e is IndexOutOfRangeException; });
789 Expect.throws(() { byte_array.getUint64(-1); },
790 (e) { return e is IndexOutOfRangeException; });
791 Expect.throws(() { byte_array.getFloat32(-1); },
792 (e) { return e is IndexOutOfRangeException; });
793 Expect.throws(() { byte_array.getFloat64(-1); },
794 (e) { return e is IndexOutOfRangeException; });
795 Expect.throws(() { byte_array.setInt8(-1, 0); },
796 (e) { return e is IndexOutOfRangeException; });
797 Expect.throws(() { byte_array.setUint8(-1, 0); },
798 (e) { return e is IndexOutOfRangeException; });
799 Expect.throws(() { byte_array.setInt16(-1, 0); },
800 (e) { return e is IndexOutOfRangeException; });
801 Expect.throws(() { byte_array.setUint16(-1, 0); },
802 (e) { return e is IndexOutOfRangeException; });
803 Expect.throws(() { byte_array.setInt32(-1, 0); },
804 (e) { return e is IndexOutOfRangeException; });
805 Expect.throws(() { byte_array.setUint32(-1, 0); },
806 (e) { return e is IndexOutOfRangeException; });
807 Expect.throws(() { byte_array.setInt64(-1, 0); },
808 (e) { return e is IndexOutOfRangeException; });
809 Expect.throws(() { byte_array.setUint64(-1, 0); },
810 (e) { return e is IndexOutOfRangeException; });
811 Expect.throws(() { byte_array.setFloat32(-1, 0.0); },
812 (e) { return e is IndexOutOfRangeException; });
813 Expect.throws(() { byte_array.setFloat64(-1, 0.0); },
814 (e) { return e is IndexOutOfRangeException; });
815 Expect.throws(() { byte_array.getInt8(8); },
816 (e) { return e is IndexOutOfRangeException; });
817 Expect.throws(() { byte_array.getUint8(8); },
818 (e) { return e is IndexOutOfRangeException; });
819 Expect.throws(() { byte_array.getInt16(8); },
820 (e) { return e is IndexOutOfRangeException; });
821 Expect.throws(() { byte_array.getUint16(8); },
822 (e) { return e is IndexOutOfRangeException; });
823 Expect.throws(() { byte_array.getInt32(8); },
824 (e) { return e is IndexOutOfRangeException; });
825 Expect.throws(() { byte_array.getUint32(8); },
826 (e) { return e is IndexOutOfRangeException; });
827 Expect.throws(() { byte_array.getInt64(8); },
828 (e) { return e is IndexOutOfRangeException; });
829 Expect.throws(() { byte_array.getUint64(8); },
830 (e) { return e is IndexOutOfRangeException; });
831 Expect.throws(() { byte_array.getFloat32(8); },
832 (e) { return e is IndexOutOfRangeException; });
833 Expect.throws(() { byte_array.getFloat64(8); },
834 (e) { return e is IndexOutOfRangeException; });
835 Expect.throws(() { byte_array.setInt8(8, 0); },
836 (e) { return e is IndexOutOfRangeException; });
837 Expect.throws(() { byte_array.setUint8(8, 0); },
838 (e) { return e is IndexOutOfRangeException; });
839 Expect.throws(() { byte_array.setInt16(8, 0); },
840 (e) { return e is IndexOutOfRangeException; });
841 Expect.throws(() { byte_array.setUint16(8, 0); },
842 (e) { return e is IndexOutOfRangeException; });
843 Expect.throws(() { byte_array.setInt32(8, 0); },
844 (e) { return e is IndexOutOfRangeException; });
845 Expect.throws(() { byte_array.setUint32(8, 0); },
846 (e) { return e is IndexOutOfRangeException; });
847 Expect.throws(() { byte_array.setInt64(8, 0); },
848 (e) { return e is IndexOutOfRangeException; });
849 Expect.throws(() { byte_array.setUint64(8, 0); },
850 (e) { return e is IndexOutOfRangeException; });
851 Expect.throws(() { byte_array.setFloat32(8, 0.0); },
852 (e) { return e is IndexOutOfRangeException; });
853 Expect.throws(() { byte_array.setFloat64(8, 0.0); },
854 (e) { return e is IndexOutOfRangeException; });
855 Expect.equals(0, byte_array.getInt8(0));
856 Expect.equals(0, byte_array.getUint8(0));
857 Expect.equals(0, byte_array.getInt16(0));
858 Expect.equals(0, byte_array.getUint16(0));
859 Expect.equals(0, byte_array.getInt32(0));
860 Expect.equals(0, byte_array.getUint32(0));
861 Expect.equals(0, byte_array.getInt64(0));
862 Expect.equals(0, byte_array.getUint64(0));
863 Expect.equals(0.0, byte_array.getFloat32(0));
864 Expect.equals(0.0, byte_array.getFloat64(0));
865 for (int i = 0; i < array.length; ++i) {
866 array[i] = 0xFF;
867 }
868 Expect.equals(-1, byte_array.getInt8(0));
869 Expect.equals(0xFF, byte_array.getUint8(0));
870 Expect.equals(-1, byte_array.getInt16(0));
871 Expect.equals(0xFFFF, byte_array.getUint16(0));
872 Expect.equals(-1, byte_array.getInt32(0));
873 Expect.equals(0xFFFFFFFF, byte_array.getUint32(0));
874 Expect.equals(-1, byte_array.getInt64(0));
875 Expect.equals(0xFFFFFFFFFFFFFFFF, byte_array.getUint64(0));
876 Expect.isTrue(byte_array.getFloat32(0).isNaN());
877 Expect.isTrue(byte_array.getFloat64(0).isNaN());
878 for (int i = 0; i < array.length; ++i) {
879 array[i] = 0xFF - i;
880 }
881 byte_array.setUint32(0, 0xBF800000);
882 Expect.equals(0, byte_array.getInt8(0));
883 Expect.equals(0, byte_array.getInt8(1));
884 Expect.equals(-128, byte_array.getInt8(2));
885 Expect.equals(-65, byte_array.getInt8(3));
886 Expect.equals(-5, byte_array.getInt8(4));
887 Expect.equals(-6, byte_array.getInt8(5));
888 Expect.equals(-7, byte_array.getInt8(6));
889 Expect.equals(-8, byte_array.getInt8(7));
890 Expect.equals(0x00, byte_array.getUint8(0));
891 Expect.equals(0x00, byte_array.getUint8(1));
892 Expect.equals(0x80, byte_array.getUint8(2));
893 Expect.equals(0xBF, byte_array.getUint8(3));
894 Expect.equals(0xFB, byte_array.getUint8(4));
895 Expect.equals(0xFA, byte_array.getUint8(5));
896 Expect.equals(0xF9, byte_array.getUint8(6));
897 Expect.equals(0xF8, byte_array.getUint8(7));
898 Expect.equals(0, byte_array.getInt16(0));
899 Expect.equals(-16512, byte_array.getInt16(2));
900 Expect.equals(-1285, byte_array.getInt16(4));
901 Expect.equals(-1799, byte_array.getInt16(6));
902 Expect.equals(0x0000, byte_array.getUint16(0));
903 Expect.equals(0xBF80, byte_array.getUint16(2));
904 Expect.equals(0xFAFB, byte_array.getUint16(4));
905 Expect.equals(0xF8F9, byte_array.getUint16(6));
906 Expect.equals(-1082130432, byte_array.getInt32(0));
907 Expect.equals(0xBF800000, byte_array.getUint32(0));
908 Expect.equals(-506097523945897984, byte_array.getInt64(0));
909 Expect.equals(0xF8F9FAFBBF800000, byte_array.getUint64(0));
910 Expect.equals(-1.0, byte_array.getFloat32(0));
911 // TODO: byte_array.getFloat64(0)
912 }
913
914 static testInt8ListView() {
915 var array = new Uint8List(12);
916 Expect.equals(12, array.length);
917 Expect.equals(1, array.bytesPerElement());
918 Expect.equals(12, array.lengthInBytes());
919 for (int i = 0; i < array.length; ++i) {
920 array[i] = 0xFF;
921 }
922 Expect.throws(() { new Int8List.view(array.asByteArray(), -1); },
923 (e) { return e is IndexOutOfRangeException; });
924 Expect.throws(() { new Int8List.view(array.asByteArray(), 0, -1); },
925 (e) { return e is IndexOutOfRangeException; });
926 Expect.throws(() { new Int8List.view(array.asByteArray(),
927 array.length); },
928 (e) { return e is IndexOutOfRangeException; });
929 Expect.throws(() { new Int8List.view(array.asByteArray(),
930 0, array.length + 1); },
931 (e) { return e is IndexOutOfRangeException; });
932 Expect.throws(() { new Int8List.view(array.asByteArray(),
933 array.length - 1, 2); },
934 (e) { return e is IndexOutOfRangeException; });
935 var view = new Int8List.view(array.asByteArray(), 1, array.length - 2);
936 Expect.isTrue(view is List<int>);
937 Expect.isTrue(view is Int8List);
938 Expect.equals(10, view.length);
939 Expect.equals(1, view.bytesPerElement());
940 Expect.equals(10, view.lengthInBytes());
941 Expect.listEquals([-1, -1, -1, -1, -1,
942 -1, -1, -1, -1, -1],
943 view);
944 Expect.throws(() { view[-1] = 0; },
945 (e) { return e is IndexOutOfRangeException; });
946 Expect.throws(() { return view[-1]; },
947 (e) { return e is IndexOutOfRangeException; });
948 Expect.throws(() { view[view.length]; },
949 (e) { return e is IndexOutOfRangeException; });
950 Expect.throws(() { view[10] = 0; },
951 (e) { return e is IndexOutOfRangeException; });
952 Expect.throws(() { view.add(0); },
953 (e) { return e is UnsupportedOperationException; });
954 Expect.throws(() { view.addAll([0]); },
955 (e) { return e is UnsupportedOperationException; });
956 Expect.throws(() { view.addLast(0); },
957 (e) { return e is UnsupportedOperationException; });
958 Expect.throws(() { view.clear(); },
959 (e) { return e is UnsupportedOperationException; });
960 Expect.throws(() { view.insertRange(0, view.length, 0); },
961 (e) { return e is UnsupportedOperationException; });
962 Expect.throws(() { view.length = 0; },
963 (e) { return e is UnsupportedOperationException; });
964 Expect.throws(() { view.removeLast(); },
965 (e) { return e is UnsupportedOperationException; });
966 Expect.throws(() { view.removeRange(0, view.length - 1); },
967 (e) { return e is UnsupportedOperationException; });
968 for (int i = 0; i < view.length; ++i) {
969 view[i] = 1 + i;
970 }
971 Expect.listEquals([1, 2, 3, 4, 5,
972 6, 7, 8, 9, 10],
973 view);
974 Expect.listEquals([0xFF, 1, 2, 3, 4, 5,
975 6, 7, 8, 9, 10, 0xFF],
976 array);
977 for (int i = 0; i < view.length; ++i) {
978 view[i] = 0x100 + i;
979 }
980 Expect.listEquals([0, 1, 2, 3, 4,
981 5, 6, 7, 8, 9],
982 view);
983 Expect.listEquals([0xFF, 0, 1, 2, 3, 4,
984 5, 6, 7, 8, 9, 0xFF],
985 array);
986 for (int i = 0; i < view.length; ++i) {
987 view[i] = -10 + i;
988 }
989 Expect.listEquals([-10, -9, -8, -7, -6,
990 -5, -4, -3, -2, -1],
991 view);
992 Expect.listEquals([0xFF, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
993 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0xFF],
994 array);
995 for (int i = 0; i < view.length; ++i) {
996 view[i] = 0x7F - i;
997 }
998 Expect.listEquals([127, 126, 125, 124, 123,
999 122, 121, 120, 119, 118],
1000 view);
1001 Expect.listEquals([0xFF, 127, 126, 125, 124, 123,
1002 122, 121, 120, 119, 118, 0xFF],
1003 array);
1004 for (int i = 0; i < view.length; ++i) {
1005 view[i] = -0x80 + i;
1006 }
1007 Expect.listEquals([-128, -127, -126, -125, -124,
1008 -123, -122, -121, -120, -119],
1009 view);
1010 Expect.listEquals([0xFF, 0x80, 0x81, 0x82, 0x83, 0x84,
1011 0x85, 0x86, 0x87, 0x88, 0x89, 0xFF],
1012 array);
1013 for (int i = 0; i < view.length; ++i) {
1014 view[i] = i;
1015 }
1016 var copy = view.getRange(0, view.length);
1017 Expect.isFalse(copy === view);
1018 Expect.isTrue(copy is Int8List);
1019 Expect.equals(10, copy.length);
1020 Expect.listEquals(view, copy);
1021 var region = view.getRange(3, view.length - 6);
1022 Expect.isTrue(copy is Int8List);
1023 Expect.equals(4, region.length);
1024 Expect.listEquals([3, 4, 5, 6], region);
1025 view.setRange(3, 4, [-128, 0, 1, 127]);
1026 Expect.listEquals([0, 1, 2, -128, 0, 1, 127, 7, 8, 9],
1027 view);
1028 Expect.listEquals([0xFF, 0, 1, 2, 128, 0, 1, 127, 7, 8, 9, 0xFF],
1029 array);
1030 }
1031
1032 static testUint8ListView() {
1033 var array = new Int8List(12);
1034 Expect.isTrue(array is List<int>);
1035 Expect.equals(12, array.length);
1036 Expect.equals(1, array.bytesPerElement());
1037 Expect.equals(12, array.lengthInBytes());
1038 for (int i = 0; i < array.length; ++i) {
1039 array[i] = -1;
1040 }
1041 Expect.throws(() { new Uint8List.view(array.asByteArray(), -1); },
1042 (e) { return e is IndexOutOfRangeException; });
1043 Expect.throws(() { new Uint8List.view(array.asByteArray(), 0, -1); },
1044 (e) { return e is IndexOutOfRangeException; });
1045 Expect.throws(() { new Uint8List.view(array.asByteArray(),
1046 array.length); },
1047 (e) { return e is IndexOutOfRangeException; });
1048 Expect.throws(() { new Uint8List.view(array.asByteArray(),
1049 0, array.length + 1); },
1050 (e) { return e is IndexOutOfRangeException; });
1051 Expect.throws(() { new Uint8List.view(array.asByteArray(),
1052 array.length - 1, 2); },
1053 (e) { return e is IndexOutOfRangeException; });
1054 var view = new Uint8List.view(array.asByteArray(), 1, array.length - 2);
1055 Expect.isTrue(view is List<int>);
1056 Expect.isTrue(view is Uint8List);
1057 Expect.equals(10, view.length);
1058 Expect.equals(1, view.bytesPerElement());
1059 Expect.equals(10, view.lengthInBytes());
1060 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1061 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1062 view);
1063 Expect.throws(() { view[-1] = 0; },
1064 (e) { return e is IndexOutOfRangeException; });
1065 Expect.throws(() { return view[-1]; },
1066 (e) { return e is IndexOutOfRangeException; });
1067 Expect.throws(() { view[view.length]; },
1068 (e) { return e is IndexOutOfRangeException; });
1069 Expect.throws(() { view[view.length] = 0; },
1070 (e) { return e is IndexOutOfRangeException; });
1071 Expect.throws(() { view.add(0); },
1072 (e) { return e is UnsupportedOperationException; });
1073 Expect.throws(() { view.addAll([0]); },
1074 (e) { return e is UnsupportedOperationException; });
1075 Expect.throws(() { view.addLast(0); },
1076 (e) { return e is UnsupportedOperationException; });
1077 Expect.throws(() { view.clear(); },
1078 (e) { return e is UnsupportedOperationException; });
1079 Expect.throws(() { view.insertRange(0, view.length, 0); },
1080 (e) { return e is UnsupportedOperationException; });
1081 Expect.throws(() { view.length = 0; },
1082 (e) { return e is UnsupportedOperationException; });
1083 Expect.throws(() { view.removeLast(); },
1084 (e) { return e is UnsupportedOperationException; });
1085 Expect.throws(() { view.removeRange(0, view.length - 1); },
1086 (e) { return e is UnsupportedOperationException; });
1087 for (int i = 0; i < view.length; ++i) {
1088 view[i] = 1 + i;
1089 }
1090 Expect.listEquals([1, 2, 3, 4, 5,
1091 6, 7, 8, 9, 10],
1092 view);
1093 Expect.listEquals([-1, 1, 2, 3, 4, 5,
1094 6, 7, 8, 9, 10, -1],
1095 array);
1096 for (int i = 0; i < view.length; ++i) {
1097 view[i] = 0x100 + i;
1098 }
1099 Expect.listEquals([0, 1, 2, 3, 4,
1100 5, 6, 7, 8, 9],
1101 view);
1102 Expect.listEquals([-1, 0, 1, 2, 3, 4,
1103 5, 6, 7, 8, 9, -1],
1104 array);
1105 for (int i = 0; i < view.length; ++i) {
1106 view[i] = 0xFF - i;
1107 }
1108 Expect.listEquals([0xFF, 0xFE, 0xFD, 0xFC, 0xFB,
1109 0xFA, 0xF9, 0xF8, 0xF7, 0xF6],
1110 view);
1111 Expect.listEquals([-1, -1, -2, -3, -4, -5,
1112 -6, -7, -8, -9, -10, -1],
1113 array);
1114 for (int i = 0; i < view.length; ++i) {
1115 view[i] = i;
1116 }
1117 var copy = view.getRange(0, view.length);
1118 Expect.isFalse(copy === view);
1119 Expect.isTrue(copy is Uint8List);
1120 Expect.equals(10, copy.length);
1121 Expect.listEquals(view, copy);
1122 var region = view.getRange(3, view.length - 6);
1123 Expect.isTrue(copy is Uint8List);
1124 Expect.equals(4, region.length);
1125 Expect.listEquals([3, 4, 5, 6], region);
1126 view.setRange(3, 4, [257, 0, 1, 255]);
1127 Expect.listEquals([0, 1, 2, 1, 0, 1, 255, 7, 8, 9],
1128 view);
1129 }
1130
1131 static testInt16ListView() {
1132 var array = new Uint8List(24);
1133 Expect.equals(24, array.length);
1134 Expect.equals(1, array.bytesPerElement());
1135 Expect.equals(24, array.lengthInBytes());
1136 for (int i = 0; i < array.length; ++i) {
1137 array[i] = 0xFF;
1138 }
1139 Expect.throws(() { new Int16List.view(array.asByteArray(), -1); },
1140 (e) { return e is IndexOutOfRangeException; });
1141 Expect.throws(() { new Int16List.view(array.asByteArray(), 0, -1); },
1142 (e) { return e is IndexOutOfRangeException; });
1143 Expect.throws(() { new Int16List.view(array.asByteArray(),
1144 array.length); },
1145 (e) { return e is IndexOutOfRangeException; });
1146 Expect.throws(() { new Int16List.view(array.asByteArray(),
1147 0, array.length + 1); },
1148 (e) { return e is IndexOutOfRangeException; });
1149 Expect.throws(() { new Int16List.view(array.asByteArray(),
1150 array.length - 1, 2); },
1151 (e) { return e is IndexOutOfRangeException; });
1152 var view = new Int16List.view(array.asByteArray(), 2, 10);
1153 Expect.isTrue(view is List<int>);
1154 Expect.isTrue(view is Int16List);
1155 Expect.equals(10, view.length);
1156 Expect.equals(2, view.bytesPerElement());
1157 Expect.equals(20, view.lengthInBytes());
1158 Expect.listEquals([-1, -1, -1, -1, -1,
1159 -1, -1, -1, -1, -1],
1160 view);
1161 Expect.throws(() { view[-1] = 0; },
1162 (e) { return e is IndexOutOfRangeException; });
1163 Expect.throws(() { return view[-1]; },
1164 (e) { return e is IndexOutOfRangeException; });
1165 Expect.throws(() { view[view.length]; },
1166 (e) { return e is IndexOutOfRangeException; });
1167 Expect.throws(() { view[10] = 0; },
1168 (e) { return e is IndexOutOfRangeException; });
1169 Expect.throws(() { view.add(0); },
1170 (e) { return e is UnsupportedOperationException; });
1171 Expect.throws(() { view.addAll([0]); },
1172 (e) { return e is UnsupportedOperationException; });
1173 Expect.throws(() { view.addLast(0); },
1174 (e) { return e is UnsupportedOperationException; });
1175 Expect.throws(() { view.clear(); },
1176 (e) { return e is UnsupportedOperationException; });
1177 Expect.throws(() { view.insertRange(0, view.length, 0); },
1178 (e) { return e is UnsupportedOperationException; });
1179 Expect.throws(() { view.length = 0; },
1180 (e) { return e is UnsupportedOperationException; });
1181 Expect.throws(() { view.removeLast(); },
1182 (e) { return e is UnsupportedOperationException; });
1183 Expect.throws(() { view.removeRange(0, view.length - 1); },
1184 (e) { return e is UnsupportedOperationException; });
1185 for (int i = 0; i < view.length; ++i) {
1186 view[i] = 1 + i;
1187 }
1188 Expect.listEquals([1, 2, 3, 4, 5,
1189 6, 7, 8, 9, 10],
1190 view);
1191 Expect.listEquals([0xFF, 0xFF, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
1192 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00,
1193 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0xFF, 0xFF],
1194 array);
1195 for (int i = 0; i < view.length; ++i) {
1196 view[i] = 0x10000 + i;
1197 }
1198 Expect.listEquals([0, 1, 2, 3, 4,
1199 5, 6, 7, 8, 9],
1200 view);
1201 Expect.listEquals([0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
1202 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00,
1203 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0xFF, 0xFF],
1204 array);
1205 for (int i = 0; i < view.length; ++i) {
1206 view[i] = -10 + i;
1207 }
1208 Expect.listEquals([-10, -9, -8, -7, -6,
1209 -5, -4, -3, -2, -1],
1210 view);
1211 Expect.listEquals([0xFF, 0xFF, 0xF6, 0xFF, 0xF7, 0xFF, 0xF8, 0xFF,
1212 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF,
1213 0xFD, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1214 array);
1215 for (int i = 0; i < view.length; ++i) {
1216 view[i] = 0x7FFF - i;
1217 }
1218 Expect.listEquals([0x7FFF, 0x7FFE, 0x7FFD, 0x7FFC, 0x7FFB,
1219 0x7FFA, 0x7FF9, 0x7FF8, 0x7FF7, 0x7FF6],
1220 view);
1221 Expect.listEquals([0xFF, 0xFF, 0xFF, 0x7F, 0xFE, 0x7F, 0xFD, 0x7F,
1222 0xFC, 0x7F, 0xFB, 0x7F, 0xFA, 0x7F, 0xF9, 0x7F,
1223 0xF8, 0x7F, 0xF7, 0x7F, 0xF6, 0x7F, 0xFF, 0xFF],
1224 array);
1225 for (int i = 0; i < view.length; ++i) {
1226 view[i] = -0x8000 + i;
1227 }
1228 Expect.listEquals([-0x8000, -0x7FFF, -0x7FFE, -0x7FFD, -0x7FFC,
1229 -0x7FFB, -0x7FFA, -0x7FF9, -0x7FF8, -0x7FF7],
1230 view);
1231 Expect.listEquals([0xFF, 0xFF, 0x00, 0x80, 0x01, 0x80, 0x02, 0x80,
1232 0x03, 0x80, 0x04, 0x80, 0x05, 0x80, 0x06, 0x80,
1233 0x07, 0x80, 0x08, 0x80, 0x09, 0x80, 0xFF, 0xFF],
1234 array);
1235 for (int i = 0; i < view.length; ++i) {
1236 view[i] = i;
1237 }
1238 var copy = view.getRange(0, view.length);
1239 Expect.isFalse(copy === view);
1240 Expect.isTrue(copy is Int16List);
1241 Expect.equals(10, copy.length);
1242 Expect.listEquals(view, copy);
1243 var region = view.getRange(3, view.length - 6);
1244 Expect.isTrue(copy is Int16List);
1245 Expect.equals(4, region.length);
1246 Expect.listEquals([3, 4, 5, 6], region);
1247 view.setRange(3, 4, [-32768, 0, 1, 32767]);
1248 Expect.listEquals([0, 1, 2, -32768, 0, 1, 32767, 7, 8, 9],
1249 view);
1250 Expect.listEquals([0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
1251 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0xFF, 0x7F,
1252 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0xFF, 0xFF],
1253 array);
1254 }
1255
1256 static testUint16ListView() {
1257 var array = new Int8List(24);
1258 Expect.isTrue(array is List<int>);
1259 Expect.equals(24, array.length);
1260 Expect.equals(1, array.bytesPerElement());
1261 Expect.equals(24, array.lengthInBytes());
1262 for (int i = 0; i < array.length; ++i) {
1263 array[i] = -1;
1264 }
1265 Expect.throws(() { new Uint16List.view(array.asByteArray(), -1); },
1266 (e) { return e is IndexOutOfRangeException; });
1267 Expect.throws(() { new Uint16List.view(array.asByteArray(), 0, -1); },
1268 (e) { return e is IndexOutOfRangeException; });
1269 Expect.throws(() { new Uint16List.view(array.asByteArray(),
1270 array.length); },
1271 (e) { return e is IndexOutOfRangeException; });
1272 Expect.throws(() { new Uint16List.view(array.asByteArray(),
1273 0, array.length + 1); },
1274 (e) { return e is IndexOutOfRangeException; });
1275 Expect.throws(() { new Uint16List.view(array.asByteArray(),
1276 array.length - 1, 2); },
1277 (e) { return e is IndexOutOfRangeException; });
1278 var view = new Uint16List.view(array.asByteArray(), 2, 10);
1279 Expect.isTrue(view is List<int>);
1280 Expect.isTrue(view is Uint16List);
1281 Expect.equals(10, view.length);
1282 Expect.equals(2, view.bytesPerElement());
1283 Expect.equals(20, view.lengthInBytes());
1284 Expect.listEquals([0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
1285 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF],
1286 view);
1287 Expect.throws(() { view[-1] = 0; },
1288 (e) { return e is IndexOutOfRangeException; });
1289 Expect.throws(() { return view[-1]; },
1290 (e) { return e is IndexOutOfRangeException; });
1291 Expect.throws(() { view[view.length]; },
1292 (e) { return e is IndexOutOfRangeException; });
1293 Expect.throws(() { view[view.length] = 0; },
1294 (e) { return e is IndexOutOfRangeException; });
1295 Expect.throws(() { view.add(0); },
1296 (e) { return e is UnsupportedOperationException; });
1297 Expect.throws(() { view.addAll([0]); },
1298 (e) { return e is UnsupportedOperationException; });
1299 Expect.throws(() { view.addLast(0); },
1300 (e) { return e is UnsupportedOperationException; });
1301 Expect.throws(() { view.clear(); },
1302 (e) { return e is UnsupportedOperationException; });
1303 Expect.throws(() { view.insertRange(0, view.length, 0); },
1304 (e) { return e is UnsupportedOperationException; });
1305 Expect.throws(() { view.length = 0; },
1306 (e) { return e is UnsupportedOperationException; });
1307 Expect.throws(() { view.removeLast(); },
1308 (e) { return e is UnsupportedOperationException; });
1309 Expect.throws(() { view.removeRange(0, view.length - 1); },
1310 (e) { return e is UnsupportedOperationException; });
1311 for (int i = 0; i < view.length; ++i) {
1312 view[i] = 1 + i;
1313 }
1314 Expect.listEquals([1, 2, 3, 4, 5,
1315 6, 7, 8, 9, 10],
1316 view);
1317 Expect.listEquals([-1, -1, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0,
1318 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, -1, -1],
1319 array);
1320 for (int i = 0; i < view.length; ++i) {
1321 view[i] = 0x10000 + i;
1322 }
1323 Expect.listEquals([0, 1, 2, 3, 4,
1324 5, 6, 7, 8, 9],
1325 view);
1326 Expect.listEquals([-1, -1, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0,
1327 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, -1, -1],
1328 array);
1329 for (int i = 0; i < view.length; ++i) {
1330 view[i] = 0xFFFF - i;
1331 }
1332 Expect.listEquals([0xFFFF, 0xFFFE, 0xFFFD, 0xFFFC, 0xFFFB,
1333 0xFFFA, 0xFFF9, 0xFFF8, 0xFFF7, 0xFFF6],
1334 view);
1335 Expect.listEquals([-1, -1, -1, -1, -2, -1, -3, -1,
1336 -4, -1, -5, -1, -6, -1, -7, -1,
1337 -8, -1, -9, -1, -10, -1, -1, -1],
1338 array);
1339 for (int i = 0; i < view.length; ++i) {
1340 view[i] = i;
1341 }
1342 var copy = view.getRange(0, view.length);
1343 Expect.isFalse(copy === view);
1344 Expect.isTrue(copy is Uint16List);
1345 Expect.equals(10, copy.length);
1346 Expect.listEquals(view, copy);
1347 var region = view.getRange(3, view.length - 6);
1348 Expect.isTrue(copy is Uint16List);
1349 Expect.equals(4, region.length);
1350 Expect.listEquals([3, 4, 5, 6], region);
1351 view.setRange(3, 4, [0x10001, 0, 1, 0xFFFF]);
1352 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFF, 7, 8, 9],
1353 view);
1354 Expect.listEquals([-1, -1, 0, 0, 1, 0, 2, 0,
1355 1, 0, 0, 0, 1, 0, -1, -1,
1356 7, 0, 8, 0, 9, 0, -1, -1],
1357 array);
1358 }
1359
1360 static testInt32ListView() {
1361 var array = new Uint8List(48);
1362 Expect.equals(48, array.length);
1363 Expect.equals(1, array.bytesPerElement());
1364 Expect.equals(48, array.lengthInBytes());
1365 for (int i = 0; i < array.length; ++i) {
1366 array[i] = 0xFF;
1367 }
1368 Expect.throws(() { new Int32List.view(array.asByteArray(), -1); },
1369 (e) { return e is IndexOutOfRangeException; });
1370 Expect.throws(() { new Int32List.view(array.asByteArray(), 0, -1); },
1371 (e) { return e is IndexOutOfRangeException; });
1372 Expect.throws(() { new Int32List.view(array.asByteArray(),
1373 array.length); },
1374 (e) { return e is IndexOutOfRangeException; });
1375 Expect.throws(() { new Int32List.view(array.asByteArray(),
1376 0, array.length + 1); },
1377 (e) { return e is IndexOutOfRangeException; });
1378 Expect.throws(() { new Int32List.view(array.asByteArray(),
1379 array.length - 1, 2); },
1380 (e) { return e is IndexOutOfRangeException; });
1381 var view = new Int32List.view(array.asByteArray(), 4, 10);
1382 Expect.isTrue(view is List<int>);
1383 Expect.isTrue(view is Int32List);
1384 Expect.equals(10, view.length);
1385 Expect.equals(4, view.bytesPerElement());
1386 Expect.equals(40, view.lengthInBytes());
1387 Expect.listEquals([-1, -1, -1, -1, -1,
1388 -1, -1, -1, -1, -1],
1389 view);
1390 Expect.throws(() { view[-1] = 0; },
1391 (e) { return e is IndexOutOfRangeException; });
1392 Expect.throws(() { return view[-1]; },
1393 (e) { return e is IndexOutOfRangeException; });
1394 Expect.throws(() { view[view.length]; },
1395 (e) { return e is IndexOutOfRangeException; });
1396 Expect.throws(() { view[10] = 0; },
1397 (e) { return e is IndexOutOfRangeException; });
1398 Expect.throws(() { view.add(0); },
1399 (e) { return e is UnsupportedOperationException; });
1400 Expect.throws(() { view.addAll([0]); },
1401 (e) { return e is UnsupportedOperationException; });
1402 Expect.throws(() { view.addLast(0); },
1403 (e) { return e is UnsupportedOperationException; });
1404 Expect.throws(() { view.clear(); },
1405 (e) { return e is UnsupportedOperationException; });
1406 Expect.throws(() { view.insertRange(0, view.length, 0); },
1407 (e) { return e is UnsupportedOperationException; });
1408 Expect.throws(() { view.length = 0; },
1409 (e) { return e is UnsupportedOperationException; });
1410 Expect.throws(() { view.removeLast(); },
1411 (e) { return e is UnsupportedOperationException; });
1412 Expect.throws(() { view.removeRange(0, view.length - 1); },
1413 (e) { return e is UnsupportedOperationException; });
1414 for (int i = 0; i < view.length; ++i) {
1415 view[i] = 1 + i;
1416 }
1417 Expect.listEquals([1, 2, 3, 4, 5,
1418 6, 7, 8, 9, 10],
1419 view);
1420 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00,
1421 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
1422 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
1423 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
1424 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
1425 0x0A, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
1426 array);
1427 for (int i = 0; i < view.length; ++i) {
1428 view[i] = 0x100000000 + i;
1429 }
1430 Expect.listEquals([0, 1, 2, 3, 4,
1431 5, 6, 7, 8, 9],
1432 view);
1433 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1434 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
1435 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
1436 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
1437 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
1438 0x09, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
1439 array);
1440 for (int i = 0; i < view.length; ++i) {
1441 view[i] = -10 + i;
1442 }
1443 Expect.listEquals([-10, -9, -8, -7, -6,
1444 -5, -4, -3, -2, -1],
1445 view);
1446 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xF6, 0xFF, 0xFF, 0xFF,
1447 0xF7, 0xFF, 0xFF, 0xFF, 0xF8, 0xFF, 0xFF, 0xFF,
1448 0xF9, 0xFF, 0xFF, 0xFF, 0xFA, 0xFF, 0xFF, 0xFF,
1449 0xFB, 0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF,
1450 0xFD, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF,
1451 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1452 array);
1453 for (int i = 0; i < view.length; ++i) {
1454 view[i] = 0x7FFFFFFF - i;
1455 }
1456 Expect.listEquals([0x7FFFFFFF, 0x7FFFFFFE,
1457 0x7FFFFFFD, 0x7FFFFFFC,
1458 0x7FFFFFFB, 0x7FFFFFFA,
1459 0x7FFFFFF9, 0x7FFFFFF8,
1460 0x7FFFFFF7, 0x7FFFFFF6],
1461 view);
1462 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1463 0xFE, 0xFF, 0xFF, 0x7F, 0xFD, 0xFF, 0xFF, 0x7F,
1464 0xFC, 0xFF, 0xFF, 0x7F, 0xFB, 0xFF, 0xFF, 0x7F,
1465 0xFA, 0xFF, 0xFF, 0x7F, 0xF9, 0xFF, 0xFF, 0x7F,
1466 0xF8, 0xFF, 0xFF, 0x7F, 0xF7, 0xFF, 0xFF, 0x7F,
1467 0xF6, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF],
1468 array);
1469 for (int i = 0; i < view.length; ++i) {
1470 view[i] = -0x80000000 + i;
1471 }
1472 Expect.listEquals([-0x80000000, -0x7FFFFFFF,
1473 -0x7FFFFFFE, -0x7FFFFFFD,
1474 -0x7FFFFFFC, -0x7FFFFFFB,
1475 -0x7FFFFFFA, -0x7FFFFFF9,
1476 -0x7FFFFFF8, -0x7FFFFFF7],
1477 view);
1478 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80,
1479 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80,
1480 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80,
1481 0x05, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x80,
1482 0x07, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x80,
1483 0x09, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF],
1484 array);
1485 for (int i = 0; i < view.length; ++i) {
1486 view[i] = i;
1487 }
1488 var copy = view.getRange(0, view.length);
1489 Expect.isFalse(copy === view);
1490 Expect.isTrue(copy is Int32List);
1491 Expect.equals(10, copy.length);
1492 Expect.listEquals(view, copy);
1493 var region = view.getRange(3, view.length - 6);
1494 Expect.isTrue(copy is Int32List);
1495 Expect.equals(4, region.length);
1496 Expect.listEquals([3, 4, 5, 6], region);
1497 view.setRange(3, 4, [-0x80000000, 0, 1, 0x7FFFFFFF]);
1498 Expect.listEquals([0, 1, 2, -0x80000000, 0, 1, 0x7FFFFFFF, 7, 8, 9],
1499 view);
1500 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1501 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
1502 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
1503 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x7F,
1504 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
1505 0x09, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF],
1506 array);
1507 }
1508
1509 static testUint32ListView() {
1510 var array = new Int8List(48);
1511 Expect.isTrue(array is List<int>);
1512 Expect.equals(48, array.length);
1513 Expect.equals(1, array.bytesPerElement());
1514 Expect.equals(48, array.lengthInBytes());
1515 for (int i = 0; i < array.length; ++i) {
1516 array[i] = -1;
1517 }
1518 Expect.throws(() { new Uint32List.view(array.asByteArray(), -1); },
1519 (e) { return e is IndexOutOfRangeException; });
1520 Expect.throws(() { new Uint32List.view(array.asByteArray(), 0, -1); },
1521 (e) { return e is IndexOutOfRangeException; });
1522 Expect.throws(() { new Uint32List.view(array.asByteArray(),
1523 array.length); },
1524 (e) { return e is IndexOutOfRangeException; });
1525 Expect.throws(() { new Uint32List.view(array.asByteArray(),
1526 0, array.length + 1); },
1527 (e) { return e is IndexOutOfRangeException; });
1528 Expect.throws(() { new Uint32List.view(array.asByteArray(),
1529 array.length - 1, 2); },
1530 (e) { return e is IndexOutOfRangeException; });
1531 var view = new Uint32List.view(array.asByteArray(), 4, 10);
1532 Expect.isTrue(view is List<int>);
1533 Expect.isTrue(view is Uint32List);
1534 Expect.equals(10, view.length);
1535 Expect.equals(4, view.bytesPerElement());
1536 Expect.equals(40, view.lengthInBytes());
1537 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF F,
1538 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF F],
1539 view);
1540 Expect.throws(() { view[-1] = 0; },
1541 (e) { return e is IndexOutOfRangeException; });
1542 Expect.throws(() { return view[-1]; },
1543 (e) { return e is IndexOutOfRangeException; });
1544 Expect.throws(() { view[view.length]; },
1545 (e) { return e is IndexOutOfRangeException; });
1546 Expect.throws(() { view[view.length] = 0; },
1547 (e) { return e is IndexOutOfRangeException; });
1548 Expect.throws(() { view.add(0); },
1549 (e) { return e is UnsupportedOperationException; });
1550 Expect.throws(() { view.addAll([0]); },
1551 (e) { return e is UnsupportedOperationException; });
1552 Expect.throws(() { view.addLast(0); },
1553 (e) { return e is UnsupportedOperationException; });
1554 Expect.throws(() { view.clear(); },
1555 (e) { return e is UnsupportedOperationException; });
1556 Expect.throws(() { view.insertRange(0, view.length, 0); },
1557 (e) { return e is UnsupportedOperationException; });
1558 Expect.throws(() { view.length = 0; },
1559 (e) { return e is UnsupportedOperationException; });
1560 Expect.throws(() { view.removeLast(); },
1561 (e) { return e is UnsupportedOperationException; });
1562 Expect.throws(() { view.removeRange(0, view.length - 1); },
1563 (e) { return e is UnsupportedOperationException; });
1564 for (int i = 0; i < view.length; ++i) {
1565 view[i] = 1 + i;
1566 }
1567 Expect.listEquals([1, 2, 3, 4, 5,
1568 6, 7, 8, 9, 10],
1569 view);
1570 Expect.listEquals([-1, -1, -1, -1, 1, 0, 0, 0,
1571 2, 0, 0, 0, 3, 0, 0, 0,
1572 4, 0, 0, 0, 5, 0, 0, 0,
1573 6, 0, 0, 0, 7, 0, 0, 0,
1574 8, 0, 0, 0, 9, 0, 0, 0,
1575 10, 0, 0, 0, -1, -1, -1, -1],
1576 array);
1577 for (int i = 0; i < view.length; ++i) {
1578 view[i] = 0x100000000 + i;
1579 }
1580 Expect.listEquals([0, 1, 2, 3, 4,
1581 5, 6, 7, 8, 9],
1582 view);
1583 Expect.listEquals([-1, -1, -1, -1, 0, 0, 0, 0,
1584 1, 0, 0, 0, 2, 0, 0, 0,
1585 3, 0, 0, 0, 4, 0, 0, 0,
1586 5, 0, 0, 0, 6, 0, 0, 0,
1587 7, 0, 0, 0, 8, 0, 0, 0,
1588 9, 0, 0, 0, -1, -1, -1, -1],
1589 array);
1590 for (int i = 0; i < view.length; ++i) {
1591 view[i] = 0xFFFFFFFF - i;
1592 }
1593 Expect.listEquals([0xFFFFFFFF, 0xFFFFFFFE,
1594 0xFFFFFFFD, 0xFFFFFFFC,
1595 0xFFFFFFFB, 0xFFFFFFFA,
1596 0xFFFFFFF9, 0xFFFFFFF8,
1597 0xFFFFFFF7, 0xFFFFFFF6],
1598 view);
1599 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
1600 -2, -1, -1, -1, -3, -1, -1, -1,
1601 -4, -1, -1, -1, -5, -1, -1, -1,
1602 -6, -1, -1, -1, -7, -1, -1, -1,
1603 -8, -1, -1, -1, -9, -1, -1, -1,
1604 -10, -1, -1, -1, -1, -1, -1, -1],
1605 array);
1606 for (int i = 0; i < view.length; ++i) {
1607 view[i] = i;
1608 }
1609 var copy = view.getRange(0, view.length);
1610 Expect.isFalse(copy === view);
1611 Expect.isTrue(copy is Uint32List);
1612 Expect.equals(10, copy.length);
1613 Expect.listEquals(view, copy);
1614 var region = view.getRange(3, view.length - 6);
1615 Expect.isTrue(copy is Uint32List);
1616 Expect.equals(4, region.length);
1617 Expect.listEquals([3, 4, 5, 6], region);
1618 view.setRange(3, 4, [0x100000001, 0, 1, 0xFFFFFFFF]);
1619 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFF, 7, 8, 9],
1620 view);
1621 Expect.listEquals([-1, -1, -1, -1, 0, 0, 0, 0,
1622 1, 0, 0, 0, 2, 0, 0, 0,
1623 1, 0, 0, 0, 0, 0, 0, 0,
1624 1, 0, 0, 0, -1, -1, -1, -1,
1625 7, 0, 0, 0, 8, 0, 0, 0,
1626 9, 0, 0, 0, -1, -1, -1, -1],
1627 array);
1628 }
1629
1630 static testInt64ListView() {
1631 var array = new Uint8List(96);
1632 Expect.equals(96, array.length);
1633 Expect.equals(1, array.bytesPerElement());
1634 Expect.equals(96, array.lengthInBytes());
1635 for (int i = 0; i < array.length; ++i) {
1636 array[i] = 0xFF;
1637 }
1638 Expect.throws(() { new Int64List.view(array.asByteArray(), -1); },
1639 (e) { return e is IndexOutOfRangeException; });
1640 Expect.throws(() { new Int64List.view(array.asByteArray(), 0, -1); },
1641 (e) { return e is IndexOutOfRangeException; });
1642 Expect.throws(() { new Int64List.view(array.asByteArray(),
1643 array.length); },
1644 (e) { return e is IndexOutOfRangeException; });
1645 Expect.throws(() { new Int64List.view(array.asByteArray(),
1646 0, array.length + 1); },
1647 (e) { return e is IndexOutOfRangeException; });
1648 Expect.throws(() { new Int64List.view(array.asByteArray(),
1649 array.length - 1, 2); },
1650 (e) { return e is IndexOutOfRangeException; });
1651 var view = new Int64List.view(array.asByteArray(), 8, 10);
1652 Expect.isTrue(view is List<int>);
1653 Expect.isTrue(view is Int64List);
1654 Expect.equals(10, view.length);
1655 Expect.equals(8, view.bytesPerElement());
1656 Expect.equals(80, view.lengthInBytes());
1657 Expect.listEquals([-1, -1, -1, -1, -1,
1658 -1, -1, -1, -1, -1],
1659 view);
1660 Expect.throws(() { view[-1] = 0; },
1661 (e) { return e is IndexOutOfRangeException; });
1662 Expect.throws(() { return view[-1]; },
1663 (e) { return e is IndexOutOfRangeException; });
1664 Expect.throws(() { view[view.length]; },
1665 (e) { return e is IndexOutOfRangeException; });
1666 Expect.throws(() { view[10] = 0; },
1667 (e) { return e is IndexOutOfRangeException; });
1668 Expect.throws(() { view.add(0); },
1669 (e) { return e is UnsupportedOperationException; });
1670 Expect.throws(() { view.addAll([0]); },
1671 (e) { return e is UnsupportedOperationException; });
1672 Expect.throws(() { view.addLast(0); },
1673 (e) { return e is UnsupportedOperationException; });
1674 Expect.throws(() { view.clear(); },
1675 (e) { return e is UnsupportedOperationException; });
1676 Expect.throws(() { view.insertRange(0, view.length, 0); },
1677 (e) { return e is UnsupportedOperationException; });
1678 Expect.throws(() { view.length = 0; },
1679 (e) { return e is UnsupportedOperationException; });
1680 Expect.throws(() { view.removeLast(); },
1681 (e) { return e is UnsupportedOperationException; });
1682 Expect.throws(() { view.removeRange(0, view.length - 1); },
1683 (e) { return e is UnsupportedOperationException; });
1684 for (int i = 0; i < view.length; ++i) {
1685 view[i] = 1 + i;
1686 }
1687 Expect.listEquals([1, 2, 3, 4, 5,
1688 6, 7, 8, 9, 10],
1689 view);
1690 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1691 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1692 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1693 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1694 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1695 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1696 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1697 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1698 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1699 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1700 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1701 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1702 array);
1703 for (int i = 0; i < view.length; ++i) {
1704 view[i] = 0x10000000000000000 + i;
1705 }
1706 Expect.listEquals([0, 1, 2, 3, 4,
1707 5, 6, 7, 8, 9],
1708 view);
1709 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1710 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1711 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1712 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1713 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1714 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1715 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1716 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1717 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1718 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1719 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1720 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1721 array);
1722 for (int i = 0; i < view.length; ++i) {
1723 view[i] = -10 + i;
1724 }
1725 Expect.listEquals([-10, -9, -8, -7, -6,
1726 -5, -4, -3, -2, -1],
1727 view);
1728 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1729 0xF6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1730 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1731 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1732 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1733 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1734 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1735 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1736 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1737 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1738 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1739 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1740 array);
1741 for (int i = 0; i < view.length; ++i) {
1742 view[i] = 0x7FFFFFFFFFFFFFFF - i;
1743 }
1744 Expect.listEquals([0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFE,
1745 0x7FFFFFFFFFFFFFFD, 0x7FFFFFFFFFFFFFFC,
1746 0x7FFFFFFFFFFFFFFB, 0x7FFFFFFFFFFFFFFA,
1747 0x7FFFFFFFFFFFFFF9, 0x7FFFFFFFFFFFFFF8,
1748 0x7FFFFFFFFFFFFFF7, 0x7FFFFFFFFFFFFFF6],
1749 view);
1750 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1751 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1752 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1753 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1754 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1755 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1756 0xFA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1757 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1758 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1759 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1760 0xF6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1761 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1762 array);
1763 for (int i = 0; i < view.length; ++i) {
1764 view[i] = -0x8000000000000000 + i;
1765 }
1766 Expect.listEquals([-0x8000000000000000, -0x7FFFFFFFFFFFFFFF,
1767 -0x7FFFFFFFFFFFFFFE, -0x7FFFFFFFFFFFFFFD,
1768 -0x7FFFFFFFFFFFFFFC, -0x7FFFFFFFFFFFFFFB,
1769 -0x7FFFFFFFFFFFFFFA, -0x7FFFFFFFFFFFFFF9,
1770 -0x7FFFFFFFFFFFFFF8, -0x7FFFFFFFFFFFFFF7],
1771 view);
1772 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1773 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1774 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1775 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1776 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1777 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1778 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1779 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1780 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1781 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1782 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1783 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1784 array);
1785 for (int i = 0; i < view.length; ++i) {
1786 view[i] = i;
1787 }
1788 var copy = view.getRange(0, view.length);
1789 Expect.isFalse(copy === view);
1790 Expect.isTrue(copy is Int64List);
1791 Expect.equals(10, copy.length);
1792 Expect.listEquals(view, copy);
1793 var region = view.getRange(3, view.length - 6);
1794 Expect.isTrue(copy is Int64List);
1795 Expect.equals(4, region.length);
1796 Expect.listEquals([3, 4, 5, 6], region);
1797 view.setRange(3, 4, [-0x8000000000000000, 0, 1, 0x7FFFFFFFFFFFFFFF]);
1798 Expect.listEquals([0, 1, 2, -0x8000000000000000, 0,
1799 1, 0x7FFFFFFFFFFFFFFF, 7, 8, 9],
1800 view);
1801 Expect.listEquals([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1802 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1803 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1804 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1805 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1806 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1807 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1808 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
1809 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1810 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1811 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1812 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
1813 array);
1814 }
1815
1816 static testUint64ListView() {
1817 var array = new Int8List(96);
1818 Expect.isTrue(array is List<int>);
1819 Expect.equals(96, array.length);
1820 Expect.equals(1, array.bytesPerElement());
1821 Expect.equals(96, array.lengthInBytes());
1822 for (int i = 0; i < array.length; ++i) {
1823 array[i] = -1;
1824 }
1825 Expect.throws(() { new Uint64List.view(array.asByteArray(), -1); },
1826 (e) { return e is IndexOutOfRangeException; });
1827 Expect.throws(() { new Uint64List.view(array.asByteArray(), 0, -1); },
1828 (e) { return e is IndexOutOfRangeException; });
1829 Expect.throws(() { new Uint64List.view(array.asByteArray(),
1830 array.length); },
1831 (e) { return e is IndexOutOfRangeException; });
1832 Expect.throws(() { new Uint64List.view(array.asByteArray(),
1833 0, array.length + 1); },
1834 (e) { return e is IndexOutOfRangeException; });
1835 Expect.throws(() { new Uint64List.view(array.asByteArray(),
1836 array.length - 1, 2); },
1837 (e) { return e is IndexOutOfRangeException; });
1838 var view = new Uint64List.view(array.asByteArray(), 8, 10);
1839 Expect.isTrue(view is List<int>);
1840 Expect.isTrue(view is Uint64List);
1841 Expect.equals(10, view.length);
1842 Expect.equals(8, view.bytesPerElement());
1843 Expect.equals(80, view.lengthInBytes());
1844 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
1845 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
1846 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
1847 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
1848 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF],
1849 view);
1850 Expect.throws(() { view[-1] = 0; },
1851 (e) { return e is IndexOutOfRangeException; });
1852 Expect.throws(() { return view[-1]; },
1853 (e) { return e is IndexOutOfRangeException; });
1854 Expect.throws(() { view[view.length]; },
1855 (e) { return e is IndexOutOfRangeException; });
1856 Expect.throws(() { view[view.length] = 0; },
1857 (e) { return e is IndexOutOfRangeException; });
1858 Expect.throws(() { view.add(0); },
1859 (e) { return e is UnsupportedOperationException; });
1860 Expect.throws(() { view.addAll([0]); },
1861 (e) { return e is UnsupportedOperationException; });
1862 Expect.throws(() { view.addLast(0); },
1863 (e) { return e is UnsupportedOperationException; });
1864 Expect.throws(() { view.clear(); },
1865 (e) { return e is UnsupportedOperationException; });
1866 Expect.throws(() { view.insertRange(0, view.length, 0); },
1867 (e) { return e is UnsupportedOperationException; });
1868 Expect.throws(() { view.length = 0; },
1869 (e) { return e is UnsupportedOperationException; });
1870 Expect.throws(() { view.removeLast(); },
1871 (e) { return e is UnsupportedOperationException; });
1872 Expect.throws(() { view.removeRange(0, view.length - 1); },
1873 (e) { return e is UnsupportedOperationException; });
1874 for (int i = 0; i < view.length; ++i) {
1875 view[i] = 1 + i;
1876 }
1877 Expect.listEquals([1, 2, 3, 4, 5,
1878 6, 7, 8, 9, 10],
1879 view);
1880 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
1881 1, 0, 0, 0, 0, 0, 0, 0,
1882 2, 0, 0, 0, 0, 0, 0, 0,
1883 3, 0, 0, 0, 0, 0, 0, 0,
1884 4, 0, 0, 0, 0, 0, 0, 0,
1885 5, 0, 0, 0, 0, 0, 0, 0,
1886 6, 0, 0, 0, 0, 0, 0, 0,
1887 7, 0, 0, 0, 0, 0, 0, 0,
1888 8, 0, 0, 0, 0, 0, 0, 0,
1889 9, 0, 0, 0, 0, 0, 0, 0,
1890 10, 0, 0, 0, 0, 0, 0, 0,
1891 -1, -1, -1, -1, -1, -1, -1, -1],
1892 array);
1893 for (int i = 0; i < view.length; ++i) {
1894 view[i] = 0x10000000000000000 + i;
1895 }
1896 Expect.listEquals([0, 1, 2, 3, 4,
1897 5, 6, 7, 8, 9],
1898 view);
1899 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
1900 0, 0, 0, 0, 0, 0, 0, 0,
1901 1, 0, 0, 0, 0, 0, 0, 0,
1902 2, 0, 0, 0, 0, 0, 0, 0,
1903 3, 0, 0, 0, 0, 0, 0, 0,
1904 4, 0, 0, 0, 0, 0, 0, 0,
1905 5, 0, 0, 0, 0, 0, 0, 0,
1906 6, 0, 0, 0, 0, 0, 0, 0,
1907 7, 0, 0, 0, 0, 0, 0, 0,
1908 8, 0, 0, 0, 0, 0, 0, 0,
1909 9, 0, 0, 0, 0, 0, 0, 0,
1910 -1, -1, -1, -1, -1, -1, -1, -1],
1911 array);
1912 for (int i = 0; i < view.length; ++i) {
1913 view[i] = 0xFFFFFFFFFFFFFFFF - i;
1914 }
1915 Expect.listEquals([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFE,
1916 0xFFFFFFFFFFFFFFFD, 0xFFFFFFFFFFFFFFFC,
1917 0xFFFFFFFFFFFFFFFB, 0xFFFFFFFFFFFFFFFA,
1918 0xFFFFFFFFFFFFFFF9, 0xFFFFFFFFFFFFFFF8,
1919 0xFFFFFFFFFFFFFFF7, 0xFFFFFFFFFFFFFFF6],
1920 view);
1921 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
1922 -1, -1, -1, -1, -1, -1, -1, -1,
1923 -2, -1, -1, -1, -1, -1, -1, -1,
1924 -3, -1, -1, -1, -1, -1, -1, -1,
1925 -4, -1, -1, -1, -1, -1, -1, -1,
1926 -5, -1, -1, -1, -1, -1, -1, -1,
1927 -6, -1, -1, -1, -1, -1, -1, -1,
1928 -7, -1, -1, -1, -1, -1, -1, -1,
1929 -8, -1, -1, -1, -1, -1, -1, -1,
1930 -9, -1, -1, -1, -1, -1, -1, -1,
1931 -10, -1, -1, -1, -1, -1, -1, -1,
1932 -1, -1, -1, -1, -1, -1, -1, -1],
1933 array);
1934 for (int i = 0; i < view.length; ++i) {
1935 view[i] = i;
1936 }
1937 var copy = view.getRange(0, view.length);
1938 Expect.isFalse(copy === view);
1939 Expect.isTrue(copy is Uint64List);
1940 Expect.equals(10, copy.length);
1941 Expect.listEquals(view, copy);
1942 var region = view.getRange(3, view.length - 6);
1943 Expect.isTrue(copy is Uint64List);
1944 Expect.equals(4, region.length);
1945 Expect.listEquals([3, 4, 5, 6], region);
1946 view.setRange(3, 4, [0x10000000000000001, 0, 1, 0xFFFFFFFFFFFFFFFF]);
1947 Expect.listEquals([0, 1, 2, 1, 0, 1, 0xFFFFFFFFFFFFFFFF, 7, 8, 9],
1948 view);
1949 Expect.listEquals([-1, -1, -1, -1, -1, -1, -1, -1,
1950 0, 0, 0, 0, 0, 0, 0, 0,
1951 1, 0, 0, 0, 0, 0, 0, 0,
1952 2, 0, 0, 0, 0, 0, 0, 0,
1953 1, 0, 0, 0, 0, 0, 0, 0,
1954 0, 0, 0, 0, 0, 0, 0, 0,
1955 1, 0, 0, 0, 0, 0, 0, 0,
1956 -1, -1, -1, -1, -1, -1, -1, -1,
1957 7, 0, 0, 0, 0, 0, 0, 0,
1958 8, 0, 0, 0, 0, 0, 0, 0,
1959 9, 0, 0, 0, 0, 0, 0, 0,
1960 -1, -1, -1, -1, -1, -1, -1, -1],
1961 array);
1962 }
1963
1964 static testFloat32ListView() {
1965 var array = new Uint32List(12);
1966 Expect.isTrue(array is List<int>);
1967 Expect.equals(12, array.length);
1968 Expect.equals(4, array.bytesPerElement());
1969 Expect.equals(48, array.lengthInBytes());
1970 for (int i = 0; i < array.length; ++i) {
1971 array[i] = 0xBF800000;
1972 }
1973 Expect.throws(() { new Float32List.view(array.asByteArray(), -1); },
1974 (e) { return e is IndexOutOfRangeException; });
1975 Expect.throws(() { new Float32List.view(array.asByteArray(), 0, -1); },
1976 (e) { return e is IndexOutOfRangeException; });
1977 Expect.throws(() { new Float32List.view(array.asByteArray(),
1978 array.lengthInBytes() + 1); },
1979 (e) { return e is IndexOutOfRangeException; });
1980 Expect.throws(() { new Float32List.view(array.asByteArray(),
1981 0, array.lengthInBytes() + 1); },
1982 (e) { return e is IndexOutOfRangeException; });
1983 Expect.throws(() { new Float32List.view(array.asByteArray(),
1984 array.lengthInBytes() - 1, 2); },
1985 (e) { return e is IndexOutOfRangeException; });
1986 var view = new Float32List.view(array.asByteArray(), 4, 10);
1987 Expect.isTrue(view is List<double>);
1988 Expect.equals(10, view.length);
1989 Expect.equals(4, view.bytesPerElement());
1990 Expect.equals(40, view.lengthInBytes());
1991 Expect.listEquals([-1.0, -1.0, -1.0, -1.0, -1.0,
1992 -1.0, -1.0, -1.0, -1.0, -1.0],
1993 view);
1994 Expect.throws(() { view[-1] = 0.0; },
1995 (e) { return e is IndexOutOfRangeException; });
1996 Expect.throws(() { return view[-1]; },
1997 (e) { return e is IndexOutOfRangeException; });
1998 Expect.throws(() { view[10]; },
1999 (e) { return e is IndexOutOfRangeException; });
2000 Expect.throws(() { view[10] = 0.0; },
2001 (e) { return e is IndexOutOfRangeException; });
2002 Expect.throws(() { array.add(0.0); },
2003 (e) { return e is UnsupportedOperationException; });
2004 Expect.throws(() { array.addAll([0]); },
2005 (e) { return e is UnsupportedOperationException; });
2006 Expect.throws(() { array.addLast(0.0); },
2007 (e) { return e is UnsupportedOperationException; });
2008 Expect.throws(() { array.clear(); },
2009 (e) { return e is UnsupportedOperationException; });
2010 Expect.throws(() { array.insertRange(0, array.length, 0.0); },
2011 (e) { return e is UnsupportedOperationException; });
2012 Expect.throws(() { array.length = 0; },
2013 (e) { return e is UnsupportedOperationException; });
2014 Expect.throws(() { array.removeLast(); },
2015 (e) { return e is UnsupportedOperationException; });
2016 Expect.throws(() { array.removeRange(0, array.length - 1); },
2017 (e) { return e is UnsupportedOperationException; });
2018 for (int i = 0; i < view.length; ++i) {
2019 view[i] = 1.0 + i;
2020 }
2021 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
2022 6.0, 7.0, 8.0, 9.0, 10.0],
2023 view);
2024 Expect.listEquals([0xBF800000, 0x3F800000,
2025 0x40000000, 0x40400000,
2026 0x40800000, 0x40A00000,
2027 0x40C00000, 0x40E00000,
2028 0x41000000, 0x41100000,
2029 0x41200000, 0xBF800000],
2030 array);
2031 // TODO: min, max, and round
2032 for (int i = 0; i < view.length; ++i) {
2033 view[i] = i * 1.0;
2034 }
2035 var copy = view.getRange(0, view.length);
2036 Expect.isFalse(copy === view);
2037 Expect.isTrue(copy is Float32List);
2038 Expect.equals(10, copy.length);
2039 Expect.listEquals(view, copy);
2040 var region = view.getRange(3, view.length - 6);
2041 Expect.isTrue(copy is Float32List);
2042 Expect.equals(4, region.length);
2043 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
2044 view.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
2045 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
2046 1.0, double.INFINITY, 7.0, 8.0, 9.0],
2047 view);
2048 Expect.listEquals([0xBF800000, 0x00000000,
2049 0x3F800000, 0x40000000,
2050 0xFF800000, 0x00000000,
2051 0x3F800000, 0x7F800000,
2052 0x40E00000, 0x41000000,
2053 0x41100000, 0xBF800000],
2054 array);
2055 }
2056
2057 static testFloat64ListView() {
2058 var array = new Uint64List(12);
2059 Expect.isTrue(array is List<int>);
2060 Expect.equals(12, array.length);
2061 Expect.equals(8, array.bytesPerElement());
2062 Expect.equals(96, array.lengthInBytes());
2063 for (int i = 0; i < array.length; ++i) {
2064 array[i] = 0xBFF0000000000000;
2065 }
2066 Expect.throws(() { new Float64List.view(array.asByteArray(), -1); },
2067 (e) { return e is IndexOutOfRangeException; });
2068 Expect.throws(() { new Float64List.view(array.asByteArray(), 0, -1); },
2069 (e) { return e is IndexOutOfRangeException; });
2070 Expect.throws(() { new Float64List.view(array.asByteArray(),
2071 array.lengthInBytes() + 1); },
2072 (e) { return e is IndexOutOfRangeException; });
2073 Expect.throws(() { new Float64List.view(array.asByteArray(),
2074 0, array.lengthInBytes() + 1); },
2075 (e) { return e is IndexOutOfRangeException; });
2076 Expect.throws(() { new Float64List.view(array.asByteArray(),
2077 array.lengthInBytes() - 1, 2); },
2078 (e) { return e is IndexOutOfRangeException; });
2079 var view = new Float64List.view(array.asByteArray(), 8, 10);
2080 Expect.isTrue(view is List<double>);
2081 Expect.equals(10, view.length);
2082 Expect.equals(8, view.bytesPerElement());
2083 Expect.equals(80, view.lengthInBytes());
2084 Expect.listEquals([-1.0, -1.0, -1.0, -1.0, -1.0,
2085 -1.0, -1.0, -1.0, -1.0, -1.0],
2086 view);
2087 Expect.throws(() { view[-1] = 0.0; },
2088 (e) { return e is IndexOutOfRangeException; });
2089 Expect.throws(() { return view[-1]; },
2090 (e) { return e is IndexOutOfRangeException; });
2091 Expect.throws(() { view[10]; },
2092 (e) { return e is IndexOutOfRangeException; });
2093 Expect.throws(() { view[10] = 0.0; },
2094 (e) { return e is IndexOutOfRangeException; });
2095 Expect.throws(() { array.add(0.0); },
2096 (e) { return e is UnsupportedOperationException; });
2097 Expect.throws(() { array.addAll([0]); },
2098 (e) { return e is UnsupportedOperationException; });
2099 Expect.throws(() { array.addLast(0.0); },
2100 (e) { return e is UnsupportedOperationException; });
2101 Expect.throws(() { array.clear(); },
2102 (e) { return e is UnsupportedOperationException; });
2103 Expect.throws(() { array.insertRange(0, array.length, 0.0); },
2104 (e) { return e is UnsupportedOperationException; });
2105 Expect.throws(() { array.length = 0; },
2106 (e) { return e is UnsupportedOperationException; });
2107 Expect.throws(() { array.removeLast(); },
2108 (e) { return e is UnsupportedOperationException; });
2109 Expect.throws(() { array.removeRange(0, array.length - 1); },
2110 (e) { return e is UnsupportedOperationException; });
2111 for (int i = 0; i < view.length; ++i) {
2112 view[i] = 1.0 + i;
2113 }
2114 Expect.listEquals([1.0, 2.0, 3.0, 4.0, 5.0,
2115 6.0, 7.0, 8.0, 9.0, 10.0],
2116 view);
2117 Expect.listEquals([0xBFF0000000000000, 0x3FF0000000000000,
2118 0x4000000000000000, 0x4008000000000000,
2119 0x4010000000000000, 0x4014000000000000,
2120 0x4018000000000000, 0x401C000000000000,
2121 0x4020000000000000, 0x4022000000000000,
2122 0x4024000000000000, 0xBFF0000000000000],
2123 array);
2124 // TODO: min, max
2125 for (int i = 0; i < view.length; ++i) {
2126 view[i] = i * 1.0;
2127 }
2128 var copy = view.getRange(0, view.length);
2129 Expect.isFalse(copy === view);
2130 Expect.isTrue(copy is Float64List);
2131 Expect.equals(10, copy.length);
2132 Expect.listEquals(view, copy);
2133 var region = view.getRange(3, view.length - 6);
2134 Expect.isTrue(copy is Float64List);
2135 Expect.equals(4, region.length);
2136 Expect.listEquals([3.0, 4.0, 5.0, 6.0], region);
2137 view.setRange(3, 4, [double.NEGATIVE_INFINITY, 0.0, 1.0, double.INFINITY]);
2138 Expect.listEquals([0.0, 1.0, 2.0, double.NEGATIVE_INFINITY, 0.0,
2139 1.0, double.INFINITY, 7.0, 8.0, 9.0],
2140 view);
2141 Expect.listEquals([0xBFF0000000000000, 0x0000000000000000,
2142 0x3FF0000000000000, 0x4000000000000000,
2143 0xFFF0000000000000, 0x0000000000000000,
2144 0x3FF0000000000000, 0x7FF0000000000000,
2145 0x401C000000000000, 0x4020000000000000,
2146 0x4022000000000000, 0xBFF0000000000000],
2147 array);
2148 }
2149
2150 static testMain() {
2151 testInt8List();
2152 testUint8List();
2153 testInt16List();
2154 testUint16List();
2155 testInt32List();
2156 testUint32List();
2157 testInt64List();
2158 testUint64List();
2159 testFloat32List();
2160 testFloat64List();
2161 testByteList();
2162 testInt8ListView();
2163 testUint8ListView();
2164 testInt16ListView();
2165 testUint16ListView();
2166 testInt32ListView();
2167 testUint32ListView();
2168 testInt64ListView();
2169 testUint64ListView();
2170 testFloat32ListView();
2171 testFloat64ListView();
2172 }
2173 }
2174
2175 main() {
2176 ByteArrayTest.testMain();
2177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698