~aleteoryx/muditaos

97f60737bf5ff08bcab692a907c288cd6127b6fa — Przemyslaw Brudny 5 years ago edc7fd6
[EGD-5010] Fix Text tests leaks

Fixed leaks in gui Text tests.
A .idea/modules.xml => .idea/modules.xml +8 -0
@@ 0,0 1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/PurePhone.iml" filepath="$PROJECT_DIR$/.idea/PurePhone.iml" />
    </modules>
  </component>
</project>

M module-gui/gui/widgets/TextBlockCursor.hpp => module-gui/gui/widgets/TextBlockCursor.hpp +1 -0
@@ 51,6 51,7 @@ namespace gui
        /// and check if this one is needed
        BlockCursor(TextDocument *document, unsigned int pos, unsigned int block_nr, RawFont *default_font);
        BlockCursor() = default; /// bad cursor
        virtual ~BlockCursor() = default;

        [[nodiscard]] auto getPosition() const -> unsigned int
        {

M module-gui/gui/widgets/TextLine.cpp => module-gui/gui/widgets/TextLine.cpp +1 -0
@@ 51,6 51,7 @@ namespace gui

            auto textFormat = localCursor->getFormat();
            if (textFormat->getFont() == nullptr) {
                lineEnd = true;
                return;
            }


M module-gui/test/test-catch-text/main.cpp => module-gui/test/test-catch-text/main.cpp +0 -13
@@ 3,16 3,3 @@

#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <vfs.hpp>
#include <i18n/i18n.hpp>

class vfs vfs;        // needed for compilation, our vfs is global
utils::i18n localize; // needed to load any keymap - these are stored in i18

struct vfs_initializer
{
    vfs_initializer()
    {
        vfs.Init();
    }
} vfs_initializer;

M module-gui/test/test-catch-text/test-gui-Text.cpp => module-gui/test/test-catch-text/test-gui-Text.cpp +40 -40
@@ 263,7 263,7 @@ TEST_CASE("Text backup and restore tests")
    SECTION("Backup one line text with moved cursor, overwrite text and restore")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        text->addText(testStringOneLine);



@@ 289,7 289,7 @@ TEST_CASE("Text backup and restore tests")
    SECTION("Backup two line text with moved cursor, overwrite text and restore")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        text->addText(testStringTwoLines);



@@ 326,7 326,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, 0);

        text->addText(testStringOneLine);


@@ 338,7 338,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, 1);

        text->addText(testStringOneLine);


@@ 350,7 350,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, testStringOneLine.length());

        text->addText(testStringTwoLines);


@@ 362,7 362,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, testStringTwoLines.length());

        text->addText(testStringTwoLines);


@@ 374,7 374,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, testStringOneLine.length());

        text->addText(TextBlock(testStringTwoLines, Font(27).raw(), TextBlock::End::None));


@@ 390,7 390,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")

        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, textLimit);

        text->addText(TextBlock(testStringOneLine, Font(27).raw(), TextBlock::End::None));


@@ 408,7 408,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")

        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, signCountRestricted);



@@ 423,7 423,7 @@ TEST_CASE("Text addition bounds - text sings count restricted")

        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        auto format         = text->getTextFormat();
        auto parsedRichText = gui::text::RichTextParser().parse(richTextTwoLines, &format);


@@ 450,14 450,14 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    std::string testStringSecondLine = "Test String 2";

    std::string richTextTwoLines =
        "<text font='gt_pressura' color='12' size='30'>Test </text><text size='25'>String </text><text size='20' "
        "<text font='gt_pressura' color='12' size='30'>Test </text><text size='20'>String </text><text size='27' "
        "weight='bold'>1</text><br></br><text>Test String 2</text>";

    SECTION("Adding text to 0 size text and no parent to grant size")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(0, 0);



@@ 485,7 485,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(200, 30);



@@ 500,7 500,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(200, 60);



@@ 533,7 533,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(0, 0);



@@ 561,7 561,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(150, 30);



