From c6609ec2fe1d36cbc5b4c3c88f01d198230612b7 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 14 Sep 2020 01:10:07 +0300 Subject: unit_tests: rework enum_symbols test --- test/unit_tests/dbghelp.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/test/unit_tests/dbghelp.cpp b/test/unit_tests/dbghelp.cpp index 13d22b8..c950899 100644 --- a/test/unit_tests/dbghelp.cpp +++ b/test/unit_tests/dbghelp.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,7 @@ public: return name; } - typedef std::unordered_set SymbolList; + typedef Set SymbolList; static SymbolList expected_functions() { return make_qualified({"foo", "bar", "baz"}); } @@ -75,21 +76,30 @@ private: } // namespace -BOOST_AUTO_TEST_SUITE(dbghelp_tests) -BOOST_FIXTURE_TEST_SUITE(enum_symbols_tests, DbgHelpWithSymbols) +BOOST_FIXTURE_TEST_SUITE(dbghelp_tests, DbgHelpWithSymbols) -BOOST_AUTO_TEST_CASE(basic) { +BOOST_AUTO_TEST_CASE(enum_symbols) { // Symbols can be enumerated, and all the expected symbols are there. - auto all_symbols = expected_symbols(); - const auto callback = [&all_symbols](const pdb::SymbolInfo& symbol) { - const auto name = symbol.get_name(); - all_symbols.erase(name); - }; - dbghelp.enum_symbols(callback); - for (const auto& missing : all_symbols) { - BOOST_TEST(false, "Symbol wasn't enumerated: " << missing); + + // First, enumerate all the symbols: + std::vector 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_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3