aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests/dbghelp.cpp
blob: 4346bf7120decbb548b606388b228bc3074d284f (plain) (blame)
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
#include "fixtures.hpp"
#include "paths.hpp"

#include <pdb/all.hpp>
#include <test_lib.hpp>

#include <boost/test/unit_test.hpp>

#include <algorithm>
#include <string>
#include <vector>

namespace {

void throw_call_stack() {
    throw pdb::CallStack::capture();
}

} // namespace

BOOST_FIXTURE_TEST_SUITE(dbghelp_tests, DbgHelpWithSymbols)

BOOST_AUTO_TEST_CASE(enum_symbols) {
    // Symbols can be enumerated, and all the expected symbols are there.

    // First, enumerate all the symbols:
    std::vector<std::string> all_symbols;
    {
        const auto callback = [&all_symbols](const pdb::SymbolInfo& symbol) {
            all_symbols.emplace_back(symbol.get_name());
        };
        dbghelp.enum_symbols(callback);
    }

    // Next, check that all the expected symbols are there:
    {
        const auto expected = expected_symbols();
        const auto check = [&all_symbols](const std::string& name) {
            return std::find(all_symbols.cbegin(), all_symbols.cend(), name) != all_symbols.cend();
        };
        for (const auto& name : expected) {
            BOOST_TEST(check(name), "Symbol wasn't enumerated: " << name);
        }
    }
}

BOOST_AUTO_TEST_CASE(call_stack) {
    try {
        test_ns::foo(&throw_call_stack);
    } catch (const pdb::CallStack& call_stack) {
        BOOST_TEST(true, "Caught the call stack");
        return;
    }
    BOOST_TEST(false, "Didn't catch the call stack");
}

BOOST_AUTO_TEST_SUITE_END()