Skip to content

Commit

Permalink
Add X11 mocking utilities
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Dec 9, 2024
1 parent 089f9ce commit 14193db
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 30 deletions.
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ excluding_any("wayland" IF NOT BUILD_WAYLAND)

# Mocking works because it's linked before conky_core, so the linker uses mock
# implementations instead of those that are linked later.
add_library(conky-mock OBJECT ${mock_sources})
add_library(Catch2 STATIC catch2/catch_amalgamated.cpp)

add_library(conky-mock OBJECT ${mock_sources})
target_link_libraries(conky-mock Catch2)

add_executable(test-conky test-common.cc ${test_sources})
target_include_directories(test-conky
PUBLIC
Expand Down
6 changes: 4 additions & 2 deletions tests/mock/mock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ std::string debug_format(const std::string& format, Args... args) {
/// This is intended for cases where some library function is internally invoked
/// but would fail if conditions only present at runtime aren't met.
struct state_change {
public:
virtual ~state_change() = default;

static std::string change_name() { return "state_change"; }

/// Returns a string representation of this state change with information
/// necessary to differentiate it from other variants of the same type.
virtual std::string debug() = 0;
Expand Down Expand Up @@ -70,7 +72,7 @@ std::optional<T> next_state_change_t() {
} // namespace mock

/// A variant of `mock::next_state_change_t` that integrates into Catch2.
/// It's a macro because using `FAIL` outside of a test doesn't work.
/// It's a macro because using `FAIL` outside of a test doesn't compile.
#define EXPECT_NEXT_CHANGE(T) \
[]() { \
static_assert(std::is_base_of_v<mock::state_change, T>, \
Expand Down
Loading

0 comments on commit 14193db

Please sign in to comment.