| 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/utils.h" | 7 #include "platform/utils.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), | 556 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), |
| 557 NULL, NULL); | 557 NULL, NULL); |
| 558 EXPECT_VALID(ext32); | 558 EXPECT_VALID(ext32); |
| 559 EXPECT(Dart_IsString(ext32)); | 559 EXPECT(Dart_IsString(ext32)); |
| 560 EXPECT(!Dart_IsString8(ext32)); | 560 EXPECT(!Dart_IsString8(ext32)); |
| 561 EXPECT(!Dart_IsString16(ext32)); | 561 EXPECT(!Dart_IsString16(ext32)); |
| 562 EXPECT(Dart_IsExternalString(ext32)); | 562 EXPECT(Dart_IsExternalString(ext32)); |
| 563 } | 563 } |
| 564 | 564 |
| 565 | 565 |
| 566 TEST_CASE(NewString) { |
| 567 const char* ascii = "string"; |
| 568 Dart_Handle ascii_str = Dart_NewString(ascii); |
| 569 EXPECT_VALID(ascii_str); |
| 570 EXPECT(Dart_IsString(ascii_str)); |
| 571 |
| 572 const char* null = NULL; |
| 573 Dart_Handle null_str = Dart_NewString(null); |
| 574 EXPECT(Dart_IsError(null_str)); |
| 575 |
| 576 const char* utf8 = "\xE4\xBA\x8C"; // U+4E8C |
| 577 Dart_Handle utf8_str = Dart_NewString(utf8); |
| 578 EXPECT_VALID(utf8_str); |
| 579 EXPECT(Dart_IsString(utf8_str)); |
| 580 |
| 581 const char* invalid = "\xE4\xBA"; // underflow |
| 582 Dart_Handle invalid_str = Dart_NewString(invalid); |
| 583 EXPECT(Dart_IsError(invalid_str)); |
| 584 } |
| 585 |
| 586 |
| 566 TEST_CASE(ExternalStringGetPeer) { | 587 TEST_CASE(ExternalStringGetPeer) { |
| 567 Dart_Handle result; | 588 Dart_Handle result; |
| 568 | 589 |
| 569 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; | 590 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; |
| 570 int peer_data = 123; | 591 int peer_data = 123; |
| 571 void* peer = NULL; | 592 void* peer = NULL; |
| 572 | 593 |
| 573 // Success. | 594 // Success. |
| 574 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), | 595 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), |
| 575 &peer_data, NULL); | 596 &peer_data, NULL); |
| (...skipping 4877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5453 EXPECT_VALID(result); | 5474 EXPECT_VALID(result); |
| 5454 EXPECT(Dart_IsInteger(result)); | 5475 EXPECT(Dart_IsInteger(result)); |
| 5455 int64_t value = 0; | 5476 int64_t value = 0; |
| 5456 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5477 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 5457 EXPECT_EQ(0, value); | 5478 EXPECT_EQ(0, value); |
| 5458 } | 5479 } |
| 5459 | 5480 |
| 5460 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 5481 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 5461 | 5482 |
| 5462 } // namespace dart | 5483 } // namespace dart |
| OLD | NEW |