-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Split apart some of existing X11 functions so they can be unit tested. - Improvements of testing code. Signed-off-by: Tin Švagelj <[email protected]>
- Loading branch information
Showing
10 changed files
with
289 additions
and
55 deletions.
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
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
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
Oops, something went wrong.