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 
10 #include <boost/predef.h>
11 
12 #if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
13 
14 #include "../example/b2_workarounds.hpp"
15 
16 #include <iostream>
17 
18 using namespace std;
19 
20 #include <boost/dll/smart_library.hpp>
21 #include <boost/dll/import_mangled.hpp>
22 #include <boost/dll/import_class.hpp>
23 
24 #include <boost/core/lightweight_test.hpp>
25 #include <boost/filesystem.hpp>
26 #include <boost/variant.hpp>
27 #include <boost/function.hpp>
28 
29 #define L cout << __LINE__ << endl;
30 
main(int argc,char * argv[])31 int main(int argc, char* argv[])
32 {
33      using namespace boost::dll;
34     using namespace boost::dll::experimental;
35     boost::dll::fs::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 static_val = import_mangled<int>(sm, "some_space::some_class::value");
43 
44     std::cout << "--------------------- Entry Points ------------------------\n" << std::endl;
45     for (auto &s : sm.symbol_storage().get_storage())
46         std::cout << s.demangled << std::endl;
47 
48     std::cout << "-----------------------------------------------------------\n\n" << std::endl;
49 
50 
51     auto sp_variable = import_mangled<double>(sm, "some_space::variable");
52 
53     auto unscoped_var = import_mangled<int>(sm, "unscoped_var");
54 
55     std::size_t type_size = *import_mangled<std::size_t>(sm, "some_space::size_of_some_class");
56     {
57 
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);
61 #else
62        auto cl = import_class<class override_class, int>(sm, "some_space::some_class", type_size, 42);
63 #endif
64        BOOST_TEST(!cl.is_copy_assignable());
65        BOOST_TEST(!cl.is_copy_constructible());
66 
67        BOOST_TEST( cl.is_move_assignable());
68        BOOST_TEST( cl.is_move_constructible());
69 
70        BOOST_TEST(*static_val == 42);
71 
72        auto i = cl.call<const override_class, int()>("get")();
73        BOOST_TEST(i == 456);
74        cl.call<void(int)>("set")(42);
75        i = 0;
76        i = cl.call<const override_class, int()>("get")();
77        BOOST_TEST(i == 42);
78 
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");
83 
84 
85 
86         BOOST_TEST((cl->*func)(3.,2.) == 6.);
87         BOOST_TEST((cl->*func)(1 ,2 ) == 3 );
88 
89         auto fun2 = cl.import<double(double, double), int(int, int)>("func");
90 
91         BOOST_TEST((cl->*fun2)(3.,2.) == 6.);
92         BOOST_TEST((cl->*fun2)(5 ,2 ) == 7 );
93 
94         //test if it binds.
95         boost::function<int(override_class* const, int, int)> mem_fn_obj = func;
96 
97 
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";
102 #else
103         std::string exp_name = "some_space::some_class";
104 #endif
105         BOOST_TEST(imp_name == exp_name);
106     }
107 
108     BOOST_TEST(*static_val == 0);
109 
110     return boost::report_errors();
111 }
112 
113 #else
main()114 int main() {return 0;}
115 #endif
116