emitting and testing protected methods for director protected members
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5512 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
833b2f7f0a
commit
ae75ec65dd
3 changed files with 45 additions and 24 deletions
|
|
@ -1,32 +1,41 @@
|
||||||
require 'director_nested'
|
require 'director_nested'
|
||||||
|
|
||||||
|
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
|
||||||
|
|
||||||
class A < Director_nested::FooBar_int
|
class A < Director_nested::FooBar_int
|
||||||
def do_step
|
protected
|
||||||
"A::do_step;"
|
def do_step
|
||||||
end
|
"A::do_step;"
|
||||||
|
end
|
||||||
|
|
||||||
def get_value
|
def get_value
|
||||||
"A::get_value"
|
"A::get_value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
a = A.new
|
a = A.new
|
||||||
|
|
||||||
|
begin
|
||||||
|
a.do_advance
|
||||||
|
rescue NoProtectedError
|
||||||
|
end
|
||||||
|
|
||||||
raise RuntimeError if a.step != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;"
|
raise RuntimeError if a.step != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;"
|
||||||
|
|
||||||
|
|
||||||
class B < Director_nested::FooBar_int
|
class B < Director_nested::FooBar_int
|
||||||
def do_advance
|
protected
|
||||||
"B::do_advance;" + do_step
|
def do_advance
|
||||||
end
|
"B::do_advance;" + do_step
|
||||||
|
end
|
||||||
|
|
||||||
def do_step
|
def do_step
|
||||||
"B::do_step;"
|
"B::do_step;"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_value
|
def get_value
|
||||||
"B::get_value"
|
"B::get_value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,21 @@
|
||||||
require 'director_protected'
|
require 'director_protected'
|
||||||
|
|
||||||
|
NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
|
||||||
|
|
||||||
class FooBar < Director_protected::Bar
|
class FooBar < Director_protected::Bar
|
||||||
def ping
|
protected
|
||||||
"FooBar::ping();"
|
def ping
|
||||||
end
|
"FooBar::ping();"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
b = Director_protected::Bar.new
|
b = Director_protected::Bar.new
|
||||||
fb = FooBar.new
|
fb = FooBar.new
|
||||||
|
|
||||||
|
begin
|
||||||
|
fb.ping
|
||||||
|
rescue NoProtectedError
|
||||||
|
end
|
||||||
|
|
||||||
raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();"
|
raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();"
|
||||||
raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();"
|
raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();"
|
||||||
|
|
|
||||||
|
|
@ -588,13 +588,17 @@ public:
|
||||||
String *temp = NewString("");
|
String *temp = NewString("");
|
||||||
|
|
||||||
switch (current) {
|
switch (current) {
|
||||||
case MEMBER_FUNC:
|
case MEMBER_FUNC:
|
||||||
if (multipleInheritance) {
|
if (multipleInheritance) {
|
||||||
Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"",
|
const char* rb_define_method = !is_protected(n) ?
|
||||||
iname, "\", ", wname, ", -1);\n", NIL);
|
"rb_define_method" : "rb_define_protected_method";
|
||||||
|
Printv(klass->init, tab4, rb_define_method,"(", klass->mImpl, ", \"",
|
||||||
|
iname, "\", ", wname, ", -1);\n", NIL);
|
||||||
} else {
|
} else {
|
||||||
Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"",
|
const char* rb_define_method = !is_protected(n) ?
|
||||||
iname, "\", ", wname, ", -1);\n", NIL);
|
"rb_define_method" : "rb_define_protected_method";
|
||||||
|
Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"",
|
||||||
|
iname, "\", ", wname, ", -1);\n", NIL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CONSTRUCTOR_ALLOCATE:
|
case CONSTRUCTOR_ALLOCATE:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue