From 2c5dc2113bde3d60e30d1442053898ca23eb41b9 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Mon, 29 Mar 2004 06:01:39 +0000 Subject: [PATCH] more cases git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5796 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/lib_std_pair.i | 21 ++++++++++- Examples/test-suite/python/lib_std_string.i | 19 ++++++++++ .../test-suite/python/lib_std_string_runme.py | 37 +++++++++++++++++++ .../python/primitive_types_runme.py | 3 ++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/python/lib_std_pair.i b/Examples/test-suite/python/lib_std_pair.i index 3b1579b68..b93af5f64 100644 --- a/Examples/test-suite/python/lib_std_pair.i +++ b/Examples/test-suite/python/lib_std_pair.i @@ -1,25 +1,38 @@ %module lib_std_pair %include std_pair.i +%include std_string.i +%include std_complex.i +%inline %{ struct A { + int val; + + A(int v = 0): val(v) + { + } + }; struct B { }; %} - namespace std { %template() pair; + %template(String) basic_string; %template(IntPair) pair; + %template(SIPair) pair; + %template(CIPair) pair, int>; + %template(SIIPair) pair, int>; %template(AIntPair) pair; %template(ABPair) pair; %template(IntAPair) pair; } +%std_comp_methods(std::pair, int>); %apply std::pair *INOUT {std::pair *INOUT2}; @@ -113,6 +126,11 @@ p_inoutd(std::pair *INOUT) { std::swap(INOUT->first, INOUT->second); } +std::string + s_ident(const std::string& s) { + return s; +} + #if 0 std::pair p_ident(std::pair p, const std::pair& q) { @@ -143,6 +161,7 @@ std::pair } + #endif %} diff --git a/Examples/test-suite/python/lib_std_string.i b/Examples/test-suite/python/lib_std_string.i index f9ce9e48b..b2cc353fc 100644 --- a/Examples/test-suite/python/lib_std_string.i +++ b/Examples/test-suite/python/lib_std_string.i @@ -9,9 +9,28 @@ struct A : std::string A(const std::string& s) : std::string(s) { } +}; + +struct B +{ + B(const std::string& s) : cname(0), name(s), a(s) + { + } + char *cname; + std::string name; + A a; + }; + +const char* test_ccvalue(const char* x) { + return x; +} + +char* test_cvalue(char* x) { + return x; +} std::string test_value(std::string x) { diff --git a/Examples/test-suite/python/lib_std_string_runme.py b/Examples/test-suite/python/lib_std_string_runme.py index 9adb227db..041e7016a 100644 --- a/Examples/test-suite/python/lib_std_string_runme.py +++ b/Examples/test-suite/python/lib_std_string_runme.py @@ -2,6 +2,14 @@ import lib_std_string x="hello" + + +if lib_std_string.test_ccvalue(x) != x: + raise RuntimeError, "bad string mapping" + +if lib_std_string.test_cvalue(x) != x: + raise RuntimeError, "bad string mapping" + if lib_std_string.test_value(x) != x: raise RuntimeError, "bad string mapping" @@ -34,3 +42,32 @@ if lib_std_string.test_value(a) != x: if lib_std_string.test_const_reference(a) != x: raise RuntimeError, "bad string mapping" +b = lib_std_string.string(" world") + +if a + b != "hello world": + raise RuntimeError, "bad string mapping" + +if a + " world" != "hello world": + raise RuntimeError, "bad string mapping" + +if "hello" + b != "hello world": + raise RuntimeError, "bad string mapping" + +c = "hello" + b +if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" + +s = "hello world" + +b = lib_std_string.B("hi") + +b.name = "hello" +if b.name != "hello": + raise RuntimeError, "bad string mapping" + + +b.a = lib_std_string.A("hello") +if b.a != "hello": + raise RuntimeError, "bad string mapping" + + diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 0eb80c8b5..95e65d1cf 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -196,6 +196,7 @@ if t.var_namet != 'hol\0\0': if t.strlen('hile') != 4: + print t.strlen('hile') raise RuntimeError, "bad string typemap" if t.strlen('hil\0') != 4: @@ -224,6 +225,7 @@ if cvar.var_pchar != None: cvar.var_pchar = '' if cvar.var_pchar != '': + print '%c' % (cvar.var_pchar[0],) raise RuntimeError, "bad char empty case" cvar.var_pcharc = None @@ -251,6 +253,7 @@ if t.strlen(pc) != 4: cvar.var_pchar = pc if cvar.var_pchar != "hola": + print cvar.var_pchar raise RuntimeError, "bad pointer case" cvar.var_namet = pc