import source from 1.3.40
[external/swig.git] / Examples / test-suite / ruby / primitive_types_runme.rb
1 #!/usr/bin/env ruby
2 #
3 # Put description here
4 #
5
6
7
8 #
9
10 require 'swig_assert'
11
12 require 'primitive_types'
13
14 include Primitive_types
15
16
17 raise RuntimeError if val_uchar(255) != 255
18
19 fail = 0
20 begin
21   val_uchar(-1)
22 rescue RangeError
23   fail = 1
24 end
25
26 fail = 0
27 begin
28   val_uchar(256)
29 rescue RangeError
30   fail = 1
31 end
32
33 raise RuntimeError if fail != 1
34
35 fail = 0
36 begin
37   val_uchar(256.0)
38 rescue TypeError
39   fail = 1
40 end
41
42 raise RuntimeError if fail != 1
43
44 fail = 0
45 begin
46   val_uchar("caca")
47 rescue TypeError
48   fail = 1
49 end
50
51 raise RuntimeError if fail != 1
52
53 # Test a number which won't fit in a 32 bit integer and is represented
54 # as a FIXNUM by Ruby.
55 raise RuntimeError if val_double(51767811298) != 51767811298
56
57 raise RuntimeError if val_double_2(1.0) != 4.0
58 raise RuntimeError if val_double_2(1) != 4
59 raise RuntimeError if val_double_2(1,1) != 2
60
61 fail = 0
62 begin
63   val_double_2("1.0",1.0)
64 rescue 
65   fail = 1
66 end
67 raise RuntimeError if fail != 1
68
69
70 fail = 0
71 begin
72   val_double_2(1.0,"1.0")
73 rescue 
74   fail = 1
75 end
76 raise RuntimeError if fail != 1
77
78
79 raise RuntimeError if val_float_2(1.0) != 4.0
80 raise RuntimeError if val_float_2(1) != 4
81 raise RuntimeError if val_float_2(1,1) != 2
82
83 fail = 0
84 begin
85   val_float_2("1.0",1.0)
86 rescue 
87   fail = 1
88 end
89 raise RuntimeError if fail != 1
90
91
92 fail = 0
93 begin
94   val_float_2(1.0,"1.0")
95 rescue 
96   fail = 1
97 end
98 raise RuntimeError if fail != 1