File: li_std_string_runme.py

package info (click to toggle)
swig 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 46,232 kB
  • sloc: cpp: 54,631; ansic: 29,122; java: 17,530; python: 12,505; cs: 10,369; ruby: 7,232; yacc: 6,477; makefile: 5,965; javascript: 5,520; sh: 5,415; perl: 4,187; php: 3,693; ml: 2,187; lisp: 2,056; tcl: 1,991; xml: 115
file content (137 lines) | stat: -rw-r--r-- 3,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import sys
from li_std_string import *

def check(condition):
    if not condition:
        raise RuntimeError

# Bad Unicode input check
# This check is run first to check that %error_clear is called the first time SWIG_AsPtr_std_string()
# is called setting the descriptor singleton (by calling SWIG_TypeQuery()).
# Bug https://github.com/swig/swig/issues/3051.
exceptionRaised = False
try:
    if sys.version_info[0:2] < (3, 0):
        v = u"./\uDCFC.conf"
    else:
        v = "./\uDCFC.conf"
    test_value(v)
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

# Checking expected use of %typemap(in) std::string {}
test_value("Fee")

# Checking expected result of %typemap(out) std::string {}
check(test_value("Fi") == "Fi")

# Verify type-checking for %typemap(in) std::string {}
exceptionRaised = False
try:
    test_value(0)
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

# Checking expected use of %typemap(in) const std::string & {}
test_const_reference("Fo")

# Checking expected result of %typemap(out) const std::string& {}
check(test_const_reference("Fum") == "Fum")

# Verify type-checking for %typemap(in) const std::string & {}
exceptionRaised = False
try:
    test_const_reference(0)
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

#
# Input and output typemaps for pointers and non-const references to
# std::string are *not* supported; the following tests confirm
# that none of these cases are slipping through.
#

exceptionRaised = False
try:
    test_pointer("foo")
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

result = test_pointer_out()
check(not isinstance(result, str))

exceptionRaised = False
try:
    test_const_pointer("bar")
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

result = test_const_pointer_out()
check(not isinstance(result, str))

exceptionRaised = False
try:
    test_reference("foo")
except TypeError:
    exceptionRaised = True
check(exceptionRaised)

result = test_reference_out()
check(not isinstance(result, str))


# Member Strings
myStructure = Structure()
if myStructure.MemberString2 != "member string 2":
    raise RuntimeError
s = "Hello"
myStructure.MemberString2 = s
if myStructure.MemberString2 != s:
    raise RuntimeError
if myStructure.ConstMemberString != "const member string":
    raise RuntimeError 


if cvar.Structure_StaticMemberString2 != "static member string 2":
    raise RuntimeError
cvar.Structure_StaticMemberString2 = s
if cvar.Structure_StaticMemberString2 != s:
    raise RuntimeError
if Structure.ConstStaticMemberString != "const static member string":
    raise RuntimeError


if test_reference_input("hello") != "hello":
    raise RuntimeError
s = test_reference_inout("hello")
if s != "hellohello":
    raise RuntimeError
if test_reference_output() != "output":
    raise RuntimeError


if stdstring_empty() != "":
    raise RuntimeError

if c_empty() != "":
    raise RuntimeError


if c_null() != None:
    raise RuntimeError


if get_null(c_null()) != None:
    raise RuntimeError


if get_null(c_empty()) != "non-null":
    raise RuntimeError

if get_null(stdstring_empty()) != "non-null":
    raise RuntimeError