import source from 1.3.40
[external/swig.git] / Examples / test-suite / ruby / director_wombat_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 'director_wombat'
13
14 include Director_wombat
15
16 # Test base class functionality
17 barObj = Bar.new
18
19 # Bar#meth should return a Foo_integers instance
20 fooIntsObj = barObj.meth
21 raise RuntimeError unless fooIntsObj.instance_of?(Foo_integers)
22
23 # Foo_integers#meth(n) should return n
24 raise RuntimeError if fooIntsObj.meth(42) != 42
25
26 #
27 # Now subclass Foo_integers, but override its virtual method
28 # meth(n) so that it returns the number plus one.
29 #
30 class MyFooInts < Foo_integers
31   def meth(n)
32     n + 1
33   end
34 end
35
36 #
37 # Subclass Bar and override its virtual method meth()
38 # so that it returns a new MyFooInts instance instead of
39 # a Foo_integers instance.
40 #
41 class MyBar < Bar
42   def meth
43     MyFooInts.new
44   end
45 end
46
47 #
48 # Now repeat previous tests:
49 #
50 # Create a MyBar instance...
51 #
52 barObj = MyBar.new
53
54 # MyBar#meth should return a MyFooInts instance
55 fooIntsObj = barObj.meth
56 raise RuntimeError unless fooIntsObj.instance_of?(MyFooInts)
57
58 # MyFooInts#meth(n) should return n+1
59 raise RuntimeError if fooIntsObj.meth(42) != 43
60