-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.py
163 lines (133 loc) · 3.14 KB
/
example.py
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import example
from example import EnumFoo
r=example.root
assert r.bar.ch=='M'
r.bar.ch='A'
assert r.bar.ch=='A'
assert r.bar.bf==False
assert r.bar.bt==True
r.bar.bt=False
assert r.bar.bt==False
assert r.bar.c=='\r hello & 123 '
assert len(r.bar.c)==len('\r hello & 123 ')
assert len(r.bar.c1)==2
# doesn't work???
for i in r.bar.c1:
assert i=='\r'
assert len(r.bar.d)==3
for i in range(len(r.bar.d)):
assert r.bar.d[i]==i
assert len(r.bar.d1)==3
for i in range(len(r.bar.d1)):
assert len(r.bar.d1[i])==2
for j in range(len(r.bar.d1[i])):
assert r.bar.d1[i][j]==2*i+j
r.bar.d1[0][1]=10
assert r.bar.d1[0][1]==10
assert len(r.bar.h)==3
for i in r.bar.h:
assert i==2
assert len(r.bar.l)==3
for i in r.bar.h:
assert i==2
r.bar.h[1]=3
assert r.bar.h[1]==3
r.bar.l[1]=3
assert r.bar.l[1]==3
assert r.bar.m[0]==5
assert r.bar.m[3]==2
try:
r.bar.m[1]
assert False
except:
pass
r.bar.m[3]=1
assert r.bar.m[3]==1
assert len(r.bar.llex)==2
for i in r.bar.llex:
assert len(i)==2
for j in i:
assert j=="hello"
assert "iex" not in r.bar.__dict__ # tests Exclude
assert len(r.bar.vs)==2
for i in r.bar.vs:
assert i==' hello'
r.bar.vs[1]="world"
assert r.bar.vs[1]=="world"
assert r.bar.ef==EnumFoo.ea
assert r.bar.getEF()==0
r.bar.ef=EnumFoo.ec
assert r.bar.getEF()==12
sm=r.bar.sm
assert len(sm)==0
sm['foo']=2
sm['bar']=3
assert len(sm)==2
assert sm['foo']==2
assert sm['bar']==3
for i in sm: assert i in sm
assert r.bar.vs0()==' hello'
from example import Foo
assert Foo.shello()=='hello'
# check reference returning functions
f=r.bar1.fooRef()
f.a=3
assert f.a==r.bar1.f.a
# check reference to a static object
assert r.getFB1().f.a!=3
r.getFB1().f.a=3
assert r.getFB1().f.a==3
# assign to a shared pointer target
r.bar1.fp.target=r.bar1.f
# chack we can examine a shared ppointer target
assert r.bar1.fp.target.a==r.bar1.f.a
b1=example.Bar1()
# assign a reference
b1.fp=r.bar1.fp
b1.fp.target.a=54
assert r.bar1.fp.target.a==54
nullRef=getattr(example.classdesc,"shared_ptr<::Foo>")()
try:
nullRef.target
assert False
except RuntimeError:
pass
try:
r.bar1.foop()
assert False
except AttributeError:
pass
# this doesn't work!!!
#b1.fp=nullRef
#try:
# b1.fp.target
# assert False
#except RuntimeError:
# pass
# check that the various aliases set up do refer to the same object
example.registerRoot1()
root.bar.a+=0.1
assert root.bar.a==root1.bar.a
assert root.bar.a==example.root.bar.a
assert root.bar.a==example.root1.bar.a
assert root.bar.a==example.static.root.bar.a
b=root.bar.self()
assert b.a==root.bar.a
assert b.overloadExample().a==b.a
assert b.overloadExample(1)==1
assert b.overloadExample(1,2)==3
v=example.std.__dict__['vector<int>']
assert root.bar.seqLength(v([0,1])) == 2
# checks automatic overloading
BarE=example.Bar.BarE
assert r.bar.barE(BarE.b)==BarE.b
assert r.bar.barE()==BarE.a
assert r.bar.globE()==example.GlobE.ga
# test constructor with arguments
assert example.Foo(1).b==1
assert example.Foo(2).b==2
# check that virtual functions work correctly from polymorphic returns
assert r.bar.foo().name()=="Bar"
# test static member
assert r.sbar.name()=="Bar"
exit(0)