Add Ruby support for std::unique_ptr inputs
Equivalent to Java/C#/Python implementations.
This commit is contained in:
parent
c3c061cac8
commit
f99a2e6f64
4 changed files with 114 additions and 3 deletions
|
|
@ -11,6 +11,97 @@ def gc_check(expected_count)
|
|||
# swig_assert_equal_simple(expected_count, Cpp11_std_unique_ptr::Klass::getTotal_count())
|
||||
end
|
||||
|
||||
def checkCount(expected_count)
|
||||
actual_count = Cpp11_std_unique_ptr::Klass.getTotal_count()
|
||||
if (actual_count != expected_count)
|
||||
raise RuntimeError, "Counts incorrect, expected:" + expected_count + " actual:" + actual_count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# unique_ptr as input
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
rescue RuntimeError => e
|
||||
# puts e.message
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "double usage of takeKlassUniquePtr should have been an error"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
exception_thrown = false
|
||||
begin
|
||||
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
|
||||
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
|
||||
rescue RuntimeError
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||
end
|
||||
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
|
||||
checkCount(0)
|
||||
|
||||
kini = Cpp11_std_unique_ptr::KlassInheritance.new("KlassInheritanceInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kini)
|
||||
checkCount(0)
|
||||
if (s != "KlassInheritanceInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kini)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kini = nil
|
||||
checkCount(0)
|
||||
|
||||
# unique_ptr as output
|
||||
k1 = Cpp11_std_unique_ptr::makeKlassUniquePtr("first")
|
||||
k2 = Cpp11_std_unique_ptr::makeKlassUniquePtr("second")
|
||||
swig_assert_equal_simple(2, Cpp11_std_unique_ptr::Klass::getTotal_count())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue