library_info_test.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2011-2012 Renato Tegon Forti
  2. // Copyright 2015-2019 Antony Polukhin
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. // MinGW related workaround
  9. #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
  10. #include "../example/b2_workarounds.hpp"
  11. #include <boost/dll/library_info.hpp>
  12. #include <boost/core/lightweight_test.hpp>
  13. #include "../example/tutorial4/static_plugin.hpp"
  14. // Unit Tests
  15. #include <iterator>
  16. int main(int argc, char* argv[])
  17. {
  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::dll::library_info lib_info(shared_library_path);
  21. std::vector<std::string> sec = lib_info.sections();
  22. std::copy(sec.begin(), sec.end(), std::ostream_iterator<std::string>(std::cout, ", "));
  23. BOOST_TEST(std::find(sec.begin(), sec.end(), "boostdll") != sec.end());
  24. std::cout << "\n\n\n";
  25. std::vector<std::string> symb = lib_info.symbols();
  26. std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  27. BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g") != symb.end());
  28. BOOST_TEST(std::find(symb.begin(), symb.end(), "say_hello") != symb.end());
  29. symb = lib_info.symbols("boostdll");
  30. std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  31. BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g_alias") != symb.end());
  32. BOOST_TEST(std::find(symb.begin(), symb.end(), "foo_variable") != symb.end());
  33. BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g") == symb.end());
  34. BOOST_TEST(std::find(symb.begin(), symb.end(), "say_hello") == symb.end());
  35. BOOST_TEST(lib_info.symbols(std::string("boostdll")) == symb);
  36. std::vector<std::string> empty = lib_info.symbols("empty");
  37. BOOST_TEST(empty.empty() == true);
  38. BOOST_TEST(lib_info.symbols("section_that_does_not_exist").empty());
  39. // Self testing
  40. std::cout << "Self: " << argv[0];
  41. boost::dll::library_info self_info(argv[0]);
  42. sec = self_info.sections();
  43. //std::copy(sec.begin(), sec.end(), std::ostream_iterator<std::string>(std::cout, ", "));
  44. BOOST_TEST(std::find(sec.begin(), sec.end(), "boostdll") != sec.end());
  45. symb = self_info.symbols("boostdll");
  46. std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  47. BOOST_TEST(std::find(symb.begin(), symb.end(), "create_plugin") != symb.end());
  48. return boost::report_errors();
  49. }