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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 11280241: Fix StringBase_createFromCodePoints to correctly accept Latin-1 characters (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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
« no previous file with comments | « 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) 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 514
515 TEST_CASE(IsString) { 515 TEST_CASE(IsString) {
516 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; 516 uint8_t data8[] = { 'o', 'n', 'e', 0x7F };
517 517
518 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); 518 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8));
519 EXPECT_VALID(str8); 519 EXPECT_VALID(str8);
520 EXPECT(Dart_IsString(str8)); 520 EXPECT(Dart_IsString(str8));
521 EXPECT(Dart_IsStringLatin1(str8)); 521 EXPECT(Dart_IsStringLatin1(str8));
522 EXPECT(!Dart_IsExternalString(str8)); 522 EXPECT(!Dart_IsExternalString(str8));
523 523
524 Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), 524 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8),
525 NULL, NULL); 525 NULL, NULL);
526 EXPECT_VALID(ext8); 526 EXPECT_VALID(ext8);
527 EXPECT(Dart_IsString(ext8)); 527 EXPECT(Dart_IsString(ext8));
528 EXPECT(Dart_IsExternalString(ext8)); 528 EXPECT(Dart_IsExternalString(ext8));
529 529
530 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; 530 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF };
531 531
532 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); 532 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16));
533 EXPECT_VALID(str16); 533 EXPECT_VALID(str16);
534 EXPECT(Dart_IsString(str16)); 534 EXPECT(Dart_IsString(str16));
535 EXPECT(!Dart_IsStringLatin1(str16)); 535 EXPECT(!Dart_IsStringLatin1(str16));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. 568 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow.
569 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, 569 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid,
570 ARRAY_SIZE(invalid)); 570 ARRAY_SIZE(invalid));
571 EXPECT(Dart_IsError(invalid_str)); 571 EXPECT(Dart_IsError(invalid_str));
572 } 572 }
573 573
574 574
575 TEST_CASE(ExternalStringGetPeer) { 575 TEST_CASE(ExternalStringGetPeer) {
576 Dart_Handle result; 576 Dart_Handle result;
577 577
578 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; 578 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
579 int peer_data = 123; 579 int peer_data = 123;
580 void* peer = NULL; 580 void* peer = NULL;
581 581
582 // Success. 582 // Success.
583 Dart_Handle ext8 = Dart_NewExternalUTF8String(data8, ARRAY_SIZE(data8), 583 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8),
584 &peer_data, NULL); 584 &peer_data, NULL);
585 EXPECT_VALID(ext8); 585 EXPECT_VALID(ext8);
586 586
587 result = Dart_ExternalStringGetPeer(ext8, &peer); 587 result = Dart_ExternalStringGetPeer(ext8, &peer);
588 EXPECT_VALID(result); 588 EXPECT_VALID(result);
589 EXPECT_EQ(&peer_data, peer); 589 EXPECT_EQ(&peer_data, peer);
590 590
591 // NULL peer. 591 // NULL peer.
592 result = Dart_ExternalStringGetPeer(ext8, NULL); 592 result = Dart_ExternalStringGetPeer(ext8, NULL);
593 EXPECT(Dart_IsError(result)); 593 EXPECT(Dart_IsError(result));
594 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'peer' to be " 594 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'peer' to be "
595 "non-null.", Dart_GetError(result)); 595 "non-null.", Dart_GetError(result));
596 596
597 // String is not external. 597 // String is not external.
598 peer = NULL; 598 peer = NULL;
599 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); 599 uint8_t utf8_data8[] = { 'o', 'n', 'e', 0x7F };
600 Dart_Handle str8 = Dart_NewStringFromUTF8(utf8_data8, ARRAY_SIZE(data8));
600 EXPECT_VALID(str8); 601 EXPECT_VALID(str8);
601 result = Dart_ExternalStringGetPeer(str8, &peer); 602 result = Dart_ExternalStringGetPeer(str8, &peer);
602 EXPECT(Dart_IsError(result)); 603 EXPECT(Dart_IsError(result));
603 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " 604 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be "
604 "an external String.", Dart_GetError(result)); 605 "an external String.", Dart_GetError(result));
605 EXPECT(peer == NULL); 606 EXPECT(peer == NULL);
606 607
607 // Not a String. 608 // Not a String.
608 peer = NULL; 609 peer = NULL;
609 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); 610 result = Dart_ExternalStringGetPeer(Dart_True(), &peer);
(...skipping 13 matching lines...) Expand all
623 624
624 625
625 TEST_CASE(ExternalStringCallback) { 626 TEST_CASE(ExternalStringCallback) {
626 int peer8 = 40; 627 int peer8 = 40;
627 int peer16 = 41; 628 int peer16 = 41;
628 629
629 { 630 {
630 Dart_EnterScope(); 631 Dart_EnterScope();
631 632
632 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; 633 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
633 Dart_Handle obj8 = Dart_NewExternalUTF8String( 634 Dart_Handle obj8 = Dart_NewExternalLatin1String(
634 data8, 635 data8,
635 ARRAY_SIZE(data8), 636 ARRAY_SIZE(data8),
636 &peer8, 637 &peer8,
637 ExternalStringCallbackFinalizer); 638 ExternalStringCallbackFinalizer);
638 EXPECT_VALID(obj8); 639 EXPECT_VALID(obj8);
639 void* api_peer8 = NULL; 640 void* api_peer8 = NULL;
640 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8)); 641 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8));
641 EXPECT_EQ(api_peer8, &peer8); 642 EXPECT_EQ(api_peer8, &peer8);
642 643
643 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; 644 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' };
(...skipping 6524 matching lines...) Expand 10 before | Expand all | Expand 10 after
7168 int peer16 = 41; 7169 int peer16 = 41;
7169 intptr_t length = 0; 7170 intptr_t length = 0;
7170 intptr_t expected_length = 0; 7171 intptr_t expected_length = 0;
7171 { 7172 {
7172 Dart_EnterScope(); 7173 Dart_EnterScope();
7173 7174
7174 // First test some negative conditions. 7175 // First test some negative conditions.
7175 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; 7176 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
7176 const char* err = "string"; 7177 const char* err = "string";
7177 Dart_Handle err_str = NewString(err); 7178 Dart_Handle err_str = NewString(err);
7178 Dart_Handle ext_err_str = Dart_NewExternalUTF8String( 7179 Dart_Handle ext_err_str = Dart_NewExternalLatin1String(
7179 data8, ARRAY_SIZE(data8), NULL, NULL); 7180 data8, ARRAY_SIZE(data8), NULL, NULL);
7180 Dart_Handle result = Dart_MakeExternalString(Dart_Null(), 7181 Dart_Handle result = Dart_MakeExternalString(Dart_Null(),
7181 data8, 7182 data8,
7182 ARRAY_SIZE(data8), 7183 ARRAY_SIZE(data8),
7183 NULL, 7184 NULL,
7184 NULL); 7185 NULL);
7185 EXPECT(Dart_IsError(result)); // Null string object passed in. 7186 EXPECT(Dart_IsError(result)); // Null string object passed in.
7186 result = Dart_MakeExternalString(err_str, 7187 result = Dart_MakeExternalString(err_str,
7187 NULL, 7188 NULL,
7188 ARRAY_SIZE(data8), 7189 ARRAY_SIZE(data8),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
7337 Dart_LoadSource(TestCase::lib(), url, source); 7338 Dart_LoadSource(TestCase::lib(), url, source);
7338 7339
7339 dart_args[0] = Dart_NewInteger(1); 7340 dart_args[0] = Dart_NewInteger(1);
7340 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); 7341 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args);
7341 EXPECT_VALID(result); 7342 EXPECT_VALID(result);
7342 } 7343 }
7343 7344
7344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7345 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7345 7346
7346 } // namespace dart 7347 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698