more tests
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5784 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d42bf081b3
commit
5a656bf645
13 changed files with 161 additions and 18 deletions
|
|
@ -28,9 +28,9 @@ double average(std::vector<int> v) {
|
||||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> half(const std::vector<float>& v) {
|
std::vector<Real> half(const std::vector<Real>& v) {
|
||||||
std::vector<float> w(v);
|
std::vector<Real> w(v);
|
||||||
for (unsigned int i=0; i<w.size(); i++)
|
for (std::vector<Real>::size_type i=0; i<w.size(); i++)
|
||||||
w[i] /= 2.0;
|
w[i] /= 2.0;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
%include "typemaps.i"
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%apply int &INOUT { int &INOUT2 };
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
bool in_bool(bool *INPUT) { return *INPUT; }
|
bool in_bool(bool *INPUT) { return *INPUT; }
|
||||||
|
|
@ -88,6 +89,8 @@ void inoutr_double(double &INOUT) { INOUT = INOUT; }
|
||||||
void inoutr_longlong(long long &INOUT) { INOUT = INOUT; }
|
void inoutr_longlong(long long &INOUT) { INOUT = INOUT; }
|
||||||
void inoutr_ulonglong(unsigned long long &INOUT) { INOUT = INOUT; }
|
void inoutr_ulonglong(unsigned long long &INOUT) { INOUT = INOUT; }
|
||||||
|
|
||||||
|
void inoutr_int2(int &INOUT, int &INOUT2) { INOUT = INOUT; INOUT2 = INOUT2;}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,18 @@ srcdir = @srcdir@
|
||||||
top_srcdir = @top_srcdir@
|
top_srcdir = @top_srcdir@
|
||||||
top_builddir = @top_builddir@
|
top_builddir = @top_builddir@
|
||||||
|
|
||||||
|
CPP_TEST_CASES += \
|
||||||
|
argcargvtest \
|
||||||
|
attributetest \
|
||||||
|
complextest \
|
||||||
|
director_stl \
|
||||||
|
implicittest \
|
||||||
|
lib_std_vectora \
|
||||||
|
std_containers
|
||||||
|
|
||||||
|
C_TEST_CASES += \
|
||||||
|
complextest
|
||||||
|
|
||||||
include $(srcdir)/../common.mk
|
include $(srcdir)/../common.mk
|
||||||
|
|
||||||
# Overridden variables here
|
# Overridden variables here
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ if aa.a != 1:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
aa.a = 3
|
aa.a = 3
|
||||||
if aa.a != 3:
|
if aa.a != 3:
|
||||||
|
print aa.a
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ if complextest.Conj(a) != a.conjugate():
|
||||||
v = (complex(1,2), complex(2,3), complex(4,3), 1)
|
v = (complex(1,2), complex(2,3), complex(4,3), 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print complextest.Copy_h(v)
|
complextest.Copy_h(v)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,15 @@
|
||||||
%include "std_pair.i"
|
%include "std_pair.i"
|
||||||
%include "std_vector.i"
|
%include "std_vector.i"
|
||||||
|
|
||||||
|
#ifndef SWIG_STD_DEFAULT_INSTANTIATION
|
||||||
|
%template() std::vector<double>;
|
||||||
|
%template() std::vector<int>;
|
||||||
|
%template() std::vector<std::string>;
|
||||||
|
%template() std::pair<std::string, int>;
|
||||||
|
%template() std::pair<int,double>;
|
||||||
|
%template() std::pair<double,int>;
|
||||||
|
#endif
|
||||||
|
|
||||||
%feature("director") Foo;
|
%feature("director") Foo;
|
||||||
|
|
||||||
%feature("director:except") {
|
%feature("director:except") {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ ai = A(1)
|
||||||
ad = A(2.0)
|
ad = A(2.0)
|
||||||
ab = A(b)
|
ab = A(b)
|
||||||
|
|
||||||
print ai, get(ai)
|
ai, get(ai)
|
||||||
print ad, get(ad)
|
ad, get(ad)
|
||||||
print ab, get(ab)
|
ab, get(ab)
|
||||||
|
|
||||||
if get(ai) != get(1):
|
if get(ai) != get(1):
|
||||||
raise RuntimeError,"bad implicit type"
|
raise RuntimeError,"bad implicit type"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%module lib_std_pair
|
%module lib_std_pair
|
||||||
|
|
||||||
%include "std_pair.i"
|
%include std_pair.i
|
||||||
|
|
||||||
%{
|
%{
|
||||||
struct A
|
struct A
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
%template() pair<double, double>;
|
||||||
%template(IntPair) pair<int, int>;
|
%template(IntPair) pair<int, int>;
|
||||||
%template(AIntPair) pair<A, int>;
|
%template(AIntPair) pair<A, int>;
|
||||||
|
|
||||||
|
|
@ -20,6 +21,8 @@ namespace std {
|
||||||
%template(IntAPair) pair<int, A>;
|
%template(IntAPair) pair<int, A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
/* Test the "out" typemap for pair<T, U> */
|
/* Test the "out" typemap for pair<T, U> */
|
||||||
|
|
@ -72,6 +75,44 @@ std::pair<int, int>
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
d_inout(double *INOUT) {
|
||||||
|
*INOUT += *INOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
d_inout(int *INOUT) {
|
||||||
|
*INOUT += *INOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
d_inout2(double *INOUT) {
|
||||||
|
*INOUT += *INOUT;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p_inout(std::pair<int, int> *INOUT) {
|
||||||
|
std::swap(INOUT->first, INOUT->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
p_inout2(std::pair<int, int> *INOUT) {
|
||||||
|
std::swap(INOUT->first, INOUT->second);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p_inout3(std::pair<int,int> *INOUT, std::pair<int,int> *INOUT2) {
|
||||||
|
std::swap(*INOUT, *INOUT2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p_inoutd(std::pair<double, double> *INOUT) {
|
||||||
|
std::swap(INOUT->first, INOUT->second);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::pair<char, char>
|
std::pair<char, char>
|
||||||
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
|
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
|
||||||
|
|
@ -100,6 +141,8 @@ std::pair<int, int>
|
||||||
p_ident(std::pair<int, int> p, const std::pair<A, B>& q) {
|
p_ident(std::pair<int, int> p, const std::pair<A, B>& q) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,15 @@ if lib_std_string.test_const_reference(x) != x:
|
||||||
|
|
||||||
|
|
||||||
s = lib_std_string.string("he")
|
s = lib_std_string.string("he")
|
||||||
s.append("llo")
|
s += "ll"
|
||||||
|
s.append('o')
|
||||||
|
|
||||||
|
if s != x:
|
||||||
|
print s, x
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
if s[1:4] != x[1:4]:
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
if lib_std_string.test_value(s) != x:
|
if lib_std_string.test_value(s) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
@ -18,10 +26,11 @@ if lib_std_string.test_value(s) != x:
|
||||||
if lib_std_string.test_const_reference(s) != x:
|
if lib_std_string.test_const_reference(s) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
a = lib_std_string.A("hello")
|
a = lib_std_string.A(s)
|
||||||
|
|
||||||
if lib_std_string.test_value(a) != x:
|
if lib_std_string.test_value(a) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
if lib_std_string.test_const_reference(a) != x:
|
if lib_std_string.test_const_reference(a) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
%include std_vectora.i
|
%include std_vectora.i
|
||||||
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
@ -20,7 +21,7 @@
|
||||||
std::allocator<std::vector<int,std::allocator<int> > > >
|
std::allocator<std::vector<int,std::allocator<int> > > >
|
||||||
imatrix;
|
imatrix;
|
||||||
|
|
||||||
std::vector<int> vident(const std::vector<int>& v)
|
std::vector<int> vident(const std::vector<int,std::allocator<int> >& v)
|
||||||
{
|
{
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
@ -44,12 +45,13 @@ namespace std {
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
double average(std::vector<int> v) {
|
double average(std::vector<int, std::allocator<int> > v) {
|
||||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> half(const std::vector<float>& v) {
|
std::vector<Real,std::allocator<Real> >
|
||||||
std::vector<float> w(v);
|
half(const std::vector<Real,std::allocator<Real> >& v) {
|
||||||
|
std::vector<Real> w(v);
|
||||||
for (unsigned int i=0; i<w.size(); i++)
|
for (unsigned int i=0; i<w.size(); i++)
|
||||||
w[i] /= 2.0;
|
w[i] /= 2.0;
|
||||||
return w;
|
return w;
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,6 @@ if error:
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
t2 = p.vtest(t)
|
t2 = p.vtest(t)
|
||||||
if "%s" % (t2,) != "%s" % (t,):
|
if t.var_namet != t2.var_namet:
|
||||||
raise RuntimeError, "bad SWIGTYPE* typemap"
|
raise RuntimeError, "bad SWIGTYPE* typemap"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,17 @@
|
||||||
%include std_deque.i
|
%include std_deque.i
|
||||||
%include std_list.i
|
%include std_list.i
|
||||||
%include std_set.i
|
%include std_set.i
|
||||||
|
%include std_multiset.i
|
||||||
%include std_pair.i
|
%include std_pair.i
|
||||||
%include std_map.i
|
%include std_map.i
|
||||||
|
%include std_multimap.i
|
||||||
%include std_complex.i
|
%include std_complex.i
|
||||||
|
|
||||||
|
#ifndef SWIG_STD_DEFAULT_INSTANTIATION
|
||||||
|
%template() std::vector<double>;
|
||||||
|
%template() std::pair<std::string, int>;
|
||||||
|
%template() std::pair<int,double>;
|
||||||
|
#endif
|
||||||
|
|
||||||
%template() std::vector< std::vector<double > > ;
|
%template() std::vector< std::vector<double > > ;
|
||||||
%template(ccube) std::vector< std::vector< std::vector<double > > >;
|
%template(ccube) std::vector< std::vector< std::vector<double > > >;
|
||||||
|
|
@ -28,6 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
%template(map_si) std::map<std::string, int>;
|
%template(map_si) std::map<std::string, int>;
|
||||||
|
%template(mmap_si) std::multimap<std::string, int>;
|
||||||
%template(set_i) std::set<int>;
|
%template(set_i) std::set<int>;
|
||||||
%template(multiset_i) std::multiset<int>;
|
%template(multiset_i) std::multiset<int>;
|
||||||
%template(list_i) std::list<int>;
|
%template(list_i) std::list<int>;
|
||||||
|
|
@ -40,6 +48,8 @@
|
||||||
%template(imatrix) std::vector<std::vector<int> >;
|
%template(imatrix) std::vector<std::vector<int> >;
|
||||||
%template(cmatrix) std::vector<std::vector<std::complex<double> > >;
|
%template(cmatrix) std::vector<std::vector<std::complex<double> > >;
|
||||||
|
|
||||||
|
%apply std::vector<int> *INOUT {std::vector<int> *INOUT2};
|
||||||
|
|
||||||
%inline
|
%inline
|
||||||
{
|
{
|
||||||
typedef std::vector<std::vector<int> > imatrix;
|
typedef std::vector<std::vector<int> > imatrix;
|
||||||
|
|
@ -58,6 +68,11 @@
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::multimap<std::string,int> mapident(const std::multimap<std::string,int>& v)
|
||||||
|
{
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<int> vident(const std::vector<int>& v)
|
std::vector<int> vident(const std::vector<int>& v)
|
||||||
{
|
{
|
||||||
return v;
|
return v;
|
||||||
|
|
@ -83,8 +98,17 @@
|
||||||
{
|
{
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
v_inout(std::vector<int> *INOUT) {
|
||||||
|
*INOUT = *INOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
v_inout2(std::vector<int> *INOUT, std::vector<int> *INOUT2) {
|
||||||
|
std::swap(*INOUT, *INOUT2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,11 +138,16 @@ template <class C> struct Param
|
||||||
{
|
{
|
||||||
struct A
|
struct A
|
||||||
{
|
{
|
||||||
|
A(int aa = 0) : a(aa)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
int a;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
%template() std::pair<A,int>;
|
%template() std::pair<A,int>;
|
||||||
%template(pair_iA) std::pair<int,A>;
|
%template(pair_iA) std::pair<int,A>;
|
||||||
|
%template(vector_piA) std::vector<std::pair<int,A> >;
|
||||||
|
|
||||||
|
|
||||||
%inline {
|
%inline {
|
||||||
|
|
@ -126,5 +155,12 @@ template <class C> struct Param
|
||||||
{
|
{
|
||||||
return std::pair<A,int>();
|
return std::pair<A,int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::pair<int,A> > pia_vident(std::vector<std::pair<int,A> > a )
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ if vu[2] != std_containers.videntu(vu)[2]:
|
||||||
raise RuntimeError, "bad videntu"
|
raise RuntimeError, "bad videntu"
|
||||||
|
|
||||||
|
|
||||||
if v[0:3] != vu[0:3]:
|
if v[0:3][1] != vu[0:3][1]:
|
||||||
|
print v[0:3][1], vu[0:3][1]
|
||||||
raise RuntimeError, "bad getslice"
|
raise RuntimeError, "bad getslice"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,3 +52,30 @@ if map != std_containers.mapident(map):
|
||||||
raise RuntimeError, "bad map"
|
raise RuntimeError, "bad map"
|
||||||
|
|
||||||
|
|
||||||
|
vi = std_containers.vector_i((2,2,3,4))
|
||||||
|
|
||||||
|
|
||||||
|
v = (1,2)
|
||||||
|
v1 = std_containers.v_inout(vi)
|
||||||
|
vi[1], v1[1]
|
||||||
|
|
||||||
|
v1,v2 = ((1,2),(3,4))
|
||||||
|
v1,v2 = std_containers.v_inout2(v1,v2)
|
||||||
|
|
||||||
|
a1 = std_containers.A(1)
|
||||||
|
a2 = std_containers.A(2)
|
||||||
|
|
||||||
|
p1 = (1,a1)
|
||||||
|
p2 = (2,a2)
|
||||||
|
v = (p1,p2)
|
||||||
|
v2= std_containers.pia_vident(v)
|
||||||
|
|
||||||
|
v2[0][1].a
|
||||||
|
v2[1][1].a
|
||||||
|
|
||||||
|
v3 = std_containers.vector_piA(v2)
|
||||||
|
|
||||||
|
v3[0][1].a
|
||||||
|
v3[1][1].a
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue