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 obj1 = Dart_NewByteArray(10); |
Søren Gjesse
2012/02/01 08:16:08
Why not rename "obj1" to "byte_array"?
Anders Johnsen
2012/02/01 18:54:53
Will fix!
| |
618 EXPECT_VALID(obj1); | 618 EXPECT_VALID(obj1); |
619 EXPECT(Dart_IsByteArray(obj1)); | 619 EXPECT(Dart_IsByteArray(obj1)); |
620 EXPECT(Dart_IsList(obj1)); | 620 EXPECT(Dart_IsList(obj1)); |
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(obj1, &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(obj1, -1, Dart_NewInteger(1)); |
(...skipping 28 matching lines...) Expand all Loading... | |
656 Dart_ObjectEquals(obj1, obj2, &is_equal); | 656 Dart_ObjectEquals(obj1, obj2, &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(obj1, i); |
661 Dart_Handle e2 = Dart_ListGetAt(obj2, i); | 661 Dart_Handle e2 = Dart_ListGetAt(obj2, 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(obj1, 0, data, 10); | |
669 EXPECT_VALID(result); | |
670 for (intptr_t i = 0; i < 10; ++i) { | |
671 Dart_Handle e = Dart_ListGetAt(obj1, 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(obj1, i, Dart_NewInteger(10 - i))); | |
680 } | |
681 Dart_ListGetAsBytes(obj1, 0, data, 10); | |
682 for (intptr_t i = 0; i < 10; ++i) { | |
683 Dart_Handle e = Dart_ListGetAt(obj1, 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 } | |
Søren Gjesse
2012/02/01 08:16:08
Maybe add a test with list values outside the byte
Anders Johnsen
2012/02/01 18:54:53
Added new file.
| |
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 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3052 // We should have received the expected number of interrupts. | 3076 // We should have received the expected number of interrupts. |
3053 EXPECT_EQ(kInterruptCount, interrupt_count); | 3077 EXPECT_EQ(kInterruptCount, interrupt_count); |
3054 | 3078 |
3055 // Give the spawned thread enough time to properly exit. | 3079 // Give the spawned thread enough time to properly exit. |
3056 Isolate::SetInterruptCallback(saved); | 3080 Isolate::SetInterruptCallback(saved); |
3057 } | 3081 } |
3058 | 3082 |
3059 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3083 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
3060 | 3084 |
3061 } // namespace dart | 3085 } // namespace dart |
OLD | NEW |