dispatch: Add simple test

This commit is contained in:
patrick96 2021-01-14 10:25:37 +01:00 committed by Patrick Ziegler
parent 464bedb33c
commit 8fcd514168
3 changed files with 56 additions and 0 deletions

View File

@ -251,6 +251,14 @@ void renderer::begin(xcb_rectangle_t rect) {
void renderer::end() {
m_log.trace_x("renderer: end");
/*
* Finalize the positions of the action blocks.
* Up until this point, the positions were relative to the start of the
* alignment block the action was located in.
* Here we add the start position of the block as well as the start position
* of the bar itself (without borders or tray) to create positions relative to
* the bar window.
*/
for (auto& a : m_action_ctxt.get_blocks()) {
a.start_x += block_x(a.align) + m_rect.x;
a.end_x += block_x(a.align) + m_rect.x;

View File

@ -63,6 +63,7 @@ add_unit_test(drawtypes/label)
add_unit_test(drawtypes/ramp)
add_unit_test(drawtypes/iconset)
add_unit_test(tags/parser)
add_unit_test(tags/dispatch)
# Run make check to build and run all unit tests
add_custom_target(check

View File

@ -0,0 +1,47 @@
#include "tags/dispatch.hpp"
#include "common/test.hpp"
#include "components/logger.hpp"
#include "gmock/gmock.h"
using namespace polybar;
using namespace std;
using namespace tags;
using ::testing::InSequence;
using ::testing::_;
class MockRenderer : public renderer_interface {
public:
MockRenderer(action_context& action_ctxt) : renderer_interface(action_ctxt){};
MOCK_METHOD(void, render_offset, (const context& ctxt, int pixels), (override));
MOCK_METHOD(void, render_text, (const context& ctxt, const string&& str), (override));
MOCK_METHOD(void, change_alignment, (const context& ctxt), (override));
MOCK_METHOD(void, action_open, (const context& ctxt, mousebtn btn, action_t id), (override));
MOCK_METHOD(void, action_close, (const context& ctxt, action_t id), (override));
};
class TestableDispatch : public dispatch {};
class Dispatch : public ::testing::Test {
protected:
unique_ptr<action_context> action_ctxt = make_unique<action_context>();
unique_ptr<dispatch> parser = make_unique<dispatch>(logger(loglevel::NONE), *action_ctxt);
};
TEST_F(Dispatch, ignoreFormatting) {
MockRenderer r(*action_ctxt);
{
InSequence seq;
EXPECT_CALL(r, render_offset(_, 10)).Times(1);
EXPECT_CALL(r, render_text(_, string{"abc"})).Times(1);
EXPECT_CALL(r, render_text(_, string{"foo"})).Times(1);
}
bar_settings settings;
parser->parse(settings, r, "%{O10}abc%{F-}foo");
}