]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
92f5a8d4 | 31 | boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv);; |
7c673cae FG |
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 | ||
92f5a8d4 TL |
113 | // TODO: FIX! |
114 | #ifndef BOOST_TRAVISCI_BUILD | |
115 | ||
7c673cae FG |
116 | #if defined(BOOST_MSVC) || defined(BOOST_MSVC_VER) |
117 | auto vtable = ms.get_vtable<override_class>(); | |
118 | BOOST_TEST(!vtable.empty()); | |
119 | #else | |
120 | auto ti = ms.get_type_info<override_class>(); | |
121 | BOOST_TEST(!ti.empty()); | |
122 | #endif | |
92f5a8d4 TL |
123 | |
124 | #endif // #ifndef BOOST_TRAVISCI_BUILD | |
125 | ||
7c673cae FG |
126 | return boost::report_errors(); |
127 | } | |
128 | ||
129 | #else | |
130 | int main() {return 0;} | |
131 | #endif |