summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2020-01-31 19:26:19 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2020-01-31 19:26:19 +0000
commitebc324dfd57ccb4dc09c357bcd84e6e9efc1a1f7 (patch)
tree0489bbde1952099bf30a780db6964d7349194308 /Examples
parent8c1c01f5e6550121715fdf3e1fb99b870450efc9 (diff)
parent7cc94808b6ee645247051157ad3bee20a50d47ba (diff)
downloadswig-ebc324dfd57ccb4dc09c357bcd84e6e9efc1a1f7.tar.gz
Merge branch 'ruby-autoptr'
* ruby-autoptr: Extend std::auto_ptr<> support to Ruby
Diffstat (limited to 'Examples')
-rw-r--r--Examples/test-suite/li_std_auto_ptr.i2
-rw-r--r--Examples/test-suite/ruby/li_std_auto_ptr_runme.rb43
2 files changed, 44 insertions, 1 deletions
diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i
index 5bde387a3..d83732af0 100644
--- a/Examples/test-suite/li_std_auto_ptr.i
+++ b/Examples/test-suite/li_std_auto_ptr.i
@@ -12,7 +12,7 @@
#endif
%}
-#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON)
+#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY)
%include "std_auto_ptr.i"
diff --git a/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb b/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb
new file mode 100644
index 000000000..a7f3a13ac
--- /dev/null
+++ b/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+
+require 'swig_assert'
+
+require 'li_std_auto_ptr'
+
+k1 = Li_std_auto_ptr::makeKlassAutoPtr("first")
+k2 = Li_std_auto_ptr::makeKlassAutoPtr("second")
+swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 2)
+
+k1 = nil
+GC.start
+
+# GC can need a few runs to actually collect the object.
+100.times do ||
+ next if Li_std_auto_ptr::Klass::getTotal_count() == 2
+
+ swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 1)
+ break
+end
+
+swig_assert_equal_simple(k2.getLabel(), "second")
+
+if Li_std_auto_ptr::Klass::getTotal_count() != 1
+ STDERR.puts "GC failed to collect the first object, count still #{Li_std_auto_ptr::Klass::getTotal_count()}"
+
+ # Skip the rest of the test as it's not going to work correctly anyhow.
+ exit
+end
+
+k2 = nil
+GC.start
+
+100.times do ||
+ next if Li_std_auto_ptr::Klass::getTotal_count() == 1
+
+ swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 0)
+ break
+end
+
+if Li_std_auto_ptr::Klass::getTotal_count() != 0
+ STDERR.puts "GC failed to collect the second object, count still #{Li_std_auto_ptr::Klass::getTotal_count()}"
+end