aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-09-14 01:26:08 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-09-14 01:35:04 +0300
commit25e0d87f4a0a34c0ace31965b695cbef1db7a701 (patch)
tree7d0a055109f0fd6ce85c5c20d68928514baf44b6 /test/unit_tests
parentunit_tests: rework enum_symbols test (diff)
downloadwinapi-debug-25e0d87f4a0a34c0ace31965b695cbef1db7a701.tar.gz
winapi-debug-25e0d87f4a0a34c0ace31965b695cbef1db7a701.zip
unit_tests: add a test for call stack collection
Diffstat (limited to '')
-rw-r--r--test/unit_tests/CMakeLists.txt2
-rw-r--r--test/unit_tests/dbghelp.cpp79
-rw-r--r--test/unit_tests/dbghelp.hpp74
3 files changed, 91 insertions, 64 deletions
diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt
index e7362e1..6b5eca6 100644
--- a/test/unit_tests/CMakeLists.txt
+++ b/test/unit_tests/CMakeLists.txt
@@ -1,7 +1,7 @@
find_package(Boost REQUIRED COMPONENTS filesystem unit_test_framework)
add_executable(unit_tests main.cpp dbghelp.cpp error.cpp)
-target_link_libraries(unit_tests PRIVATE pdb_repo)
+target_link_libraries(unit_tests PRIVATE pdb_repo test_lib)
target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::filesystem Boost::nowide Boost::unit_test_framework)
install(TARGETS unit_tests RUNTIME DESTINATION bin/test)
diff --git a/test/unit_tests/dbghelp.cpp b/test/unit_tests/dbghelp.cpp
index c950899..ddf5a71 100644
--- a/test/unit_tests/dbghelp.cpp
+++ b/test/unit_tests/dbghelp.cpp
@@ -1,79 +1,22 @@
+#include "dbghelp.hpp"
#include "utils.hpp"
+#include <test_lib.hpp>
+
#include <pdb/all.hpp>
-#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <algorithm>
-#include <iterator>
#include <string>
-#include <unordered_set>
-#include <utility>
+#include <vector>
namespace {
-class DbgHelp {
-public:
- DbgHelp() : dbghelp{pdb::DbgHelp::post_mortem()} { BOOST_TEST_MESSAGE("Initializing DbgHelp"); }
-
- ~DbgHelp() { BOOST_TEST_MESSAGE("Cleaning up DbgHelp"); }
-
- const pdb::DbgHelp dbghelp;
-
-private:
- DbgHelp(const DbgHelp&) = delete;
- DbgHelp& operator=(const DbgHelp&) = delete;
-};
-
-template <typename T>
-using Set = std::unordered_set<T>;
-
-template <typename T>
-Set<T> join(Set<T>&& xs, Set<T>&& ys) {
- xs.insert(std::make_move_iterator(ys.begin()), std::make_move_iterator(ys.end()));
- return std::move(xs);
+void throw_call_stack() {
+ throw pdb::CallStack::capture();
}
-class DbgHelpWithSymbols : public DbgHelp {
-public:
- DbgHelpWithSymbols() { load_test_lib_pdb(); }
-
- static const std::string& get_namespace() {
- static const std::string name{"test"};
- return name;
- }
-
- typedef Set<std::string> SymbolList;
-
- static SymbolList expected_functions() { return make_qualified({"foo", "bar", "baz"}); }
-
- static SymbolList expected_variables() { return make_qualified({"var"}); }
-
- static SymbolList expected_symbols() {
- return join(expected_functions(), expected_variables());
- }
-
-private:
- static SymbolList make_qualified(SymbolList&& plain) {
- SymbolList qualified;
- for (auto&& name : plain) {
- qualified.emplace(get_namespace() + "::" + std::move(name));
- }
- return qualified;
- }
-
- void load_test_lib_pdb() {
- const auto pdb_path = get_test_lib_pdb_path().string();
- BOOST_TEST_MESSAGE("Loading PDB: " << pdb_path);
- dbghelp.load_pdb(pdb_path);
- }
-
- static boost::filesystem::path get_test_lib_pdb_path() {
- return Paths::get().exe_dir / "test_lib.pdb";
- }
-};
-
} // namespace
BOOST_FIXTURE_TEST_SUITE(dbghelp_tests, DbgHelpWithSymbols)
@@ -102,4 +45,14 @@ BOOST_AUTO_TEST_CASE(enum_symbols) {
}
}
+BOOST_AUTO_TEST_CASE(call_stack) {
+ try {
+ test::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()
diff --git a/test/unit_tests/dbghelp.hpp b/test/unit_tests/dbghelp.hpp
new file mode 100644
index 0000000..daede68
--- /dev/null
+++ b/test/unit_tests/dbghelp.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+#include "utils.hpp"
+
+#include <pdb/all.hpp>
+
+#include <boost/filesystem.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include <iterator>
+#include <string>
+#include <unordered_set>
+#include <utility>
+
+class DbgHelp {
+public:
+ DbgHelp() : dbghelp{pdb::DbgHelp::post_mortem()} { BOOST_TEST_MESSAGE("Initializing DbgHelp"); }
+
+ ~DbgHelp() { BOOST_TEST_MESSAGE("Cleaning up DbgHelp"); }
+
+ const pdb::DbgHelp dbghelp;
+
+private:
+ DbgHelp(const DbgHelp&) = delete;
+ DbgHelp& operator=(const DbgHelp&) = delete;
+};
+
+template <typename T>
+using Set = std::unordered_set<T>;
+
+template <typename T>
+Set<T> join(Set<T>&& xs, Set<T>&& ys) {
+ xs.insert(std::make_move_iterator(ys.begin()), std::make_move_iterator(ys.end()));
+ return std::move(xs);
+}
+
+class DbgHelpWithSymbols : public DbgHelp {
+public:
+ DbgHelpWithSymbols() { load_test_lib_pdb(); }
+
+ static const std::string& get_namespace() {
+ static const std::string name{"test"};
+ return name;
+ }
+
+ typedef Set<std::string> SymbolList;
+
+ static SymbolList expected_functions() { return make_qualified({"foo", "bar", "baz"}); }
+
+ static SymbolList expected_variables() { return make_qualified({"var"}); }
+
+ static SymbolList expected_symbols() {
+ return join(expected_functions(), expected_variables());
+ }
+
+private:
+ static SymbolList make_qualified(SymbolList&& plain) {
+ SymbolList qualified;
+ for (auto&& name : plain) {
+ qualified.emplace(get_namespace() + "::" + std::move(name));
+ }
+ return qualified;
+ }
+
+ void load_test_lib_pdb() {
+ const auto pdb_path = get_test_lib_pdb_path().string();
+ BOOST_TEST_MESSAGE("Loading PDB: " << pdb_path);
+ dbghelp.load_pdb(pdb_path);
+ }
+
+ static boost::filesystem::path get_test_lib_pdb_path() {
+ return Paths::get().exe_dir / "test_lib.pdb";
+ }
+};