| 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/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/thread.h" | 10 #include "vm/thread.h" |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 EXPECT_VALID(result); | 607 EXPECT_VALID(result); |
| 608 EXPECT_EQ(30, value); | 608 EXPECT_EQ(30, value); |
| 609 | 609 |
| 610 // Check if we get an exception when accessing beyond limit. | 610 // Check if we get an exception when accessing beyond limit. |
| 611 result = Dart_ListGetAt(ListAccessTestObj, 4); | 611 result = Dart_ListGetAt(ListAccessTestObj, 4); |
| 612 EXPECT(Dart_IsError(result)); | 612 EXPECT(Dart_IsError(result)); |
| 613 } | 613 } |
| 614 | 614 |
| 615 | 615 |
| 616 TEST_CASE(ByteArray) { | 616 TEST_CASE(ByteArray) { |
| 617 Dart_Handle obj1 = Dart_NewByteArray(10); | 617 Dart_Handle byte_array1 = Dart_NewByteArray(10); |
| 618 EXPECT_VALID(obj1); | 618 EXPECT_VALID(byte_array1); |
| 619 EXPECT(Dart_IsByteArray(obj1)); | 619 EXPECT(Dart_IsByteArray(byte_array1)); |
| 620 EXPECT(Dart_IsList(obj1)); | 620 EXPECT(Dart_IsList(byte_array1)); |
| 621 | 621 |
| 622 intptr_t length = 0; | 622 intptr_t length = 0; |
| 623 Dart_Handle result = Dart_ListLength(obj1, &length); | 623 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
| 624 EXPECT_VALID(result); | 624 EXPECT_VALID(result); |
| 625 EXPECT_EQ(10, length); | 625 EXPECT_EQ(10, length); |
| 626 | 626 |
| 627 result = Dart_ListSetAt(obj1, -1, Dart_NewInteger(1)); | 627 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); |
| 628 EXPECT(Dart_IsError(result)); | 628 EXPECT(Dart_IsError(result)); |
| 629 result = Dart_ListSetAt(obj1, 10, Dart_NewInteger(1)); | 629 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); |
| 630 EXPECT(Dart_IsError(result)); | 630 EXPECT(Dart_IsError(result)); |
| 631 | 631 |
| 632 for (intptr_t i = 0; i < 10; ++i) { | 632 for (intptr_t i = 0; i < 10; ++i) { |
| 633 result = Dart_ListSetAt(obj1, i, Dart_NewInteger(i + 1)); | 633 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1)); |
| 634 EXPECT_VALID(result); | 634 EXPECT_VALID(result); |
| 635 } | 635 } |
| 636 | 636 |
| 637 for (intptr_t i = 0; i < 10; ++i) { | 637 for (intptr_t i = 0; i < 10; ++i) { |
| 638 result = Dart_ListGetAt(obj1, i); | 638 result = Dart_ListGetAt(byte_array1, i); |
| 639 EXPECT_VALID(result); | 639 EXPECT_VALID(result); |
| 640 int64_t value = 0; | 640 int64_t value = 0; |
| 641 result = Dart_IntegerToInt64(result, &value); | 641 result = Dart_IntegerToInt64(result, &value); |
| 642 EXPECT_VALID(result); | 642 EXPECT_VALID(result); |
| 643 EXPECT_EQ(i + 1, value); | 643 EXPECT_EQ(i + 1, value); |
| 644 } | 644 } |
| 645 | 645 |
| 646 Dart_Handle obj2 = Dart_NewByteArray(10); | 646 Dart_Handle byte_array2 = Dart_NewByteArray(10); |
| 647 bool is_equal = false; | 647 bool is_equal = false; |
| 648 Dart_ObjectEquals(obj1, obj2, &is_equal); | 648 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); |
| 649 EXPECT(!is_equal); | 649 EXPECT(!is_equal); |
| 650 | 650 |
| 651 for (intptr_t i = 0; i < 10; ++i) { | 651 for (intptr_t i = 0; i < 10; ++i) { |
| 652 result = Dart_ListSetAt(obj2, i, Dart_NewInteger(i + 1)); | 652 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 1)); |
| 653 EXPECT_VALID(result); | 653 EXPECT_VALID(result); |
| 654 } | 654 } |
| 655 is_equal = false; | 655 is_equal = false; |
| 656 Dart_ObjectEquals(obj1, obj2, &is_equal); | 656 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); |
| 657 EXPECT(!is_equal); | 657 EXPECT(!is_equal); |
| 658 | 658 |
| 659 for (intptr_t i = 0; i < 10; ++i) { | 659 for (intptr_t i = 0; i < 10; ++i) { |
| 660 Dart_Handle e1 = Dart_ListGetAt(obj1, i); | 660 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); |
| 661 Dart_Handle e2 = Dart_ListGetAt(obj2, i); | 661 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); |
| 662 is_equal = false; | 662 is_equal = false; |
| 663 Dart_ObjectEquals(e1, e2, &is_equal); | 663 Dart_ObjectEquals(e1, e2, &is_equal); |
| 664 EXPECT(is_equal); | 664 EXPECT(is_equal); |
| 665 } | 665 } |
| 666 |
| 667 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
| 668 result = Dart_ListSetAsBytes(byte_array1, 0, data, 10); |
| 669 EXPECT_VALID(result); |
| 670 for (intptr_t i = 0; i < 10; ++i) { |
| 671 Dart_Handle e = Dart_ListGetAt(byte_array1, i); |
| 672 int64_t value; |
| 673 result = Dart_IntegerToInt64(e, &value); |
| 674 EXPECT_VALID(result); |
| 675 EXPECT_EQ(i, value); |
| 676 } |
| 677 |
| 678 for (intptr_t i = 0; i < 10; ++i) { |
| 679 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); |
| 680 } |
| 681 Dart_ListGetAsBytes(byte_array1, 0, data, 10); |
| 682 for (intptr_t i = 0; i < 10; ++i) { |
| 683 Dart_Handle e = Dart_ListGetAt(byte_array1, i); |
| 684 EXPECT_VALID(e); |
| 685 int64_t value; |
| 686 result = Dart_IntegerToInt64(e, &value); |
| 687 EXPECT_VALID(result); |
| 688 EXPECT_EQ(10 - i, value); |
| 689 } |
| 666 } | 690 } |
| 667 | 691 |
| 668 #endif | 692 #endif |
| 669 | 693 |
| 670 | 694 |
| 671 // Unit test for entering a scope, creating a local handle and exiting | 695 // Unit test for entering a scope, creating a local handle and exiting |
| 672 // the scope. | 696 // the scope. |
| 673 UNIT_TEST_CASE(EnterExitScope) { | 697 UNIT_TEST_CASE(EnterExitScope) { |
| 674 TestIsolateScope __test_isolate__; | 698 TestIsolateScope __test_isolate__; |
| 675 | 699 |
| (...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3131 // We should have received the expected number of interrupts. | 3155 // We should have received the expected number of interrupts. |
| 3132 EXPECT_EQ(kInterruptCount, interrupt_count); | 3156 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 3133 | 3157 |
| 3134 // Give the spawned thread enough time to properly exit. | 3158 // Give the spawned thread enough time to properly exit. |
| 3135 Isolate::SetInterruptCallback(saved); | 3159 Isolate::SetInterruptCallback(saved); |
| 3136 } | 3160 } |
| 3137 | 3161 |
| 3138 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3162 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3139 | 3163 |
| 3140 } // namespace dart | 3164 } // namespace dart |
| OLD | NEW |