PageRenderTime 41ms CodeModel.GetById 13ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/octave/overload_simple_cast_runme.m

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