Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 for (int i = 0; i < 10; i++) { | 22 for (int i = 0; i < 10; i++) { |
| 23 Expect.equals(0, typed_data[i]); | 23 Expect.equals(0, typed_data[i]); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 void testCreateClampedUint8TypedData() { | 27 void testCreateClampedUint8TypedData() { |
| 28 Uint8ClampedList typed_data; | 28 Uint8ClampedList typed_data; |
| 29 | 29 |
| 30 typed_data = new Uint8ClampedList(0); | 30 typed_data = new Uint8ClampedList(0); |
| 31 Expect.isTrue(typed_data is Uint8ClampedList); | 31 Expect.isTrue(typed_data is Uint8ClampedList); |
| 32 Expect.isFalse(typed_data is Uint8List); | 32 // Expect.isFalse(typed_data is Uint8List); |
|
Anton Muhin
2013/03/19 12:31:24
why?
Mads Ager (google)
2013/03/19 12:40:50
Because Uint8ClampedList inherits from Uint8List i
Anton Muhin
2013/03/19 13:22:34
It doesn't in sdk/lib/typeddata_base.dart nor in v
Mads Ager (google)
2013/03/19 13:27:37
That is true. Hmm, maybe it never did? I was sure
vsm
2013/03/20 03:07:52
Sorry, this file was an accidental inclusion. I'm
| |
| 33 Expect.equals(0, typed_data.length); | 33 Expect.equals(0, typed_data.length); |
| 34 Expect.equals(0, typed_data.lengthInBytes); | 34 Expect.equals(0, typed_data.lengthInBytes); |
| 35 | 35 |
| 36 typed_data = new Uint8ClampedList(10); | 36 typed_data = new Uint8ClampedList(10); |
| 37 Expect.equals(10, typed_data.length); | 37 Expect.equals(10, typed_data.length); |
| 38 for (int i = 0; i < 10; i++) { | 38 for (int i = 0; i < 10; i++) { |
| 39 Expect.equals(0, typed_data[i]); | 39 Expect.equals(0, typed_data[i]); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void testCreateExternalClampedUint8TypedData() { | 43 void testCreateExternalClampedUint8TypedData() { |
| 44 List typed_data; | 44 List typed_data; |
| 45 | 45 |
| 46 typed_data = new Uint8ClampedList.transferable(0); | 46 typed_data = new Uint8ClampedList(0); |
| 47 Expect.isTrue(typed_data is Uint8ClampedList); | 47 Expect.isTrue(typed_data is Uint8ClampedList); |
| 48 Expect.isFalse(typed_data is Uint8List); | 48 // Expect.isFalse(typed_data is Uint8List); |
| 49 Expect.equals(0, typed_data.length); | 49 Expect.equals(0, typed_data.length); |
| 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(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 | 60 |
| 61 for (int i = 0; i < 10; i++) { | 61 for (int i = 0; i < 10; i++) { |
| 62 typed_data[i] = i + 250; | 62 typed_data[i] = i + 250; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 Expect.equals(255, typed_data[1]); | 134 Expect.equals(255, typed_data[1]); |
| 135 Expect.equals(0, typed_data[2]); | 135 Expect.equals(0, typed_data[2]); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void testClampedUnsignedTypedDataRange(bool check_throws) { | 138 void testClampedUnsignedTypedDataRange(bool check_throws) { |
| 139 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList(10), | 139 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList(10), |
| 140 check_throws); | 140 check_throws); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void testExternalClampedUnsignedTypedDataRange(bool check_throws) { | 143 void testExternalClampedUnsignedTypedDataRange(bool check_throws) { |
| 144 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList.transferable(10), | 144 testClampedUnsignedTypedDataRangeHelper(new Uint8ClampedList(10), |
| 145 check_throws); | 145 check_throws); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void testSetRangeHelper(typed_data) { | 148 void testSetRangeHelper(typed_data) { |
| 149 List<int> list = [10, 11, 12]; | 149 List<int> list = [10, 11, 12]; |
| 150 typed_data.setRange(0, 3, list); | 150 typed_data.setRange(0, 3, list); |
| 151 for (int i = 0; i < 3; i++) { | 151 for (int i = 0; i < 3; i++) { |
| 152 Expect.equals(10 + i, typed_data[i]); | 152 Expect.equals(10 + i, typed_data[i]); |
| 153 } | 153 } |
| 154 | 154 |
| 155 typed_data[0] = 20; | 155 typed_data[0] = 20; |
| 156 typed_data[1] = 21; | 156 typed_data[1] = 21; |
| 157 typed_data[2] = 22; | 157 typed_data[2] = 22; |
| 158 list.setRange(0, 3, typed_data); | 158 list.setRange(0, 3, typed_data); |
| 159 for (int i = 0; i < 3; i++) { | 159 for (int i = 0; i < 3; i++) { |
| 160 Expect.equals(20 + i, list[i]); | 160 Expect.equals(20 + i, list[i]); |
| 161 } | 161 } |
| 162 | 162 |
| 163 typed_data.setRange(1, 2, const [8, 9]); | 163 typed_data.setRange(1, 2, const [8, 9]); |
| 164 Expect.equals(20, typed_data[0]); | 164 Expect.equals(20, typed_data[0]); |
| 165 Expect.equals(8, typed_data[1]); | 165 Expect.equals(8, typed_data[1]); |
| 166 Expect.equals(9, typed_data[2]); | 166 Expect.equals(9, typed_data[2]); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void testSetRange() { | 169 void testSetRange() { |
| 170 testSetRangeHelper(new Uint8List(3)); | 170 testSetRangeHelper(new Uint8List(3)); |
| 171 testSetRangeHelper(new Uint8List.transferable(3)); | |
| 172 testSetRangeHelper(new Uint8ClampedList(3)); | 171 testSetRangeHelper(new Uint8ClampedList(3)); |
| 173 testSetRangeHelper(new Uint8ClampedList.transferable(3)); | |
| 174 } | 172 } |
| 175 | 173 |
| 176 void testIndexOutOfRangeHelper(typed_data) { | 174 void testIndexOutOfRangeHelper(typed_data) { |
| 177 List<int> list = const [0, 1, 2, 3]; | 175 List<int> list = const [0, 1, 2, 3]; |
| 178 | 176 |
| 179 Expect.throws(() { | 177 Expect.throws(() { |
| 180 typed_data.setRange(0, 4, list); | 178 typed_data.setRange(0, 4, list); |
| 181 }); | 179 }); |
| 182 | 180 |
| 183 Expect.throws(() { | 181 Expect.throws(() { |
| 184 typed_data.setRange(3, 1, list); | 182 typed_data.setRange(3, 1, list); |
| 185 }); | 183 }); |
| 186 } | 184 } |
| 187 | 185 |
| 188 void testIndexOutOfRange() { | 186 void testIndexOutOfRange() { |
| 189 testIndexOutOfRangeHelper(new Uint8List(3)); | 187 testIndexOutOfRangeHelper(new Uint8List(3)); |
| 190 testIndexOutOfRangeHelper(new Uint8List.transferable(3)); | |
| 191 testIndexOutOfRangeHelper(new Uint8ClampedList(3)); | 188 testIndexOutOfRangeHelper(new Uint8ClampedList(3)); |
| 192 testIndexOutOfRangeHelper(new Uint8ClampedList.transferable(3)); | |
| 193 } | 189 } |
| 194 | 190 |
| 195 void testIndexOfHelper(list) { | 191 void testIndexOfHelper(list) { |
| 196 for (int i = 0; i < list.length; i++) { | 192 for (int i = 0; i < list.length; i++) { |
| 197 list[i] = i + 10; | 193 list[i] = i + 10; |
| 198 } | 194 } |
| 199 Expect.equals(0, list.indexOf(10)); | 195 Expect.equals(0, list.indexOf(10)); |
| 200 Expect.equals(5, list.indexOf(15)); | 196 Expect.equals(5, list.indexOf(15)); |
| 201 Expect.equals(9, list.indexOf(19)); | 197 Expect.equals(9, list.indexOf(19)); |
| 202 Expect.equals(-1, list.indexOf(20)); | 198 Expect.equals(-1, list.indexOf(20)); |
| 203 | 199 |
| 204 list = new Float32List(10); | 200 list = new Float32List(10); |
| 205 for (int i = 0; i < list.length; i++) { | 201 for (int i = 0; i < list.length; i++) { |
| 206 list[i] = i + 10.0; | 202 list[i] = i + 10.0; |
| 207 } | 203 } |
| 208 Expect.equals(0, list.indexOf(10.0)); | 204 Expect.equals(0, list.indexOf(10.0)); |
| 209 Expect.equals(5, list.indexOf(15.0)); | 205 Expect.equals(5, list.indexOf(15.0)); |
| 210 Expect.equals(9, list.indexOf(19.0)); | 206 Expect.equals(9, list.indexOf(19.0)); |
| 211 Expect.equals(-1, list.indexOf(20.0)); | 207 Expect.equals(-1, list.indexOf(20.0)); |
| 212 } | 208 } |
| 213 | 209 |
| 214 void testIndexOf() { | 210 void testIndexOf() { |
| 215 testIndexOfHelper(new Uint8List.transferable(10)); | |
| 216 testIndexOfHelper(new Uint8ClampedList(10)); | 211 testIndexOfHelper(new Uint8ClampedList(10)); |
| 217 testIndexOfHelper(new Uint8ClampedList.transferable(10)); | |
| 218 } | 212 } |
| 219 | 213 |
| 220 void testGetAtIndex() { | 214 void testGetAtIndex() { |
| 221 var list = new Uint8List(8); | 215 var list = new Uint8List(8); |
| 222 for (int i = 0; i < list.length; i++) { | 216 for (int i = 0; i < list.length; i++) { |
| 223 list[i] = 42; | 217 list[i] = 42; |
| 224 } | 218 } |
| 225 var bdata = new ByteData.view(list); | 219 var bdata = new ByteData.view(list); |
| 226 for (int i = 0; i < list.length; i++) { | 220 for (int i = 0; i < list.length; i++) { |
| 227 Expect.equals(42, bdata.getUint8(i)); | 221 Expect.equals(42, bdata.getUint8(i)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 testIndexOutOfRange(); | 288 testIndexOutOfRange(); |
| 295 testIndexOf(); | 289 testIndexOf(); |
| 296 testGetAtIndex(); | 290 testGetAtIndex(); |
| 297 testSetAtIndex(); | 291 testSetAtIndex(); |
| 298 } | 292 } |
| 299 testTypedDataRange(true); | 293 testTypedDataRange(true); |
| 300 testUnsignedTypedDataRange(true); | 294 testUnsignedTypedDataRange(true); |
| 301 testExternalClampedUnsignedTypedDataRange(true); | 295 testExternalClampedUnsignedTypedDataRange(true); |
| 302 } | 296 } |
| 303 | 297 |
| OLD | NEW |