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

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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 EXPECT_VALID(result); 506 EXPECT_VALID(result);
507 int64_t value; 507 int64_t value;
508 result = Dart_IntegerToInt64(result, &value); 508 result = Dart_IntegerToInt64(result, &value);
509 EXPECT_VALID(result); 509 EXPECT_VALID(result);
510 EXPECT_EQ(i, value); 510 EXPECT_EQ(i, value);
511 } 511 }
512 } 512 }
513 513
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 };
srdjan 2012/11/29 21:05:51 How about adding chars >0x7F here?
siva 2012/11/29 23:20:41 Done.
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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', 0x7F };
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 "
(...skipping 28 matching lines...) Expand all
623 623
624 624
625 TEST_CASE(ExternalStringCallback) { 625 TEST_CASE(ExternalStringCallback) {
626 int peer8 = 40; 626 int peer8 = 40;
627 int peer16 = 41; 627 int peer16 = 41;
628 628
629 { 629 {
630 Dart_EnterScope(); 630 Dart_EnterScope();
631 631
632 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; 632 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
633 Dart_Handle obj8 = Dart_NewExternalUTF8String( 633 Dart_Handle obj8 = Dart_NewExternalLatin1String(
634 data8, 634 data8,
635 ARRAY_SIZE(data8), 635 ARRAY_SIZE(data8),
636 &peer8, 636 &peer8,
637 ExternalStringCallbackFinalizer); 637 ExternalStringCallbackFinalizer);
638 EXPECT_VALID(obj8); 638 EXPECT_VALID(obj8);
639 void* api_peer8 = NULL; 639 void* api_peer8 = NULL;
640 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8)); 640 EXPECT_VALID(Dart_ExternalStringGetPeer(obj8, &api_peer8));
641 EXPECT_EQ(api_peer8, &peer8); 641 EXPECT_EQ(api_peer8, &peer8);
642 642
643 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' }; 643 uint16_t data16[] = { 'h', 'e', 'l', 'l', 'o' };
(...skipping 6524 matching lines...) Expand 10 before | Expand all | Expand 10 after
7168 int peer16 = 41; 7168 int peer16 = 41;
7169 intptr_t length = 0; 7169 intptr_t length = 0;
7170 intptr_t expected_length = 0; 7170 intptr_t expected_length = 0;
7171 { 7171 {
7172 Dart_EnterScope(); 7172 Dart_EnterScope();
7173 7173
7174 // First test some negative conditions. 7174 // First test some negative conditions.
7175 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; 7175 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
7176 const char* err = "string"; 7176 const char* err = "string";
7177 Dart_Handle err_str = NewString(err); 7177 Dart_Handle err_str = NewString(err);
7178 Dart_Handle ext_err_str = Dart_NewExternalUTF8String( 7178 Dart_Handle ext_err_str = Dart_NewExternalLatin1String(
7179 data8, ARRAY_SIZE(data8), NULL, NULL); 7179 data8, ARRAY_SIZE(data8), NULL, NULL);
7180 Dart_Handle result = Dart_MakeExternalString(Dart_Null(), 7180 Dart_Handle result = Dart_MakeExternalString(Dart_Null(),
7181 data8, 7181 data8,
7182 ARRAY_SIZE(data8), 7182 ARRAY_SIZE(data8),
7183 NULL, 7183 NULL,
7184 NULL); 7184 NULL);
7185 EXPECT(Dart_IsError(result)); // Null string object passed in. 7185 EXPECT(Dart_IsError(result)); // Null string object passed in.
7186 result = Dart_MakeExternalString(err_str, 7186 result = Dart_MakeExternalString(err_str,
7187 NULL, 7187 NULL,
7188 ARRAY_SIZE(data8), 7188 ARRAY_SIZE(data8),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
7337 Dart_LoadSource(TestCase::lib(), url, source); 7337 Dart_LoadSource(TestCase::lib(), url, source);
7338 7338
7339 dart_args[0] = Dart_NewInteger(1); 7339 dart_args[0] = Dart_NewInteger(1);
7340 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); 7340 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args);
7341 EXPECT_VALID(result); 7341 EXPECT_VALID(result);
7342 } 7342 }
7343 7343
7344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7345 7345
7346 } // namespace dart 7346 } // 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