| 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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 testIndexOfHelper(new Uint8ClampedList(10)); | 182 testIndexOfHelper(new Uint8ClampedList(10)); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void testGetAtIndex(TypedData list, num initial_value) { | 185 void testGetAtIndex(TypedData list, num initial_value) { |
| 186 var bdata = new ByteData.view(list.buffer); | 186 var bdata = new ByteData.view(list.buffer); |
| 187 for (int i = 0; i < bdata.lengthInBytes; i++) { | 187 for (int i = 0; i < bdata.lengthInBytes; i++) { |
| 188 Expect.equals(42, bdata.getUint8(i)); | 188 Expect.equals(42, bdata.getUint8(i)); |
| 189 Expect.equals(42, bdata.getInt8(i)); | 189 Expect.equals(42, bdata.getInt8(i)); |
| 190 } | 190 } |
| 191 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { | 191 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { |
| 192 Expect.equals(10794, bdata.getUint16(i)); | 192 Expect.equals(10794, bdata.getUint16(i, Endianness.LITTLE_ENDIAN)); |
| 193 Expect.equals(10794, bdata.getInt16(i)); | 193 Expect.equals(10794, bdata.getInt16(i, Endianness.LITTLE_ENDIAN)); |
| 194 } | 194 } |
| 195 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { | 195 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { |
| 196 Expect.equals(707406378, bdata.getUint32(i)); | 196 Expect.equals(707406378, bdata.getUint32(i, Endianness.LITTLE_ENDIAN)); |
| 197 Expect.equals(707406378, bdata.getInt32(i)); | 197 Expect.equals(707406378, bdata.getInt32(i, Endianness.LITTLE_ENDIAN)); |
| 198 Expect.equals(1.511366173271439e-13, bdata.getFloat32(i)); | 198 Expect.equals(1.511366173271439e-13, |
| 199 bdata.getFloat32(i, Endianness.LITTLE_ENDIAN)); |
| 199 } | 200 } |
| 200 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { | 201 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { |
| 201 Expect.equals(3038287259199220266, bdata.getUint64(i)); | 202 Expect.equals(3038287259199220266, |
| 202 Expect.equals(3038287259199220266, bdata.getInt64(i)); | 203 bdata.getUint64(i, Endianness.LITTLE_ENDIAN)); |
| 203 Expect.equals(1.4260258159703532e-105, bdata.getFloat64(i)); | 204 Expect.equals(3038287259199220266, |
| 205 bdata.getInt64(i, Endianness.LITTLE_ENDIAN)); |
| 206 Expect.equals(1.4260258159703532e-105, |
| 207 bdata.getFloat64(i, Endianness.LITTLE_ENDIAN)); |
| 204 } | 208 } |
| 205 } | 209 } |
| 206 | 210 |
| 207 void testSetAtIndex(TypedData list, | 211 void testSetAtIndex(TypedData list, |
| 208 num initial_value, [bool use_double = false]) { | 212 num initial_value, [bool use_double = false]) { |
| 209 void validate([reinit = true]) { | 213 void validate([reinit = true]) { |
| 210 for (int i = 0; i < list.length; i++) { | 214 for (int i = 0; i < list.length; i++) { |
| 211 Expect.equals(initial_value, list[i]); | 215 Expect.equals(initial_value, list[i]); |
| 212 if (reinit) list[i] = use_double? 0.0 : 0; | 216 if (reinit) list[i] = use_double? 0.0 : 0; |
| 213 } | 217 } |
| 214 } | 218 } |
| 215 var bdata = new ByteData.view(list.buffer); | 219 var bdata = new ByteData.view(list.buffer); |
| 216 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setUint8(i, 42); | 220 for (int i = 0; i < bdata.lengthInBytes; i++) { |
| 221 bdata.setUint8(i, 42); |
| 222 } |
| 217 validate(); | 223 validate(); |
| 218 for (int i = 0; i < bdata.lengthInBytes; i++) bdata.setInt8(i, 42); | 224 for (int i = 0; i < bdata.lengthInBytes; i++) { |
| 225 bdata.setInt8(i, 42); |
| 226 } |
| 219 validate(); | 227 validate(); |
| 220 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setUint16(i, 10794); | 228 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { |
| 229 bdata.setUint16(i, 10794, Endianness.LITTLE_ENDIAN); |
| 230 } |
| 221 validate(); | 231 validate(); |
| 222 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) bdata.setInt16(i, 10794); | 232 for (int i = 0; i < bdata.lengthInBytes-1; i+=2) { |
| 223 validate(); | 233 bdata.setInt16(i, 10794, Endianness.LITTLE_ENDIAN); |
| 224 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) | 234 } |
| 225 bdata.setUint32(i, 707406378); | |
| 226 validate(); | |
| 227 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) bdata.setInt32(i, 707406378); | |
| 228 validate(); | 235 validate(); |
| 229 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { | 236 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { |
| 230 bdata.setFloat32(i, 1.511366173271439e-13); | 237 bdata.setUint32(i, 707406378, Endianness.LITTLE_ENDIAN); |
| 238 } |
| 239 validate(); |
| 240 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { |
| 241 bdata.setInt32(i, 707406378, Endianness.LITTLE_ENDIAN); |
| 242 } |
| 243 validate(); |
| 244 for (int i = 0; i < bdata.lengthInBytes-3; i+=4) { |
| 245 bdata.setFloat32(i, 1.511366173271439e-13, Endianness.LITTLE_ENDIAN); |
| 231 } | 246 } |
| 232 validate(); | 247 validate(); |
| 233 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { | 248 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { |
| 234 bdata.setUint64(i, 3038287259199220266); | 249 bdata.setUint64(i, 3038287259199220266, Endianness.LITTLE_ENDIAN); |
| 235 } | 250 } |
| 236 validate(); | 251 validate(); |
| 237 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { | 252 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { |
| 238 bdata.setInt64(i, 3038287259199220266); | 253 bdata.setInt64(i, 3038287259199220266, Endianness.LITTLE_ENDIAN); |
| 239 } | 254 } |
| 240 validate(); | 255 validate(); |
| 241 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { | 256 for (int i = 0; i < bdata.lengthInBytes-7; i+=8) { |
| 242 bdata.setFloat64(i, 1.4260258159703532e-105); | 257 bdata.setFloat64(i, 1.4260258159703532e-105, Endianness.LITTLE_ENDIAN); |
| 243 } | 258 } |
| 244 validate(false); | 259 validate(false); |
| 245 } | 260 } |
| 246 | 261 |
| 247 testViewCreation() { | 262 testViewCreation() { |
| 248 var bytes = new Uint8List(1024); | 263 var bytes = new Uint8List(1024); |
| 249 var view = new ByteData.view(bytes, 24); | 264 var view = new ByteData.view(bytes, 24); |
| 250 Expect.equals(1000, view.lengthInBytes); | 265 Expect.equals(1000, view.lengthInBytes); |
| 251 view = new Uint8List.view(bytes, 24); | 266 view = new Uint8List.view(bytes, 24); |
| 252 Expect.equals(1000, view.lengthInBytes); | 267 Expect.equals(1000, view.lengthInBytes); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 testSetAtIndex(float64list, 1.4260258159703532e-105, true); | 369 testSetAtIndex(float64list, 1.4260258159703532e-105, true); |
| 355 testGetAtIndex(float64list, 1.4260258159703532e-105); | 370 testGetAtIndex(float64list, 1.4260258159703532e-105); |
| 356 } | 371 } |
| 357 testTypedDataRange(true); | 372 testTypedDataRange(true); |
| 358 testUnsignedTypedDataRange(true); | 373 testUnsignedTypedDataRange(true); |
| 359 testViewCreation(); | 374 testViewCreation(); |
| 360 testWhere(); | 375 testWhere(); |
| 361 testCreationFromList(); | 376 testCreationFromList(); |
| 362 } | 377 } |
| 363 | 378 |
| OLD | NEW |