• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/config.hpp>
10 
11 #if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
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 
main(int argc,char * argv[])26 int main(int argc, char* argv[])
27 {
28     using namespace boost::dll;
29     using mangled_storage = detail::mangled_storage_impl;
30 
31     boost::dll::fs::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 // TODO: ms.get_name on Clang has space after comma `boost::variant<double, int>`
108 #if !(defined(BOOST_TRAVISCI_BUILD) && defined(_MSC_VER) && defined(BOOST_CLANG))
109     auto var1 = ms.get_function<void(boost::variant<int, double> &)>("use_variant");
110     auto var2 = ms.get_function<void(boost::variant<double, int> &)>("use_variant");
111 
112     BOOST_TEST(!var1.empty());
113     BOOST_TEST(!var2.empty());
114 #endif
115 
116 #ifndef BOOST_NO_RTTI
117 
118 #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows
119     auto vtable = ms.get_vtable<override_class>();
120     BOOST_TEST(!vtable.empty());
121 #else
122     auto ti  = ms.get_type_info<override_class>();
123     BOOST_TEST(!ti.empty());
124 #endif
125 
126 #endif // #ifndef BOOST_NO_RTTI
127 
128     return boost::report_errors();
129 }
130 
131 #else
main()132 int main() {return 0;}
133 #endif
134