diff --git a/SWIG/Examples/test-suite/python/virtual_derivation_runme.py b/SWIG/Examples/test-suite/python/virtual_derivation_runme.py new file mode 100644 index 000000000..8a6e743af --- /dev/null +++ b/SWIG/Examples/test-suite/python/virtual_derivation_runme.py @@ -0,0 +1,8 @@ +from virtual_derivation import * +# +# very innocent example +# +b = B(3) +if b.get_a() != b.get_b(): + raise RuntimeError, "something is really wrong" + diff --git a/SWIG/Examples/test-suite/ruby/virtual_derivation_runme.rb b/SWIG/Examples/test-suite/ruby/virtual_derivation_runme.rb new file mode 100644 index 000000000..c2f7d7851 --- /dev/null +++ b/SWIG/Examples/test-suite/ruby/virtual_derivation_runme.rb @@ -0,0 +1,8 @@ +require 'virtual_derivation' + +b = Virtual_derivation::B.new 3 + +if b.get_a() != b.get_b() + print "something is really wrong ", b.get_a(), "\n" + raise RuntimeError +end diff --git a/SWIG/Examples/test-suite/virtual_derivation.i b/SWIG/Examples/test-suite/virtual_derivation.i new file mode 100644 index 000000000..fae85de52 --- /dev/null +++ b/SWIG/Examples/test-suite/virtual_derivation.i @@ -0,0 +1,54 @@ +%module virtual_derivation + + /* + + Try to add to your favorite language a runtime test like + this: + + b = B(3) + if (b.get_a() != b.get_b()): + print "something is wrong" + + + The test runs fine with python, but not with ruby. + + */ + +%inline %{ + + struct A + { + ~A() + { + } + + int _a; + + A(int a) :_a(a) + { + } + + int get_a() + { + return _a; + } + + }; + + struct B : virtual A + { + B(int a): A(a) + { + } + + int get_b() + { + return get_a(); + } + + // in ruby, get_a() returns trash if called from b, unless is + // wrapped with the previous get_b or using the 'using' + // declaration: + // using A::get_a; + }; +%}