1
require 'track_objects'
3
def test_same_ruby_object(foo1, foo2)
4
if not foo1.equal?(foo2)
5
raise "Ruby objects should be the same."
9
def test_same_cpp_object(foo1, foo2)
10
if not foo1.cpp_equal(foo2)
11
raise "C++ objects should be the same"
15
bar = Track_objects::Bar.new
16
foo1 = Track_objects::Foo.new()
17
bar.set_unowned_foo(foo1)
19
# test_simple_identity
20
foo2 = Track_objects::Foo.new()
23
test_same_ruby_object(foo2, foo3)
24
test_same_cpp_object(foo2, foo3)
26
# test_unowned_foo_identity
27
foo4 = bar.get_unowned_foo()
29
test_same_ruby_object(foo1, foo4)
30
test_same_cpp_object(foo1, foo4)
32
# test_owned_foo_identity
33
foo5 = bar.get_owned_foo()
34
foo6 = bar.get_owned_foo()
36
test_same_ruby_object(foo5, foo6)
37
test_same_cpp_object(foo5, foo6)
39
# test_new_foo_identity
40
foo7 = Track_objects::Bar.get_new_foo()
41
foo8 = Track_objects::Bar.get_new_foo()
44
raise "Ruby objects should be different."
47
if foo7.cpp_equal(foo8)
48
raise "C++ objects should be different."
51
# test_set_owned_identity
52
foo9 = Track_objects::Foo.new
53
bar.set_owned_foo(foo9)
54
foo10 = bar.get_owned_foo()
56
test_same_ruby_object(foo9, foo10)
57
test_same_cpp_object(foo9, foo10)
59
# test_set_owned_identity2
61
foo11 = Track_objects::Foo.new
62
bar.set_owned_foo(foo11)
68
foo12 = bar.get_owned_foo()
70
if not (foo12.say_hello == "Hello")
71
raise "Invalid C++ object returned."
74
# test_set_owned_identity3
75
foo13 = bar.get_owned_foo_by_argument()
76
foo14 = bar.get_owned_foo_by_argument()
78
test_same_ruby_object(foo13, foo14)
79
test_same_cpp_object(foo13, foo14)