File: library_info_test.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (80 lines) | stat: -rw-r--r-- 3,373 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2011-2012 Renato Tegon Forti
// Copyright Antony Polukhin, 2015-2025
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

// MinGW related workaround
#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
#include "../example/b2_workarounds.hpp"

#include <boost/dll/library_info.hpp>
#include <boost/core/lightweight_test.hpp>
#include "../example/tutorial4/static_plugin.hpp"

// Unit Tests

#include <iterator>

int main(int argc, char* argv[])
{
    boost::dll::fs::path shared_library_path = b2_workarounds::first_lib_from_argv(argc, argv);
    BOOST_TEST(shared_library_path.string().find("test_library") != std::string::npos);

    boost::dll::library_info lib_info(shared_library_path);
    std::vector<std::string> sec = lib_info.sections();
    std::copy(sec.begin(), sec.end(), std::ostream_iterator<std::string>(std::cout, ",  "));
    BOOST_TEST(std::find(sec.begin(), sec.end(), "boostdll") != sec.end());


    std::cout << "\n\n\n";
    std::vector<std::string> symb = lib_info.symbols();
    std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
    BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g") != symb.end());
    BOOST_TEST(std::find(symb.begin(), symb.end(), "say_hello") != symb.end());

#if defined(__GNUC__) && __GNUC__ >= 4 && defined(__ELF__)
    BOOST_TEST(std::find(symb.begin(), symb.end(), "protected_function") != symb.end());
#endif

    std::cout << "\n\n'boostdll' symbols:\n";
    symb = lib_info.symbols("boostdll");
    std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
    BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g_alias") != symb.end());
    BOOST_TEST(std::find(symb.begin(), symb.end(), "foo_variable") != symb.end());
    BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g") == symb.end());
    BOOST_TEST(std::find(symb.begin(), symb.end(), "say_hello") == symb.end());
    BOOST_TEST(lib_info.symbols(std::string("boostdll")) == symb);

    std::cout << "\n\n'empty' symbols:\n";
    std::vector<std::string> empty = lib_info.symbols("empty");
    BOOST_TEST(empty.empty() == true);

    BOOST_TEST(lib_info.symbols("section_that_does_not_exist").empty());

    // Self testing
    std::cout << "Self: " << argv[0];
    boost::dll::library_info self_info(argv[0]);

    sec = self_info.sections();
    //std::copy(sec.begin(), sec.end(), std::ostream_iterator<std::string>(std::cout, ",  "));
    BOOST_TEST(std::find(sec.begin(), sec.end(), "boostdll") != sec.end());

    symb = self_info.symbols("boostdll");
    std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
    BOOST_TEST(std::find(symb.begin(), symb.end(), "create_plugin") != symb.end());

    boost::dll::fs::path sections_stripped_path = "/lib/x86_64-linux-gnu/libaio.so.1";
    if (exists(sections_stripped_path)) {
        boost::dll::library_info stripped_lib(sections_stripped_path);
        std::cout << "\n\n\n";
        symb = stripped_lib.symbols();
        std::copy(symb.begin(), symb.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
        BOOST_TEST(!symb.empty());
    }

    return boost::report_errors();
}