From 52fe09a938be0585eefb2f94847e371567911d3a Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Wed, 1 Dec 2004 01:17:56 +0000 Subject: [PATCH] adding more cases git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6814 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/python/.cvsignore | 2 + .../test-suite/python/li_std_pair_runme.py | 4 +- .../test-suite/python/li_std_stream.i | 37 ++++++++++++++++--- .../test-suite/python/li_std_stream_runme.py | 12 ++++-- .../test-suite/python/li_std_string.i | 14 ++++++- .../test-suite/python/li_std_string_runme.py | 11 ++++++ .../test-suite/python/li_std_wstring.i | 1 - .../test-suite/python/profiletest_runme.py | 2 +- SWIG/Examples/test-suite/python/swigobject.i | 5 +++ .../test-suite/python/swigobject_runme.py | 5 +++ 10 files changed, 79 insertions(+), 14 deletions(-) diff --git a/SWIG/Examples/test-suite/python/.cvsignore b/SWIG/Examples/test-suite/python/.cvsignore index 81e8dfe6e..da56b23ca 100644 --- a/SWIG/Examples/test-suite/python/.cvsignore +++ b/SWIG/Examples/test-suite/python/.cvsignore @@ -406,3 +406,5 @@ voidtest_runme.py wrapmacro.py wrapmacro_runme.py li_std_stream.py +swigobject.py +smart_pointer_member.py diff --git a/SWIG/Examples/test-suite/python/li_std_pair_runme.py b/SWIG/Examples/test-suite/python/li_std_pair_runme.py index 48fd4a407..b301f0d24 100644 --- a/SWIG/Examples/test-suite/python/li_std_pair_runme.py +++ b/SWIG/Examples/test-suite/python/li_std_pair_runme.py @@ -51,8 +51,8 @@ p = li_std_pair.IntPair(1,10) p.first = 1 p = li_std_pair.paircA1(1,a) -print 'f', p.first -print 's', p.second +p.first +p.second p = li_std_pair.paircA2(1,a) pp = li_std_pair.pairiiA(1,p) diff --git a/SWIG/Examples/test-suite/python/li_std_stream.i b/SWIG/Examples/test-suite/python/li_std_stream.i index 09857c2d8..22267a108 100644 --- a/SWIG/Examples/test-suite/python/li_std_stream.i +++ b/SWIG/Examples/test-suite/python/li_std_stream.i @@ -1,13 +1,26 @@ %module li_std_stream +%inline %{ + struct A; +%} + %include +%include -%pythoncallback(1) A::bar; + +%callback(1) A::bar; %inline %{ - struct A + struct B { + virtual ~B() + { + } + + }; + + struct A : B { void __add__(int a) { @@ -25,8 +38,22 @@ { return pf(a); } - - }; - + + std::ostream& __rlshift__(std::ostream& out) + { + out << "A class"; + return out; + } + }; %} + +%extend std::basic_ostream >{ + std::basic_ostream >& + operator<<(const A& a) + { + *self << "A class"; + return *self; + } +} + diff --git a/SWIG/Examples/test-suite/python/li_std_stream_runme.py b/SWIG/Examples/test-suite/python/li_std_stream_runme.py index 5c3479b96..b03bda9cb 100644 --- a/SWIG/Examples/test-suite/python/li_std_stream_runme.py +++ b/SWIG/Examples/test-suite/python/li_std_stream_runme.py @@ -1,10 +1,14 @@ import li_std_stream as std -std.cout << 2345 << " " << 1.435 << std.endl -std.endl(std.cout) a = std.A() -a.bar(2) -a.foo(4, a.bar) +o = std.ostringstream() + +o << a << " " << 2345 << " " << 1.435 + + +if o.str() != "A class 2345 1.435": + print "\"%s\"" % (o.str(),) + raise RuntimeError diff --git a/SWIG/Examples/test-suite/python/li_std_string.i b/SWIG/Examples/test-suite/python/li_std_string.i index fafdeb77d..1f769bb20 100644 --- a/SWIG/Examples/test-suite/python/li_std_string.i +++ b/SWIG/Examples/test-suite/python/li_std_string.i @@ -2,7 +2,6 @@ %include %include -%template(string) std::basic_string; %inline %{ struct A : std::string @@ -72,6 +71,19 @@ void test_throw() throw(std::string){ throw x; } + +std::basic_string test_value_basic1(std::basic_string x) { + return x; +} + +std::basic_string > test_value_basic2(std::basic_string > x) { + return x; +} + +std::basic_string,std::allocator > test_value_basic3(std::basic_string,std::allocator > x) { + return x; +} + %} diff --git a/SWIG/Examples/test-suite/python/li_std_string_runme.py b/SWIG/Examples/test-suite/python/li_std_string_runme.py index 1564da560..a30795ae6 100644 --- a/SWIG/Examples/test-suite/python/li_std_string_runme.py +++ b/SWIG/Examples/test-suite/python/li_std_string_runme.py @@ -45,7 +45,9 @@ if li_std_string.test_const_reference(a) != x: b = li_std_string.string(" world") +s = a + b if a + b != "hello world": + print a + b raise RuntimeError, "bad string mapping" if a + " world" != "hello world": @@ -72,3 +74,12 @@ if b.a != "hello": raise RuntimeError, "bad string mapping" +if li_std_string.test_value_basic1(x) != x: + raise RuntimeError, "bad string mapping" + +if li_std_string.test_value_basic2(x) != x: + raise RuntimeError, "bad string mapping" + + +if li_std_string.test_value_basic3(x) != x: + raise RuntimeError, "bad string mapping" diff --git a/SWIG/Examples/test-suite/python/li_std_wstring.i b/SWIG/Examples/test-suite/python/li_std_wstring.i index dbdf6a736..c5cd20576 100644 --- a/SWIG/Examples/test-suite/python/li_std_wstring.i +++ b/SWIG/Examples/test-suite/python/li_std_wstring.i @@ -3,7 +3,6 @@ %include -%template(wstring) std::basic_string; %inline %{ struct A : std::wstring diff --git a/SWIG/Examples/test-suite/python/profiletest_runme.py b/SWIG/Examples/test-suite/python/profiletest_runme.py index 1bf1591ce..d9653664a 100644 --- a/SWIG/Examples/test-suite/python/profiletest_runme.py +++ b/SWIG/Examples/test-suite/python/profiletest_runme.py @@ -3,5 +3,5 @@ import _profiletest a = _profiletest.new_A() b = _profiletest.new_B() -for i in range(0,1000000): +for i in range(0,10000000): a = _profiletest.B_fn(b, a) diff --git a/SWIG/Examples/test-suite/python/swigobject.i b/SWIG/Examples/test-suite/python/swigobject.i index 95447e2e4..760b64025 100644 --- a/SWIG/Examples/test-suite/python/swigobject.i +++ b/SWIG/Examples/test-suite/python/swigobject.i @@ -17,4 +17,9 @@ A *a_ptr(A *a){ return a; } + + + void *v_ptr(void *a){ + return a; + } } diff --git a/SWIG/Examples/test-suite/python/swigobject_runme.py b/SWIG/Examples/test-suite/python/swigobject_runme.py index d2b54c955..c8fda5c21 100644 --- a/SWIG/Examples/test-suite/python/swigobject_runme.py +++ b/SWIG/Examples/test-suite/python/swigobject_runme.py @@ -19,3 +19,8 @@ if xstr1 != xstr2: s = str(a.this) r = repr(a.this) + +v1 = v_ptr(a) +v2 = v_ptr(a) +if long(v1) != long(v2): + raise RuntimeError