Merge branch 'tamuratak-shared_ptr_derived_2'

* tamuratak-shared_ptr_derived_2:
  Correct comment about const removal for shared_ptr
  Correct ordering of declarations in testcase
  Ruby shared_ptr on error code improvement in traits_as::as
  Add support for pointers to shared_ptr and null shared_ptr in Ruby containers
  Add shared_ptr non-overloaded upcast tests
  use forward declaration to treat the dependency of fragments
  [ruby] must not do a null check for VALUE.
  [ruby] add tests for shared_ptr of const Type.
  [ruby] For swig::from, use template specialization to convert shared_ptr<const T> to shared_ptr<T>.
  [ruby] edit comments [skip ci]
  [ruby] move template specialization to std_shared_ptr.i.
  [ruby] add tests for upcasting std::shared_ptr within std containers.
  [ruby] use template specialization for swig::asptr,asval functions on std:shared_ptr.
This commit is contained in:
William S Fulton 2017-04-20 07:50:20 +01:00
commit c9d094e034
8 changed files with 460 additions and 1 deletions

View file

@ -32,6 +32,8 @@ CPP_TEST_CASES = \
CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_upcast \
cpp11_shared_ptr_const
C_TEST_CASES += \
li_cstring \

View file

@ -0,0 +1,9 @@
require "swig_assert"
require "cpp11_shared_ptr_const"
include Cpp11_shared_ptr_const
simple_assert_equal(1, foo( Foo.new(1) ).get_m )
simple_assert_equal(7, const_foo( Foo.new(7) ).get_m )
simple_assert_equal(7, foo_vec( Foo.new(7) )[0].get_m )
simple_assert_equal(8, const_foo_vec( Foo.new(8) )[0].get_m )

View file

@ -0,0 +1,60 @@
require 'swig_assert'
require 'cpp11_shared_ptr_upcast'
include Cpp11_shared_ptr_upcast
# non-overloaded
simple_assert_equal( 7, derived_num1(Derived.new(7)) )
simple_assert_equal( 7, derived_num2([Derived.new(7)]) )
simple_assert_equal( 7, derived_num3({0 => Derived.new(7)}) )
simple_assert_equal(-1, base_num1(Derived.new(7)) )
simple_assert_equal(-1, base_num2([Derived.new(7)]) )
simple_assert_equal(-1, base_num3({0 => Derived.new(7)}) )
simple_assert_equal( 999, derived_num1(nil) )
simple_assert_equal( 999, derived_num2([nil]) )
simple_assert_equal( 999, derived_num3({0 => nil}) )
simple_assert_equal( 999, base_num1(nil) )
simple_assert_equal( 999, base_num2([nil]) )
simple_assert_equal( 999, base_num3({0 => nil}) )
# overloaded
simple_assert_equal( 7, derived_num(Derived.new(7)) )
simple_assert_equal( 7, derived_num([Derived.new(7)]) )
simple_assert_equal( 7, derived_num({0 => Derived.new(7)}) )
simple_assert_equal(-1, base_num(Derived.new(7)) )
simple_assert_equal(-1, base_num([Derived.new(7)]) )
simple_assert_equal(-1, base_num({0 => Derived.new(7)}) )
# ptr to shared_ptr
simple_assert_equal( 7, derived2_num1(Derived2.new(7)) )
simple_assert_equal( 7, derived2_num2([Derived2.new(7)]) )
simple_assert_equal( 7, derived2_num3({0 => Derived2.new(7)}) )
simple_assert_equal( -1, base2_num1(Derived2.new(7)) )
begin
# Upcast for pointers to shared_ptr in this generic framework has not been implemented
simple_assert_equal( -1, base2_num2([Derived2.new(7)]) )
raise RuntimeError, "Failed to catch TypeError"
rescue TypeError
end
begin
# Upcast for pointers to shared_ptr in this generic framework has not been implemented
simple_assert_equal( -1, base2_num3({0 => Derived2.new(7)}) )
raise RuntimeError, "Failed to catch TypeError"
rescue TypeError
end
simple_assert_equal( 888, derived2_num1(nil) )
simple_assert_equal( 999, derived2_num2([nil]) ) # although 888 would be more consistent
simple_assert_equal( 999, derived2_num3({0 => nil}) ) # although 888 would be more consistent
simple_assert_equal( 888, base2_num1(nil) )
simple_assert_equal( 999, base2_num2([nil]) ) # although 888 would be more consistent
simple_assert_equal( 999, base2_num3({0 => nil}) ) # although 888 would be more consistent