12 require 'ruby_track_objects'
14 def test_same_ruby_object(foo1, foo2)
15 if not foo1.equal?(foo2)
16 raise "Ruby objects should be the same."
20 def test_same_cpp_object(foo1, foo2)
21 if not foo1.cpp_equal(foo2)
22 raise "C++ objects should be the same"
26 bar = Ruby_track_objects::Bar.new
27 foo1 = Ruby_track_objects::Foo.new()
28 bar.set_unowned_foo(foo1)
30 # test_simple_identity
31 foo2 = Ruby_track_objects::Foo.new()
34 test_same_ruby_object(foo2, foo3)
35 test_same_cpp_object(foo2, foo3)
37 # test_unowned_foo_identity
38 foo4 = bar.get_unowned_foo()
40 test_same_ruby_object(foo1, foo4)
41 test_same_cpp_object(foo1, foo4)
43 # test_owned_foo_identity
44 foo5 = bar.get_owned_foo()
45 foo6 = bar.get_owned_foo()
47 test_same_ruby_object(foo5, foo6)
48 test_same_cpp_object(foo5, foo6)
50 # test_new_foo_identity
51 foo7 = Ruby_track_objects::Bar.get_new_foo()
52 foo8 = Ruby_track_objects::Bar.get_new_foo()
55 raise "Ruby objects should be different."
58 if foo7.cpp_equal(foo8)
59 raise "C++ objects should be different."
62 # test_set_owned_identity
63 foo9 = Ruby_track_objects::Foo.new
64 bar.set_owned_foo(foo9)
65 foo10 = bar.get_owned_foo()
67 test_same_ruby_object(foo9, foo10)
68 test_same_cpp_object(foo9, foo10)
70 # test_set_owned_identity2
72 foo11 = Ruby_track_objects::Foo.new
73 bar.set_owned_foo(foo11)
79 foo12 = bar.get_owned_foo()
81 if not (foo12.say_hello == "Hello")
82 raise "Invalid C++ object returned."
85 # test_set_owned_identity3
86 foo13 = bar.get_owned_foo_by_argument()
87 foo14 = bar.get_owned_foo_by_argument()
89 test_same_ruby_object(foo13, foo14)
90 test_same_cpp_object(foo13, foo14)
92 # Now create the factory
93 factory = Ruby_track_objects::Factory.new
95 # Create itemA which is really an itemB
96 itemA = factory.createItem
99 if itemA.class != Ruby_track_objects::ItemA
100 raise RuntimeError, 'Item should have an ItemA class'
104 itemB = Ruby_track_objects.downcast(itemA)
106 if itemB.class != Ruby_track_objects::ItemB
107 raise RuntimeError, 'Item should have an ItemB class'
111 raise RuntimeError, 'Items should be different'