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
This commit is contained in:
parent
e63a259672
commit
baf05fd515
3 changed files with 70 additions and 0 deletions
|
|
@ -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"
|
||||||
|
|
||||||
|
|
@ -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
SWIG/Examples/test-suite/virtual_derivation.i
Normal file
54
SWIG/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