added test for simple virtual derivation, where ruby fails
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5666 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
05d6e6b04f
commit
c92d8c7cf7
3 changed files with 70 additions and 0 deletions
8
Examples/test-suite/python/virtual_derivation_runme.py
Normal file
8
Examples/test-suite/python/virtual_derivation_runme.py
Normal file
|
|
@ -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"
|
||||
|
||||
8
Examples/test-suite/ruby/virtual_derivation_runme.rb
Normal file
8
Examples/test-suite/ruby/virtual_derivation_runme.rb
Normal file
|
|
@ -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
|
||||
54
Examples/test-suite/virtual_derivation.i
Normal file
54
Examples/test-suite/virtual_derivation.i
Normal file
|
|
@ -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;
|
||||
};
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue