]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/cpp_mangle_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / dll / test / cpp_mangle_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/core/lightweight_test.hpp>
17 #include <boost/filesystem.hpp>
18 #include <boost/variant.hpp>
19
20 #include <iostream>
21
22
23 struct override_class {};
24
25
26 int main(int argc, char* argv[])
27 {
28 using namespace boost::dll;
29 using mangled_storage = detail::mangled_storage_impl;
30
31 boost::filesystem::path pt = b2_workarounds::first_lib_from_argv(argc, argv);;
32
33 std::cout << "Library: " << pt << std::endl;
34 library_info lib{pt};
35
36 mangled_storage ms(lib);
37
38 std::cout << "Symbols: " << std::endl;
39
40 for (auto &s : ms.get_storage())
41 {
42 std::cout << s.demangled << std::endl;
43 }
44
45 std::string v;
46 v = ms.get_variable<double>("some_space::variable");
47
48 BOOST_TEST(!v.empty()); //check if a symbols was found.
49 BOOST_TEST(v != "some_space::variable"); //demangle is different
50
51 v = ms.get_variable<double>("some_space::variable_typo");
52 BOOST_TEST(v.empty());
53
54
55 v = ms.get_variable<const double>("unscoped_c_var");
56
57 BOOST_TEST(!v.empty()); //check if a symbols was found.
58
59 v = ms.get_variable<int>("unscoped_var");
60
61 BOOST_TEST(!v.empty()); //check if a symbols was found.
62
63
64 v = ms.get_function<const int &()>("some_space::scoped_fun");
65
66 BOOST_TEST(!v.empty());
67 BOOST_TEST(v != "some_space::scoped_fun");
68
69
70 auto v1 = ms.get_function<void(const double)>("overloaded");
71 auto v2 = ms.get_function<void(const volatile int)>("overloaded");
72 BOOST_TEST(!v1.empty());
73 BOOST_TEST(!v2.empty());
74 BOOST_TEST(v1 != v2);
75
76 v = ms.get_variable<int>("some_space::some_class::value");
77 BOOST_TEST(!v.empty());
78 BOOST_TEST(v != "some_space::some_class::value");
79
80 v = ms.get_function<void(const int &)>("some_space::some_class::set_value");
81
82 BOOST_TEST(!v.empty());
83 BOOST_TEST(v != "some_space::some_class::set_value");
84
85
86
87 ms.add_alias<override_class>("some_space::some_class");
88
89 auto ctor1 = ms.get_constructor<override_class()>();
90 BOOST_TEST(!ctor1.empty());
91
92 auto ctor2 = ms.get_constructor<override_class(int)>();
93 BOOST_TEST(!ctor2.empty());
94
95
96 v = ms.get_mem_fn<override_class, double(double, double)>("func");
97 BOOST_TEST(!v.empty());
98
99 v = ms.get_mem_fn<override_class, int(int, int)>("func");
100 BOOST_TEST(!v.empty());
101
102
103 auto dtor = ms.get_destructor<override_class>();
104
105 BOOST_TEST(!dtor.empty());
106
107 auto var1 = ms.get_function<void(boost::variant<int, double> &)>("use_variant");
108 auto var2 = ms.get_function<void(boost::variant<double, int> &)>("use_variant");
109
110 BOOST_TEST(!var1.empty());
111 BOOST_TEST(!var2.empty());
112
113 #if defined(BOOST_MSVC) || defined(BOOST_MSVC_VER)
114 auto vtable = ms.get_vtable<override_class>();
115 BOOST_TEST(!vtable.empty());
116 #else
117 auto ti = ms.get_type_info<override_class>();
118 BOOST_TEST(!ti.empty());
119 #endif
120 return boost::report_errors();
121 }
122
123 #else
124 int main() {return 0;}
125 #endif