shared_library_search_symbol_test.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2011-2012 Renato Tegon Forti
  2. // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
  3. // Copyright 2015-2019 Antony Polukhin.
  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. // For more information, see http://www.boost.org
  9. #include "../example/b2_workarounds.hpp"
  10. #include <boost/dll.hpp>
  11. #include <boost/core/lightweight_test.hpp>
  12. // Unit Tests
  13. extern "C" void BOOST_SYMBOL_EXPORT exef() {
  14. }
  15. int main(int argc, char* argv[])
  16. {
  17. using namespace boost::dll;
  18. boost::dll::fs::path shared_library_path = b2_workarounds::first_lib_from_argv(argc, argv);
  19. BOOST_TEST(shared_library_path.string().find("test_library") != std::string::npos);
  20. BOOST_TEST(b2_workarounds::is_shared_library(shared_library_path));
  21. std::cout << "Library: " << shared_library_path;
  22. {
  23. shared_library sl(shared_library_path);
  24. BOOST_TEST(sl.has("say_hello"));
  25. BOOST_TEST(sl.has("lib_version"));
  26. BOOST_TEST(sl.has("integer_g"));
  27. BOOST_TEST(sl.has(std::string("integer_g")));
  28. BOOST_TEST(!sl.has("i_do_not_exist"));
  29. BOOST_TEST(!sl.has(std::string("i_do_not_exist")));
  30. }
  31. {
  32. shared_library sl(program_location());
  33. BOOST_TEST(sl.has("exef"));
  34. BOOST_TEST(!sl.has("i_do_not_exist"));
  35. }
  36. exef(); // Make sure that this function still callable in traditional way
  37. return boost::report_errors();
  38. }