OLD | NEW |
---|---|
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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 | 543 |
544 int32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; | 544 int32_t data32[] = { 'f', 'o', 'u', 'r', 0x10FFFF }; |
545 | 545 |
546 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); | 546 Dart_Handle str32 = Dart_NewStringFromUTF32(data32, ARRAY_SIZE(data32)); |
547 EXPECT_VALID(str32); | 547 EXPECT_VALID(str32); |
548 EXPECT(Dart_IsString(str32)); | 548 EXPECT(Dart_IsString(str32)); |
549 EXPECT(!Dart_IsExternalString(str32)); | 549 EXPECT(!Dart_IsExternalString(str32)); |
550 } | 550 } |
551 | 551 |
552 | 552 |
553 static void CheckToUTF8(Dart_Handle str, | |
554 intptr_t expected_len, | |
555 uint8_t* expected_utf8, | |
556 intptr_t expected_utf8_len) { | |
557 intptr_t len; | |
558 EXPECT_VALID(Dart_StringLength(str, &len)); | |
559 EXPECT_EQ(expected_len, len); | |
560 uint8_t* utf8_out; | |
561 EXPECT_VALID(Dart_StringToUTF8(str, &utf8_out, &len)); | |
562 EXPECT_EQ(expected_utf8_len, len); | |
563 EXPECT(!memcmp(expected_utf8, utf8_out, expected_utf8_len)); | |
564 } | |
565 | |
566 | |
553 TEST_CASE(NewString) { | 567 TEST_CASE(NewString) { |
554 const char* ascii = "string"; | 568 const char* ascii = "string"; |
555 Dart_Handle ascii_str = NewString(ascii); | 569 Dart_Handle ascii_str = NewString(ascii); |
556 EXPECT_VALID(ascii_str); | 570 EXPECT_VALID(ascii_str); |
557 EXPECT(Dart_IsString(ascii_str)); | 571 EXPECT(Dart_IsString(ascii_str)); |
558 | 572 |
559 const char* null = NULL; | 573 const char* null = NULL; |
560 Dart_Handle null_str = NewString(null); | 574 Dart_Handle null_str = NewString(null); |
561 EXPECT(Dart_IsError(null_str)); | 575 EXPECT(Dart_IsError(null_str)); |
562 | 576 |
563 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. | 577 { |
564 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | 578 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. |
565 EXPECT_VALID(utf8_str); | 579 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
566 EXPECT(Dart_IsString(utf8_str)); | 580 EXPECT_VALID(utf8_str); |
581 EXPECT(Dart_IsString(utf8_str)); | |
582 CheckToUTF8(utf8_str, 1, data, sizeof(data)); | |
583 } | |
567 | 584 |
568 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. | 585 { |
569 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, | 586 uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C. |
570 ARRAY_SIZE(invalid)); | 587 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); |
571 EXPECT(Dart_IsError(invalid_str)); | 588 EXPECT_VALID(utf8_str); |
589 EXPECT(Dart_IsString(utf8_str)); | |
590 CheckToUTF8(utf8_str, 1, data, sizeof(data)); | |
591 } | |
siva
2012/11/28 18:22:46
This test and the one above seem to test identical
Søren Gjesse
2012/11/29 09:06:14
This is all reverted.
| |
592 | |
593 { | |
594 uint8_t data[] = {0xf0, 0x90, 0x80, 0x80, // U+10000. | |
595 0xf0, 0x9f, 0x98, 0x81, // U+1F601. | |
596 0xf0, 0x9f, 0x98, 0xb7, // U+1F637. | |
597 0xf0, 0xa0, 0x80, 0x80}; // U+20000. | |
598 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | |
599 EXPECT_VALID(utf8_str); | |
600 EXPECT(Dart_IsString(utf8_str)); | |
601 CheckToUTF8(utf8_str, 8, data, sizeof(data)); | |
602 } | |
603 | |
604 { | |
605 uint8_t data[] = {0xed, 0xa0, 0x80}; // U+D800. | |
606 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | |
607 EXPECT_VALID(utf8_str); | |
608 EXPECT(Dart_IsString(utf8_str)); | |
609 CheckToUTF8(utf8_str, 1, data, sizeof(data)); | |
610 } | |
611 | |
612 { | |
613 uint8_t data[] = {0xed, 0xb0, 0x80}; // U+DC00. | |
614 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | |
615 EXPECT_VALID(utf8_str); | |
616 EXPECT(Dart_IsString(utf8_str)); | |
617 CheckToUTF8(utf8_str, 1, data, sizeof(data)); | |
618 } | |
619 | |
620 { | |
621 uint8_t data[] = {0xed, 0xa0, 0x80, // U+D800. | |
622 0xed, 0xb0, 0x80}; // U+DC00. | |
623 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | |
624 EXPECT_VALID(utf8_str); | |
625 EXPECT(Dart_IsString(utf8_str)); | |
626 uint8_t expected_out[] = {0xf0, 0x90, 0x80, 0x80}; // U+10000. | |
627 CheckToUTF8(utf8_str, 2, expected_out, sizeof(expected_out)); | |
628 } | |
629 | |
630 { | |
631 uint8_t data[] = {0xed, 0xb0, 0x80, // U+DC00. | |
632 0xed, 0xa0, 0x80}; // U+D800. | |
633 Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data)); | |
634 EXPECT_VALID(utf8_str); | |
635 EXPECT(Dart_IsString(utf8_str)); | |
636 CheckToUTF8(utf8_str, 2, data, sizeof(data)); | |
637 } | |
638 | |
639 { | |
640 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. | |
641 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, | |
642 ARRAY_SIZE(invalid)); | |
643 EXPECT(Dart_IsError(invalid_str)); | |
644 } | |
572 } | 645 } |
573 | 646 |
574 | 647 |
575 TEST_CASE(ExternalStringGetPeer) { | 648 TEST_CASE(ExternalStringGetPeer) { |
576 Dart_Handle result; | 649 Dart_Handle result; |
577 | 650 |
578 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; | 651 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; |
579 int peer_data = 123; | 652 int peer_data = 123; |
580 void* peer = NULL; | 653 void* peer = NULL; |
581 | 654 |
(...skipping 6798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7380 Dart_LoadSource(TestCase::lib(), url, source); | 7453 Dart_LoadSource(TestCase::lib(), url, source); |
7381 | 7454 |
7382 dart_args[0] = Dart_NewInteger(1); | 7455 dart_args[0] = Dart_NewInteger(1); |
7383 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7456 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
7384 EXPECT_VALID(result); | 7457 EXPECT_VALID(result); |
7385 } | 7458 } |
7386 | 7459 |
7387 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7460 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7388 | 7461 |
7389 } // namespace dart | 7462 } // namespace dart |
OLD | NEW |