From baf05fd515db7ea40e9fb4d542208b96e2211d24 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Thu, 22 Jan 2004 06:23:57 +0000 Subject: [PATCH] added test for simple virtual derivation, where ruby fails git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5666 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../python/virtual_derivation_runme.py | 8 +++ .../ruby/virtual_derivation_runme.rb | 8 +++ SWIG/Examples/test-suite/virtual_derivation.i | 54 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 SWIG/Examples/test-suite/python/virtual_derivation_runme.py create mode 100644 SWIG/Examples/test-suite/ruby/virtual_derivation_runme.rb create mode 100644 SWIG/Examples/test-suite/virtual_derivation.i 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; + }; +%}