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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 native float and int arrays. 64-bit int arrays 5 // Dart test program for testing native float and int arrays. 64-bit int arrays
6 // are in a separate test. 6 // are in a separate test.
7 7
8 // Library tag to be able to run in html test framework. 8 // Library tag to be able to run in html test framework.
9 library TypedArray; 9 library TypedArray;
10
10 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
11 import 'package:async_helper/async_helper.dart'; 12 import 'package:async_helper/async_helper.dart';
12 import 'dart:isolate'; 13 import 'dart:isolate';
13 import 'dart:typed_data'; 14 import 'dart:typed_data';
14 15
15 void main() { 16 void main() {
16 test(int8_receiver); 17 test(int8_receiver);
17 test(uint8_receiver); 18 test(uint8_receiver);
18 test(int16_receiver); 19 test(int16_receiver);
19 test(uint16_receiver); 20 test(uint16_receiver);
20 test(int32_receiver); 21 test(int32_receiver);
21 test(uint32_receiver); 22 test(uint32_receiver);
22 // int64 and uint64 in separate test. 23 // int64 and uint64 in separate test.
23 test(float32_receiver); 24 test(float32_receiver);
24 test(float64_receiver); 25 test(float64_receiver);
25 } 26 }
26 27
27 test(f) { 28 test(f) {
28 asyncStart(); 29 asyncStart();
29 return f().whenComplete(asyncEnd); 30 return f().whenComplete(asyncEnd);
30 } 31 }
31 32
32 // Int8 array. 33 // Int8 array.
33 Int8List initInt8() { 34 Int8List initInt8() {
34 var int8 = new Int8List(2); 35 var int8 = new Int8List(2);
35 int8[0] = 10; 36 int8[0] = 10;
36 int8[1] = 100; 37 int8[1] = 100;
37 return int8; 38 return int8;
38 } 39 }
40
39 Int8List int8 = initInt8(); 41 Int8List int8 = initInt8();
40 42
41 int8_receiver() { 43 int8_receiver() {
42 var response = new ReceivePort(); 44 var response = new ReceivePort();
43 var remote = Isolate.spawn(int8_sender, [int8.length, response.sendPort]); 45 var remote = Isolate.spawn(int8_sender, [int8.length, response.sendPort]);
44 asyncStart(); 46 asyncStart();
45 return response.first.then((a) { 47 return response.first.then((a) {
46 Expect.equals(int8.length, a.length); 48 Expect.equals(int8.length, a.length);
47 for (int i = 0; i < a.length; i++) { 49 for (int i = 0; i < a.length; i++) {
48 Expect.equals(int8[i], a[i]); 50 Expect.equals(int8[i], a[i]);
49 } 51 }
50 print("int8_receiver"); 52 print("int8_receiver");
51 asyncEnd(); 53 asyncEnd();
52 }); 54 });
53 } 55 }
54 56
55 int8_sender(message) { 57 int8_sender(message) {
56 var len = message[0]; 58 var len = message[0];
57 var r = message[1]; 59 var r = message[1];
58 Expect.equals(int8.length, len); 60 Expect.equals(int8.length, len);
59 var a = new Int8List(len); 61 var a = new Int8List(len);
60 for (int i = 0; i < len; i++) { 62 for (int i = 0; i < len; i++) {
61 a[i] = int8[i]; 63 a[i] = int8[i];
62 } 64 }
63 r.send(a); 65 r.send(a);
64 } 66 }
65 67
66
67 // Uint8 array. 68 // Uint8 array.
68 Uint8List initUint8() { 69 Uint8List initUint8() {
69 var uint8 = new Uint8List(2); 70 var uint8 = new Uint8List(2);
70 uint8[0] = 0xff; 71 uint8[0] = 0xff;
71 uint8[1] = 0x7f; 72 uint8[1] = 0x7f;
72 return uint8; 73 return uint8;
73 } 74 }
75
74 Uint8List uint8 = initUint8(); 76 Uint8List uint8 = initUint8();
75 77
76 uint8_receiver() { 78 uint8_receiver() {
77 var response = new ReceivePort(); 79 var response = new ReceivePort();
78 var remote = Isolate.spawn(uint8_sender, [uint8.length, response.sendPort]); 80 var remote = Isolate.spawn(uint8_sender, [uint8.length, response.sendPort]);
79 asyncStart(); 81 asyncStart();
80 return response.first.then((a) { 82 return response.first.then((a) {
81 Expect.equals(uint8.length, a.length); 83 Expect.equals(uint8.length, a.length);
82 for (int i = 0; i < a.length; i++) { 84 for (int i = 0; i < a.length; i++) {
83 Expect.equals(uint8[i], a[i]); 85 Expect.equals(uint8[i], a[i]);
84 } 86 }
85 print("uint8_receiver"); 87 print("uint8_receiver");
86 asyncEnd(); 88 asyncEnd();
87 }); 89 });
88 } 90 }
89 91
90 uint8_sender(message) { 92 uint8_sender(message) {
91 var len = message[0]; 93 var len = message[0];
92 var r = message[1]; 94 var r = message[1];
93 Expect.equals(uint8.length, len); 95 Expect.equals(uint8.length, len);
94 var a = new Uint8List(len); 96 var a = new Uint8List(len);
95 for (int i = 0; i < len; i++) { 97 for (int i = 0; i < len; i++) {
96 a[i] = uint8[i]; 98 a[i] = uint8[i];
97 } 99 }
98 r.send(a); 100 r.send(a);
99 } 101 }
100 102
101
102 // Int16 array. 103 // Int16 array.
103 Int16List initInt16() { 104 Int16List initInt16() {
104 var int16 = new Int16List(2); 105 var int16 = new Int16List(2);
105 int16[0] = 1000; 106 int16[0] = 1000;
106 int16[1] = 10000; 107 int16[1] = 10000;
107 return int16; 108 return int16;
108 } 109 }
110
109 Int16List int16 = initInt16(); 111 Int16List int16 = initInt16();
110 112
111 int16_receiver() { 113 int16_receiver() {
112 var response = new ReceivePort(); 114 var response = new ReceivePort();
113 var remote = Isolate.spawn(int16_sender, [int16.length, response.sendPort]); 115 var remote = Isolate.spawn(int16_sender, [int16.length, response.sendPort]);
114 asyncStart(); 116 asyncStart();
115 return response.first.then((a) { 117 return response.first.then((a) {
116 Expect.equals(int16.length, a.length); 118 Expect.equals(int16.length, a.length);
117 for (int i = 0; i < a.length; i++) { 119 for (int i = 0; i < a.length; i++) {
118 Expect.equals(int16[i], a[i]); 120 Expect.equals(int16[i], a[i]);
119 } 121 }
120 print("int16_receiver"); 122 print("int16_receiver");
121 asyncEnd(); 123 asyncEnd();
122 }); 124 });
123 } 125 }
124 126
125 int16_sender(message) { 127 int16_sender(message) {
126 var len = message[0]; 128 var len = message[0];
127 var r = message[1]; 129 var r = message[1];
128 Expect.equals(int16.length, len); 130 Expect.equals(int16.length, len);
129 var a = new Int16List(len); 131 var a = new Int16List(len);
130 for (int i = 0; i < len; i++) { 132 for (int i = 0; i < len; i++) {
131 a[i] = int16[i]; 133 a[i] = int16[i];
132 } 134 }
133 r.send(a); 135 r.send(a);
134 } 136 }
135 137
136
137 // Uint16 array. 138 // Uint16 array.
138 Uint16List initUint16() { 139 Uint16List initUint16() {
139 var uint16 = new Uint16List(2); 140 var uint16 = new Uint16List(2);
140 uint16[0] = 0xffff; 141 uint16[0] = 0xffff;
141 uint16[1] = 0x7fff; 142 uint16[1] = 0x7fff;
142 return uint16; 143 return uint16;
143 } 144 }
145
144 Uint16List uint16 = initUint16(); 146 Uint16List uint16 = initUint16();
145 147
146 uint16_receiver() { 148 uint16_receiver() {
147 var response = new ReceivePort(); 149 var response = new ReceivePort();
148 var remote = Isolate.spawn(uint16_sender, [uint16.length, response.sendPort]); 150 var remote = Isolate.spawn(uint16_sender, [uint16.length, response.sendPort]);
149 asyncStart(); 151 asyncStart();
150 return response.first.then((a) { 152 return response.first.then((a) {
151 Expect.equals(uint16.length, a.length); 153 Expect.equals(uint16.length, a.length);
152 for (int i = 0; i < a.length; i++) { 154 for (int i = 0; i < a.length; i++) {
153 Expect.equals(uint16[i], a[i]); 155 Expect.equals(uint16[i], a[i]);
154 } 156 }
155 print("uint16_receiver"); 157 print("uint16_receiver");
156 asyncEnd(); 158 asyncEnd();
157 }); 159 });
158 } 160 }
159 161
160 uint16_sender(message) { 162 uint16_sender(message) {
161 var len = message[0]; 163 var len = message[0];
162 var r = message[1]; 164 var r = message[1];
163 Expect.equals(uint16.length, len); 165 Expect.equals(uint16.length, len);
164 var a = new Uint16List(len); 166 var a = new Uint16List(len);
165 for (int i = 0; i < len; i++) { 167 for (int i = 0; i < len; i++) {
166 a[i] = uint16[i]; 168 a[i] = uint16[i];
167 } 169 }
168 r.send(a); 170 r.send(a);
169 } 171 }
170 172
171
172 // Int32 array. 173 // Int32 array.
173 Int32List initInt32() { 174 Int32List initInt32() {
174 var int32 = new Int32List(2); 175 var int32 = new Int32List(2);
175 int32[0] = 100000; 176 int32[0] = 100000;
176 int32[1] = 1000000; 177 int32[1] = 1000000;
177 return int32; 178 return int32;
178 } 179 }
180
179 Int32List int32 = initInt32(); 181 Int32List int32 = initInt32();
180 182
181 int32_receiver() { 183 int32_receiver() {
182 var response = new ReceivePort(); 184 var response = new ReceivePort();
183 var remote = Isolate.spawn(int32_sender, [int32.length, response.sendPort]); 185 var remote = Isolate.spawn(int32_sender, [int32.length, response.sendPort]);
184 asyncStart(); 186 asyncStart();
185 return response.first.then((a) { 187 return response.first.then((a) {
186 Expect.equals(int32.length, a.length); 188 Expect.equals(int32.length, a.length);
187 for (int i = 0; i < a.length; i++) { 189 for (int i = 0; i < a.length; i++) {
188 Expect.equals(int32[i], a[i]); 190 Expect.equals(int32[i], a[i]);
189 } 191 }
190 print("int32_receiver"); 192 print("int32_receiver");
191 asyncEnd(); 193 asyncEnd();
192 }); 194 });
193 } 195 }
194 196
195 int32_sender(message) { 197 int32_sender(message) {
196 var len = message[0]; 198 var len = message[0];
197 var r = message[1]; 199 var r = message[1];
198 Expect.equals(int32.length, len); 200 Expect.equals(int32.length, len);
199 var a = new Int32List(len); 201 var a = new Int32List(len);
200 for (int i = 0; i < len; i++) { 202 for (int i = 0; i < len; i++) {
201 a[i] = int32[i]; 203 a[i] = int32[i];
202 } 204 }
203 r.send(a); 205 r.send(a);
204 } 206 }
205 207
206
207 // Uint32 array. 208 // Uint32 array.
208 Uint32List initUint32() { 209 Uint32List initUint32() {
209 var uint32 = new Uint32List(2); 210 var uint32 = new Uint32List(2);
210 uint32[0] = 0xffffffff; 211 uint32[0] = 0xffffffff;
211 uint32[1] = 0x7fffffff; 212 uint32[1] = 0x7fffffff;
212 return uint32; 213 return uint32;
213 } 214 }
215
214 Uint32List uint32 = initUint32(); 216 Uint32List uint32 = initUint32();
215 217
216 uint32_receiver() { 218 uint32_receiver() {
217 var response = new ReceivePort(); 219 var response = new ReceivePort();
218 var remote = Isolate.spawn(uint32_sender, [uint32.length, response.sendPort]); 220 var remote = Isolate.spawn(uint32_sender, [uint32.length, response.sendPort]);
219 asyncStart(); 221 asyncStart();
220 return response.first.then((a) { 222 return response.first.then((a) {
221 Expect.equals(uint32.length, a.length); 223 Expect.equals(uint32.length, a.length);
222 for (int i = 0; i < a.length; i++) { 224 for (int i = 0; i < a.length; i++) {
223 Expect.equals(uint32[i], a[i]); 225 Expect.equals(uint32[i], a[i]);
224 } 226 }
225 print("uint32_receiver"); 227 print("uint32_receiver");
226 asyncEnd(); 228 asyncEnd();
227 }); 229 });
228 } 230 }
229 231
230 uint32_sender(message) { 232 uint32_sender(message) {
231 var len = message[0]; 233 var len = message[0];
232 var r = message[1]; 234 var r = message[1];
233 Expect.equals(uint32.length, len); 235 Expect.equals(uint32.length, len);
234 var a = new Uint32List(len); 236 var a = new Uint32List(len);
235 for (int i = 0; i < len; i++) { 237 for (int i = 0; i < len; i++) {
236 a[i] = uint32[i]; 238 a[i] = uint32[i];
237 } 239 }
238 r.send(a); 240 r.send(a);
239 } 241 }
240 242
241
242 // Float32 Array. 243 // Float32 Array.
243 Float32List initFloat32() { 244 Float32List initFloat32() {
244 var float32 = new Float32List(2); 245 var float32 = new Float32List(2);
245 float32[0] = 1.0; 246 float32[0] = 1.0;
246 float32[1] = 2.0; 247 float32[1] = 2.0;
247 return float32; 248 return float32;
248 } 249 }
250
249 Float32List float32 = initFloat32(); 251 Float32List float32 = initFloat32();
250 252
251 float32_receiver() { 253 float32_receiver() {
252 var response = new ReceivePort(); 254 var response = new ReceivePort();
253 var remote = 255 var remote =
254 Isolate.spawn(float32_sender, [float32.length, response.sendPort]); 256 Isolate.spawn(float32_sender, [float32.length, response.sendPort]);
255 asyncStart(); 257 asyncStart();
256 return response.first.then((a) { 258 return response.first.then((a) {
257 Expect.equals(float32.length, a.length); 259 Expect.equals(float32.length, a.length);
258 for (int i = 0; i < a.length; i++) { 260 for (int i = 0; i < a.length; i++) {
259 Expect.equals(float32[i], a[i]); 261 Expect.equals(float32[i], a[i]);
260 } 262 }
261 print("float32_receiver"); 263 print("float32_receiver");
262 asyncEnd(); 264 asyncEnd();
263 }); 265 });
264 } 266 }
265 267
266 float32_sender(message) { 268 float32_sender(message) {
267 var len = message[0]; 269 var len = message[0];
268 var r = message[1]; 270 var r = message[1];
269 Expect.equals(float32.length, len); 271 Expect.equals(float32.length, len);
270 var a = new Float32List(len); 272 var a = new Float32List(len);
271 for (int i = 0; i < len; i++) { 273 for (int i = 0; i < len; i++) {
272 a[i] = float32[i]; 274 a[i] = float32[i];
273 } 275 }
274 r.send(a); 276 r.send(a);
275 } 277 }
276 278
277
278 // Float64 Array. 279 // Float64 Array.
279 Float64List initFloat64() { 280 Float64List initFloat64() {
280 var float64 = new Float64List(2); 281 var float64 = new Float64List(2);
281 float64[0] = 101.234; 282 float64[0] = 101.234;
282 float64[1] = 201.765; 283 float64[1] = 201.765;
283 return float64; 284 return float64;
284 } 285 }
286
285 Float64List float64 = initFloat64(); 287 Float64List float64 = initFloat64();
286 288
287 float64_receiver() { 289 float64_receiver() {
288 var response = new ReceivePort(); 290 var response = new ReceivePort();
289 var remote = 291 var remote =
290 Isolate.spawn(float64_sender, [float64.length, response.sendPort]); 292 Isolate.spawn(float64_sender, [float64.length, response.sendPort]);
291 asyncStart(); 293 asyncStart();
292 return response.first.then((a) { 294 return response.first.then((a) {
293 Expect.equals(float64.length, a.length); 295 Expect.equals(float64.length, a.length);
294 for (int i = 0; i < a.length; i++) { 296 for (int i = 0; i < a.length; i++) {
295 Expect.equals(float64[i], a[i]); 297 Expect.equals(float64[i], a[i]);
296 } 298 }
297 print("float64_receiver"); 299 print("float64_receiver");
298 asyncEnd(); 300 asyncEnd();
299 }); 301 });
300 } 302 }
301 303
302 float64_sender(message) { 304 float64_sender(message) {
303 var len = message[0]; 305 var len = message[0];
304 var r = message[1]; 306 var r = message[1];
305 Expect.equals(float64.length, len); 307 Expect.equals(float64.length, len);
306 var a = new Float64List(len); 308 var a = new Float64List(len);
307 for (int i = 0; i < len; i++) { 309 for (int i = 0; i < len; i++) {
308 a[i] = float64[i]; 310 a[i] = float64[i];
309 } 311 }
310 r.send(a); 312 r.send(a);
311 } 313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698