mirror of https://github.com/swig/swig
Split testcases li_std_wstring.i and li_std_wstring_inherit.i
Not many languages have support for std_wstring.i, so disable testing for these languages until added.
This commit is contained in:
parent
5131096b80
commit
a9a7b03ba6
|
@ -655,6 +655,7 @@ CPP_STD_TEST_CASES += \
|
||||||
li_std_vector_enum \
|
li_std_vector_enum \
|
||||||
li_std_vector_member_var\
|
li_std_vector_member_var\
|
||||||
li_std_vector_ptr \
|
li_std_vector_ptr \
|
||||||
|
li_std_wstring \
|
||||||
smart_pointer_inherit \
|
smart_pointer_inherit \
|
||||||
template_typedef_fnc \
|
template_typedef_fnc \
|
||||||
template_type_namespace \
|
template_type_namespace \
|
||||||
|
|
|
@ -3,74 +3,74 @@ using li_std_wstringNamespace;
|
||||||
|
|
||||||
public class runme
|
public class runme
|
||||||
{
|
{
|
||||||
|
static private void check_equal(char a, char b)
|
||||||
|
{
|
||||||
|
if (a != b)
|
||||||
|
throw new Exception("failed " + a + " " + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static private void check_equal(string a, string b)
|
||||||
|
{
|
||||||
|
if (a != b)
|
||||||
|
throw new Exception("failed " + a + " " + b);
|
||||||
|
}
|
||||||
|
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
char y='h';
|
char h = 'h';
|
||||||
|
check_equal(li_std_wstring.test_wcvalue(h), h);
|
||||||
|
|
||||||
if (li_std_wstring.test_wcvalue(y) != y)
|
string x = "abc";
|
||||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue(y));
|
check_equal(li_std_wstring.test_ccvalue(x), x);
|
||||||
|
check_equal(li_std_wstring.test_cvalue(x), x);
|
||||||
|
|
||||||
if (li_std_wstring.test_wcvalue_w() != 'W')
|
check_equal(li_std_wstring.test_wchar_overload(x), x);
|
||||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue_w());
|
check_equal(li_std_wstring.test_wchar_overload(), null);
|
||||||
|
|
||||||
string x="hello";
|
li_std_wstring.test_pointer(null);
|
||||||
|
li_std_wstring.test_const_pointer(null);
|
||||||
|
|
||||||
if (li_std_wstring.test_ccvalue(x) != x)
|
try {
|
||||||
throw new Exception("bad string mapping");
|
li_std_wstring.test_value(null);
|
||||||
|
throw new Exception("NULL check failed");
|
||||||
|
} catch (ArgumentNullException) {
|
||||||
|
}
|
||||||
|
|
||||||
if (li_std_wstring.test_cvalue(x) != x)
|
try {
|
||||||
throw new Exception("bad string mapping");
|
li_std_wstring.test_reference(null);
|
||||||
|
throw new Exception("NULL check failed");
|
||||||
|
} catch (ArgumentNullException e) {
|
||||||
|
if (!e.Message.Contains("type is null"))
|
||||||
|
throw new Exception("Missing text " + e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
li_std_wstring.test_const_reference(null);
|
||||||
|
throw new Exception("NULL check failed");
|
||||||
|
} catch (ArgumentNullException e) {
|
||||||
|
if (!e.Message.Contains("null wstring"))
|
||||||
|
throw new Exception("Missing text " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = "hello";
|
||||||
|
check_equal(li_std_wstring.test_const_reference(x), x);
|
||||||
|
|
||||||
if (li_std_wstring.test_value(x) != x)
|
/* TODO
|
||||||
throw new Exception("bad string mapping: " + x + li_std_wstring.test_value(x));
|
string s = "abc";
|
||||||
|
if (!li_std_wstring.test_equal_abc(s))
|
||||||
|
throw new Exception("Not equal " + s);
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(x) != x)
|
try {
|
||||||
throw new Exception("bad string mapping");
|
li_std_wstring.test_throw();
|
||||||
|
} catch (Exception e) {
|
||||||
|
check_equal(e.Message, "throwing test_throw");
|
||||||
|
}
|
||||||
|
|
||||||
|
x = "abc\0def";
|
||||||
|
check_equal(li_std_wstring.test_value(x), x);
|
||||||
|
check_equal(li_std_wstring.test_ccvalue(x), "abc");
|
||||||
|
check_equal(li_std_wstring.test_wchar_overload(x), "abc");
|
||||||
|
*/
|
||||||
|
|
||||||
string s = "he";
|
|
||||||
s = s + "llo";
|
|
||||||
|
|
||||||
if (s != x)
|
|
||||||
throw new Exception("bad string mapping: " + s + x);
|
|
||||||
|
|
||||||
if (li_std_wstring.test_value(s) != x)
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(s) != x)
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
string a = s;
|
|
||||||
|
|
||||||
if (li_std_wstring.test_value(a) != x)
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(a) != x)
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
string b = " world";
|
|
||||||
|
|
||||||
if (a + b != "hello world")
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
if (a + " world" != "hello world")
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
if ("hello" + b != "hello world")
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
s = "hello world";
|
|
||||||
|
|
||||||
B myB = new B("hi");
|
|
||||||
|
|
||||||
myB.name = "hello";
|
|
||||||
if (myB.name != "hello")
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
|
|
||||||
myB.a = "hello";
|
|
||||||
if (myB.a != "hello")
|
|
||||||
throw new Exception("bad string mapping");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
%module li_std_wstring
|
%module li_std_wstring
|
||||||
%include <std_basic_string.i>
|
|
||||||
%include <std_wstring.i>
|
|
||||||
|
|
||||||
|
// The languages below are yet to provide std_wstring.i
|
||||||
|
#if !(defined(SWIGD) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVASCRIPT) || defined(SWIGLUA) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGOCTAVE) || defined(SWIGPERL) || defined(SWIGPHP) || defined(SWIGR) || defined(SWIGSCILAB))
|
||||||
|
|
||||||
|
%include <std_wstring.i>
|
||||||
|
|
||||||
// throw is invalid in C++17 and later, only SWIG to use it
|
// throw is invalid in C++17 and later, only SWIG to use it
|
||||||
#define TESTCASE_THROW1(T1) throw(T1)
|
#define TESTCASE_THROW1(T1) throw(T1)
|
||||||
|
@ -10,26 +12,7 @@
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
#include <string>
|
||||||
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;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
wchar_t test_wcvalue(wchar_t x) {
|
wchar_t test_wcvalue(wchar_t x) {
|
||||||
return x;
|
return x;
|
||||||
|
@ -63,33 +46,18 @@ const std::wstring& test_const_reference(const std::wstring &x) {
|
||||||
void test_pointer(std::wstring *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) {
|
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) {
|
void test_reference(std::wstring &x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring& test_reference_out() {
|
|
||||||
static std::wstring x = L"x";
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_equal_abc(const std::wstring &s) {
|
bool test_equal_abc(const std::wstring &s) {
|
||||||
return L"abc" == s;
|
return L"abc" == s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_throw() TESTCASE_THROW1(std::wstring){
|
void test_throw() TESTCASE_THROW1(std::wstring){
|
||||||
static std::wstring x = L"x";
|
static std::wstring x = L"throwing test_throw";
|
||||||
|
|
||||||
throw x;
|
throw x;
|
||||||
}
|
}
|
||||||
|
@ -102,12 +70,7 @@ size_t size_wstring(const std::wstring& s) {
|
||||||
return s.size();
|
return s.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SWIGPYTHON_BUILTIN
|
|
||||||
bool is_python_builtin() { return true; }
|
|
||||||
#else
|
|
||||||
bool is_python_builtin() { return false; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,6 @@
|
||||||
%include <std_wstring.i>
|
%include <std_wstring.i>
|
||||||
|
|
||||||
|
|
||||||
// throw is invalid in C++17 and later, only SWIG to use it
|
|
||||||
#define TESTCASE_THROW1(T1) throw(T1)
|
|
||||||
%{
|
|
||||||
#define TESTCASE_THROW1(T1)
|
|
||||||
%}
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
struct A : std::wstring
|
struct A : std::wstring
|
||||||
|
@ -30,78 +24,10 @@ struct B
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
wchar_t test_wcvalue(wchar_t x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wchar_t* test_ccvalue(const wchar_t* x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t* test_cvalue(wchar_t* x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wchar_t* test_wchar_overload() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t* test_wchar_overload(wchar_t *x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring test_value(std::wstring x) {
|
std::wstring test_value(std::wstring x) {
|
||||||
return 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_equal_abc(const std::wstring &s) {
|
|
||||||
return L"abc" == s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_throw() TESTCASE_THROW1(std::wstring){
|
|
||||||
static std::wstring x = L"x";
|
|
||||||
|
|
||||||
throw x;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * non_utf8_c_str() {
|
|
||||||
return "h\xe9llo";
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size_wstring_size(const std::wstring& s) {
|
|
||||||
return s.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SWIGPYTHON_BUILTIN
|
#ifdef SWIGPYTHON_BUILTIN
|
||||||
bool is_python_builtin() { return true; }
|
bool is_python_builtin() { return true; }
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
# do not dump Octave core
|
|
||||||
if exist("crash_dumps_octave_core", "builtin")
|
|
||||||
crash_dumps_octave_core(0);
|
|
||||||
endif
|
|
||||||
|
|
||||||
li_std_wstring
|
|
||||||
|
|
||||||
x="h";
|
|
||||||
|
|
||||||
if (li_std_wstring.test_wcvalue(x) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
x="hello";
|
|
||||||
if (li_std_wstring.test_ccvalue(x) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_cvalue(x) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_value(x) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(x) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
s = li_std_wstring.wstring("he");
|
|
||||||
s = s + "llo";
|
|
||||||
|
|
||||||
if (s != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (s(1:4) != x(1:4))
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_value(s) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(s) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
a = li_std_wstring.A(s);
|
|
||||||
|
|
||||||
if (li_std_wstring.test_value(a) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (li_std_wstring.test_const_reference(a) != x)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
b = li_std_wstring.wstring(" world");
|
|
||||||
|
|
||||||
if (a + b != "hello world")
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (a + " world" != "hello world")
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
if ("hello" + b != "hello world")
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
c = "hello" + b;
|
|
||||||
if (c.find_last_of("l") != 9)
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
s = "hello world";
|
|
||||||
|
|
||||||
b = li_std_wstring.B("hi");
|
|
||||||
|
|
||||||
b.name = li_std_wstring.wstring("hello");
|
|
||||||
if (b.name != "hello")
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
b.a = li_std_wstring.A("hello");
|
|
||||||
if (b.a != "hello")
|
|
||||||
error("bad string mapping")
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,7 @@
|
||||||
import li_std_wstring_inherit
|
import li_std_wstring_inherit
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
x = u"h"
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_wcvalue(x) != x:
|
|
||||||
print li_std_wstring_inherit.test_wcvalue(x)
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
x = u"hello"
|
x = u"hello"
|
||||||
if li_std_wstring_inherit.test_ccvalue(x) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_cvalue(x) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_wchar_overload(x) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_wchar_overload("not unicode") != "not unicode":
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_value(x) != x:
|
|
||||||
print x, li_std_wstring_inherit.test_value(x)
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_const_reference(x) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
|
|
||||||
s = li_std_wstring_inherit.wstring(u"he")
|
s = li_std_wstring_inherit.wstring(u"he")
|
||||||
s = s + u"llo"
|
s = s + u"llo"
|
||||||
|
@ -38,20 +13,7 @@ if s != x:
|
||||||
if s[1:4] != x[1:4]:
|
if s[1:4] != x[1:4]:
|
||||||
raise RuntimeError("bad string mapping")
|
raise RuntimeError("bad string mapping")
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_value(s) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_const_reference(s) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
a = li_std_wstring_inherit.A(s)
|
a = li_std_wstring_inherit.A(s)
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_value(a) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring_inherit.test_const_reference(a) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
b = li_std_wstring_inherit.wstring(" world")
|
b = li_std_wstring_inherit.wstring(" world")
|
||||||
|
|
||||||
if a + b != "hello world":
|
if a + b != "hello world":
|
||||||
|
@ -70,8 +32,6 @@ if not li_std_wstring_inherit.is_python_builtin():
|
||||||
if c.find_last_of("l") != 9:
|
if c.find_last_of("l") != 9:
|
||||||
raise RuntimeError("bad string mapping")
|
raise RuntimeError("bad string mapping")
|
||||||
|
|
||||||
s = "hello world"
|
|
||||||
|
|
||||||
b = li_std_wstring_inherit.B("hi")
|
b = li_std_wstring_inherit.B("hi")
|
||||||
|
|
||||||
b.name = li_std_wstring_inherit.wstring(u"hello")
|
b.name = li_std_wstring_inherit.wstring(u"hello")
|
||||||
|
@ -83,24 +43,3 @@ b.a = li_std_wstring_inherit.A("hello")
|
||||||
if b.a != u"hello":
|
if b.a != u"hello":
|
||||||
raise RuntimeError("bad string mapping")
|
raise RuntimeError("bad string mapping")
|
||||||
|
|
||||||
# Byte strings only converted in Python 2
|
|
||||||
if sys.version_info[0:2] < (3, 0):
|
|
||||||
x = b"hello there"
|
|
||||||
if li_std_wstring_inherit.test_value(x) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
# Invalid utf-8 in a byte string fails in all versions
|
|
||||||
x = b"h\xe9llo"
|
|
||||||
try:
|
|
||||||
li_std_wstring_inherit.test_value(x)
|
|
||||||
raise RuntimeError("TypeError not thrown")
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Check surrogateescape
|
|
||||||
if sys.version_info[0:2] > (3, 1):
|
|
||||||
x = u"h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
|
|
||||||
if li_std_wstring_inherit.non_utf8_c_str() != x:
|
|
||||||
raise RuntimeError("surrogateescape not working")
|
|
||||||
if li_std_wstring_inherit.size_wstring(x) != 5 and len(x) != 5:
|
|
||||||
raise RuntimeError("Unexpected length")
|
|
||||||
|
|
|
@ -1,87 +1,60 @@
|
||||||
import li_std_wstring
|
import li_std_wstring
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
x = u"h"
|
def check_equal(a, b):
|
||||||
|
if a != b:
|
||||||
|
raise RuntimeError("failed {} {}".format(a, b))
|
||||||
|
|
||||||
if li_std_wstring.test_wcvalue(x) != x:
|
h = u"h"
|
||||||
print li_std_wstring.test_wcvalue(x)
|
check_equal(li_std_wstring.test_wcvalue(h), h)
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
x = u"hello"
|
x = u"abc"
|
||||||
if li_std_wstring.test_ccvalue(x) != x:
|
check_equal(li_std_wstring.test_ccvalue(x), x)
|
||||||
raise RuntimeError("bad string mapping")
|
check_equal(li_std_wstring.test_cvalue(x), x)
|
||||||
|
|
||||||
if li_std_wstring.test_cvalue(x) != x:
|
check_equal(li_std_wstring.test_wchar_overload(x), x)
|
||||||
raise RuntimeError("bad string mapping")
|
check_equal(li_std_wstring.test_wchar_overload(), None)
|
||||||
|
|
||||||
if li_std_wstring.test_wchar_overload(x) != x:
|
li_std_wstring.test_pointer(None)
|
||||||
raise RuntimeError("bad string mapping")
|
li_std_wstring.test_const_pointer(None)
|
||||||
|
|
||||||
if li_std_wstring.test_wchar_overload("not unicode") != "not unicode":
|
try:
|
||||||
raise RuntimeError("bad string mapping")
|
li_std_wstring.test_value(None)
|
||||||
|
raise RuntimeError("NULL check failed")
|
||||||
|
except TypeError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
if li_std_wstring.test_value(x) != x:
|
try:
|
||||||
print x, li_std_wstring.test_value(x)
|
li_std_wstring.test_reference(None)
|
||||||
raise RuntimeError("bad string mapping")
|
raise RuntimeError("NULL check failed")
|
||||||
|
except ValueError as e:
|
||||||
|
if "invalid null reference" not in str(e):
|
||||||
|
raise RuntimeError("Missing text {}".format(e))
|
||||||
|
try:
|
||||||
|
li_std_wstring.test_const_reference(None)
|
||||||
|
raise RuntimeError("NULL check failed")
|
||||||
|
except ValueError as e:
|
||||||
|
if "invalid null reference" not in str(e):
|
||||||
|
raise RuntimeError("Missing text {}".format(e))
|
||||||
|
|
||||||
if li_std_wstring.test_const_reference(x) != x:
|
x = "hello"
|
||||||
raise RuntimeError("bad string mapping")
|
check_equal(li_std_wstring.test_const_reference(x), x)
|
||||||
|
|
||||||
|
s = "abc"
|
||||||
|
if not li_std_wstring.test_equal_abc(s):
|
||||||
|
raise RuntimeError("Not equal {}".format(s))
|
||||||
|
|
||||||
s = li_std_wstring.wstring(u"he")
|
try:
|
||||||
s = s + u"llo"
|
li_std_wstring.test_throw
|
||||||
|
except RuntimeError as e:
|
||||||
|
check_equal(e.message, "throwing test_throw")
|
||||||
|
|
||||||
if s != x:
|
x = "abc\0def"
|
||||||
print s, x
|
check_equal(li_std_wstring.test_value(x), x)
|
||||||
raise RuntimeError("bad string mapping")
|
check_equal(li_std_wstring.test_ccvalue(x), "abc")
|
||||||
|
check_equal(li_std_wstring.test_wchar_overload(x), "abc")
|
||||||
|
|
||||||
if s[1:4] != x[1:4]:
|
################### Python specific
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring.test_value(s) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring.test_const_reference(s) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
a = li_std_wstring.A(s)
|
|
||||||
|
|
||||||
if li_std_wstring.test_value(a) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if li_std_wstring.test_const_reference(a) != x:
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
b = li_std_wstring.wstring(" world")
|
|
||||||
|
|
||||||
if a + b != "hello world":
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
if a + " world" != "hello world":
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
# This is expected to fail if -builtin is used
|
|
||||||
# Reverse operators not supported in builtin types
|
|
||||||
if not li_std_wstring.is_python_builtin():
|
|
||||||
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 = li_std_wstring.B("hi")
|
|
||||||
|
|
||||||
b.name = li_std_wstring.wstring(u"hello")
|
|
||||||
if b.name != "hello":
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
|
|
||||||
b.a = li_std_wstring.A("hello")
|
|
||||||
if b.a != u"hello":
|
|
||||||
raise RuntimeError("bad string mapping")
|
|
||||||
|
|
||||||
# Byte strings only converted in Python 2
|
# Byte strings only converted in Python 2
|
||||||
if sys.version_info[0:2] < (3, 0):
|
if sys.version_info[0:2] < (3, 0):
|
||||||
|
|
|
@ -1,42 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
require 'swig_assert'
|
require 'swig_assert'
|
||||||
require 'li_std_wstring_inherit'
|
require 'li_std_wstring_inherit'
|
||||||
|
|
||||||
x = "abc"
|
x = "abc"
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_wchar_overload(x)", "x", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_ccvalue(x)", "x", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_value(Li_std_wstring_inherit::Wstring.new(x))", "x", binding)
|
swig_assert_equal("Li_std_wstring_inherit.test_value(Li_std_wstring_inherit::Wstring.new(x))", "x", binding)
|
||||||
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_wchar_overload()", "nil", binding)
|
|
||||||
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_pointer(Li_std_wstring_inherit::Wstring.new(x))", "nil", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_const_pointer(Li_std_wstring_inherit::Wstring.new(x))", "nil", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_const_pointer(Li_std_wstring_inherit::Wstring.new(x))", "nil", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_reference(Li_std_wstring_inherit::Wstring.new(x))", "nil", binding)
|
|
||||||
|
|
||||||
x = "y"
|
x = "y"
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_value(x)", "x", binding)
|
swig_assert_equal("Li_std_wstring_inherit.test_value(x)", "x", binding)
|
||||||
a = Li_std_wstring_inherit::A.new(x)
|
a = Li_std_wstring_inherit::A.new(x)
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_value(a)", "x", binding)
|
swig_assert_equal("Li_std_wstring_inherit.test_value(a)", "x", binding)
|
||||||
|
|
||||||
x = "hello"
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_const_reference(x)", "x", binding)
|
|
||||||
|
|
||||||
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_pointer_out", "'x'", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_const_pointer_out", "'x'", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_reference_out()", "'x'", binding)
|
|
||||||
|
|
||||||
s = "abc"
|
|
||||||
swig_assert("Li_std_wstring_inherit.test_equal_abc(s)", binding)
|
|
||||||
|
|
||||||
begin
|
|
||||||
Li_std_wstring_inherit.test_throw
|
|
||||||
rescue RuntimeError => e
|
|
||||||
swig_assert_equal("e.message", "'x'", binding)
|
|
||||||
end
|
|
||||||
|
|
||||||
x = "abc\0def"
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_value(x)", "x", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_ccvalue(x)", '"abc"', binding)
|
|
||||||
swig_assert_equal("Li_std_wstring_inherit.test_wchar_overload(x)", '"abc"', binding)
|
|
||||||
|
|
|
@ -2,38 +2,48 @@
|
||||||
require 'swig_assert'
|
require 'swig_assert'
|
||||||
require 'li_std_wstring'
|
require 'li_std_wstring'
|
||||||
|
|
||||||
x = "abc"
|
h = "h"
|
||||||
swig_assert_equal("Li_std_wstring.test_wchar_overload(x)", "x", binding)
|
swig_assert_equal("Li_std_wstring.test_wcvalue(h)", "h", binding)
|
||||||
swig_assert_equal("Li_std_wstring.test_ccvalue(x)", "x", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring.test_value(Li_std_wstring::Wstring.new(x))", "x", binding)
|
|
||||||
|
|
||||||
|
x = "abc"
|
||||||
|
swig_assert_equal("Li_std_wstring.test_ccvalue(x)", "x", binding)
|
||||||
|
swig_assert_equal("Li_std_wstring.test_cvalue(x)", "x", binding)
|
||||||
|
|
||||||
|
swig_assert_equal("Li_std_wstring.test_wchar_overload(x)", "x", binding)
|
||||||
swig_assert_equal("Li_std_wstring.test_wchar_overload()", "nil", binding)
|
swig_assert_equal("Li_std_wstring.test_wchar_overload()", "nil", binding)
|
||||||
|
|
||||||
swig_assert_equal("Li_std_wstring.test_pointer(Li_std_wstring::Wstring.new(x))", "nil", binding)
|
Li_std_wstring.test_pointer(nil)
|
||||||
swig_assert_equal("Li_std_wstring.test_const_pointer(Li_std_wstring::Wstring.new(x))", "nil", binding)
|
Li_std_wstring.test_const_pointer(nil)
|
||||||
swig_assert_equal("Li_std_wstring.test_const_pointer(Li_std_wstring::Wstring.new(x))", "nil", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring.test_reference(Li_std_wstring::Wstring.new(x))", "nil", binding)
|
|
||||||
|
|
||||||
x = "y"
|
begin
|
||||||
swig_assert_equal("Li_std_wstring.test_value(x)", "x", binding)
|
Li_std_wstring.test_value(nil)
|
||||||
a = Li_std_wstring::A.new(x)
|
raise RuntimeError, "NULL check failed"
|
||||||
swig_assert_equal("Li_std_wstring.test_value(a)", "x", binding)
|
rescue TypeError => e
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
Li_std_wstring.test_reference(nil)
|
||||||
|
raise RuntimeError, "NULL check failed"
|
||||||
|
rescue ArgumentError => e
|
||||||
|
swig_assert_simple(e.message.include? "invalid null reference")
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
Li_std_wstring.test_const_reference(nil)
|
||||||
|
raise RuntimeError, "NULL check failed"
|
||||||
|
rescue ArgumentError => e
|
||||||
|
swig_assert_simple(e.message.include? "invalid null reference")
|
||||||
|
end
|
||||||
|
|
||||||
x = "hello"
|
x = "hello"
|
||||||
swig_assert_equal("Li_std_wstring.test_const_reference(x)", "x", binding)
|
swig_assert_equal("Li_std_wstring.test_const_reference(x)", "x", binding)
|
||||||
|
|
||||||
|
|
||||||
swig_assert_equal("Li_std_wstring.test_pointer_out", "'x'", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring.test_const_pointer_out", "'x'", binding)
|
|
||||||
swig_assert_equal("Li_std_wstring.test_reference_out()", "'x'", binding)
|
|
||||||
|
|
||||||
s = "abc"
|
s = "abc"
|
||||||
swig_assert("Li_std_wstring.test_equal_abc(s)", binding)
|
swig_assert("Li_std_wstring.test_equal_abc(s)", binding)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Li_std_wstring.test_throw
|
Li_std_wstring.test_throw
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
swig_assert_equal("e.message", "'x'", binding)
|
swig_assert_equal("e.message", "'throwing test_throw'", binding)
|
||||||
end
|
end
|
||||||
|
|
||||||
x = "abc\0def"
|
x = "abc\0def"
|
||||||
|
|
Loading…
Reference in New Issue