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

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

Issue 14205004: Remove typeddata transferable constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove private static methods that are unused Created 7 years, 8 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
« no previous file with comments | « tests/standalone/byte_array_view_optimized_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 // Library tag to be able to run in html test framework. 7 // Library tag to be able to run in html test framework.
8 library TypedDataTest; 8 library TypedDataTest;
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 23 matching lines...) Expand all
34 Expect.equals(0, typed_data.length); 34 Expect.equals(0, typed_data.length);
35 Expect.equals(0, typed_data.lengthInBytes); 35 Expect.equals(0, typed_data.lengthInBytes);
36 36
37 typed_data = new Uint8ClampedList(10); 37 typed_data = new Uint8ClampedList(10);
38 Expect.equals(10, typed_data.length); 38 Expect.equals(10, typed_data.length);
39 for (int i = 0; i < 10; i++) { 39 for (int i = 0; i < 10; i++) {
40 Expect.equals(0, typed_data[i]); 40 Expect.equals(0, typed_data[i]);
41 } 41 }
42 } 42 }
43 43
44 void testCreateExternalClampedUint8TypedData() {
45 List typed_data;
46
47 typed_data = new Uint8ClampedList.transferable(0);
48 Expect.isTrue(typed_data is Uint8ClampedList);
49 Expect.isFalse(typed_data is Uint8List);
50 Expect.equals(0, typed_data.length);
51 Expect.equals(0, typed_data.lengthInBytes);
52
53 typed_data = new Uint8ClampedList.transferable(10);
54 Expect.equals(10, typed_data.length);
55 for (int i = 0; i < 10; i++) {
56 Expect.equals(0, typed_data[i]);
57 }
58
59 typed_data[0] = -1;
60 Expect.equals(0, typed_data[0]);
61
62 for (int i = 0; i < 10; i++) {
63 typed_data[i] = i + 250;
64 }
65 for (int i = 0; i < 10; i++) {
66 Expect.equals(i + 250 > 255 ? 255 : i + 250, typed_data[i]);
67 }
68 }
69
70 void testTypedDataRange(bool check_throws) { 44 void testTypedDataRange(bool check_throws) {
71 Int8List typed_data; 45 Int8List typed_data;
72 typed_data = new Int8List(10); 46 typed_data = new Int8List(10);
73 typed_data[1] = 0; 47 typed_data[1] = 0;
74 Expect.equals(0, typed_data[1]); 48 Expect.equals(0, typed_data[1]);
75 typed_data[2] = -128; 49 typed_data[2] = -128;
76 Expect.equals(-128, typed_data[2]); 50 Expect.equals(-128, typed_data[2]);
77 typed_data[3] = 127; 51 typed_data[3] = 127;
78 Expect.equals(127, typed_data[3]); 52 Expect.equals(127, typed_data[3]);
79 // This should eventually throw. 53 // This should eventually throw.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 typed_data[2] = -129; 108 typed_data[2] = -129;
135 Expect.equals(255, typed_data[1]); 109 Expect.equals(255, typed_data[1]);
136 Expect.equals(0, typed_data[2]); 110 Expect.equals(0, typed_data[2]);
137 } 111 }
138 112
139 void testClampedUnsignedTypedDataRange(bool check_throws) { 113 void testClampedUnsignedTypedDataRange(bool check_throws) {
140 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList(10), 114 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList(10),
141 check_throws); 115 check_throws);
142 } 116 }
143 117
144 void testExternalClampedUnsignedTypedDataRange(bool check_throws) {
145 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList.transferable(10),
146 check_throws);
147 }
148
149 void testSetRangeHelper(typed_data) { 118 void testSetRangeHelper(typed_data) {
150 List<int> list = [10, 11, 12]; 119 List<int> list = [10, 11, 12];
151 typed_data.setRange(0, 3, list); 120 typed_data.setRange(0, 3, list);
152 for (int i = 0; i < 3; i++) { 121 for (int i = 0; i < 3; i++) {
153 Expect.equals(10 + i, typed_data[i]); 122 Expect.equals(10 + i, typed_data[i]);
154 } 123 }
155 124
156 typed_data[0] = 20; 125 typed_data[0] = 20;
157 typed_data[1] = 21; 126 typed_data[1] = 21;
158 typed_data[2] = 22; 127 typed_data[2] = 22;
159 list.setRange(0, 3, typed_data); 128 list.setRange(0, 3, typed_data);
160 for (int i = 0; i < 3; i++) { 129 for (int i = 0; i < 3; i++) {
161 Expect.equals(20 + i, list[i]); 130 Expect.equals(20 + i, list[i]);
162 } 131 }
163 132
164 typed_data.setRange(1, 3, const [8, 9]); 133 typed_data.setRange(1, 3, const [8, 9]);
165 Expect.equals(20, typed_data[0]); 134 Expect.equals(20, typed_data[0]);
166 Expect.equals(8, typed_data[1]); 135 Expect.equals(8, typed_data[1]);
167 Expect.equals(9, typed_data[2]); 136 Expect.equals(9, typed_data[2]);
168 } 137 }
169 138
170 void testSetRange() { 139 void testSetRange() {
171 testSetRangeHelper(new Uint8List(3)); 140 testSetRangeHelper(new Uint8List(3));
172 testSetRangeHelper(new Uint8List.transferable(3));
173 testSetRangeHelper(new Uint8ClampedList(3)); 141 testSetRangeHelper(new Uint8ClampedList(3));
174 testSetRangeHelper(new Uint8ClampedList.transferable(3));
175 } 142 }
176 143
177 void testIndexOutOfRangeHelper(typed_data) { 144 void testIndexOutOfRangeHelper(typed_data) {
178 List<int> list = const [0, 1, 2, 3]; 145 List<int> list = const [0, 1, 2, 3];
179 146
180 Expect.throws(() { 147 Expect.throws(() {
181 typed_data.setRange(0, 4, list); 148 typed_data.setRange(0, 4, list);
182 }); 149 });
183 150
184 Expect.throws(() { 151 Expect.throws(() {
185 typed_data.setRange(3, 4, list); 152 typed_data.setRange(3, 4, list);
186 }); 153 });
187 } 154 }
188 155
189 void testIndexOutOfRange() { 156 void testIndexOutOfRange() {
190 testIndexOutOfRangeHelper(new Uint8List(3)); 157 testIndexOutOfRangeHelper(new Uint8List(3));
191 testIndexOutOfRangeHelper(new Uint8List.transferable(3));
192 testIndexOutOfRangeHelper(new Uint8ClampedList(3)); 158 testIndexOutOfRangeHelper(new Uint8ClampedList(3));
193 testIndexOutOfRangeHelper(new Uint8ClampedList.transferable(3));
194 } 159 }
195 160
196 void testIndexOfHelper(list) { 161 void testIndexOfHelper(list) {
197 for (int i = 0; i < list.length; i++) { 162 for (int i = 0; i < list.length; i++) {
198 list[i] = i + 10; 163 list[i] = i + 10;
199 } 164 }
200 Expect.equals(0, list.indexOf(10)); 165 Expect.equals(0, list.indexOf(10));
201 Expect.equals(5, list.indexOf(15)); 166 Expect.equals(5, list.indexOf(15));
202 Expect.equals(9, list.indexOf(19)); 167 Expect.equals(9, list.indexOf(19));
203 Expect.equals(-1, list.indexOf(20)); 168 Expect.equals(-1, list.indexOf(20));
204 169
205 list = new Float32List(10); 170 list = new Float32List(10);
206 for (int i = 0; i < list.length; i++) { 171 for (int i = 0; i < list.length; i++) {
207 list[i] = i + 10.0; 172 list[i] = i + 10.0;
208 } 173 }
209 Expect.equals(0, list.indexOf(10.0)); 174 Expect.equals(0, list.indexOf(10.0));
210 Expect.equals(5, list.indexOf(15.0)); 175 Expect.equals(5, list.indexOf(15.0));
211 Expect.equals(9, list.indexOf(19.0)); 176 Expect.equals(9, list.indexOf(19.0));
212 Expect.equals(-1, list.indexOf(20.0)); 177 Expect.equals(-1, list.indexOf(20.0));
213 } 178 }
214 179
215 void testIndexOf() { 180 void testIndexOf() {
216 testIndexOfHelper(new Uint8List.transferable(10)); 181 testIndexOfHelper(new Uint8List(10));
217 testIndexOfHelper(new Uint8ClampedList(10)); 182 testIndexOfHelper(new Uint8ClampedList(10));
218 testIndexOfHelper(new Uint8ClampedList.transferable(10));
219 } 183 }
220 184
221 void testGetAtIndex(TypedData list, num initial_value) { 185 void testGetAtIndex(TypedData list, num initial_value) {
222 var bdata = new ByteData.view(list.buffer); 186 var bdata = new ByteData.view(list.buffer);
223 for (int i = 0; i < bdata.lengthInBytes; i++) { 187 for (int i = 0; i < bdata.lengthInBytes; i++) {
224 Expect.equals(42, bdata.getUint8(i)); 188 Expect.equals(42, bdata.getUint8(i));
225 Expect.equals(42, bdata.getInt8(i)); 189 Expect.equals(42, bdata.getInt8(i));
226 } 190 }
227 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { 191 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) {
228 Expect.equals(10794, bdata.getUint16(i)); 192 Expect.equals(10794, bdata.getUint16(i));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 Expect.throws(() => ints[0] = doubles[0]); 300 Expect.throws(() => ints[0] = doubles[0]);
337 Expect.throws(() => doubles[0] = ints[0]); 301 Expect.throws(() => doubles[0] = ints[0]);
338 } 302 }
339 } 303 }
340 } 304 }
341 305
342 main() { 306 main() {
343 for (int i = 0; i < 2000; i++) { 307 for (int i = 0; i < 2000; i++) {
344 testCreateUint8TypedData(); 308 testCreateUint8TypedData();
345 testCreateClampedUint8TypedData(); 309 testCreateClampedUint8TypedData();
346 testCreateExternalClampedUint8TypedData();
347 testTypedDataRange(false); 310 testTypedDataRange(false);
348 testUnsignedTypedDataRange(false); 311 testUnsignedTypedDataRange(false);
349 testClampedUnsignedTypedDataRange(false); 312 testClampedUnsignedTypedDataRange(false);
350 testExternalClampedUnsignedTypedDataRange(false);
351 testSetRange(); 313 testSetRange();
352 testIndexOutOfRange(); 314 testIndexOutOfRange();
353 testIndexOf(); 315 testIndexOf();
354 316
355 var int8list = new Int8List(128); 317 var int8list = new Int8List(128);
356 testSetAtIndex(int8list, 42); 318 testSetAtIndex(int8list, 42);
357 testGetAtIndex(int8list, 42); 319 testGetAtIndex(int8list, 42);
358 320
359 var uint8list = new Uint8List(128); 321 var uint8list = new Uint8List(128);
360 testSetAtIndex(uint8list, 42); 322 testSetAtIndex(uint8list, 42);
(...skipping 26 matching lines...) Expand all
387 var float32list = new Float32List(32); 349 var float32list = new Float32List(32);
388 testSetAtIndex(float32list, 1.511366173271439e-13, true); 350 testSetAtIndex(float32list, 1.511366173271439e-13, true);
389 testGetAtIndex(float32list, 1.511366173271439e-13); 351 testGetAtIndex(float32list, 1.511366173271439e-13);
390 352
391 var float64list = new Float64List(16); 353 var float64list = new Float64List(16);
392 testSetAtIndex(float64list, 1.4260258159703532e-105, true); 354 testSetAtIndex(float64list, 1.4260258159703532e-105, true);
393 testGetAtIndex(float64list, 1.4260258159703532e-105); 355 testGetAtIndex(float64list, 1.4260258159703532e-105);
394 } 356 }
395 testTypedDataRange(true); 357 testTypedDataRange(true);
396 testUnsignedTypedDataRange(true); 358 testUnsignedTypedDataRange(true);
397 testExternalClampedUnsignedTypedDataRange(true);
398 testViewCreation(); 359 testViewCreation();
399 testWhere(); 360 testWhere();
400 testCreationFromList(); 361 testCreationFromList();
401 } 362 }
402 363
OLDNEW
« no previous file with comments | « tests/standalone/byte_array_view_optimized_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698