import source from 1.3.40
[external/swig.git] / Examples / test-suite / python / python_overload_simple_cast_runme.py
1 from python_overload_simple_cast import *
2
3 class Ai:
4     def __init__(self,x):
5         self.x = x
6         
7     def __int__(self):
8         return self.x
9
10 class Ad:
11     def __init__(self,x):
12         self.x = x
13         
14     def __float__(self):
15         return self.x
16
17 ai = Ai(4)
18
19 ad = Ad(5.0)
20 add = Ad(5.5)
21
22 try:
23     fint(add)
24     good = 0
25 except:
26     good = 1
27
28 if not good:
29     raise RuntimeError, "fint(int)"    
30
31
32 if fint(ad) != "fint:int":
33     raise RuntimeError, "fint(int)"
34
35 if fdouble(ad) != "fdouble:double":
36     raise RuntimeError, "fdouble(double)"
37
38 if fint(ai) != "fint:int":
39     raise RuntimeError, "fint(int)"
40
41 if fint(5.0) != "fint:int":
42     raise RuntimeError, "fint(int)"
43     
44 if fint(3) != "fint:int":
45     raise RuntimeError, "fint(int)"
46 if fint(3.0) != "fint:int":
47     raise RuntimeError, "fint(int)"
48
49 if fdouble(ad) != "fdouble:double":
50     raise RuntimeError, "fdouble(double)"
51 if fdouble(3) != "fdouble:double":
52     raise RuntimeError, "fdouble(double)"
53 if fdouble(3.0) != "fdouble:double":
54     raise RuntimeError, "fdouble(double)"
55
56 if fid(3,3.0) != "fid:intdouble":
57     raise RuntimeError, "fid:intdouble"
58
59 if fid(3.0,3) != "fid:doubleint":
60     raise RuntimeError, "fid:doubleint"
61
62 if fid(ad,ai) != "fid:doubleint":
63     raise RuntimeError, "fid:doubleint"
64
65 if fid(ai,ad) != "fid:intdouble":
66     raise RuntimeError, "fid:intdouble"
67
68
69
70 if foo(3) != "foo:int":
71     raise RuntimeError, "foo(int)"
72
73 if foo(3.0) != "foo:double":
74     raise RuntimeError, "foo(double)"
75
76 if foo("hello") != "foo:char *":
77     raise RuntimeError, "foo(char *)"
78
79 f = Foo()
80 b = Bar()
81
82 if foo(f) != "foo:Foo *":
83     raise RuntimeError, "foo(Foo *)"
84
85 if foo(b) != "foo:Bar *":
86     raise RuntimeError, "foo(Bar *)"
87
88 v = malloc_void(32)
89
90 if foo(v) != "foo:void *":
91     raise RuntimeError, "foo(void *)"
92
93 s = Spam()
94
95 if s.foo(3) != "foo:int":
96     raise RuntimeError, "Spam::foo(int)"
97
98 if s.foo(3.0) != "foo:double":
99     raise RuntimeError, "Spam::foo(double)"
100
101 if s.foo("hello") != "foo:char *":
102     raise RuntimeError, "Spam::foo(char *)"
103
104 if s.foo(f) != "foo:Foo *":
105     raise RuntimeError, "Spam::foo(Foo *)"
106
107 if s.foo(b) != "foo:Bar *":
108     raise RuntimeError, "Spam::foo(Bar *)"
109
110 if s.foo(v) != "foo:void *":
111     raise RuntimeError, "Spam::foo(void *)"
112
113 if Spam_bar(3) != "bar:int":
114     raise RuntimeError, "Spam::bar(int)"
115
116 if Spam_bar(3.0) != "bar:double":
117     raise RuntimeError, "Spam::bar(double)"
118
119 if Spam_bar("hello") != "bar:char *":
120     raise RuntimeError, "Spam::bar(char *)"
121
122 if Spam_bar(f) != "bar:Foo *":
123     raise RuntimeError, "Spam::bar(Foo *)"
124
125 if Spam_bar(b) != "bar:Bar *":
126     raise RuntimeError, "Spam::bar(Bar *)"
127
128 if Spam_bar(v) != "bar:void *":
129     raise RuntimeError, "Spam::bar(void *)"
130
131 # Test constructors
132
133 s = Spam()
134 if s.type != "none":
135     raise RuntimeError, "Spam()"
136
137 s = Spam(3)
138 if s.type != "int":
139     raise RuntimeError, "Spam(int)"
140     
141 s = Spam(3.4)
142 if s.type != "double":
143     raise RuntimeError, "Spam(double)"
144
145 s = Spam("hello")
146 if s.type != "char *":
147     raise RuntimeError, "Spam(char *)"
148
149 s = Spam(f)
150 if s.type != "Foo *":
151     raise RuntimeError, "Spam(Foo *)"
152
153 s = Spam(b)
154 if s.type != "Bar *":
155     raise RuntimeError, "Spam(Bar *)"
156
157 s = Spam(v)
158 if s.type != "void *":
159     raise RuntimeError, "Spam(void *)"
160
161
162 # unsigned long long
163 ullmax = 9223372036854775807 #0xffffffffffffffff
164 ullmaxd = 9007199254740992.0
165 ullmin = 0
166 ullmind = 0.0
167 if ull(ullmin) != ullmin:
168     raise runtimeerror, "ull(ullmin)"
169 if ull(ullmax) != ullmax:
170     raise runtimeerror, "ull(ullmax)"
171 if ull(ullmind) != ullmind:
172     raise RuntimeError, "ull(ullmind)"
173 if ull(ullmaxd) != ullmaxd:
174     raise RuntimeError, "ull(ullmaxd)"
175
176 # long long
177 llmax = 9223372036854775807 #0x7fffffffffffffff
178 llmin = -9223372036854775808
179 # these are near the largest  floats we can still convert into long long
180 llmaxd = 9007199254740992.0
181 llmind = -9007199254740992.0
182 if ll(llmin) != llmin:
183     raise runtimeerror, "ll(llmin)"
184 if ll(llmax) != llmax:
185     raise runtimeerror, "ll(llmax)"
186 if ll(llmind) != llmind:
187     raise RuntimeError, "ll(llmind)"
188 if ll(llmaxd) != llmaxd:
189     raise RuntimeError, "ll(llmaxd)"
190
191
192 free_void(v)