diff --git a/SWIG/Examples/test-suite/python/virtual_poly_runme.py b/SWIG/Examples/test-suite/python/virtual_poly_runme.py index e0e3bc5b2..42f92af42 100644 --- a/SWIG/Examples/test-suite/python/virtual_poly_runme.py +++ b/SWIG/Examples/test-suite/python/virtual_poly_runme.py @@ -1,9 +1,11 @@ import virtual_poly - d = virtual_poly.NDouble(3.5) i = virtual_poly.NInt(2) +# +# the copy methods return the right polymorphic types +# dc = d.copy() ic = i.copy() @@ -14,6 +16,14 @@ if i.get() != ic.get(): raise RuntimeError -ddc = virtual_poly.NDouble_dynamic_cast(dc) +# +# here this dynamic_cast is not needed at all, +# but works fine anyway ('nnumber()' returns a NNumber). +# +ddc = virtual_poly.NDouble_dynamic_cast(dc.nnumber()) if d.get() != ddc.get(): raise RuntimeError + +dic = virtual_poly.NInt_dynamic_cast(ic.nnumber()) +if i.get() != dic.get(): + raise RuntimeError diff --git a/SWIG/Examples/test-suite/ruby/virtual_poly_runme.rb b/SWIG/Examples/test-suite/ruby/virtual_poly_runme.rb new file mode 100644 index 000000000..09aeeca46 --- /dev/null +++ b/SWIG/Examples/test-suite/ruby/virtual_poly_runme.rb @@ -0,0 +1,22 @@ +require 'virtual_poly' + +d = Virtual_poly::NDouble.new(3.5) +i = Virtual_poly::NInt.new(2) + +# +# polymorphic return type working +# +dc = d.copy +ic = i.copy + +raise RuntimeError if d.get != dc.get +raise RuntimeError if i.get != ic.get + +# +# dynamic cast working ('nnumber' returns a NNumber) +# +ddc = Virtual_poly.NDouble_dynamic_cast(dc.nnumber) +raise RuntimeError if d.get != ddc.get + +dic = Virtual_poly.NInt_dynamic_cast(ic.nnumber) +raise RuntimeError if i.get != dic.get diff --git a/SWIG/Examples/test-suite/virtual_poly.i b/SWIG/Examples/test-suite/virtual_poly.i index 1e9759fde..c0e70ad65 100644 --- a/SWIG/Examples/test-suite/virtual_poly.i +++ b/SWIG/Examples/test-suite/virtual_poly.i @@ -1,4 +1,15 @@ -%module virtual_poly +%module(directors="1") virtual_poly + +// +// Check this example with directors wherever is possible. +// It seems to be a good test since it breaks ruby at least. +// python works fine with and without directors +// In theory, Java should starts working with directors, +// but this is not tested yet (my Java installation is broken). +// +//%feature("director"); + +%newobject *::copy(); %inline %{ @@ -6,6 +17,12 @@ { virtual ~NNumber() {}; virtual NNumber* copy() const = 0; + + NNumber* nnumber() + { + return this; + } + }; /*