]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/cpp_import_class_test.cpp
1 // Copyright 2016 Klemens Morgenstern
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)
7 // For more information, see http://www.boost.org
10 #include <boost/predef.h>
12 #if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
14 #include "../example/b2_workarounds.hpp"
20 #include <boost/dll/smart_library.hpp>
21 #include <boost/dll/import_mangled.hpp>
22 #include <boost/dll/import_class.hpp>
24 #include <boost/core/lightweight_test.hpp>
25 #include <boost/filesystem.hpp>
26 #include <boost/variant.hpp>
27 #include <boost/function.hpp>
29 #define L cout << __LINE__ << endl;
31 int main(int argc
, char* argv
[])
33 using namespace boost::dll
;
34 using namespace boost::dll::experimental
;
35 boost::filesystem::path pt
= b2_workarounds::first_lib_from_argv(argc
, argv
);
37 BOOST_TEST(!pt
.empty());
38 std::cout
<< "Library: " << pt
<< std::endl
;
42 auto static_val
= import_mangled
<int>(sm
, "some_space::some_class::value");
44 std::cout
<< "--------------------- Entry Points ------------------------\n" << std::endl
;
45 for (auto &s
: sm
.symbol_storage().get_storage())
46 std::cout
<< s
.demangled
<< std::endl
;
48 std::cout
<< "-----------------------------------------------------------\n\n" << std::endl
;
51 auto sp_variable
= import_mangled
<double>(sm
, "some_space::variable");
53 auto unscoped_var
= import_mangled
<int>(sm
, "unscoped_var");
55 std::size_t type_size
= *import_mangled
<std::size_t>(sm
, "some_space::size_of_some_class");
58 #if defined(BOOST_MSVC) || defined(BOOST_MSVC_FULL_VER)
59 class override_class
{};
60 auto cl
= import_class
<override_class
, int>(sm
, "some_space::some_class", type_size
, 42);
62 auto cl
= import_class
<class override_class
, int>(sm
, "some_space::some_class", type_size
, 42);
64 BOOST_TEST(!cl
.is_copy_assignable());
65 BOOST_TEST(!cl
.is_copy_constructible());
67 BOOST_TEST( cl
.is_move_assignable());
68 BOOST_TEST( cl
.is_move_constructible());
70 BOOST_TEST(*static_val
== 42);
72 auto i
= cl
.call
<const override_class
, int()>("get")();
74 cl
.call
<void(int)>("set")(42);
76 i
= cl
.call
<const override_class
, int()>("get")();
79 auto func
= import_mangled
<
80 override_class
, double(double, double), int(int, int),
81 volatile override_class
, int(int, int),
82 const volatile override_class
, double(double, double)>(sm
, "func");
86 BOOST_TEST((cl
->*func
)(3.,2.) == 6.);
87 BOOST_TEST((cl
->*func
)(1 ,2 ) == 3 );
89 auto fun2
= cl
.import
<double(double, double), int(int, int)>("func");
91 BOOST_TEST((cl
->*fun2
)(3.,2.) == 6.);
92 BOOST_TEST((cl
->*fun2
)(5 ,2 ) == 7 );
95 boost::function
<int(override_class
* const, int, int)> mem_fn_obj
= func
;
98 const std::type_info
& ti
= cl
.get_type_info();
99 std::string imp_name
= boost::core::demangle(ti
.name());
100 #if defined(BOOST_MSVC) || defined(BOOST_MSVC_FULL_VER)
101 std::string exp_name
= "struct some_space::some_class";
103 std::string exp_name
= "some_space::some_class";
105 BOOST_TEST(imp_name
== exp_name
);
108 BOOST_TEST(*static_val
== 0);
110 return boost::report_errors();
114 int main() {return 0;}