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

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

Issue 14980002: Fix for issue 10395, call noSUchMethod if a method is not found when using the Dart C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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/vm/dart_api_impl.cc ('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 "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 3737 matching lines...) Expand 10 before | Expand all | Expand 10 after
3748 name = NewString("instanceMethod"); 3748 name = NewString("instanceMethod");
3749 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 3749 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
3750 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 3750 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args)));
3751 result = Dart_Invoke(instance, name, 1, args); 3751 result = Dart_Invoke(instance, name, 1, args);
3752 EXPECT_VALID(result); 3752 EXPECT_VALID(result);
3753 result = Dart_StringToCString(result, &str); 3753 result = Dart_StringToCString(result, &str);
3754 EXPECT_STREQ("instance !!!", str); 3754 EXPECT_STREQ("instance !!!", str);
3755 3755
3756 // Instance method, wrong arg count. 3756 // Instance method, wrong arg count.
3757 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), 3757 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args),
3758 "did not find instance method 'Methods.instanceMethod'"); 3758 "Class 'Methods' has no instance method 'instanceMethod'"
3759 " with matching arguments");
srdjan 2013/05/06 16:10:41 Please add a test with noSuchMethod to verify prop
siva 2013/05/06 16:20:25 I did add one, see below (InvokeNoSuchMethod). The
3759 3760
3760 name = PrivateLibName(lib, "_instanceMethod"); 3761 name = PrivateLibName(lib, "_instanceMethod");
3761 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 3762 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
3762 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 3763 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args)));
3763 result = Dart_Invoke(instance, name, 1, args); 3764 result = Dart_Invoke(instance, name, 1, args);
3764 EXPECT_VALID(result); 3765 EXPECT_VALID(result);
3765 result = Dart_StringToCString(result, &str); 3766 result = Dart_StringToCString(result, &str);
3766 EXPECT_STREQ("hidden instance !!!", str); 3767 EXPECT_STREQ("hidden instance !!!", str);
3767 3768
3768 // Inherited method. 3769 // Inherited method.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 NewString("toString"), 3882 NewString("toString"),
3882 0, 3883 0,
3883 NULL); 3884 NULL);
3884 EXPECT_VALID(result); 3885 EXPECT_VALID(result);
3885 EXPECT(Dart_IsString(result)); 3886 EXPECT(Dart_IsString(result));
3886 3887
3887 const char* value = ""; 3888 const char* value = "";
3888 EXPECT_VALID(Dart_StringToCString(result, &value)); 3889 EXPECT_VALID(Dart_StringToCString(result, &value));
3889 EXPECT_STREQ("null", value); 3890 EXPECT_STREQ("null", value);
3890 3891
3891 // Should throw a NullPointerException. Disabled due to bug 5415268. 3892 Dart_Handle function_name = NewString("NoNoNo");
3892 /* 3893 result = Dart_Invoke(Dart_Null(),
3893 Dart_Handle function_name2 = NewString("NoNoNo"); 3894 function_name,
3894 result = Dart_Invoke(null_receiver, 3895 0,
3895 function_name2, 3896 NULL);
3896 number_of_arguments, 3897 EXPECT(Dart_IsError(result));
3897 dart_arguments); 3898 EXPECT(Dart_ErrorHasException(result));
3898 EXPECT(Dart_IsError(result)); 3899 }
3899 EXPECT(Dart_ErrorHasException(result)); */ 3900
3901
3902 TEST_CASE(InvokeNoSuchMethod) {
3903 const char* kScriptChars =
3904 "import 'dart:_collection-dev' as _collection_dev;\n"
3905 "class Expect {\n"
3906 " static equals(a, b) {\n"
3907 " if (a != b) {\n"
3908 " throw 'not equal. expected: $a, got: $b';\n"
3909 " }\n"
3910 " }\n"
3911 "}\n"
3912 "class TestClass {\n"
3913 " static int fld1 = 0;\n"
3914 " void noSuchMethod(Invocation invocation) {\n"
3915 " var name = _collection_dev.Symbol.getName(invocation.memberName);\n"
3916 " if (name == 'fld') {\n"
3917 " Expect.equals(true, invocation.isGetter);\n"
3918 " Expect.equals(false, invocation.isMethod);\n"
3919 " Expect.equals(false, invocation.isSetter);\n"
3920 " } else if (name == 'setfld') {\n"
3921 " Expect.equals(true, invocation.isSetter);\n"
3922 " Expect.equals(false, invocation.isMethod);\n"
3923 " Expect.equals(false, invocation.isGetter);\n"
3924 " } else if (name == 'method') {\n"
3925 " Expect.equals(true, invocation.isMethod);\n"
3926 " Expect.equals(false, invocation.isSetter);\n"
3927 " Expect.equals(false, invocation.isGetter);\n"
3928 " }\n"
3929 " TestClass.fld1 += 1;\n"
3930 " }\n"
3931 " static void testMain() {\n"
3932 " return new TestClass();\n"
3933 " }\n"
3934 "}\n";
3935 Dart_Handle result;
3936 Dart_Handle instance;
3937 // Create a test library and Load up a test script in it.
3938 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3939 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass"));
3940 EXPECT_VALID(cls);
3941
3942 // Invoke a function which returns an object.
3943 instance = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
3944 EXPECT_VALID(instance);
3945
3946 // Try to get a field that does not exist, should call noSuchMethod.
3947 result = Dart_GetField(instance, NewString("fld"));
3948 EXPECT_VALID(result);
3949
3950 // Try to set a field that does not exist, should call noSuchMethod.
3951 result = Dart_SetField(instance, NewString("setfld"), Dart_NewInteger(13));
3952 EXPECT_VALID(result);
3953
3954 // Try to invoke a method that does not exist, should call noSuchMethod.
3955 result = Dart_Invoke(instance, NewString("method"), 0, NULL);
3956 EXPECT_VALID(result);
3957
3958 result = Dart_GetField(cls, NewString("fld1"));
3959 EXPECT_VALID(result);
3960 int64_t value = 0;
3961 result = Dart_IntegerToInt64(result, &value);
3962 EXPECT_EQ(3, value);
3900 } 3963 }
3901 3964
3902 3965
3903 TEST_CASE(Invoke_CrossLibrary) { 3966 TEST_CASE(Invoke_CrossLibrary) {
3904 const char* kLibrary1Chars = 3967 const char* kLibrary1Chars =
3905 "library library1_name;\n" 3968 "library library1_name;\n"
3906 "void local() {}\n" 3969 "void local() {}\n"
3907 "void _local() {}\n"; 3970 "void _local() {}\n";
3908 const char* kLibrary2Chars = 3971 const char* kLibrary2Chars =
3909 "library library2_name;\n" 3972 "library library2_name;\n"
(...skipping 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after
7614 NewString("main"), 7677 NewString("main"),
7615 0, 7678 0,
7616 NULL); 7679 NULL);
7617 int64_t value = 0; 7680 int64_t value = 0;
7618 result = Dart_IntegerToInt64(result, &value); 7681 result = Dart_IntegerToInt64(result, &value);
7619 EXPECT_VALID(result); 7682 EXPECT_VALID(result);
7620 EXPECT_EQ(260, value); 7683 EXPECT_EQ(260, value);
7621 } 7684 }
7622 7685
7623 } // namespace dart 7686 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('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