// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include #include #include #include #include #include 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(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); } }