| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 Expect.equals(0, typed_data.lengthInBytes); | 50 Expect.equals(0, typed_data.lengthInBytes); |
| 51 | 51 |
| 52 typed_data = new Uint8ClampedList.transferable(10); | 52 typed_data = new Uint8ClampedList.transferable(10); |
| 53 Expect.equals(10, typed_data.length); | 53 Expect.equals(10, typed_data.length); |
| 54 for (int i = 0; i < 10; i++) { | 54 for (int i = 0; i < 10; i++) { |
| 55 Expect.equals(0, typed_data[i]); | 55 Expect.equals(0, typed_data[i]); |
| 56 } | 56 } |
| 57 | 57 |
| 58 typed_data[0] = -1; | 58 typed_data[0] = -1; |
| 59 Expect.equals(0, typed_data[0]); | 59 Expect.equals(0, typed_data[0]); |
| 60 | |
| 61 | 60 |
| 62 for (int i = 0; i < 10; i++) { | 61 for (int i = 0; i < 10; i++) { |
| 63 typed_data[i] = i + 250; | 62 typed_data[i] = i + 250; |
| 64 } | 63 } |
| 65 for (int i = 0; i < 10; i++) { | 64 for (int i = 0; i < 10; i++) { |
| 66 Expect.equals(i + 250 > 255 ? 255 : i + 250, typed_data[i]); | 65 Expect.equals(i + 250 > 255 ? 255 : i + 250, typed_data[i]); |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 | 68 |
| 70 void testTypedDataRange(bool check_throws) { | 69 void testTypedDataRange(bool check_throws) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 for (int i = 0; i < list.length; i++) { | 205 for (int i = 0; i < list.length; i++) { |
| 207 list[i] = i + 10.0; | 206 list[i] = i + 10.0; |
| 208 } | 207 } |
| 209 Expect.equals(0, list.indexOf(10.0)); | 208 Expect.equals(0, list.indexOf(10.0)); |
| 210 Expect.equals(5, list.indexOf(15.0)); | 209 Expect.equals(5, list.indexOf(15.0)); |
| 211 Expect.equals(9, list.indexOf(19.0)); | 210 Expect.equals(9, list.indexOf(19.0)); |
| 212 Expect.equals(-1, list.indexOf(20.0)); | 211 Expect.equals(-1, list.indexOf(20.0)); |
| 213 } | 212 } |
| 214 | 213 |
| 215 void testIndexOf() { | 214 void testIndexOf() { |
| 216 testIndexOfHelper(new Uint8List(10)); | |
| 217 testIndexOfHelper(new Uint8List.transferable(10)); | 215 testIndexOfHelper(new Uint8List.transferable(10)); |
| 218 testIndexOfHelper(new Uint8ClampedList(10)); | 216 testIndexOfHelper(new Uint8ClampedList(10)); |
| 219 testIndexOfHelper(new Uint8ClampedList.transferable(10)); | 217 testIndexOfHelper(new Uint8ClampedList.transferable(10)); |
| 220 } | 218 } |
| 221 | 219 |
| 220 void testGetAtIndex() { |
| 221 var list = new Uint8List(8); |
| 222 for (int i = 0; i < list.length; i++) { |
| 223 list[i] = 42; |
| 224 } |
| 225 var bdata = new ByteData.view(list); |
| 226 for (int i = 0; i < list.length; i++) { |
| 227 Expect.equals(42, bdata.getUint8(i)); |
| 228 Expect.equals(42, bdata.getInt8(i)); |
| 229 } |
| 230 for (int i = 0; i < list.length ~/ 2; i++) { |
| 231 Expect.equals(10794, bdata.getUint16(i)); |
| 232 Expect.equals(10794, bdata.getInt16(i)); |
| 233 } |
| 234 for (int i = 0; i < list.length ~/ 4; i++) { |
| 235 Expect.equals(707406378, bdata.getUint32(i)); |
| 236 Expect.equals(707406378, bdata.getInt32(i)); |
| 237 Expect.equals(1.511366173271439e-13, bdata.getFloat32(i)); |
| 238 } |
| 239 for (int i = 0; i < list.length ~/ 8; i++) { |
| 240 Expect.equals(3038287259199220266, bdata.getUint64(i)); |
| 241 Expect.equals(3038287259199220266, bdata.getInt64(i)); |
| 242 Expect.equals(1.4260258159703532e-105, bdata.getFloat64(i)); |
| 243 } |
| 244 } |
| 245 |
| 246 void testSetAtIndex() { |
| 247 var list = new Uint8List(8); |
| 248 void validate() { |
| 249 for (int i = 0; i < list.length; i++) { |
| 250 Expect.equals(42, list[i]); |
| 251 } |
| 252 } |
| 253 var bdata = new ByteData.view(list); |
| 254 for (int i = 0; i < list.length; i++) bdata.setUint8(i, 42); |
| 255 validate(); |
| 256 for (int i = 0; i < list.length; i++) bdata.setInt8(i, 42); |
| 257 validate(); |
| 258 for (int i = 0; i < list.length ~/ 2; i++) bdata.setUint16(i, 10794); |
| 259 validate(); |
| 260 for (int i = 0; i < list.length ~/ 2; i++) bdata.setInt16(i, 10794); |
| 261 validate(); |
| 262 for (int i = 0; i < list.length ~/ 4; i++) bdata.setUint32(i, 707406378); |
| 263 validate(); |
| 264 for (int i = 0; i < list.length ~/ 4; i++) bdata.setInt32(i, 707406378); |
| 265 validate(); |
| 266 for (int i = 0; i < list.length ~/ 4; i++) { |
| 267 bdata.setFloat32(i, 1.511366173271439e-13); |
| 268 } |
| 269 validate(); |
| 270 for (int i = 0; i < list.length ~/ 8; i++) { |
| 271 bdata.setUint64(i, 3038287259199220266); |
| 272 } |
| 273 validate(); |
| 274 for (int i = 0; i < list.length ~/ 8; i++) { |
| 275 bdata.setInt64(i, 3038287259199220266); |
| 276 } |
| 277 validate(); |
| 278 for (int i = 0; i < list.length ~/ 8; i++) { |
| 279 bdata.setFloat64(i, 1.4260258159703532e-105); |
| 280 } |
| 281 validate(); |
| 282 } |
| 283 |
| 222 main() { | 284 main() { |
| 223 for (int i = 0; i < 2000; i++) { | 285 for (int i = 0; i < 2000; i++) { |
| 224 testCreateUint8TypedData(); | 286 testCreateUint8TypedData(); |
| 225 testCreateClampedUint8TypedData(); | 287 testCreateClampedUint8TypedData(); |
| 226 testCreateExternalClampedUint8TypedData(); | 288 testCreateExternalClampedUint8TypedData(); |
| 227 testTypedDataRange(false); | 289 testTypedDataRange(false); |
| 228 testUnsignedTypedDataRange(false); | 290 testUnsignedTypedDataRange(false); |
| 229 testClampedUnsignedTypedDataRange(false); | 291 testClampedUnsignedTypedDataRange(false); |
| 230 testExternalClampedUnsignedTypedDataRange(false); | 292 testExternalClampedUnsignedTypedDataRange(false); |
| 231 testSetRange(); | 293 testSetRange(); |
| 232 testIndexOutOfRange(); | 294 testIndexOutOfRange(); |
| 233 testIndexOf(); | 295 testIndexOf(); |
| 296 testGetAtIndex(); |
| 297 testSetAtIndex(); |
| 234 } | 298 } |
| 235 testTypedDataRange(true); | 299 testTypedDataRange(true); |
| 236 testUnsignedTypedDataRange(true); | 300 testUnsignedTypedDataRange(true); |
| 237 testExternalClampedUnsignedTypedDataRange(true); | 301 testExternalClampedUnsignedTypedDataRange(true); |
| 238 } | 302 } |
| 239 | 303 |
| OLD | NEW |