@@ 577,7 577,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(200, 60);



@@ 612,7 612,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(0, 0);



@@ 640,9 640,9 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(160, 40);
        text->setMaximumSize(140, 40);

        text->addRichText(richTextTwoLines);



@@ 655,7 655,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(200, 80);



@@ 674,7 674,7 @@ TEST_CASE("Text addition bounds - text widget size restricted")
        text->setTextLimitType(gui::TextLimitType::MaxSize);
        text->setMaximumSize(200, 80);
        BoxLayout layout = BoxLayout(nullptr, 0, 0, 0, 0);
        layout.setMaximumSize(160, 40);
        layout.setMaximumSize(140, 40);
        layout.addWidget(text);

        text->addRichText(richTextTwoLines);


@@ 694,14 694,14 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    std::string testStringSecondLine = "Test String 2";

    std::string richTextTwoLines =
        "<text font='gt_pressura' color='12' size='30'>Test </text><text size='25'>String </text><text size='20' "
        "<text font='gt_pressura' color='12' size='30'>Test </text><text size='20'>String </text><text size='27' "
        "weight='bold'>1</text><br></br><text>Test String 2</text>";

    SECTION("Adding text to 0 line size text")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 0);
        text->setMaximumSize(150, 100);



@@ 714,7 714,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 1);
        text->setMaximumSize(150, 100);



@@ 729,7 729,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 2);
        text->setMaximumSize(150, 100);



@@ 744,7 744,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 0);
        text->setMaximumSize(150, 100);



@@ 757,7 757,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 1);
        text->setMaximumSize(150, 100);



@@ 773,7 773,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 2);
        text->setMaximumSize(150, 100);



@@ 789,7 789,7 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 0);
        text->setMaximumSize(150, 100);



@@ 802,9 802,9 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 1);
        text->setMaximumSize(160, 100);
        text->setMaximumSize(140, 100);

        text->addRichText(richTextTwoLines);



@@ 817,9 817,9 @@ TEST_CASE("Text addition bounds - text widget line size restricted")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setTextLimitType(gui::TextLimitType::MaxLines, 2);
        text->setMaximumSize(160, 100);
        text->setMaximumSize(140, 100);

        text->addRichText(richTextTwoLines);



@@ 842,7 842,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        text->setTextLimitType(gui::TextLimitType::MaxLines, 2);
        text->setTextLimitType(gui::TextLimitType::MaxSignsCount, testStringOneLine.length());


@@ 860,7 860,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        unsigned int signsLimit = 100;



@@ 881,7 881,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        unsigned int signsLimit = 100;



@@ 903,7 903,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        auto format         = text->getTextFormat();
        auto parsedRichText = gui::text::RichTextParser().parse(richTextTwoLines, &format);


@@ 923,7 923,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        unsigned int signsLimit = 100;



@@ 942,7 942,7 @@ TEST_CASE("Text addition bounds - multiple limits tests")
    {
        mockup::fontManager();
        using namespace gui;
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();

        unsigned int signsLimit = 100;


M module-gui/test/test-catch-text/test-gui-TextLine.cpp => module-gui/test/test-catch-text/test-gui-TextLine.cpp +9 -9
@@ 34,7 34,7 @@ TEST_CASE("TextLine - ctor")
        auto texts            = mockup::lineStrings(3);
        auto [document, font] = mockup::buildMultilineTestDocument(texts);

        auto cursor = new BlockCursor(&document, 0, 0, font);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, font);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() > 0);


@@ 46,7 46,7 @@ TEST_CASE("TextLine - ctor")
        auto test_text        = mockup::multiWordString(5);
        auto [document, font] = mockup::buildOnelineTestDocument(test_text);

        auto cursor = new BlockCursor(&document, 0, 0, font);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, font);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() > 0);


@@ 63,7 63,7 @@ TEST_CASE("TextLine - non fitting text")
        auto test_text        = mockup::multiWordString(5);
        auto [document, font] = mockup::buildOnelineTestDocument(test_text);

        auto cursor = new BlockCursor(&document, 0, 0, font);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, font);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() != 0);


