File: cpp11_shared_ptr_upcast_runme.rb

package info (click to toggle)
swig 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 46,232 kB
  • sloc: cpp: 54,631; ansic: 29,122; java: 17,530; python: 12,505; cs: 10,369; ruby: 7,232; yacc: 6,477; makefile: 5,965; javascript: 5,520; sh: 5,415; perl: 4,187; php: 3,693; ml: 2,187; lisp: 2,056; tcl: 1,991; xml: 115
file content (60 lines) | stat: -rw-r--r-- 2,412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'swig_assert'
require 'cpp11_shared_ptr_upcast'


include Cpp11_shared_ptr_upcast

# non-overloaded
swig_assert_equal_simple( 7, derived_num1(Derived.new(7)) )
swig_assert_equal_simple( 7, derived_num2([Derived.new(7)]) )
swig_assert_equal_simple( 7, derived_num3({0 => Derived.new(7)}) )

swig_assert_equal_simple(-1, base_num1(Derived.new(7)) )
swig_assert_equal_simple(-1, base_num2([Derived.new(7)]) )
swig_assert_equal_simple(-1, base_num3({0 => Derived.new(7)}) )

swig_assert_equal_simple( 999, derived_num1(nil) )
swig_assert_equal_simple( 999, derived_num2([nil]) )
swig_assert_equal_simple( 999, derived_num3({0 => nil}) )

swig_assert_equal_simple( 999, base_num1(nil) )
swig_assert_equal_simple( 999, base_num2([nil]) )
swig_assert_equal_simple( 999, base_num3({0 => nil}) )

# overloaded
swig_assert_equal_simple( 7, derived_num(Derived.new(7)) )
swig_assert_equal_simple( 7, derived_num([Derived.new(7)]) )
swig_assert_equal_simple( 7, derived_num({0 => Derived.new(7)}) )

swig_assert_equal_simple(-1, base_num(Derived.new(7)) )
swig_assert_equal_simple(-1, base_num([Derived.new(7)]) )
swig_assert_equal_simple(-1, base_num({0 => Derived.new(7)}) )

# ptr to shared_ptr
swig_assert_equal_simple( 7, derived2_num1(Derived2.new(7)) )
swig_assert_equal_simple( 7, derived2_num2([Derived2.new(7)]) )
swig_assert_equal_simple( 7, derived2_num3({0 => Derived2.new(7)}) )

swig_assert_equal_simple( -1, base2_num1(Derived2.new(7)) )

begin
    # Upcast for pointers to shared_ptr in this generic framework has not been implemented
    swig_assert_equal_simple( -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
    swig_assert_equal_simple( -1, base2_num3({0 => Derived2.new(7)}) )
    raise RuntimeError, "Failed to catch TypeError"
rescue TypeError
end

swig_assert_equal_simple( 888, derived2_num1(nil) )
swig_assert_equal_simple( 999, derived2_num2([nil]) ) # although 888 would be more consistent
swig_assert_equal_simple( 999, derived2_num3({0 => nil}) ) # although 888 would be more consistent

swig_assert_equal_simple( 888, base2_num1(nil) )
swig_assert_equal_simple( 999, base2_num2([nil]) ) # although 888 would be more consistent
swig_assert_equal_simple( 999, base2_num3({0 => nil}) ) # although 888 would be more consistent