]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/cpp_import_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / dll / test / cpp_import_test.cpp
1 // Copyright 2016 Klemens Morgenstern
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // For more information, see http://www.boost.org
8
9 #include <boost/predef.h>
10
11 #if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
12
13 #include "../example/b2_workarounds.hpp"
14
15 #include <boost/dll/smart_library.hpp>
16 #include <boost/dll/import_mangled.hpp>
17
18 #include <boost/core/lightweight_test.hpp>
19 #include <boost/filesystem.hpp>
20 #include <boost/variant.hpp>
21 #include <boost/function.hpp>
22
23 #include <iostream>
24
25 struct override_class
26 {
27 int arr[32];
28 };
29
30
31 int main(int argc, char* argv[])
32 {
33 using namespace boost::dll;
34 using namespace boost::dll::experimental;
35 boost::filesystem::path pt = b2_workarounds::first_lib_from_argv(argc, argv);
36
37 BOOST_TEST(!pt.empty());
38 std::cout << "Library: " << pt << std::endl;
39
40 smart_library sm(pt);
41
42 auto sp_variable = import_mangled<double>(sm, "some_space::variable");
43
44 auto unscoped_var = import_mangled<int>(sm, "unscoped_var");
45
46
47 auto ovl = import_mangled<void(int), void(double)>(sm, "overloaded");
48
49 ovl(12);
50 BOOST_TEST(*unscoped_var == 12);
51 ovl(5.0);
52 BOOST_TEST(*sp_variable == 5.0);
53
54 boost::function<void(int)> f_test = ovl;//test if it binds
55 f_test(-2);
56 BOOST_TEST(*unscoped_var == -2);
57
58 sm.add_type_alias<override_class>("some_space::some_class");
59
60 auto func = import_mangled<
61 override_class, double(double, double), int(int, int),
62 volatile override_class, int(int, int),
63 const volatile override_class, double(double, double)>(sm, "func");
64
65
66 override_class *ov = 0;
67 volatile override_class *ovv = ov;
68 const volatile override_class *ovcv = ov;
69
70 BOOST_TEST(func(ov, 3.,2.) == 6.);
71 BOOST_TEST(func(ov, 1,2 ) == 3 );
72 BOOST_TEST(func(ovv, 10,2) == 8 );
73 BOOST_TEST(func(ovcv, 9,2) == 4.5 );
74
75 return boost::report_errors();
76 }
77
78 #else
79 int main() {return 0;}
80 #endif