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

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

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 1 month 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 | Annotate | Revision Log
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 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 15 matching lines...) Expand all
26 // Int8 array. 26 // Int8 array.
27 Int8List initInt8() { 27 Int8List initInt8() {
28 var int8 = new Int8List(2); 28 var int8 = new Int8List(2);
29 int8[0] = 10; 29 int8[0] = 10;
30 int8[1] = 100; 30 int8[1] = 100;
31 return int8; 31 return int8;
32 } 32 }
33 Int8List int8 = initInt8(); 33 Int8List int8 = initInt8();
34 34
35 void int8_receiver() { 35 void int8_receiver() {
36 var sp = spawnFunction(int8_sender); 36 var response = new ReceivePort();
37 sp.call(int8.length).then((a) { 37 var remote = Isolate.spawn(int8_sender, [int8.length, response.sendPort]);
38 response.first.then((a) {
38 Expect.equals(int8.length, a.length); 39 Expect.equals(int8.length, a.length);
39 for (int i = 0; i < a.length; i++) { 40 for (int i = 0; i < a.length; i++) {
40 Expect.equals(int8[i], a[i]); 41 Expect.equals(int8[i], a[i]);
41 } 42 }
42 print("int8_receiver"); 43 print("int8_receiver");
43 }); 44 });
44 } 45 }
45 46
46 int8_sender() { 47 int8_sender(message) {
47 port.receive((len, r) { 48 var len = message[0];
48 Expect.equals(int8.length, len); 49 var r = message[1];
49 var a = new Int8List(len); 50 Expect.equals(int8.length, len);
50 for (int i = 0; i < len; i++) { 51 var a = new Int8List(len);
51 a[i] = int8[i]; 52 for (int i = 0; i < len; i++) {
52 } 53 a[i] = int8[i];
53 r.send(a); 54 }
54 }); 55 r.send(a);
55 } 56 }
56 57
57 58
58 // Uint8 array. 59 // Uint8 array.
59 Uint8List initUint8() { 60 Uint8List initUint8() {
60 var uint8 = new Uint8List(2); 61 var uint8 = new Uint8List(2);
61 uint8[0] = 0xff; 62 uint8[0] = 0xff;
62 uint8[1] = 0x7f; 63 uint8[1] = 0x7f;
63 return uint8; 64 return uint8;
64 } 65 }
65 Uint8List uint8 = initUint8(); 66 Uint8List uint8 = initUint8();
66 67
67 void uint8_receiver() { 68 void uint8_receiver() {
68 var sp = spawnFunction(uint8_sender); 69 var response = new ReceivePort();
69 sp.call(uint8.length).then((a) { 70 var remote = Isolate.spawn(uint8_sender, [uint8.length, response.sendPort]);
71 response.first.then((a) {
70 Expect.equals(uint8.length, a.length); 72 Expect.equals(uint8.length, a.length);
71 for (int i = 0; i < a.length; i++) { 73 for (int i = 0; i < a.length; i++) {
72 Expect.equals(uint8[i], a[i]); 74 Expect.equals(uint8[i], a[i]);
73 } 75 }
74 print("uint8_receiver"); 76 print("uint8_receiver");
75 }); 77 });
76 } 78 }
77 79
78 uint8_sender() { 80 uint8_sender(message) {
79 port.receive((len, r) { 81 var len = message[0];
80 Expect.equals(uint8.length, len); 82 var r = message[1];
81 var a = new Uint8List(len); 83 Expect.equals(uint8.length, len);
82 for (int i = 0; i < len; i++) { 84 var a = new Uint8List(len);
83 a[i] = uint8[i]; 85 for (int i = 0; i < len; i++) {
84 } 86 a[i] = uint8[i];
85 r.send(a); 87 }
86 }); 88 r.send(a);
87 } 89 }
88 90
89 91
90 // Int16 array. 92 // Int16 array.
91 Int16List initInt16() { 93 Int16List initInt16() {
92 var int16 = new Int16List(2); 94 var int16 = new Int16List(2);
93 int16[0] = 1000; 95 int16[0] = 1000;
94 int16[1] = 10000; 96 int16[1] = 10000;
95 return int16; 97 return int16;
96 } 98 }
97 Int16List int16 = initInt16(); 99 Int16List int16 = initInt16();
98 100
99 void int16_receiver() { 101 void int16_receiver() {
100 var sp = spawnFunction(int16_sender); 102 var response = new ReceivePort();
101 sp.call(int16.length).then((a) { 103 var remote = Isolate.spawn(int16_sender, [int16.length, response.sendPort]);
104 response.first.then((a) {
102 Expect.equals(int16.length, a.length); 105 Expect.equals(int16.length, a.length);
103 for (int i = 0; i < a.length; i++) { 106 for (int i = 0; i < a.length; i++) {
104 Expect.equals(int16[i], a[i]); 107 Expect.equals(int16[i], a[i]);
105 } 108 }
106 print("int16_receiver"); 109 print("int16_receiver");
107 }); 110 });
108 } 111 }
109 112
110 int16_sender() { 113 int16_sender(message) {
111 port.receive((len, r) { 114 var len = message[0];
112 Expect.equals(int16.length, len); 115 var r = message[1];
113 var a = new Int16List(len); 116 Expect.equals(int16.length, len);
114 for (int i = 0; i < len; i++) { 117 var a = new Int16List(len);
115 a[i] = int16[i]; 118 for (int i = 0; i < len; i++) {
116 } 119 a[i] = int16[i];
117 r.send(a); 120 }
118 }); 121 r.send(a);
119 } 122 }
120 123
121 124
122 // Uint16 array. 125 // Uint16 array.
123 Uint16List initUint16() { 126 Uint16List initUint16() {
124 var uint16 = new Uint16List(2); 127 var uint16 = new Uint16List(2);
125 uint16[0] = 0xffff; 128 uint16[0] = 0xffff;
126 uint16[1] = 0x7fff; 129 uint16[1] = 0x7fff;
127 return uint16; 130 return uint16;
128 } 131 }
129 Uint16List uint16 = initUint16(); 132 Uint16List uint16 = initUint16();
130 133
131 void uint16_receiver() { 134 void uint16_receiver() {
132 var sp = spawnFunction(uint16_sender); 135 var response = new ReceivePort();
133 sp.call(uint16.length).then((a) { 136 var remote = Isolate.spawn(uint16_sender, [uint16.length, response.sendPort]);
137 response.first.then((a) {
134 Expect.equals(uint16.length, a.length); 138 Expect.equals(uint16.length, a.length);
135 for (int i = 0; i < a.length; i++) { 139 for (int i = 0; i < a.length; i++) {
136 Expect.equals(uint16[i], a[i]); 140 Expect.equals(uint16[i], a[i]);
137 } 141 }
138 print("uint16_receiver"); 142 print("uint16_receiver");
139 }); 143 });
140 } 144 }
141 145
142 uint16_sender() { 146 uint16_sender(message) {
143 port.receive((len, r) { 147 var len = message[0];
144 Expect.equals(uint16.length, len); 148 var r = message[1];
145 var a = new Uint16List(len); 149 Expect.equals(uint16.length, len);
146 for (int i = 0; i < len; i++) { 150 var a = new Uint16List(len);
147 a[i] = uint16[i]; 151 for (int i = 0; i < len; i++) {
148 } 152 a[i] = uint16[i];
149 r.send(a); 153 }
150 }); 154 r.send(a);
151 } 155 }
152 156
153 157
154 // Int32 array. 158 // Int32 array.
155 Int32List initInt32() { 159 Int32List initInt32() {
156 var int32 = new Int32List(2); 160 var int32 = new Int32List(2);
157 int32[0] = 100000; 161 int32[0] = 100000;
158 int32[1] = 1000000; 162 int32[1] = 1000000;
159 return int32; 163 return int32;
160 } 164 }
161 Int32List int32 = initInt32(); 165 Int32List int32 = initInt32();
162 166
163 void int32_receiver() { 167 void int32_receiver() {
164 var sp = spawnFunction(int32_sender); 168 var response = new ReceivePort();
165 sp.call(int32.length).then((a) { 169 var remote = Isolate.spawn(int32_sender, [int32.length, response.sendPort]);
170 response.first.then((a) {
166 Expect.equals(int32.length, a.length); 171 Expect.equals(int32.length, a.length);
167 for (int i = 0; i < a.length; i++) { 172 for (int i = 0; i < a.length; i++) {
168 Expect.equals(int32[i], a[i]); 173 Expect.equals(int32[i], a[i]);
169 } 174 }
170 print("int32_receiver"); 175 print("int32_receiver");
171 }); 176 });
172 } 177 }
173 178
174 int32_sender() { 179 int32_sender(message) {
175 port.receive((len, r) { 180 var len = message[0];
176 Expect.equals(int32.length, len); 181 var r = message[1];
177 var a = new Int32List(len); 182 Expect.equals(int32.length, len);
178 for (int i = 0; i < len; i++) { 183 var a = new Int32List(len);
179 a[i] = int32[i]; 184 for (int i = 0; i < len; i++) {
180 } 185 a[i] = int32[i];
181 r.send(a); 186 }
182 }); 187 r.send(a);
183 } 188 }
184 189
185 190
186 // Uint32 array. 191 // Uint32 array.
187 Uint32List initUint32() { 192 Uint32List initUint32() {
188 var uint32 = new Uint32List(2); 193 var uint32 = new Uint32List(2);
189 uint32[0] = 0xffffffff; 194 uint32[0] = 0xffffffff;
190 uint32[1] = 0x7fffffff; 195 uint32[1] = 0x7fffffff;
191 return uint32; 196 return uint32;
192 } 197 }
193 Uint32List uint32 = initUint32(); 198 Uint32List uint32 = initUint32();
194 199
195 void uint32_receiver() { 200 void uint32_receiver() {
196 var sp = spawnFunction(uint32_sender); 201 var response = new ReceivePort();
197 sp.call(uint32.length).then((a) { 202 var remote = Isolate.spawn(uint32_sender, [uint32.length, response.sendPort]);
203 response.first.then((a) {
198 Expect.equals(uint32.length, a.length); 204 Expect.equals(uint32.length, a.length);
199 for (int i = 0; i < a.length; i++) { 205 for (int i = 0; i < a.length; i++) {
200 Expect.equals(uint32[i], a[i]); 206 Expect.equals(uint32[i], a[i]);
201 } 207 }
202 print("uint32_receiver"); 208 print("uint32_receiver");
203 }); 209 });
204 } 210 }
205 211
206 uint32_sender() { 212 uint32_sender(message) {
207 port.receive((len, r) { 213 var len = message[0];
208 Expect.equals(uint32.length, len); 214 var r = message[1];
209 var a = new Uint32List(len); 215 Expect.equals(uint32.length, len);
210 for (int i = 0; i < len; i++) { 216 var a = new Uint32List(len);
211 a[i] = uint32[i]; 217 for (int i = 0; i < len; i++) {
212 } 218 a[i] = uint32[i];
213 r.send(a); 219 }
214 }); 220 r.send(a);
215 } 221 }
216 222
217 223
218 // Float32 Array. 224 // Float32 Array.
219 Float32List initFloat32() { 225 Float32List initFloat32() {
220 var float32 = new Float32List(2); 226 var float32 = new Float32List(2);
221 float32[0] = 1.0; 227 float32[0] = 1.0;
222 float32[1] = 2.0; 228 float32[1] = 2.0;
223 return float32; 229 return float32;
224 } 230 }
225 Float32List float32 = initFloat32(); 231 Float32List float32 = initFloat32();
226 232
227 void float32_receiver() { 233 void float32_receiver() {
228 var sp = spawnFunction(float32_sender); 234 var response = new ReceivePort();
229 sp.call(float32.length).then((a) { 235 var remote =
236 Isolate.spawn(float32_sender, [float32.length, response.sendPort]);
237 response.first.then((a) {
230 Expect.equals(float32.length, a.length); 238 Expect.equals(float32.length, a.length);
231 for (int i = 0; i < a.length; i++) { 239 for (int i = 0; i < a.length; i++) {
232 Expect.equals(float32[i], a[i]); 240 Expect.equals(float32[i], a[i]);
233 } 241 }
234 print("float32_receiver"); 242 print("float32_receiver");
235 }); 243 });
236 } 244 }
237 245
238 float32_sender() { 246 float32_sender(message) {
239 port.receive((len, r) { 247 var len = message[0];
240 Expect.equals(float32.length, len); 248 var r = message[1];
241 var a = new Float32List(len); 249 Expect.equals(float32.length, len);
242 for (int i = 0; i < len; i++) { 250 var a = new Float32List(len);
243 a[i] = float32[i]; 251 for (int i = 0; i < len; i++) {
244 } 252 a[i] = float32[i];
245 r.send(a); 253 }
246 }); 254 r.send(a);
247 } 255 }
248 256
249 257
250 // Float64 Array. 258 // Float64 Array.
251 Float64List initFloat64() { 259 Float64List initFloat64() {
252 var float64 = new Float64List(2); 260 var float64 = new Float64List(2);
253 float64[0] = 101.234; 261 float64[0] = 101.234;
254 float64[1] = 201.765; 262 float64[1] = 201.765;
255 return float64; 263 return float64;
256 } 264 }
257 Float64List float64 = initFloat64(); 265 Float64List float64 = initFloat64();
258 266
259 void float64_receiver() { 267 void float64_receiver() {
260 var sp = spawnFunction(float64_sender); 268 var response = new ReceivePort();
261 sp.call(float64.length).then((a) { 269 var remote =
270 Isolate.spawn(float64_sender, [float64.length, response.sendPort]);
271 response.first.then((a) {
262 Expect.equals(float64.length, a.length); 272 Expect.equals(float64.length, a.length);
263 for (int i = 0; i < a.length; i++) { 273 for (int i = 0; i < a.length; i++) {
264 Expect.equals(float64[i], a[i]); 274 Expect.equals(float64[i], a[i]);
265 } 275 }
266 print("float64_receiver"); 276 print("float64_receiver");
267 }); 277 });
268 } 278 }
269 279
270 float64_sender() { 280 float64_sender(message) {
271 port.receive((len, r) { 281 var len = message[0];
272 Expect.equals(float64.length, len); 282 var r = message[1];
273 var a = new Float64List(len); 283 Expect.equals(float64.length, len);
274 for (int i = 0; i < len; i++) { 284 var a = new Float64List(len);
275 a[i] = float64[i]; 285 for (int i = 0; i < len; i++) {
276 } 286 a[i] = float64[i];
277 r.send(a); 287 }
278 }); 288 r.send(a);
279 } 289 }
OLDNEW
« no previous file with comments | « tests/standalone/typed_array_int64_uint64_test.dart ('k') | tests/standalone/typed_data_isolate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698