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 // 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 'dart:typeddata'; | 10 import 'dart:typeddata'; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 Expect.equals(-1, list.indexOf(20.0)); | 211 Expect.equals(-1, list.indexOf(20.0)); |
212 } | 212 } |
213 | 213 |
214 void testIndexOf() { | 214 void testIndexOf() { |
215 testIndexOfHelper(new Uint8List.transferable(10)); | 215 testIndexOfHelper(new Uint8List.transferable(10)); |
216 testIndexOfHelper(new Uint8ClampedList(10)); | 216 testIndexOfHelper(new Uint8ClampedList(10)); |
217 testIndexOfHelper(new Uint8ClampedList.transferable(10)); | 217 testIndexOfHelper(new Uint8ClampedList.transferable(10)); |
218 } | 218 } |
219 | 219 |
220 void testGetAtIndex(TypedData list, num initial_value) { | 220 void testGetAtIndex(TypedData list, num initial_value) { |
221 var bdata = new ByteData.view(list); | 221 var bdata = new ByteData.view(list.buffer); |
222 for (int i = 0; i < bdata.lengthInBytes; i++) { | 222 for (int i = 0; i < bdata.lengthInBytes; i++) { |
223 Expect.equals(42, bdata.getUint8(i)); | 223 Expect.equals(42, bdata.getUint8(i)); |
224 Expect.equals(42, bdata.getInt8(i)); | 224 Expect.equals(42, bdata.getInt8(i)); |
225 } | 225 } |
226 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { | 226 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { |
227 Expect.equals(10794, bdata.getUint16(i)); | 227 Expect.equals(10794, bdata.getUint16(i)); |
228 Expect.equals(10794, bdata.getInt16(i)); | 228 Expect.equals(10794, bdata.getInt16(i)); |
229 } | 229 } |
230 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { | 230 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { |
231 Expect.equals(707406378, bdata.getUint32(i)); | 231 Expect.equals(707406378, bdata.getUint32(i)); |
232 Expect.equals(707406378, bdata.getInt32(i)); | 232 Expect.equals(707406378, bdata.getInt32(i)); |
233 Expect.equals(1.511366173271439e-13, bdata.getFloat32(i)); | 233 Expect.equals(1.511366173271439e-13, bdata.getFloat32(i)); |
234 } | 234 } |
235 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { | 235 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { |
236 Expect.equals(3038287259199220266, bdata.getUint64(i)); | 236 Expect.equals(3038287259199220266, bdata.getUint64(i)); |
237 Expect.equals(3038287259199220266, bdata.getInt64(i)); | 237 Expect.equals(3038287259199220266, bdata.getInt64(i)); |
238 Expect.equals(1.4260258159703532e-105, bdata.getFloat64(i)); | 238 Expect.equals(1.4260258159703532e-105, bdata.getFloat64(i)); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 void testSetAtIndex(TypedData list, | 242 void testSetAtIndex(TypedData list, |
243 num initial_value, [bool use_double = false]) { | 243 num initial_value, [bool use_double = false]) { |
244 void validate([reinit = true]) { | 244 void validate([reinit = true]) { |
245 for (int i = 0; i < list.length; i++) { | 245 for (int i = 0; i < list.length; i++) { |
246 Expect.equals(initial_value, list[i]); | 246 Expect.equals(initial_value, list[i]); |
247 if (reinit) list[i] = use_double? 0.0 : 0; | 247 if (reinit) list[i] = use_double? 0.0 : 0; |
248 } | 248 } |
249 } | 249 } |
250 var bdata = new ByteData.view(list); | 250 var bdata = new ByteData.view(list.buffer); |
251 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setUint8(i, 42); | 251 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setUint8(i, 42); |
252 validate(); | 252 validate(); |
253 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setInt8(i, 42); | 253 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setInt8(i, 42); |
254 validate(); | 254 validate(); |
255 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setUint16(i, 10794); | 255 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setUint16(i, 10794); |
256 validate(); | 256 validate(); |
257 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setInt16(i, 10794); | 257 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setInt16(i, 10794); |
258 validate(); | 258 validate(); |
259 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) | 259 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) |
260 bdata.setUint32(i, 707406378); | 260 bdata.setUint32(i, 707406378); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 var float64list = new Float64List(16); | 331 var float64list = new Float64List(16); |
332 testSetAtIndex(float64list, 1.4260258159703532e-105, true); | 332 testSetAtIndex(float64list, 1.4260258159703532e-105, true); |
333 testGetAtIndex(float64list, 1.4260258159703532e-105); | 333 testGetAtIndex(float64list, 1.4260258159703532e-105); |
334 } | 334 } |
335 testTypedDataRange(true); | 335 testTypedDataRange(true); |
336 testUnsignedTypedDataRange(true); | 336 testUnsignedTypedDataRange(true); |
337 testExternalClampedUnsignedTypedDataRange(true); | 337 testExternalClampedUnsignedTypedDataRange(true); |
338 } | 338 } |
339 | 339 |
OLD | NEW |