From c8a76f8587dc1fbb8871b9ea93094d4f541fef91 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sat, 24 Sep 2005 22:30:30 +0000 Subject: [PATCH] Added test case for Ruby using track objects and directors at the same time. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7524 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../ruby/track_objects_directors_runme.rb | 29 ++++++++++++ Examples/test-suite/track_objects_directors.i | 44 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Examples/test-suite/ruby/track_objects_directors_runme.rb create mode 100644 Examples/test-suite/track_objects_directors.i diff --git a/Examples/test-suite/ruby/track_objects_directors_runme.rb b/Examples/test-suite/ruby/track_objects_directors_runme.rb new file mode 100644 index 000000000..e1eafcca5 --- /dev/null +++ b/Examples/test-suite/ruby/track_objects_directors_runme.rb @@ -0,0 +1,29 @@ +require 'test/unit' +require 'track_objects_directors' + +class MyFoo < Track_objects_directors::Foo + def ping + "MyFoo::ping()" + end +end + +a = MyFoo.new + +raise RuntimeError if a.ping != "MyFoo::ping()" +raise RuntimeError if a.pong != "Foo::pong();MyFoo::ping()" + +b = Track_objects_directors::Foo.new + +raise RuntimeError if b.ping != "Foo::ping()" +raise RuntimeError if b.pong != "Foo::pong();Foo::ping()" + +container = Track_objects_directors::Container.new +foo = MyFoo.new +container.set_foo(foo) + +myFoo1 = container.get_foo +myFoo2 = container.get_foo + +if not myFoo1.equal?(myFoo2) + raise RuntimeError, "MyFoo's should be the same" +end diff --git a/Examples/test-suite/track_objects_directors.i b/Examples/test-suite/track_objects_directors.i new file mode 100644 index 000000000..adac8ae4d --- /dev/null +++ b/Examples/test-suite/track_objects_directors.i @@ -0,0 +1,44 @@ +%module(directors="1") track_objects_directors + +%{ +#include +%} + +%include "std_string.i"; +%feature("director") Foo; + +%trackobjects; + +%inline %{ + +class Foo { +public: + Foo() {} + virtual ~Foo() {} + virtual std::string ping() + { + return "Foo::ping()"; + } + + virtual std::string pong() + { + return "Foo::pong();" + ping(); + } +}; + + +class Container { + Foo* foo_; +public: + Foo* get_foo() + { + return foo_; + } + + void set_foo(Foo *foo) + { + foo_ = foo; + } +}; + +%}