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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 12038066: Change a couple of API functions to return unhandled exception errors instead of fatal errors on im… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 months 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 | « runtime/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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 688
689 689
690 TEST_CASE(ListAccess) { 690 TEST_CASE(ListAccess) {
691 const char* kScriptChars = 691 const char* kScriptChars =
692 "List testMain() {" 692 "List testMain() {"
693 " List a = new List();" 693 " List a = new List();"
694 " a.add(10);" 694 " a.add(10);"
695 " a.add(20);" 695 " a.add(20);"
696 " a.add(30);" 696 " a.add(30);"
697 " return a;" 697 " return a;"
698 "}"
699 ""
700 "List immutable() {"
701 " return const [0, 1, 2];"
698 "}"; 702 "}";
699 Dart_Handle result; 703 Dart_Handle result;
700 704
701 // Create a test library and Load up a test script in it. 705 // Create a test library and Load up a test script in it.
702 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 706 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
703 707
704 // Invoke a function which returns an object of type List. 708 // Invoke a function which returns an object of type List.
705 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 709 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
706 EXPECT_VALID(result); 710 EXPECT_VALID(result);
707 711
708 // First ensure that the returned object is an array. 712 // First ensure that the returned object is an array.
709 Dart_Handle ListAccessTestObj = result; 713 Dart_Handle list_access_test_obj = result;
710 714
711 EXPECT(Dart_IsList(ListAccessTestObj)); 715 EXPECT(Dart_IsList(list_access_test_obj));
712 716
713 // Get length of array object. 717 // Get length of array object.
714 intptr_t len = 0; 718 intptr_t len = 0;
715 result = Dart_ListLength(ListAccessTestObj, &len); 719 result = Dart_ListLength(list_access_test_obj, &len);
716 EXPECT_VALID(result); 720 EXPECT_VALID(result);
717 EXPECT_EQ(3, len); 721 EXPECT_EQ(3, len);
718 722
719 // Access elements in the array. 723 // Access elements in the array.
720 int64_t value; 724 int64_t value;
721 725
722 result = Dart_ListGetAt(ListAccessTestObj, 0); 726 result = Dart_ListGetAt(list_access_test_obj, 0);
723 EXPECT_VALID(result); 727 EXPECT_VALID(result);
724 result = Dart_IntegerToInt64(result, &value); 728 result = Dart_IntegerToInt64(result, &value);
725 EXPECT_VALID(result); 729 EXPECT_VALID(result);
726 EXPECT_EQ(10, value); 730 EXPECT_EQ(10, value);
727 731
728 result = Dart_ListGetAt(ListAccessTestObj, 1); 732 result = Dart_ListGetAt(list_access_test_obj, 1);
729 EXPECT_VALID(result); 733 EXPECT_VALID(result);
730 result = Dart_IntegerToInt64(result, &value); 734 result = Dart_IntegerToInt64(result, &value);
731 EXPECT_VALID(result); 735 EXPECT_VALID(result);
732 EXPECT_EQ(20, value); 736 EXPECT_EQ(20, value);
733 737
734 result = Dart_ListGetAt(ListAccessTestObj, 2); 738 result = Dart_ListGetAt(list_access_test_obj, 2);
735 EXPECT_VALID(result); 739 EXPECT_VALID(result);
736 result = Dart_IntegerToInt64(result, &value); 740 result = Dart_IntegerToInt64(result, &value);
737 EXPECT_VALID(result); 741 EXPECT_VALID(result);
738 EXPECT_EQ(30, value); 742 EXPECT_EQ(30, value);
739 743
740 // Set some elements in the array. 744 // Set some elements in the array.
741 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); 745 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(0));
742 EXPECT_VALID(result); 746 EXPECT_VALID(result);
743 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); 747 result = Dart_ListSetAt(list_access_test_obj, 1, Dart_NewInteger(1));
744 EXPECT_VALID(result); 748 EXPECT_VALID(result);
745 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); 749 result = Dart_ListSetAt(list_access_test_obj, 2, Dart_NewInteger(2));
746 EXPECT_VALID(result); 750 EXPECT_VALID(result);
747 751
748 // Get length of array object. 752 // Get length of array object.
749 result = Dart_ListLength(ListAccessTestObj, &len); 753 result = Dart_ListLength(list_access_test_obj, &len);
750 EXPECT_VALID(result); 754 EXPECT_VALID(result);
751 EXPECT_EQ(3, len); 755 EXPECT_EQ(3, len);
752 756
753 // Now try and access these elements in the array. 757 // Now try and access these elements in the array.
754 result = Dart_ListGetAt(ListAccessTestObj, 0); 758 result = Dart_ListGetAt(list_access_test_obj, 0);
755 EXPECT_VALID(result); 759 EXPECT_VALID(result);
756 result = Dart_IntegerToInt64(result, &value); 760 result = Dart_IntegerToInt64(result, &value);
757 EXPECT_VALID(result); 761 EXPECT_VALID(result);
758 EXPECT_EQ(0, value); 762 EXPECT_EQ(0, value);
759 763
760 result = Dart_ListGetAt(ListAccessTestObj, 1); 764 result = Dart_ListGetAt(list_access_test_obj, 1);
761 EXPECT_VALID(result); 765 EXPECT_VALID(result);
762 result = Dart_IntegerToInt64(result, &value); 766 result = Dart_IntegerToInt64(result, &value);
763 EXPECT_VALID(result); 767 EXPECT_VALID(result);
764 EXPECT_EQ(1, value); 768 EXPECT_EQ(1, value);
765 769
766 result = Dart_ListGetAt(ListAccessTestObj, 2); 770 result = Dart_ListGetAt(list_access_test_obj, 2);
767 EXPECT_VALID(result); 771 EXPECT_VALID(result);
768 result = Dart_IntegerToInt64(result, &value); 772 result = Dart_IntegerToInt64(result, &value);
769 EXPECT_VALID(result); 773 EXPECT_VALID(result);
770 EXPECT_EQ(2, value); 774 EXPECT_EQ(2, value);
771 775
772 uint8_t native_array[3]; 776 uint8_t native_array[3];
773 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 777 result = Dart_ListGetAsBytes(list_access_test_obj, 0, native_array, 3);
774 EXPECT_VALID(result); 778 EXPECT_VALID(result);
775 EXPECT_EQ(0, native_array[0]); 779 EXPECT_EQ(0, native_array[0]);
776 EXPECT_EQ(1, native_array[1]); 780 EXPECT_EQ(1, native_array[1]);
777 EXPECT_EQ(2, native_array[2]); 781 EXPECT_EQ(2, native_array[2]);
778 782
779 native_array[0] = 10; 783 native_array[0] = 10;
780 native_array[1] = 20; 784 native_array[1] = 20;
781 native_array[2] = 30; 785 native_array[2] = 30;
782 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); 786 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3);
783 EXPECT_VALID(result); 787 EXPECT_VALID(result);
784 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 788 result = Dart_ListGetAsBytes(list_access_test_obj, 0, native_array, 3);
785 EXPECT_VALID(result); 789 EXPECT_VALID(result);
786 EXPECT_EQ(10, native_array[0]); 790 EXPECT_EQ(10, native_array[0]);
787 EXPECT_EQ(20, native_array[1]); 791 EXPECT_EQ(20, native_array[1]);
788 EXPECT_EQ(30, native_array[2]); 792 EXPECT_EQ(30, native_array[2]);
789 result = Dart_ListGetAt(ListAccessTestObj, 2); 793 result = Dart_ListGetAt(list_access_test_obj, 2);
790 EXPECT_VALID(result); 794 EXPECT_VALID(result);
791 result = Dart_IntegerToInt64(result, &value); 795 result = Dart_IntegerToInt64(result, &value);
792 EXPECT_VALID(result); 796 EXPECT_VALID(result);
793 EXPECT_EQ(30, value); 797 EXPECT_EQ(30, value);
794 798
795 // Check if we get an exception when accessing beyond limit. 799 // Check if we get an exception when accessing beyond limit.
796 result = Dart_ListGetAt(ListAccessTestObj, 4); 800 result = Dart_ListGetAt(list_access_test_obj, 4);
797 EXPECT(Dart_IsError(result)); 801 EXPECT(Dart_IsError(result));
802
803 // Check that we get an exception (and not a fatal error) when
804 // calling ListSetAt and ListSetAsBytes with an immutable list.
805 list_access_test_obj = Dart_Invoke(lib, NewString("immutable"), 0, NULL);
806 EXPECT_VALID(list_access_test_obj);
807 EXPECT(Dart_IsList(list_access_test_obj));
808
809 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3);
810 EXPECT(Dart_IsError(result));
811 EXPECT(Dart_IsUnhandledExceptionError(result));
812
813 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42));
814 EXPECT(Dart_IsError(result));
815 EXPECT(Dart_IsUnhandledExceptionError(result));
798 } 816 }
799 817
800 818
801 TEST_CASE(ByteArrayAccess) { 819 TEST_CASE(ByteArrayAccess) {
802 Dart_Handle byte_array1 = Dart_NewByteArray(10); 820 Dart_Handle byte_array1 = Dart_NewByteArray(10);
803 EXPECT_VALID(byte_array1); 821 EXPECT_VALID(byte_array1);
804 EXPECT(Dart_IsByteArray(byte_array1)); 822 EXPECT(Dart_IsByteArray(byte_array1));
805 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); 823 EXPECT(!Dart_IsByteArrayExternal(byte_array1));
806 EXPECT(Dart_IsList(byte_array1)); 824 EXPECT(Dart_IsList(byte_array1));
807 825
(...skipping 6704 matching lines...) Expand 10 before | Expand all | Expand 10 after
7512 NULL); 7530 NULL);
7513 int64_t value = 0; 7531 int64_t value = 0;
7514 result = Dart_IntegerToInt64(result, &value); 7532 result = Dart_IntegerToInt64(result, &value);
7515 EXPECT_VALID(result); 7533 EXPECT_VALID(result);
7516 EXPECT_EQ(260, value); 7534 EXPECT_EQ(260, value);
7517 } 7535 }
7518 7536
7519 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7537 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7520 7538
7521 } // namespace dart 7539 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698