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

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

Issue 17346002: Fix for issue 11262. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« runtime/include/dart_api.h ('K') | « 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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 2784
2785 // Error cases. 2785 // Error cases.
2786 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len), 2786 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len),
2787 "Dart_ClassGetInterfaceCount expects argument 'clazz' to be of " 2787 "Dart_ClassGetInterfaceCount expects argument 'clazz' to be of "
2788 "type Class."); 2788 "type Class.");
2789 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len), 2789 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len),
2790 "MyError"); 2790 "MyError");
2791 } 2791 }
2792 2792
2793 2793
2794 TEST_CASE(TypeGetNonParamtericTypes) {
2795 const char* kScriptChars =
2796 "class MyClass0 {\n"
2797 "}\n"
2798 "\n"
2799 "class MyClass1 implements MyInterface1 {\n"
2800 "}\n"
2801 "\n"
2802 "class MyClass2 implements MyInterface0, MyInterface1 {\n"
2803 "}\n"
2804 "\n"
2805 "abstract class MyInterface0 {\n"
2806 "}\n"
2807 "\n"
2808 "abstract class MyInterface1 implements MyInterface0 {\n"
2809 "}\n"
2810 "MyClass0 getMyClass0() { return new MyClass0(); }\n"
2811 "MyClass1 getMyClass1() { return new MyClass1(); }\n"
2812 "MyClass2 getMyClass2() { return new MyClass2(); }\n"
2813 "MyClass0 getMyClass0Type() { return new MyClass0().runtimeType; }\n"
2814 "MyClass1 getMyClass1Type() { return new MyClass1().runtimeType; }\n"
2815 "MyClass2 getMyClass2Type() { return new MyClass2().runtimeType; }\n";
2816 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2817 bool instanceof = false;
2818
2819 // First get the type objects of these non parameterized types.
2820 Dart_Handle type0 = Dart_GetType(lib, NewString("MyClass0"), 0, NULL);
2821 EXPECT_VALID(type0);
2822 Dart_Handle type1 = Dart_GetType(lib, NewString("MyClass1"), 0, NULL);
2823 EXPECT_VALID(type1);
2824 Dart_Handle type2 = Dart_GetType(lib, NewString("MyClass2"), 0, NULL);
2825 EXPECT_VALID(type2);
2826 Dart_Handle type3 = Dart_GetType(lib, NewString("MyInterface0"), 0, NULL);
2827 EXPECT_VALID(type3);
2828 Dart_Handle type4 = Dart_GetType(lib, NewString("MyInterface1"), 0, NULL);
2829 EXPECT_VALID(type4);
2830
2831 // Now create objects of these non parameterized types and check
2832 // that the validity of the type of the created object.
2833 // MyClass0 type.
2834 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL);
2835 EXPECT_VALID(type0_obj);
2836 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type0, &instanceof));
2837 EXPECT(instanceof);
2838 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type1, &instanceof));
2839 EXPECT(!instanceof);
2840 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type2, &instanceof));
2841 EXPECT(!instanceof);
2842 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type3, &instanceof));
2843 EXPECT(!instanceof);
2844 EXPECT_VALID(Dart_ObjectIsType(type0_obj, type4, &instanceof));
2845 EXPECT(!instanceof);
2846 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL);
2847 EXPECT_VALID(type0_obj);
2848 EXPECT(Dart_IdentityEquals(type0, type0_obj));
2849
2850 // MyClass1 type.
2851 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL);
2852 EXPECT_VALID(type1_obj);
2853 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type1, &instanceof));
2854 EXPECT(instanceof);
2855 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type0, &instanceof));
2856 EXPECT(!instanceof);
2857 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type2, &instanceof));
2858 EXPECT(!instanceof);
2859 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type3, &instanceof));
2860 EXPECT(instanceof);
2861 EXPECT_VALID(Dart_ObjectIsType(type1_obj, type4, &instanceof));
2862 EXPECT(instanceof);
2863 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL);
2864 EXPECT_VALID(type1_obj);
2865 EXPECT(Dart_IdentityEquals(type1, type1_obj));
2866
2867 // MyClass2 type.
2868 Dart_Handle type2_obj = Dart_Invoke(lib, NewString("getMyClass2"), 0, NULL);
2869 EXPECT_VALID(type2_obj);
2870 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type2, &instanceof));
2871 EXPECT(instanceof);
2872 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type0, &instanceof));
2873 EXPECT(!instanceof);
2874 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type1, &instanceof));
2875 EXPECT(!instanceof);
2876 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type3, &instanceof));
2877 EXPECT(instanceof);
2878 EXPECT_VALID(Dart_ObjectIsType(type2_obj, type4, &instanceof));
2879 EXPECT(instanceof);
2880 type2_obj = Dart_Invoke(lib, NewString("getMyClass2Type"), 0, NULL);
2881 EXPECT_VALID(type2_obj);
2882 EXPECT(Dart_IdentityEquals(type2, type2_obj));
2883 }
2884
2885
2886 TEST_CASE(TypeGetParamterizedTypes) {
2887 const char* kScriptChars =
2888 "class MyClass0<A, B> {\n"
2889 "}\n"
2890 "\n"
2891 "class MyClass1<A, C> {\n"
2892 "}\n"
2893 "MyClass0 getMyClass0() {\n"
2894 " return new MyClass0<int, double>();\n"
2895 "}\n"
2896 "MyClass0 getMyClass0Type() {\n"
2897 " return new MyClass0<int, double>().runtimeType;\n"
2898 "}\n"
2899 "MyClass1 getMyClass1() {\n"
2900 " return new MyClass1<List<int>, List>();\n"
2901 "}\n"
2902 "MyClass1 getMyClass1Type() {\n"
2903 " return new MyClass1<List<int>, List>().runtimeType;\n"
2904 "}\n"
2905 "MyClass0 getMyClass0_1() {\n"
2906 " return new MyClass0<double, int>();\n"
2907 "}\n"
2908 "MyClass0 getMyClass0_1Type() {\n"
2909 " return new MyClass0<double, int>().runtimeType;\n"
2910 "}\n"
2911 "MyClass1 getMyClass1_1() {\n"
2912 " return new MyClass1<List<int>, List<double>>();\n"
2913 "}\n"
2914 "MyClass1 getMyClass1_1Type() {\n"
2915 " return new MyClass1<List<int>, List<double>>().runtimeType;\n"
2916 "}\n";
2917 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2918 bool instanceof = false;
2919
2920 // First get type objects of some of the basic types used in the test.
2921 Dart_Handle int_type = Dart_GetType(lib, NewString("int"), 0, NULL);
2922 EXPECT_VALID(int_type);
2923 Dart_Handle double_type = Dart_GetType(lib, NewString("double"), 0, NULL);
2924 EXPECT_VALID(double_type);
2925 Dart_Handle list_type = Dart_GetType(lib, NewString("List"), 0, NULL);
2926 EXPECT_VALID(list_type);
2927 Dart_Handle type_args = Dart_NewList(1);
2928 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type));
2929 Dart_Handle list_int_type = Dart_GetType(lib,
2930 NewString("List"),
2931 1,
2932 &type_args);
2933 EXPECT_VALID(list_int_type);
2934
2935 // Now instantiate MyClass0 and MyClass1 types with the same type arguments
2936 // used in the code above.
2937 type_args = Dart_NewList(2);
2938 EXPECT_VALID(Dart_ListSetAt(type_args, 0, int_type));
2939 EXPECT_VALID(Dart_ListSetAt(type_args, 1, double_type));
2940 Dart_Handle myclass0_type = Dart_GetType(lib,
2941 NewString("MyClass0"),
2942 2,
2943 &type_args);
2944 EXPECT_VALID(myclass0_type);
2945
2946 type_args = Dart_NewList(2);
2947 EXPECT_VALID(Dart_ListSetAt(type_args, 0, list_int_type));
2948 EXPECT_VALID(Dart_ListSetAt(type_args, 1, list_type));
2949 Dart_Handle myclass1_type = Dart_GetType(lib,
2950 NewString("MyClass1"),
2951 2,
2952 &type_args);
2953 EXPECT_VALID(myclass1_type);
2954
2955 // Now create objects of the type and validate the object type matches
2956 // the one returned above. Also get the runtime type of the object and
2957 // verify that it matches the type returned above.
2958 // MyClass0<int, double> type.
2959 Dart_Handle type0_obj = Dart_Invoke(lib, NewString("getMyClass0"), 0, NULL);
2960 EXPECT_VALID(type0_obj);
2961 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceof));
2962 EXPECT(instanceof);
2963 type0_obj = Dart_Invoke(lib, NewString("getMyClass0Type"), 0, NULL);
2964 EXPECT_VALID(type0_obj);
2965 EXPECT(Dart_IdentityEquals(type0_obj, myclass0_type));
2966
2967 // MyClass1<List<int>, List> type.
2968 Dart_Handle type1_obj = Dart_Invoke(lib, NewString("getMyClass1"), 0, NULL);
2969 EXPECT_VALID(type1_obj);
2970 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceof));
2971 EXPECT(instanceof);
2972 type1_obj = Dart_Invoke(lib, NewString("getMyClass1Type"), 0, NULL);
2973 EXPECT_VALID(type1_obj);
2974 EXPECT(Dart_IdentityEquals(type1_obj, myclass1_type));
2975
2976 // MyClass0<double, int> type.
2977 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1"), 0, NULL);
2978 EXPECT_VALID(type0_obj);
2979 EXPECT_VALID(Dart_ObjectIsType(type0_obj, myclass0_type, &instanceof));
2980 EXPECT(!instanceof);
2981 type0_obj = Dart_Invoke(lib, NewString("getMyClass0_1Type"), 0, NULL);
2982 EXPECT_VALID(type0_obj);
2983 EXPECT(!Dart_IdentityEquals(type0_obj, myclass0_type));
2984
2985 // MyClass1<List<int>, List<double>> type.
2986 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1"), 0, NULL);
2987 EXPECT_VALID(type1_obj);
2988 EXPECT_VALID(Dart_ObjectIsType(type1_obj, myclass1_type, &instanceof));
2989 EXPECT(instanceof);
2990 type1_obj = Dart_Invoke(lib, NewString("getMyClass1_1Type"), 0, NULL);
2991 EXPECT_VALID(type1_obj);
2992 EXPECT(!Dart_IdentityEquals(type1_obj, myclass1_type));
2993 }
2994
2995
2794 static void TestFieldOk(Dart_Handle container, 2996 static void TestFieldOk(Dart_Handle container,
2795 Dart_Handle name, 2997 Dart_Handle name,
2796 bool final, 2998 bool final,
2797 const char* initial_value) { 2999 const char* initial_value) {
2798 Dart_Handle result; 3000 Dart_Handle result;
2799 3001
2800 // Make sure we have the right initial value. 3002 // Make sure we have the right initial value.
2801 result = Dart_GetField(container, name); 3003 result = Dart_GetField(container, name);
2802 EXPECT_VALID(result); 3004 EXPECT_VALID(result);
2803 const char* value = ""; 3005 const char* value = "";
(...skipping 5093 matching lines...) Expand 10 before | Expand all | Expand 10 after
7897 NewString("main"), 8099 NewString("main"),
7898 0, 8100 0,
7899 NULL); 8101 NULL);
7900 int64_t value = 0; 8102 int64_t value = 0;
7901 result = Dart_IntegerToInt64(result, &value); 8103 result = Dart_IntegerToInt64(result, &value);
7902 EXPECT_VALID(result); 8104 EXPECT_VALID(result);
7903 EXPECT_EQ(8, value); 8105 EXPECT_EQ(8, value);
7904 } 8106 }
7905 8107
7906 } // namespace dart 8108 } // namespace dart
OLDNEW
« runtime/include/dart_api.h ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698