more tests

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5784 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-21 23:38:59 +00:00
commit 5a656bf645
13 changed files with 161 additions and 18 deletions

View file

@ -9,6 +9,18 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
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
# Overridden variables here

View file

@ -6,6 +6,7 @@ if aa.a != 1:
raise RuntimeError
aa.a = 3
if aa.a != 3:
print aa.a
raise RuntimeError

View file

@ -9,6 +9,6 @@ if complextest.Conj(a) != a.conjugate():
v = (complex(1,2), complex(2,3), complex(4,3), 1)
try:
print complextest.Copy_h(v)
complextest.Copy_h(v)
except:
pass

View file

@ -4,6 +4,15 @@
%include "std_pair.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:except") {

View file

@ -4,9 +4,9 @@ ai = A(1)
ad = A(2.0)
ab = A(b)
print ai, get(ai)
print ad, get(ad)
print ab, get(ab)
ai, get(ai)
ad, get(ad)
ab, get(ab)
if get(ai) != get(1):
raise RuntimeError,"bad implicit type"

View file

@ -1,6 +1,6 @@
%module lib_std_pair
%include "std_pair.i"
%include std_pair.i
%{
struct A
@ -13,6 +13,7 @@
namespace std {
%template() pair<double, double>;
%template(IntPair) pair<int, int>;
%template(AIntPair) pair<A, int>;
@ -20,6 +21,8 @@ namespace std {
%template(IntAPair) pair<int, A>;
}
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
%inline %{
/* Test the "out" typemap for pair<T, U> */
@ -72,6 +75,44 @@ std::pair<int, int>
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
std::pair<char, char>
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) {
return p;
}
#endif
%}

View file

@ -10,7 +10,15 @@ if lib_std_string.test_const_reference(x) != x:
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:
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:
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:
raise RuntimeError, "bad string mapping"
if lib_std_string.test_const_reference(a) != x:
raise RuntimeError, "bad string mapping"

View file

@ -2,6 +2,7 @@
%include std_vectora.i
%{
#include <algorithm>
#include <functional>
@ -20,7 +21,7 @@
std::allocator<std::vector<int,std::allocator<int> > > >
imatrix;
std::vector<int> vident(const std::vector<int>& v)
std::vector<int> vident(const std::vector<int,std::allocator<int> >& v)
{
return v;
}
@ -44,12 +45,13 @@ namespace std {
%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();
}
std::vector<float> half(const std::vector<float>& v) {
std::vector<float> w(v);
std::vector<Real,std::allocator<Real> >
half(const std::vector<Real,std::allocator<Real> >& v) {
std::vector<Real> w(v);
for (unsigned int i=0; i<w.size(); i++)
w[i] /= 2.0;
return w;

View file

@ -319,6 +319,6 @@ if error:
#
#
t2 = p.vtest(t)
if "%s" % (t2,) != "%s" % (t,):
if t.var_namet != t2.var_namet:
raise RuntimeError, "bad SWIGTYPE* typemap"

View file

@ -5,10 +5,17 @@
%include std_deque.i
%include std_list.i
%include std_set.i
%include std_multiset.i
%include std_pair.i
%include std_map.i
%include std_multimap.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(ccube) std::vector< std::vector< std::vector<double > > >;
@ -28,6 +35,7 @@
%template(map_si) std::map<std::string, int>;
%template(mmap_si) std::multimap<std::string, int>;
%template(set_i) std::set<int>;
%template(multiset_i) std::multiset<int>;
%template(list_i) std::list<int>;
@ -40,6 +48,8 @@
%template(imatrix) std::vector<std::vector<int> >;
%template(cmatrix) std::vector<std::vector<std::complex<double> > >;
%apply std::vector<int> *INOUT {std::vector<int> *INOUT2};
%inline
{
typedef std::vector<std::vector<int> > imatrix;
@ -58,6 +68,11 @@
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)
{
return v;
@ -83,8 +98,17 @@
{
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
{
A(int aa = 0) : a(aa)
{
}
int a;
};
}
%template() std::pair<A,int>;
%template(pair_iA) std::pair<int,A>;
%template(vector_piA) std::vector<std::pair<int,A> >;
%inline {
@ -126,5 +155,12 @@ template <class C> struct Param
{
return std::pair<A,int>();
}
std::vector<std::pair<int,A> > pia_vident(std::vector<std::pair<int,A> > a )
{
return a;
}
}

View file

@ -27,7 +27,8 @@ if vu[2] != std_containers.videntu(vu)[2]:
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"
@ -51,3 +52,30 @@ if map != std_containers.mapident(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