@@ 89,7 89,7 @@ TEST_CASE("TextLine - multiple styles text")
        auto testblock = mockup::getBlock(mockup::BlockFactory::Type::Block0);
        auto document  = TextDocument(testblock);

        auto cursor = new BlockCursor(&document, 0, 0, nullptr);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, nullptr);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.width() > 0);


@@ 105,7 105,7 @@ TEST_CASE("TextLine - multiple styles text")
        testblock.insert(testblock.end(), block1.begin(), block1.end());
        auto document = TextDocument(testblock);

        auto cursor = new BlockCursor(&document, 0, 0, nullptr);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, nullptr);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() == getTextLen(block0));


@@ 121,7 121,7 @@ TEST_CASE("TextLine - multiple styles text")
        testblock.insert(testblock.end(), block1.begin(), block1.end());
        auto document = TextDocument(testblock);

        auto cursor = new BlockCursor(&document, 0, block0.size(), nullptr);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, block0.size(), nullptr);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() == getTextLen(block1));


@@ 132,7 132,7 @@ TEST_CASE("TextLine - multiple styles text")
        auto testblock = mockup::getBlock(mockup::BlockFactory::Type::NoneBlock0);
        auto document  = TextDocument(testblock);

        auto cursor = new BlockCursor(&document, 0, 0, nullptr);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, nullptr);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() == 0);


@@ 144,7 144,7 @@ TEST_CASE("TextLine - multiple styles text")
        auto testblock = mockup::getBlock(mockup::BlockFactory::Type::NoneBlock1);
        auto document  = TextDocument(testblock);

        auto cursor = new BlockCursor(&document, 0, 0, nullptr);
        auto cursor = std::make_unique<BlockCursor>(&document, 0, 0, nullptr);
        auto line   = gui::TextLine(*cursor, maxWidth);

        REQUIRE(line.length() == 0);


@@ 159,7 159,7 @@ TEST_CASE("TextLine - elements sizes checkup")
    auto testblock = mockup::getBlock(mockup::BlockFactory::Type::Block0);
    auto document  = TextDocument(testblock);

    auto cursor    = new BlockCursor(&document, 0, 0, nullptr);
    auto cursor    = std::make_unique<BlockCursor>(&document, 0, 0, nullptr);
    auto text_line = TextLine(*cursor, maxWidth);

    REQUIRE(text_line.length() > 0);

M module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp => module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp +9 -9
@@ 55,7 55,7 @@ TEST_CASE("TextLineCursor - navigation without scroll")
    SECTION("Default position three lines text")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));


@@ 72,7 72,7 @@ TEST_CASE("TextLineCursor - navigation without scroll")
    SECTION("Movement three lines text test -> short|normal|long")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;


@@ 162,7 162,7 @@ TEST_CASE("TextLineCursor - navigation without scroll")
    SECTION("Movement three lines text test -> long|short|normal")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;


@@ 222,7 222,7 @@ TEST_CASE("TextLineCursor - navigation with scroll")
    {

        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);



@@ 326,7 326,7 @@ TEST_CASE("TextLineCursor - navigation with scroll")
    {

        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);



@@ 379,7 379,7 @@ TEST_CASE("TextLineCursor - navigation with scroll")
    SECTION("One 10 lines text space text containing three lines - scroll init position at document begin")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);



@@ 455,7 455,7 @@ TEST_CASE("TextLineCursor - navigation with scroll")
    SECTION("One 10 lines text space text containing three lines - scroll init position at document end")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);



@@ 535,7 535,7 @@ TEST_CASE("TextLineCursor - addition and deletion with scroll")
    {

        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(600, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);



@@ 597,7 597,7 @@ TEST_CASE("TextLineCursor - addition and deletion with scroll")
    SECTION("One 10 lines text space text containing three lines - scroll init position at document end")
    {
        mockup::fontManager();
        auto text = new gui::TestText();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);