OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // Dart test program for testing typed data. | 5 // Dart test program for testing typed data. |
6 | 6 |
7 // VMOptions=--optimization_counter_threshold=10 | 7 // VMOptions=--optimization_counter_threshold=10 |
8 | 8 |
9 // Library tag to be able to run in html test framework. | 9 // Library tag to be able to run in html test framework. |
10 library TypedDataTest; | 10 library TypedDataTest; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 typed_data.setRange(1, 3, const [8, 9]); | 141 typed_data.setRange(1, 3, const [8, 9]); |
142 Expect.equals(20, typed_data[0]); | 142 Expect.equals(20, typed_data[0]); |
143 Expect.equals(8, typed_data[1]); | 143 Expect.equals(8, typed_data[1]); |
144 Expect.equals(9, typed_data[2]); | 144 Expect.equals(9, typed_data[2]); |
145 } | 145 } |
146 | 146 |
147 void testSetRange() { | 147 void testSetRange() { |
148 testSetRangeHelper(new Uint8List(3)); | 148 testSetRangeHelper(new Uint8List(3)); |
149 testSetRangeHelper(new Uint8ClampedList(3)); | 149 testSetRangeHelper(new Uint8ClampedList(3)); |
| 150 testSetRangeHelper(new Uint16List(3)); |
| 151 |
| 152 var list = new Uint8List(4); |
| 153 list.setRange(0, 4, "abcd".codeUnits, 0); |
| 154 Expect.listEquals(list, "abcd".codeUnits); |
| 155 list = new Uint16List(4); |
| 156 list.setRange(0, 4, "abcd".codeUnits, 0); |
| 157 Expect.listEquals(list, "abcd".codeUnits); |
| 158 list.setRange(0, 4, "\xff\u0100\uffff\x00".codeUnits, 0); |
| 159 Expect.listEquals(list, "abcd".codeUnits); |
150 } | 160 } |
151 | 161 |
152 class C { | 162 class C { |
153 final x; | 163 final x; |
154 C(this.x); | 164 C(this.x); |
155 operator<(o) => false; | 165 operator<(o) => false; |
156 operator>=(o) => false; | 166 operator>=(o) => false; |
157 operator*(o) => x; | 167 operator*(o) => x; |
158 } | 168 } |
159 | 169 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 doubleLists.add(new Float32List.fromList(doubleList)); | 432 doubleLists.add(new Float32List.fromList(doubleList)); |
423 doubleLists.add(new Float64List.fromList(doubleList)); | 433 doubleLists.add(new Float64List.fromList(doubleList)); |
424 for (var ints in intLists) { | 434 for (var ints in intLists) { |
425 for (var doubles in doubleLists) { | 435 for (var doubles in doubleLists) { |
426 Expect.throws(() => ints[0] = doubles[0]); | 436 Expect.throws(() => ints[0] = doubles[0]); |
427 Expect.throws(() => doubles[0] = ints[0]); | 437 Expect.throws(() => doubles[0] = ints[0]); |
428 } | 438 } |
429 } | 439 } |
430 } | 440 } |
431 | 441 |
| 442 void testStrings() { |
| 443 test(list) { |
| 444 Uint16List uints = new Uint16List(list.length)..setAll(0, list); |
| 445 String string = new String.fromCharCodes(list); |
| 446 for (int i = 0; i < string.length; i++) { |
| 447 for (int j = i; j < string.length; j++) { |
| 448 int length = j - i; |
| 449 { |
| 450 Uint16List copy = new Uint16List(length); |
| 451 copy.setRange(0, length, string.codeUnits, i); |
| 452 Expect.listEquals(uints.sublist(i, j), copy); |
| 453 } |
| 454 { |
| 455 Uint8List buffer = new Uint8List(length * 2 + 8); |
| 456 Uint16List copy = new Uint16List.view(buffer.buffer, 4, length); |
| 457 copy.setRange(0, length, string.codeUnits, i); |
| 458 Expect.listEquals(uints.sublist(i, j), copy); |
| 459 } |
| 460 { |
| 461 String copy = new String.fromCharCodes(uints, i, j); |
| 462 Expect.equals(string.substring(i, j), copy); |
| 463 } |
| 464 } |
| 465 } |
| 466 } |
| 467 test([]); |
| 468 test([0x00, 0x7f, 0xff]); |
| 469 test([0x00, 0xdfff, 0xffff]); |
| 470 test([0xd800, 0xdc00, 0x20, 0xdbff, 0xdfff]); |
| 471 } |
| 472 |
432 main() { | 473 main() { |
433 for (int i = 0; i < 20; i++) { | 474 for (int i = 0; i < 20; i++) { |
434 testCreateUint8TypedData(); | 475 testCreateUint8TypedData(); |
435 testCreateClampedUint8TypedData(); | 476 testCreateClampedUint8TypedData(); |
436 testTypedDataRange(false); | 477 testTypedDataRange(false); |
437 testUnsignedTypedDataRange(false); | 478 testUnsignedTypedDataRange(false); |
438 testClampedUnsignedTypedDataRange(false); | 479 testClampedUnsignedTypedDataRange(false); |
439 testSetRange(); | 480 testSetRange(); |
440 testIndexOutOfRange(); | 481 testIndexOutOfRange(); |
441 testIndexOf(); | 482 testIndexOf(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 519 |
479 var float64list = new Float64List(16); | 520 var float64list = new Float64List(16); |
480 testSetAtIndex(float64list, 1.4260258159703532e-105, true); | 521 testSetAtIndex(float64list, 1.4260258159703532e-105, true); |
481 testGetAtIndex(float64list, 1.4260258159703532e-105); | 522 testGetAtIndex(float64list, 1.4260258159703532e-105); |
482 } | 523 } |
483 testTypedDataRange(true); | 524 testTypedDataRange(true); |
484 testUnsignedTypedDataRange(true); | 525 testUnsignedTypedDataRange(true); |
485 testViewCreation(); | 526 testViewCreation(); |
486 testWhere(); | 527 testWhere(); |
487 testCreationFromList(); | 528 testCreationFromList(); |
| 529 testStrings(); |
488 } | 530 } |
OLD | NEW |