-
-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for mocking to tests & test X11 struts #2115
Draft
Caellian
wants to merge
6
commits into
main
Choose a base branch
from
dev/test-x11-struts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44cd89c
Add support for mocking to tests
Caellian a0c1502
Properly handle predefined X11 atoms in mocking
Caellian 089f9ce
Fix mock linking
Caellian 384822e
Add X11 mocking utilities
Caellian 1784a59
Fix x11_change_property not properly copying data
Caellian 992e67c
Add display mocking
Caellian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "catch2/catch.hpp" | ||
#include "mock/display-mock.hh" | ||
#include "mock/mock.hh" | ||
|
||
class testRunListener : public Catch::EventListenerBase { | ||
public: | ||
using Catch::EventListenerBase::EventListenerBase; | ||
|
||
void testRunStarting(Catch::TestRunInfo const&) { | ||
mock::__internal::init_display_output_mock(); | ||
} | ||
void testRunEnded(Catch::TestRunStats const&) { | ||
mock::__internal::delete_display_output_mock(); | ||
} | ||
void testCaseStarting(Catch::SectionInfo const&) { | ||
mock::__internal::state_changes.clear(); | ||
} | ||
}; | ||
|
||
CATCH_REGISTER_LISTENER(testRunListener) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "display-mock.hh" | ||
#include "display-output.hh" | ||
|
||
namespace mock { | ||
display_output_mock *output; | ||
|
||
display_output_mock &get_mock_output() { return *output; } | ||
|
||
namespace __internal { | ||
void init_display_output_mock() { | ||
output = new display_output_mock(); | ||
conky::active_display_outputs.push_back(output); | ||
conky::current_display_outputs.push_back(output); | ||
} | ||
void delete_display_output_mock() { | ||
delete output; | ||
conky::current_display_outputs.clear(); | ||
conky::active_display_outputs.clear(); | ||
} | ||
} // namespace __internal | ||
} // namespace mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* | ||
* Conky, a system monitor, based on torsmo | ||
* | ||
* Please see COPYING for details | ||
* | ||
* Copyright (C) 2018-2021 François Revol et al. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef DISPLAY_MOCK_HH | ||
#define DISPLAY_MOCK_HH | ||
|
||
#include "colours.h" | ||
#include "display-output.hh" | ||
|
||
namespace mock { | ||
/// These are called by Catch2 events, DO NOT use them directly | ||
namespace __internal { | ||
void init_display_output_mock(); | ||
void delete_display_output_mock(); | ||
} // namespace __internal | ||
|
||
/* | ||
* A base class for mock display output that emulates a GUI. | ||
*/ | ||
class display_output_mock : public conky::display_output_base { | ||
// Use `mock::get_mock_output`. | ||
explicit display_output_mock() : conky::display_output_base("mock") {}; | ||
~display_output_mock() {}; | ||
|
||
public: | ||
float dpi_scale = 1.0; | ||
|
||
// check if available and enabled in settings | ||
bool detect() { return true; } | ||
// connect to DISPLAY and other stuff | ||
bool initialize() { return true; } | ||
bool shutdown() { return true; } | ||
|
||
bool graphical() { return true; }; | ||
bool draw_line_inner_required() { return true; } | ||
|
||
bool main_loop_wait(double t) { return false; } | ||
|
||
void sigterm_cleanup() {} | ||
void cleanup() {} | ||
|
||
// drawing primitives | ||
void set_foreground_color(Colour c) {} | ||
|
||
int calc_text_width(const char *s) { return 0; } | ||
|
||
void begin_draw_text() {} | ||
void end_draw_text() {} | ||
void draw_string(const char *s, int w) {} | ||
void line_inner_done() {} | ||
|
||
// GUI interface | ||
void draw_string_at(int /*x*/, int /*y*/, const char * /*s*/, int /*w*/) {} | ||
// X11 lookalikes | ||
void set_line_style(int /*w*/, bool /*solid*/) {} | ||
void set_dashes(char * /*s*/) {} | ||
void draw_line(int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/) {} | ||
void draw_rect(int /*x*/, int /*y*/, int /*w*/, int /*h*/) {} | ||
void fill_rect(int /*x*/, int /*y*/, int /*w*/, int /*h*/) {} | ||
void draw_arc(int /*x*/, int /*y*/, int /*w*/, int /*h*/, int /*a1*/, | ||
int /*a2*/) {} | ||
void move_win(int /*x*/, int /*y*/) {} | ||
float get_dpi_scale() { return dpi_scale; }; | ||
|
||
void begin_draw_stuff() {} | ||
void end_draw_stuff() {} | ||
void clear_text(int /*exposures*/) {} | ||
|
||
// font stuff | ||
int font_height(unsigned int) { return 0; } | ||
int font_ascent(unsigned int) { return 0; } | ||
int font_descent(unsigned int) { return 0; } | ||
void setup_fonts(void) {} | ||
void set_font(unsigned int) {} | ||
void free_fonts(bool /*utf8*/) {} | ||
void load_fonts(bool /*utf8*/) {} | ||
|
||
// tty interface | ||
int getx() { return 0; } | ||
int gety() { return 0; } | ||
void gotox(int /*x*/) {} | ||
void gotoy(int /*y*/) {} | ||
void gotoxy(int /*x*/, int /*y*/) {} | ||
|
||
void flush() {} | ||
|
||
protected: | ||
bool active() { return true; } | ||
|
||
friend void __internal::init_display_output_mock(); | ||
friend void __internal::delete_display_output_mock(); | ||
}; | ||
|
||
display_output_mock &get_mock_output(); | ||
} // namespace mock | ||
|
||
#endif /* DISPLAY_MOCK_HH */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "mock.hh" | ||
#include <optional> | ||
#include <utility> | ||
|
||
namespace mock { | ||
std::deque<std::unique_ptr<state_change>> __internal::state_changes; | ||
|
||
std::deque<std::unique_ptr<state_change>> take_state_changes() { | ||
std::deque<std::unique_ptr<mock::state_change>> result; | ||
std::swap(__internal::state_changes, result); | ||
return result; | ||
} | ||
std::optional<std::unique_ptr<state_change>> next_state_change() { | ||
if (__internal::state_changes.empty()) { return std::nullopt; } | ||
auto front = std::move(__internal::state_changes.front()); | ||
__internal::state_changes.pop_front(); | ||
return front; | ||
} | ||
void push_state_change(std::unique_ptr<state_change> change) { | ||
__internal::state_changes.push_back(std::move(change)); | ||
} | ||
} // namespace mock |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment
wasn't available to some file (wayland?) that uses it. Note to self to check before merge.