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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 8372094: Renaming Array -> List in the VM API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Dart_ShutdownIsolate(); 173 Dart_ShutdownIsolate();
174 } 174 }
175 175
176 176
177 UNIT_TEST_CASE(ArrayValues) { 177 UNIT_TEST_CASE(ArrayValues) {
178 Dart_CreateIsolate(NULL, NULL); 178 Dart_CreateIsolate(NULL, NULL);
179 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 179 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
180 180
181 const int kArrayLength = 10; 181 const int kArrayLength = 10;
182 Dart_Handle str = Dart_NewString("test"); 182 Dart_Handle str = Dart_NewString("test");
183 EXPECT(!Dart_IsArray(str)); 183 EXPECT(!Dart_IsList(str));
184 Dart_Handle val = Dart_NewArray(kArrayLength); 184 Dart_Handle val = Dart_NewList(kArrayLength);
185 EXPECT(Dart_IsArray(val)); 185 EXPECT(Dart_IsList(val));
186 intptr_t len = 0; 186 intptr_t len = 0;
187 Dart_Handle result = Dart_GetLength(val, &len); 187 Dart_Handle result = Dart_ListLength(val, &len);
188 EXPECT_VALID(result); 188 EXPECT_VALID(result);
189 EXPECT_EQ(kArrayLength, len); 189 EXPECT_EQ(kArrayLength, len);
190 190
191 // Check invalid array access. 191 // Check invalid array access.
192 result = Dart_ArraySetAt(val, (kArrayLength + 10), Dart_NewInteger(10)); 192 result = Dart_ListSetAt(val, (kArrayLength + 10), Dart_NewInteger(10));
193 EXPECT(!Dart_IsValid(result)); 193 EXPECT(!Dart_IsValid(result));
194 result = Dart_ArraySetAt(val, -10, Dart_NewInteger(10)); 194 result = Dart_ListSetAt(val, -10, Dart_NewInteger(10));
195 EXPECT(!Dart_IsValid(result)); 195 EXPECT(!Dart_IsValid(result));
196 result = Dart_ArrayGetAt(val, (kArrayLength + 10)); 196 result = Dart_ListGetAt(val, (kArrayLength + 10));
197 EXPECT(!Dart_IsValid(result)); 197 EXPECT(!Dart_IsValid(result));
198 result = Dart_ArrayGetAt(val, -10); 198 result = Dart_ListGetAt(val, -10);
199 EXPECT(!Dart_IsValid(result)); 199 EXPECT(!Dart_IsValid(result));
200 200
201 for (int i = 0; i < kArrayLength; i++) { 201 for (int i = 0; i < kArrayLength; i++) {
202 result = Dart_ArraySetAt(val, i, Dart_NewInteger(i)); 202 result = Dart_ListSetAt(val, i, Dart_NewInteger(i));
203 EXPECT_VALID(result); 203 EXPECT_VALID(result);
204 } 204 }
205 for (int i = 0; i < kArrayLength; i++) { 205 for (int i = 0; i < kArrayLength; i++) {
206 result = Dart_ArrayGetAt(val, i); 206 result = Dart_ListGetAt(val, i);
207 EXPECT_VALID(result); 207 EXPECT_VALID(result);
208 int64_t value; 208 int64_t value;
209 result = Dart_IntegerValue(result, &value); 209 result = Dart_IntegerValue(result, &value);
210 EXPECT_VALID(result); 210 EXPECT_VALID(result);
211 EXPECT_EQ(i, value); 211 EXPECT_EQ(i, value);
212 } 212 }
213 213
214 Dart_ExitScope(); // Exit the Dart API scope. 214 Dart_ExitScope(); // Exit the Dart API scope.
215 Dart_ShutdownIsolate(); 215 Dart_ShutdownIsolate();
216 } 216 }
(...skipping 27 matching lines...) Expand all
244 Dart_NewString("ListAccessTest"), 244 Dart_NewString("ListAccessTest"),
245 Dart_NewString("testMain"), 245 Dart_NewString("testMain"),
246 0, 246 0,
247 NULL); 247 NULL);
248 EXPECT(Dart_IsValid(result)); 248 EXPECT(Dart_IsValid(result));
249 EXPECT(!Dart_ExceptionOccurred(result)); 249 EXPECT(!Dart_ExceptionOccurred(result));
250 250
251 // First ensure that the returned object is an array. 251 // First ensure that the returned object is an array.
252 Dart_Handle ListAccessTestObj = result; 252 Dart_Handle ListAccessTestObj = result;
253 253
254 EXPECT(Dart_IsArray(ListAccessTestObj)); 254 EXPECT(Dart_IsList(ListAccessTestObj));
255 255
256 // Get length of array object. 256 // Get length of array object.
257 intptr_t len = 0; 257 intptr_t len = 0;
258 result = Dart_GetLength(ListAccessTestObj, &len); 258 result = Dart_ListLength(ListAccessTestObj, &len);
259 EXPECT(Dart_IsValid(result)); 259 EXPECT(Dart_IsValid(result));
260 EXPECT_EQ(3, len); 260 EXPECT_EQ(3, len);
261 261
262 // Access elements in the array. 262 // Access elements in the array.
263 int64_t value; 263 int64_t value;
264 264
265 result = Dart_ArrayGetAt(ListAccessTestObj, 0); 265 result = Dart_ListGetAt(ListAccessTestObj, 0);
266 EXPECT(Dart_IsValid(result)); 266 EXPECT(Dart_IsValid(result));
267 result = Dart_IntegerValue(result, &value); 267 result = Dart_IntegerValue(result, &value);
268 EXPECT(Dart_IsValid(result)); 268 EXPECT(Dart_IsValid(result));
269 EXPECT_EQ(10, value); 269 EXPECT_EQ(10, value);
270 270
271 result = Dart_ArrayGetAt(ListAccessTestObj, 1); 271 result = Dart_ListGetAt(ListAccessTestObj, 1);
272 EXPECT(Dart_IsValid(result)); 272 EXPECT(Dart_IsValid(result));
273 result = Dart_IntegerValue(result, &value); 273 result = Dart_IntegerValue(result, &value);
274 EXPECT(Dart_IsValid(result)); 274 EXPECT(Dart_IsValid(result));
275 EXPECT_EQ(20, value); 275 EXPECT_EQ(20, value);
276 276
277 result = Dart_ArrayGetAt(ListAccessTestObj, 2); 277 result = Dart_ListGetAt(ListAccessTestObj, 2);
278 EXPECT(Dart_IsValid(result)); 278 EXPECT(Dart_IsValid(result));
279 result = Dart_IntegerValue(result, &value); 279 result = Dart_IntegerValue(result, &value);
280 EXPECT(Dart_IsValid(result)); 280 EXPECT(Dart_IsValid(result));
281 EXPECT_EQ(30, value); 281 EXPECT_EQ(30, value);
282 282
283 // Set some elements in the array. 283 // Set some elements in the array.
284 result = Dart_ArraySetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); 284 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0));
285 EXPECT(Dart_IsValid(result)); 285 EXPECT(Dart_IsValid(result));
286 result = Dart_ArraySetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); 286 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1));
287 EXPECT(Dart_IsValid(result)); 287 EXPECT(Dart_IsValid(result));
288 result = Dart_ArraySetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); 288 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2));
289 EXPECT(Dart_IsValid(result)); 289 EXPECT(Dart_IsValid(result));
290 290
291 // Get length of array object. 291 // Get length of array object.
292 result = Dart_GetLength(ListAccessTestObj, &len); 292 result = Dart_ListLength(ListAccessTestObj, &len);
293 EXPECT(Dart_IsValid(result)); 293 EXPECT(Dart_IsValid(result));
294 EXPECT_EQ(3, len); 294 EXPECT_EQ(3, len);
295 295
296 // Now try and access these elements in the array. 296 // Now try and access these elements in the array.
297 result = Dart_ArrayGetAt(ListAccessTestObj, 0); 297 result = Dart_ListGetAt(ListAccessTestObj, 0);
298 EXPECT(Dart_IsValid(result)); 298 EXPECT(Dart_IsValid(result));
299 result = Dart_IntegerValue(result, &value); 299 result = Dart_IntegerValue(result, &value);
300 EXPECT(Dart_IsValid(result)); 300 EXPECT(Dart_IsValid(result));
301 EXPECT_EQ(0, value); 301 EXPECT_EQ(0, value);
302 302
303 result = Dart_ArrayGetAt(ListAccessTestObj, 1); 303 result = Dart_ListGetAt(ListAccessTestObj, 1);
304 EXPECT(Dart_IsValid(result)); 304 EXPECT(Dart_IsValid(result));
305 result = Dart_IntegerValue(result, &value); 305 result = Dart_IntegerValue(result, &value);
306 EXPECT(Dart_IsValid(result)); 306 EXPECT(Dart_IsValid(result));
307 EXPECT_EQ(1, value); 307 EXPECT_EQ(1, value);
308 308
309 result = Dart_ArrayGetAt(ListAccessTestObj, 2); 309 result = Dart_ListGetAt(ListAccessTestObj, 2);
310 EXPECT(Dart_IsValid(result)); 310 EXPECT(Dart_IsValid(result));
311 result = Dart_IntegerValue(result, &value); 311 result = Dart_IntegerValue(result, &value);
312 EXPECT(Dart_IsValid(result)); 312 EXPECT(Dart_IsValid(result));
313 EXPECT_EQ(2, value); 313 EXPECT_EQ(2, value);
314 314
315 uint8_t native_array[3]; 315 uint8_t native_array[3];
316 result = Dart_ArrayGet(ListAccessTestObj, 0, native_array, 3); 316 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
317 EXPECT(Dart_IsValid(result)); 317 EXPECT(Dart_IsValid(result));
318 EXPECT_EQ(0, native_array[0]); 318 EXPECT_EQ(0, native_array[0]);
319 EXPECT_EQ(1, native_array[1]); 319 EXPECT_EQ(1, native_array[1]);
320 EXPECT_EQ(2, native_array[2]); 320 EXPECT_EQ(2, native_array[2]);
321 321
322 native_array[0] = 10; 322 native_array[0] = 10;
323 native_array[1] = 20; 323 native_array[1] = 20;
324 native_array[2] = 30; 324 native_array[2] = 30;
325 result = Dart_ArraySet(ListAccessTestObj, 0, native_array, 3); 325 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3);
326 EXPECT(Dart_IsValid(result)); 326 EXPECT(Dart_IsValid(result));
327 result = Dart_ArrayGet(ListAccessTestObj, 0, native_array, 3); 327 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
328 EXPECT(Dart_IsValid(result)); 328 EXPECT(Dart_IsValid(result));
329 EXPECT_EQ(10, native_array[0]); 329 EXPECT_EQ(10, native_array[0]);
330 EXPECT_EQ(20, native_array[1]); 330 EXPECT_EQ(20, native_array[1]);
331 EXPECT_EQ(30, native_array[2]); 331 EXPECT_EQ(30, native_array[2]);
332 result = Dart_ArrayGetAt(ListAccessTestObj, 2); 332 result = Dart_ListGetAt(ListAccessTestObj, 2);
333 EXPECT(Dart_IsValid(result)); 333 EXPECT(Dart_IsValid(result));
334 result = Dart_IntegerValue(result, &value); 334 result = Dart_IntegerValue(result, &value);
335 EXPECT(Dart_IsValid(result)); 335 EXPECT(Dart_IsValid(result));
336 EXPECT_EQ(30, value); 336 EXPECT_EQ(30, value);
337 337
338 // Check if we get an exception when accessing beyond limit. 338 // Check if we get an exception when accessing beyond limit.
339 result = Dart_ArrayGetAt(ListAccessTestObj, 4); 339 result = Dart_ListGetAt(ListAccessTestObj, 4);
340 EXPECT(!Dart_IsValid(result)); 340 EXPECT(!Dart_IsValid(result));
341 341
342 Dart_ExitScope(); // Exit the Dart API scope. 342 Dart_ExitScope(); // Exit the Dart API scope.
343 } 343 }
344 Dart_ShutdownIsolate(); 344 Dart_ShutdownIsolate();
345 } 345 }
346 346
347 #endif // TARGET_ARCH_IA32. 347 #endif // TARGET_ARCH_IA32.
348 348
349 349
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 NULL); 1858 NULL);
1859 EXPECT_VALID(result); 1859 EXPECT_VALID(result);
1860 1860
1861 Dart_ExitScope(); // Exit the Dart API scope. 1861 Dart_ExitScope(); // Exit the Dart API scope.
1862 } 1862 }
1863 Dart_ShutdownIsolate(); 1863 Dart_ShutdownIsolate();
1864 } 1864 }
1865 #endif // TARGET_ARCH_IA32. 1865 #endif // TARGET_ARCH_IA32.
1866 1866
1867 } // namespace dart 1867 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698