|
| 1 | +// Copyright 2026 Roman Savchenko |
| 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 | +#include <boost/predef.h> |
| 11 | + |
| 12 | +#include "../example/b2_workarounds.hpp" |
| 13 | + |
| 14 | +#include <boost/core/lightweight_test.hpp> |
| 15 | +#include <boost/filesystem.hpp> |
| 16 | + |
| 17 | +#include <iostream> |
| 18 | + |
| 19 | +#include <boost/dll/smart_library.hpp> |
| 20 | + |
| 21 | +// Test for smart_library construction from empty/unloaded shared_library objects. |
| 22 | +int main(int argc, char* argv[]) |
| 23 | +{ |
| 24 | + using namespace boost::dll; |
| 25 | + using namespace boost::dll::experimental; |
| 26 | + boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv); |
| 27 | + |
| 28 | + BOOST_TEST(!pt.empty()); |
| 29 | + std::cout << "Library: " << pt << std::endl; |
| 30 | + |
| 31 | + { |
| 32 | + shared_library empty_lib; |
| 33 | + BOOST_TEST(!empty_lib.is_loaded()); |
| 34 | + |
| 35 | + // Should not access location() for an unloaded library. |
| 36 | + smart_library sm(empty_lib); |
| 37 | + BOOST_TEST(!sm.is_loaded()); |
| 38 | + } |
| 39 | + |
| 40 | + { |
| 41 | + shared_library lib(pt); |
| 42 | + BOOST_TEST(lib.is_loaded()); |
| 43 | + |
| 44 | + shared_library moved_to = std::move(lib); |
| 45 | + BOOST_TEST(!lib.is_loaded()); |
| 46 | + BOOST_TEST(moved_to.is_loaded()); |
| 47 | + |
| 48 | + // Should not access location() for a moved-from library. |
| 49 | + smart_library sm(std::move(lib)); |
| 50 | + BOOST_TEST(!sm.is_loaded()); |
| 51 | + } |
| 52 | + |
| 53 | + { |
| 54 | + shared_library lib(pt); |
| 55 | + BOOST_TEST(lib.is_loaded()); |
| 56 | + |
| 57 | + smart_library sm(lib); |
| 58 | + BOOST_TEST(sm.is_loaded()); |
| 59 | + } |
| 60 | + |
| 61 | + { |
| 62 | + shared_library lib(pt); |
| 63 | + BOOST_TEST(lib.is_loaded()); |
| 64 | + |
| 65 | + smart_library sm(std::move(lib)); |
| 66 | + BOOST_TEST(sm.is_loaded()); |
| 67 | + } |
| 68 | + |
| 69 | + return boost::report_errors(); |
| 70 | +} |
0 commit comments