Files
MuditaOS/module-gui/test/test-catch-text/test-gui-TextBounds.cpp
T
Tomek Sobkowiak 1e78053bb0 EDG-3409 Check text boundaries on input (#716)
* [EDG-3409] Check text boundaries during input processing
2020-10-19 09:14:41 +02:00

79 lines
2.4 KiB
C++

#include <catch2/catch.hpp>
#include <limits>
#include <module-gui/gui/widgets/TextBlock.hpp>
#include <mock/buildTextDocument.hpp>
#include <module-gui/gui/widgets/Text.hpp>
#include <mock/multi-line-string.hpp>
TEST_CASE("Text bounds")
{
using namespace gui;
auto key_up = gui::InputEvent(
{
RawKey::State::Released,
bsp::KeyCodes::Undefined,
},
gui::InputEvent::State::keyReleasedShort,
gui::KeyCode::KEY_UP);
auto key_left = gui::InputEvent(
{
RawKey::State::Released,
bsp::KeyCodes::Undefined,
},
gui::InputEvent::State::keyReleasedShort,
gui::KeyCode::KEY_LEFT);
auto key_down = gui::InputEvent(
{
RawKey::State::Released,
bsp::KeyCodes::Undefined,
},
gui::InputEvent::State::keyReleasedShort,
gui::KeyCode::KEY_DOWN);
auto texts = mockup::lineStrings(6);
auto [document, font] = mockup::buildMultilineTestDocument(texts);
auto text = gui::Text();
text.setText(std::make_unique<gui::TextDocument>(document));
text.setFont(font);
SECTION("moving cursor - hit bound")
{
auto lines = Lines(&text);
auto cursor = new gui::TextLineCursor(&text);
lines.emplace(TextLine(*cursor, 1000));
lines.emplace(TextLine(*cursor, 1000));
lines.emplace(TextLine(*cursor, 1000));
lines.emplace(TextLine(*cursor, 1000));
lines.emplace(TextLine(*cursor, 1000));
cursor->moveCursor(NavigationDirection::DOWN);
cursor->moveCursor(NavigationDirection::DOWN);
cursor->moveCursor(NavigationDirection::DOWN);
auto bound = lines.checkBounds(*cursor, key_down);
REQUIRE(bound == InputBound::HIT_BOUND);
}
SECTION("moving cursor - reach data end")
{
auto lines = Lines(&text);
auto cursor = new gui::TextLineCursor(&text);
lines.emplace(TextLine(*cursor, 100));
auto bound = lines.checkBounds(*cursor, key_up);
REQUIRE(bound == InputBound::NO_DATA);
cursor->moveCursor(NavigationDirection::RIGHT);
bound = lines.checkBounds(*cursor, key_left);
REQUIRE(bound == InputBound::CAN_MOVE);
cursor->moveCursor(NavigationDirection::DOWN);
bound = lines.checkBounds(*cursor, key_up);
REQUIRE(bound == InputBound::NO_DATA);
}
}