Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
dll/test/cpp_load_test.cpp at develop · hia3/dll · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
hia3
/
dll
Public
forked from
boostorg/dll
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
dll
/
test
/
cpp_load_test.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
226 lines (183 loc) · 7.24 KB
develop
Breadcrumbs
dll
/
test
/
cpp_load_test.cpp
Copy path
Top
File metadata and controls
Code
Blame
226 lines (183 loc) · 7.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//
Copyright 2016 Klemens Morgenstern
//
//
Distributed under the Boost Software License, Version 1.0.
//
(See accompanying file LICENSE_1_0.txt
//
or copy at http://www.boost.org/LICENSE_1_0.txt)
//
For more information, see http://www.boost.org
#
include
<
boost/predef.h
>
#
if
(__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
#
include
"
../example/b2_workarounds.hpp
"
#
include
<
boost/dll/smart_library.hpp
>
#
include
<
boost/core/lightweight_test.hpp
>
#
include
<
boost/filesystem.hpp
>
#
include
<
boost/variant.hpp
>
#
include
<
iostream
>
struct
override_class
{
int
arr[
32
];
};
int
main
(
int
argc,
char
* argv[])
{
using
namespace
boost
::dll
;
using
namespace
boost
::dll::experimental
;
boost::filesystem::path pt =
b2_workarounds::first_lib_from_argv
(argc, argv);
BOOST_TEST
(!pt.
empty
());
std::cout <<
"
Library:
"
<< pt << std::endl;
std::cerr <<
1
<<
'
'
;
smart_library
sm
(pt);
auto
& unscoped_var = sm.
get_variable
<
int
>(
"
unscoped_var
"
);
BOOST_TEST
(unscoped_var ==
42
);
std::cerr <<
2
<<
'
'
;
auto
& unscoped_c_var = sm.
get_variable
<
const
double
>(
"
unscoped_c_var
"
);
BOOST_TEST
(unscoped_c_var ==
1.234
);
std::cerr <<
3
<<
'
'
;
auto
& sp_variable = sm.
get_variable
<
double
>(
"
some_space::variable
"
);
BOOST_TEST
(sp_variable ==
0.2
);
std::cerr <<
4
<<
'
'
;
auto
scoped_fun = sm.
get_function
<
const
int
&()>(
"
some_space::scoped_fun
"
);
BOOST_TEST
(scoped_fun !=
nullptr
);
{ std::cerr <<
5
<<
'
'
;
auto
&res =
scoped_fun
();
const
int
expected =
0xDEADBEEF
;
BOOST_TEST
(res == expected);
}
std::cerr <<
6
<<
'
'
;
auto
ovl1 = sm.
get_function
<
void
(
int
)> (
"
overloaded
"
);
auto
ovl2 = sm.
get_function
<
void
(
double
)>(
"
overloaded
"
);
std::cerr <<
7
<<
'
'
;
BOOST_TEST
(ovl1 !=
nullptr
);
BOOST_TEST
(ovl2 !=
nullptr
);
BOOST_TEST
(
reinterpret_cast
<
void
*>(ovl1) !=
reinterpret_cast
<
void
*>(ovl2));
std::cerr <<
8
<<
'
'
;
ovl1
(
12
);
BOOST_TEST
(unscoped_var ==
12
);
ovl2
(
5.0
);
BOOST_TEST
(sp_variable ==
5.0
);
std::cerr <<
9
<<
'
'
;
auto
var1 = sm.
get_function
<
void
(boost::variant<
int
,
double
> &)>(
"
use_variant
"
);
auto
var2 = sm.
get_function
<
void
(boost::variant<
double
,
int
> &)>(
"
use_variant
"
);
std::cerr <<
10
<<
'
'
;
BOOST_TEST
(var1 !=
nullptr
);
BOOST_TEST
(var2 !=
nullptr
);
BOOST_TEST
(
reinterpret_cast
<
void
*>(var1) !=
reinterpret_cast
<
void
*>(var2));
{
boost::variant<
int
,
double
> v1 =
232.22
;
boost::variant<
double
,
int
> v2 = -
1
;
std::cerr <<
11
<<
'
'
;
var1
(v1);
var2
(v2);
struct
: boost::static_visitor<
void
>
{
void
operator
()(
double
) {
BOOST_TEST
(
false
);}
void
operator
()(
int
i) {
BOOST_TEST
(i ==
42
);}
} vis1;
struct
: boost::static_visitor<
void
>
{
void
operator
()(
double
d) {
BOOST_TEST
(d ==
3.124
);}
void
operator
()(
int
) {
BOOST_TEST
(
false
);}
} vis2;
boost::apply_visitor
(vis1, v1);
boost::apply_visitor
(vis2, v2);
}
std::cerr <<
12
<<
'
'
;
/*
now test the class stuff
*/
//
first we import and test the global variables
auto
& father_val = sm.
get_variable
<
int
>(
"
some_space::father_value
"
);
auto
& static_val = sm.
get_variable
<
int
>(
"
some_space::some_class::value
"
);
BOOST_TEST
(father_val ==
12
);
BOOST_TEST
(static_val == -
1
);
std::cerr <<
13
<<
'
'
;
//
now get the static function.
auto
set_value = sm.
get_function
<
void
(
const
int
&)>(
"
some_space::some_class::set_value
"
);
BOOST_TEST
(set_value !=
nullptr
);
std::cerr <<
14
<<
'
'
;
set_value
(
42
);
BOOST_TEST
(static_val ==
42
);
//
alright, static method works.
//
alright, now import the class members
//
first add the type alias.
sm.
add_type_alias
<override_class>(
"
some_space::some_class
"
);
std::cerr <<
15
<<
'
'
;
auto
set = sm.
get_mem_fn
<override_class,
void
(
int
)>(
"
set
"
);
std::cerr <<
16
<<
'
'
;
try
{
sm.
get_mem_fn
<override_class,
int
()>(
"
get
"
);
BOOST_TEST
(
false
);
}
catch
(boost::system::system_error &) {}
auto
get = sm.
get_mem_fn
<
const
override_class,
int
()>(
"
get
"
);
std::cerr <<
17
<<
'
'
;
BOOST_TEST
(get !=
nullptr
);
BOOST_TEST
(set !=
nullptr
);
std::cerr <<
18
<<
'
'
;
auto
func_dd = sm.
get_mem_fn
<override_class,
double
(
double
,
double
)>(
"
func
"
);
auto
func_ii = sm.
get_mem_fn
<override_class,
int
(
int
,
int
)> (
"
func
"
);
auto
func_iiv = sm.
get_mem_fn
<
volatile
override_class,
int
(
int
,
int
)> (
"
func
"
);
auto
func_ddc = sm.
get_mem_fn
<
const
volatile
override_class,
double
(
double
,
double
)>(
"
func
"
);
std::cerr <<
19
<<
'
'
;
BOOST_TEST
(func_dd !=
nullptr
);
BOOST_TEST
(func_ii !=
nullptr
);
std::cerr <<
20
<<
'
'
;
auto
ctor_v = sm.
get_constructor
<
override_class
()>();
auto
ctor_i = sm.
get_constructor
<
override_class
(
int
)>();
auto
dtor = sm.
get_destructor
<override_class>();
std::cerr <<
21
<<
'
'
;
//
actually never used.
if
(ctor_v.
has_allocating
())
{
//
allocate
auto
p = ctor_v.
call_allocating
();
//
assert it works
auto
val = (p->*get)();
BOOST_TEST
(val ==
123
);
//
deallocate
dtor.
call_deleting
(p);
//
now i cannot assert that it deletes, since it would crash.
}
//
More tests to assure the correct this-ptr
std::cerr <<
22
<<
'
'
;
typedef
override_class * override_class_p;
override_class_p &this_dll = sm.
shared_lib
().
get
<override_class_p>(
"
this_
"
);
std::cerr <<
23
<<
'
'
;
//
ok, now load the ctor/dtor
override_class oc;
override_class_p this_exe = &oc;
for
(
auto
& i : oc.
arr
) {
i =
0
;
}
std::cerr <<
24
<<
'
'
;
BOOST_TEST
((oc.*get)() ==
0
);
BOOST_TEST
(this_dll == this_exe);
ctor_i.
call_standard
(&oc,
12
);
BOOST_TEST
(this_dll == this_exe);
BOOST_TEST
(static_val ==
12
);
BOOST_TEST
((oc.*get)() ==
456
);
BOOST_TEST
(this_dll == this_exe);
(oc.*set)(
42
);
BOOST_TEST
((oc.*get)() ==
42
);
BOOST_TEST
(this_dll == this_exe);
std::cerr <<
25
<<
'
'
;
BOOST_TEST
((oc.*func_dd)(
3
,
2
) ==
6
);
BOOST_TEST
(this_dll == this_exe);
BOOST_TEST
((oc.*func_ii)(
1
,
2
) ==
3
);
BOOST_TEST
(this_dll == this_exe);
BOOST_TEST
((oc.*func_ddc)(
10
,
2
) ==
5
);
BOOST_TEST
(this_dll == this_exe);
BOOST_TEST
((oc.*func_iiv)(
9
,
2
) ==
7
);
BOOST_TEST
(this_dll == this_exe);
std::cerr <<
26
<<
'
'
;
dtor.
call_standard
(&oc);
BOOST_TEST
(this_dll == this_exe);
BOOST_TEST
(static_val ==
0
);
//
TODO: FIX!
#
ifndef
BOOST_TRAVISCI_BUILD
const
auto
& ti = sm.
get_type_info
<override_class>();
BOOST_TEST
(ti.
name
() !=
nullptr
);
#
endif
std::cerr <<
27
<<
'
'
;
//
test the ovls helper.
{
namespace
ex
=
boost::dll::experimental;
auto
&var = ex::get<
double
>(sm,
"
some_space::variable
"
);
BOOST_TEST
(&var == &sp_variable);
auto
fun = ex::get<
void
(
int
)>(sm,
"
overloaded
"
);
BOOST_TEST
(fun == ovl1);
auto
func_ii = sm.
get_mem_fn
<override_class,
int
(
int
,
int
)> (
"
func
"
);
auto
mem_fn = ex::get<override_class,
int
(
int
,
int
)>(sm,
"
func
"
);
BOOST_TEST
(mem_fn == func_ii);
}
std::cerr <<
28
<<
'
'
;
return
boost::report_errors
();
}
#
else
int
main
() {
return
0
;}
#
endif
You can’t perform that action at this time.