]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/shared_library_errors.cpp
1 // Copyright 2011-2012 Renato Tegon Forti.
2 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
3 // Copyright 2015-2019 Antony Polukhin.
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)
9 // For more information, see http://www.boost.org
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>
19 int main(int argc
, char* argv
[]) {
20 using namespace boost::dll
;
22 boost::dll::fs::path shared_library_path
= b2_workarounds::first_lib_from_argv(argc
, argv
);
23 BOOST_TEST(shared_library_path
.string().find("test_library") != std::string::npos
);
24 BOOST_TEST(b2_workarounds::is_shared_library(shared_library_path
));
25 boost::dll::fs::path bad_path
= shared_library_path
/ "directory_that_does_not_exist";
28 shared_library
lib(bad_path
);
30 } catch (const boost::dll::fs::system_error
& e
) {
31 std::cout
<< e
.what() << '\n';
36 lib
.get
<int>("variable_or_function_that_does_not_exist");
38 } catch (const boost::dll::fs::system_error
& e
) {
39 std::cout
<< e
.what() << '\n';
43 shared_library
lib("");
45 } catch (const boost::dll::fs::system_error
& e
) {
46 std::cout
<< e
.what() << '\n';
50 shared_library
lib("\0\0");
52 } catch (const boost::dll::fs::system_error
& e
) {
53 std::cout
<< e
.what() << '\n';
60 } catch (const boost::dll::fs::system_error
& e
) {
61 std::cout
<< e
.what() << '\n';
66 lib
.load("\0\0", load_mode::rtld_global
);
68 } catch (const boost::dll::fs::system_error
& e
) {
69 std::cout
<< e
.what() << '\n';
72 shared_library
sl(shared_library_path
);
74 sl
.get
<int>("variable_or_function_that_does_not_exist");
76 } catch (const boost::dll::fs::system_error
& e
) {
77 std::cout
<< e
.what() << '\n';
81 library_info
lib("\0");
83 } catch (const std::exception
& e
) {
84 std::cout
<< e
.what() << '\n';
88 std::string
not_a_binary(argv
[1]);
89 not_a_binary
+= "/not_a_binary";
90 std::ofstream
ofs(not_a_binary
.c_str());
91 ofs
<< "This is not a binary file, so library_info must report 'Unsupported binary format'";
93 library_info
lib(not_a_binary
);
95 } catch (const std::exception
& e
) {
96 std::cout
<< e
.what() << '\n';
98 return boost::report_errors();