mirror of https://github.com/swig/swig
add more cases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7686 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e5f50bd942
commit
ab790f802a
|
@ -1,67 +1,77 @@
|
|||
%module(directors="1") director_basic
|
||||
%{
|
||||
#include <string>
|
||||
%module(directors="1") director_basic
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
|
||||
%}
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") Foo;
|
||||
%feature("director") Foo;
|
||||
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() { return "Foo::ping()"; }
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
%feature("director");
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
%feature("director");
|
||||
|
||||
// basic renaming
|
||||
%rename(rg) A::gg;
|
||||
%feature("nodirector") hi::A1::gg;
|
||||
// basic renaming
|
||||
%rename(rg) A::gg;
|
||||
%feature("nodirector") hi::A1::gg;
|
||||
|
||||
%inline %{
|
||||
%inline %{
|
||||
|
||||
struct A{
|
||||
A(std::complex<int> i, double d=0.0) {}
|
||||
A(int i, bool j=false) {}
|
||||
virtual ~A() {}
|
||||
|
||||
virtual int f(int i=0) {return i;}
|
||||
virtual int gg(int i=0) {return i;}
|
||||
};
|
||||
struct A{
|
||||
A(std::complex<int> i, double d=0.0) {}
|
||||
A(int i, bool j=false) {}
|
||||
virtual ~A() {}
|
||||
|
||||
namespace hi {
|
||||
virtual int f(int i=0) {return i;}
|
||||
virtual int gg(int i=0) {return i;}
|
||||
};
|
||||
|
||||
struct A1 : public A {
|
||||
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
|
||||
A1(int i, bool j=false) : A(i, j) {}
|
||||
|
||||
virtual int ff(int i = 0) {return i;}
|
||||
};
|
||||
}
|
||||
namespace hi {
|
||||
|
||||
struct A1 : public A {
|
||||
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
|
||||
A1(int i, bool j=false) : A(i, j) {}
|
||||
|
||||
virtual int ff(int i = 0) {return i;}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%feature("director") MyClass;
|
||||
|
||||
%inline %{
|
||||
|
||||
typedef void VoidType;
|
||||
|
||||
struct Bar
|
||||
{
|
||||
int x;
|
||||
Bar(int _x = 0) : x(_x)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%feature("director") MyClass;
|
||||
|
||||
%inline %{
|
||||
|
||||
typedef void VoidType;
|
||||
|
||||
class MyClass {
|
||||
public:
|
||||
|
@ -76,6 +86,22 @@ public:
|
|||
virtual ~MyClass()
|
||||
{
|
||||
}
|
||||
|
||||
virtual Bar vmethod(Bar b)
|
||||
{
|
||||
b.x += 13;
|
||||
return b;
|
||||
}
|
||||
|
||||
Bar cmethod(const Bar &b)
|
||||
{
|
||||
return vmethod(b);
|
||||
}
|
||||
|
||||
static MyClass *get_self(MyClass *c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -452,3 +452,7 @@ template_typedef_import.py
|
|||
li_cwstring.py
|
||||
compactdefaultargs.py
|
||||
refcount.py
|
||||
li_implicit.py
|
||||
director_wstring.py
|
||||
immutable.py
|
||||
inherit.py
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import director_basic
|
||||
|
||||
class MyFoo(director_basic.Foo):
|
||||
class PyFoo(director_basic.Foo):
|
||||
def ping(self):
|
||||
return "MyFoo::ping()"
|
||||
return "PyFoo::ping()"
|
||||
|
||||
|
||||
a = MyFoo()
|
||||
a = PyFoo()
|
||||
|
||||
if a.ping() != "MyFoo::ping()":
|
||||
if a.ping() != "PyFoo::ping()":
|
||||
raise RuntimeError, a.ping()
|
||||
|
||||
if a.pong() != "Foo::pong();MyFoo::ping()":
|
||||
if a.pong() != "Foo::pong();PyFoo::ping()":
|
||||
raise RuntimeError, a.pong()
|
||||
|
||||
b = director_basic.Foo()
|
||||
|
@ -26,3 +26,28 @@ a = director_basic.A1(1)
|
|||
if a.rg(2) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
|
||||
class PyClass(director_basic.MyClass):
|
||||
def vmethod(self, b):
|
||||
b.x += 31
|
||||
return b
|
||||
|
||||
|
||||
b = director_basic.Bar(3)
|
||||
d = director_basic.MyClass()
|
||||
c = PyClass()
|
||||
|
||||
cc = PyClass.get_self(c)
|
||||
dd = PyClass.get_self(d)
|
||||
|
||||
bc = cc.cmethod(b)
|
||||
bd = dd.cmethod(b)
|
||||
|
||||
if bc.x != 34:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if bd.x != 16:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from li_cmalloc import *
|
||||
|
||||
p = malloc_int()
|
||||
free_int(p)
|
||||
|
||||
ok = 0
|
||||
try:
|
||||
p = calloc_int(-1)
|
||||
free_int(p)
|
||||
except:
|
||||
ok = 1
|
||||
|
||||
if ok != 1:
|
||||
raise RuntimeError
|
|
@ -0,0 +1,10 @@
|
|||
from li_cpointer import *
|
||||
|
||||
|
||||
p = new_intp()
|
||||
intp_assign(p,3)
|
||||
|
||||
if intp_value(p) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
delete_intp(p)
|
|
@ -265,6 +265,7 @@ cvar.var_namet = pc
|
|||
if cvar.var_namet != "hola":
|
||||
raise RuntimeError, "bad pointer case"
|
||||
|
||||
delete_pchar(pc)
|
||||
|
||||
#
|
||||
# Now when things should fail
|
||||
|
|
Loading…
Reference in New Issue