move ruby only test to ruby directory
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7512 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7046de706a
commit
a6ac0941e7
3 changed files with 97 additions and 2 deletions
|
|
@ -280,7 +280,6 @@ CPP_TEST_CASES += \
|
||||||
template_whitespace \
|
template_whitespace \
|
||||||
threads \
|
threads \
|
||||||
throw_exception \
|
throw_exception \
|
||||||
track_objects \
|
|
||||||
typedef_array_member \
|
typedef_array_member \
|
||||||
typedef_class \
|
typedef_class \
|
||||||
typedef_funcptr \
|
typedef_funcptr \
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ top_builddir = @top_builddir@
|
||||||
include $(srcdir)/../common.mk
|
include $(srcdir)/../common.mk
|
||||||
|
|
||||||
# Overridden variables here
|
# Overridden variables here
|
||||||
# none!
|
CPP_TEST_CASES = \
|
||||||
|
track_objects
|
||||||
|
|
||||||
# Rules for the different types of tests
|
# Rules for the different types of tests
|
||||||
%.cpptest:
|
%.cpptest:
|
||||||
|
|
|
||||||
95
Examples/test-suite/ruby/track_objects.i
Normal file
95
Examples/test-suite/ruby/track_objects.i
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
%module track_objects
|
||||||
|
|
||||||
|
%include typemaps.i
|
||||||
|
|
||||||
|
%trackobjects Foo;
|
||||||
|
|
||||||
|
%newobject Bar::get_new_foo;
|
||||||
|
|
||||||
|
%typemap(in, numinputs=0) Foo** foo (Foo *temp) {
|
||||||
|
/* %typemap(in, numinputs=0) Foo** foo */
|
||||||
|
$1 = &temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(argout) Foo** foo {
|
||||||
|
/* %typemap(argout) Foo** foo */
|
||||||
|
$result = SWIG_NewPointerObj((void *) *$1, $*1_descriptor, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
%apply SWIGTYPE *DISOWN {Foo* ownedFoo};
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Foo() {}
|
||||||
|
~Foo() {}
|
||||||
|
|
||||||
|
/* Helper method that can be called from Ruby that checks
|
||||||
|
that two Ruby objects are pointing to the same underlying
|
||||||
|
C++ object */
|
||||||
|
bool cpp_equal(const Foo* other)
|
||||||
|
{
|
||||||
|
return (this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Just a simple method to call on Foo*/
|
||||||
|
char* say_hello()
|
||||||
|
{
|
||||||
|
return "Hello";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Bar
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Foo* owned_;
|
||||||
|
Foo* unowned_;
|
||||||
|
public:
|
||||||
|
Bar(): owned_(new Foo), unowned_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~Bar()
|
||||||
|
{
|
||||||
|
delete owned_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test that track objects works with %newobject */
|
||||||
|
static Foo* get_new_foo()
|
||||||
|
{
|
||||||
|
return new Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test the same foo Ruby object is created each time */
|
||||||
|
Foo* get_owned_foo()
|
||||||
|
{
|
||||||
|
return owned_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test that track objects works with argout parameters.*/
|
||||||
|
void get_owned_foo_by_argument(Foo** foo)
|
||||||
|
{
|
||||||
|
*foo = owned_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test that track objects works with the DISOWN typemap.*/
|
||||||
|
void set_owned_foo(Foo* ownedFoo)
|
||||||
|
{
|
||||||
|
delete owned_;
|
||||||
|
owned_ = ownedFoo;
|
||||||
|
}
|
||||||
|
|
||||||
|
Foo* get_unowned_foo()
|
||||||
|
{
|
||||||
|
return unowned_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_unowned_foo(Foo* foo)
|
||||||
|
{
|
||||||
|
unowned_ = foo;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
%}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue