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

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

Issue 8775039: Add Dart_IsExternalString and Dart_ExternalStringGetPeer to the dart (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years 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) 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 result = Dart_ListGetAt(val, i); 347 result = Dart_ListGetAt(val, i);
348 EXPECT_VALID(result); 348 EXPECT_VALID(result);
349 int64_t value; 349 int64_t value;
350 result = Dart_IntegerValue(result, &value); 350 result = Dart_IntegerValue(result, &value);
351 EXPECT_VALID(result); 351 EXPECT_VALID(result);
352 EXPECT_EQ(i, value); 352 EXPECT_EQ(i, value);
353 } 353 }
354 } 354 }
355 355
356 356
357 UNIT_TEST_CASE(IsString) { 357 UNIT_TEST_CASE(IsString) {
siva 2011/12/02 01:53:01 I am wondering why many of the tests in this file
turnidge 2011/12/05 17:54:28 True. Yes.
358 TestIsolateScope __test_isolate__; 358 TestIsolateScope __test_isolate__;
359 359
360 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 360 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
361 361
362 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); 362 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8));
363 EXPECT_VALID(str8); 363 EXPECT_VALID(str8);
364 EXPECT(Dart_IsString(str8)); 364 EXPECT(Dart_IsString(str8));
365 EXPECT(Dart_IsString8(str8)); 365 EXPECT(Dart_IsString8(str8));
366 EXPECT(Dart_IsString16(str8)); 366 EXPECT(Dart_IsString16(str8));
367 EXPECT(!Dart_IsExternalString(str8));
367 368
368 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), 369 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8),
369 NULL, NULL); 370 NULL, NULL);
370 EXPECT_VALID(ext8); 371 EXPECT_VALID(ext8);
371 EXPECT(Dart_IsString(ext8)); 372 EXPECT(Dart_IsString(ext8));
372 EXPECT(Dart_IsString8(ext8)); 373 EXPECT(Dart_IsString8(ext8));
373 EXPECT(Dart_IsString16(ext8)); 374 EXPECT(Dart_IsString16(ext8));
375 EXPECT(Dart_IsExternalString(ext8));
374 376
375 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; 377 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF };
376 378
377 Dart_Handle str16 = Dart_NewString16(data16, ARRAY_SIZE(data16)); 379 Dart_Handle str16 = Dart_NewString16(data16, ARRAY_SIZE(data16));
378 EXPECT_VALID(str16); 380 EXPECT_VALID(str16);
379 EXPECT(Dart_IsString(str16)); 381 EXPECT(Dart_IsString(str16));
380 EXPECT(!Dart_IsString8(str16)); 382 EXPECT(!Dart_IsString8(str16));
381 EXPECT(Dart_IsString16(str16)); 383 EXPECT(Dart_IsString16(str16));
384 EXPECT(!Dart_IsExternalString(str16));
382 385
383 Dart_Handle ext16 = Dart_NewExternalString16(data16, ARRAY_SIZE(data16), 386 Dart_Handle ext16 = Dart_NewExternalString16(data16, ARRAY_SIZE(data16),
384 NULL, NULL); 387 NULL, NULL);
385 EXPECT_VALID(ext16); 388 EXPECT_VALID(ext16);
386 EXPECT(Dart_IsString(ext16)); 389 EXPECT(Dart_IsString(ext16));
387 EXPECT(!Dart_IsString8(ext16)); 390 EXPECT(!Dart_IsString8(ext16));
388 EXPECT(Dart_IsString16(ext16)); 391 EXPECT(Dart_IsString16(ext16));
392 EXPECT(Dart_IsExternalString(ext16));
389 393
390 uint32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; 394 uint32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF };
391 395
392 Dart_Handle str32 = Dart_NewString32(data32, ARRAY_SIZE(data32)); 396 Dart_Handle str32 = Dart_NewString32(data32, ARRAY_SIZE(data32));
393 EXPECT_VALID(str32); 397 EXPECT_VALID(str32);
394 EXPECT(Dart_IsString(str32)); 398 EXPECT(Dart_IsString(str32));
395 EXPECT(!Dart_IsString8(str32)); 399 EXPECT(!Dart_IsString8(str32));
396 EXPECT(!Dart_IsString16(str32)); 400 EXPECT(!Dart_IsString16(str32));
401 EXPECT(!Dart_IsExternalString(str32));
397 402
398 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), 403 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32),
399 NULL, NULL); 404 NULL, NULL);
400 EXPECT_VALID(ext32); 405 EXPECT_VALID(ext32);
401 EXPECT(Dart_IsString(ext32)); 406 EXPECT(Dart_IsString(ext32));
402 EXPECT(!Dart_IsString8(ext32)); 407 EXPECT(!Dart_IsString8(ext32));
403 EXPECT(!Dart_IsString16(ext32)); 408 EXPECT(!Dart_IsString16(ext32));
409 EXPECT(Dart_IsExternalString(ext32));
410 }
411
412
413 UNIT_TEST_CASE(ExternalStringGetPeer) {
414 TestIsolateScope __test_isolate__;
415 Dart_Handle result;
416
417 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
418 int peer_data = 123;
419 void* peer = NULL;
420
421 // Success.
422 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8),
423 &peer_data, NULL);
424 EXPECT_VALID(ext8);
425
426 result = Dart_ExternalStringGetPeer(ext8, &peer);
427 EXPECT_VALID(result);
428 EXPECT_EQ(&peer_data, peer);
429
430 // NULL peer
siva 2011/12/02 01:53:01 missing '.'
turnidge 2011/12/05 17:54:28 Fixed.
431 result = Dart_ExternalStringGetPeer(ext8, NULL);
432 EXPECT(Dart_IsError(result));
433 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'peer' to be "
434 "non-NULL.", Dart_GetError(result));
435
436 // String is not external.
437 peer = NULL;
438 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8));
439 EXPECT_VALID(str8);
440 result = Dart_ExternalStringGetPeer(str8, &peer);
441 EXPECT(Dart_IsError(result));
442 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be "
443 "an external String.", Dart_GetError(result));
444 EXPECT(peer == NULL);
445
446 // Not a String.
447 peer = NULL;
448 result = Dart_ExternalStringGetPeer(Dart_True(), &peer);
449 EXPECT(Dart_IsError(result));
450 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be "
451 "of type String.", Dart_GetError(result));
452 EXPECT(peer == NULL);
404 } 453 }
405 454
406 455
407 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 456 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
408 457
409 UNIT_TEST_CASE(ListAccess) { 458 UNIT_TEST_CASE(ListAccess) {
410 const char* kScriptChars = 459 const char* kScriptChars =
411 "class ListAccessTest {" 460 "class ListAccessTest {"
412 " ListAccessTest() {}" 461 " ListAccessTest() {}"
413 " static List testMain() {" 462 " static List testMain() {"
(...skipping 2293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2707 } 2756 }
2708 2757
2709 2758
2710 UNIT_TEST_CASE(RunLoop_Exception) { 2759 UNIT_TEST_CASE(RunLoop_Exception) {
2711 RunLoopTest(true); 2760 RunLoopTest(true);
2712 } 2761 }
2713 2762
2714 #endif // TARGET_ARCH_IA32. 2763 #endif // TARGET_ARCH_IA32.
2715 2764
2716 } // namespace dart 2765 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698