]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright 2011-2012 Renato Tegon Forti. |
2 | // Copyright 2014 Renato Tegon Forti, Antony Polukhin. | |
20effc67 | 3 | // Copyright 2015-2020 Antony Polukhin. |
7c673cae FG |
4 | // |
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // (See accompanying file LICENSE_1_0.txt | |
7 | // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | // For more information, see http://www.boost.org | |
10 | ||
11 | #include "../example/b2_workarounds.hpp" | |
12 | #include <boost/dll/shared_library.hpp> | |
13 | #include <boost/dll/library_info.hpp> | |
14 | #include <boost/core/lightweight_test.hpp> | |
15 | #include <boost/function.hpp> | |
16 | ||
17 | ||
18 | // Unit Tests | |
19 | int main(int argc, char* argv[]) { | |
20 | using namespace boost::dll; | |
21 | ||
92f5a8d4 | 22 | boost::dll::fs::path shared_library_path = b2_workarounds::first_lib_from_argv(argc, argv); |
7c673cae FG |
23 | BOOST_TEST(shared_library_path.string().find("test_library") != std::string::npos); |
24 | BOOST_TEST(b2_workarounds::is_shared_library(shared_library_path)); | |
92f5a8d4 | 25 | boost::dll::fs::path bad_path = shared_library_path / "directory_that_does_not_exist"; |
7c673cae FG |
26 | |
27 | try { | |
28 | shared_library lib(bad_path); | |
29 | BOOST_TEST(false); | |
92f5a8d4 | 30 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
31 | std::cout << e.what() << '\n'; |
32 | } | |
33 | ||
34 | try { | |
35 | shared_library lib; | |
36 | lib.get<int>("variable_or_function_that_does_not_exist"); | |
37 | BOOST_TEST(false); | |
92f5a8d4 | 38 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
39 | std::cout << e.what() << '\n'; |
40 | } | |
41 | ||
42 | try { | |
43 | shared_library lib(""); | |
44 | BOOST_TEST(false); | |
92f5a8d4 | 45 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
46 | std::cout << e.what() << '\n'; |
47 | } | |
48 | ||
49 | try { | |
50 | shared_library lib("\0\0"); | |
51 | BOOST_TEST(false); | |
92f5a8d4 | 52 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
53 | std::cout << e.what() << '\n'; |
54 | } | |
55 | ||
56 | try { | |
57 | shared_library lib; | |
58 | lib.location(); | |
59 | BOOST_TEST(false); | |
92f5a8d4 | 60 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
61 | std::cout << e.what() << '\n'; |
62 | } | |
63 | ||
64 | try { | |
65 | shared_library lib; | |
66 | lib.load("\0\0", load_mode::rtld_global); | |
67 | BOOST_TEST(false); | |
92f5a8d4 | 68 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
69 | std::cout << e.what() << '\n'; |
70 | } | |
71 | ||
72 | shared_library sl(shared_library_path); | |
73 | try { | |
74 | sl.get<int>("variable_or_function_that_does_not_exist"); | |
75 | BOOST_TEST(false); | |
92f5a8d4 | 76 | } catch (const boost::dll::fs::system_error& e) { |
7c673cae FG |
77 | std::cout << e.what() << '\n'; |
78 | } | |
79 | ||
80 | try { | |
81 | library_info lib("\0"); | |
82 | BOOST_TEST(false); | |
83 | } catch (const std::exception& e) { | |
84 | std::cout << e.what() << '\n'; | |
85 | } | |
86 | ||
87 | try { | |
92f5a8d4 TL |
88 | std::string not_a_binary(argv[1]); |
89 | not_a_binary += "/not_a_binary"; | |
90 | std::ofstream ofs(not_a_binary.c_str()); | |
7c673cae FG |
91 | ofs << "This is not a binary file, so library_info must report 'Unsupported binary format'"; |
92 | ofs.close(); | |
93 | library_info lib(not_a_binary); | |
94 | BOOST_TEST(false); | |
95 | } catch (const std::exception& e) { | |
96 | std::cout << e.what() << '\n'; | |
97 | } | |
98 | return boost::report_errors(); | |
99 | } | |
100 |