PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/test-suite/python/python_overload_simple_cast_runme.py

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