add test for wstring
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5828 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3c0fe7cae7
commit
39e2071d68
2 changed files with 150 additions and 0 deletions
78
Examples/test-suite/python/lib_std_wstring.i
Normal file
78
Examples/test-suite/python/lib_std_wstring.i
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
%module lib_std_wstring
|
||||
|
||||
%include "std_wstring.i"
|
||||
|
||||
|
||||
%template(wstring) std::basic_string<wchar_t>;
|
||||
%inline %{
|
||||
|
||||
struct A : std::wstring
|
||||
{
|
||||
A(const std::wstring& s) : std::wstring(s)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct B
|
||||
{
|
||||
B(const std::wstring& s) : cname(0), name(s), a(s)
|
||||
{
|
||||
}
|
||||
|
||||
char *cname;
|
||||
std::wstring name;
|
||||
A a;
|
||||
|
||||
};
|
||||
|
||||
|
||||
const wchar_t* test_ccvalue(const wchar_t* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
wchar_t* test_cvalue(wchar_t* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
std::wstring test_value(std::wstring x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
const std::wstring& test_const_reference(const std::wstring &x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
void test_pointer(std::wstring *x) {
|
||||
}
|
||||
|
||||
std::wstring *test_pointer_out() {
|
||||
static std::wstring x = L"x";
|
||||
return &x;
|
||||
}
|
||||
|
||||
void test_const_pointer(const std::wstring *x) {
|
||||
}
|
||||
|
||||
const std::wstring *test_const_pointer_out() {
|
||||
static std::wstring x = L"x";
|
||||
return &x;
|
||||
}
|
||||
|
||||
void test_reference(std::wstring &x) {
|
||||
}
|
||||
|
||||
std::wstring& test_reference_out() {
|
||||
static std::wstring x = L"x";
|
||||
return x;
|
||||
}
|
||||
|
||||
void test_throw() throw(std::wstring){
|
||||
static std::wstring x = L"x";
|
||||
|
||||
throw x;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
72
Examples/test-suite/python/lib_std_wstring_runme.py
Normal file
72
Examples/test-suite/python/lib_std_wstring_runme.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import lib_std_wstring
|
||||
|
||||
x=u"hello"
|
||||
|
||||
|
||||
if lib_std_wstring.test_ccvalue(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if lib_std_wstring.test_cvalue(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if lib_std_wstring.test_value(x) != x:
|
||||
print x, lib_std_wstring.test_value(x)
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if lib_std_wstring.test_const_reference(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
s = lib_std_wstring.wstring(u"he")
|
||||
s += u"llo"
|
||||
|
||||
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_wstring.test_value(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if lib_std_wstring.test_const_reference(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
a = lib_std_wstring.A(s)
|
||||
|
||||
if lib_std_wstring.test_value(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if lib_std_wstring.test_const_reference(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
b = lib_std_wstring.wstring(" 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_wstring.B("hi")
|
||||
|
||||
b.name = u"hello"
|
||||
if b.name != "hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
b.a = lib_std_wstring.A("hello")
|
||||
if b.a != u"hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue