forked from JuliaInterop/CxxWrap.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance.jl
71 lines (50 loc) · 1.48 KB
/
inheritance.jl
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
61
62
63
64
65
66
67
68
69
70
71
include(joinpath(@__DIR__, "testcommon.jl"))
# Wrap the functions defined in C++
module CppInheritance
using CxxWrap
@wrapmodule(CxxWrap.CxxWrapCore.libinheritance, :define_types_module)
function __init__()
@initcxx
end
export A, B, C, D, message, create_abstract, shared_ptr_message, shared_b, shared_c, shared_d, weak_ptr_message_a, weak_ptr_message_b, dynamic_message_c, take_ref
end
module VirtualSolver
using CxxWrap
@wrapmodule(CxxWrap.CxxWrapCore.libinheritance, :define_vsolver_module)
function __init__()
@initcxx
end
end
using .CppInheritance
@testset "$(basename(@__FILE__)[1:end-3])" begin
b = B()
c = C()
global d = D()
@test message(b) == "B"
@test message(c) == "C"
@test message(d) == "D"
@test take_ref(b) == "B"
@test take_ref(c) == "C"
@test take_ref(d) == "D"
# factory function returning an abstract type A
@test message(create_abstract()) == "B"
@test dynamic_message_c(c) == "C"
# shared ptr variants
b_ptr = shared_b()
c_ptr = shared_c()
d_ptr = shared_d()
@test shared_ptr_message(b_ptr) == "B"
@test shared_ptr_message(c_ptr) == "C"
@test shared_ptr_message(d_ptr) == "D"
@test message(b_ptr[]) == "B"
@test message(c_ptr[]) == "C"
@test message(d_ptr[]) == "D"
@test weak_ptr_message_b(b_ptr) == "B"
@test weak_ptr_message_a(b_ptr) == "B"
@test weak_ptr_message_a(c_ptr) == "C"
@test weak_ptr_message_a(d_ptr) == "D"
a = VirtualSolver.E()
VirtualSolver.solve(a)
b = VirtualSolver.F(@safe_cfunction(x -> 2x, Float64, (Float64,)))
VirtualSolver.solve(b)
end