From 97f60737bf5ff08bcab692a907c288cd6127b6fa Mon Sep 17 00:00:00 2001 From: Przemyslaw Brudny Date: Thu, 17 Dec 2020 14:13:17 +0100 Subject: [PATCH] [EGD-5010] Fix Text tests leaks Fixed leaks in gui Text tests. --- .idea/modules.xml | 8 ++ module-gui/gui/widgets/TextBlockCursor.hpp | 1 + module-gui/gui/widgets/TextLine.cpp | 1 + module-gui/test/test-catch-text/main.cpp | 13 --- .../test/test-catch-text/test-gui-Text.cpp | 80 +++++++++---------- .../test-catch-text/test-gui-TextLine.cpp | 18 ++--- .../test-gui-TextLineCursor.cpp | 18 ++--- 7 files changed, 68 insertions(+), 71 deletions(-) create mode 100644 .idea/modules.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c94f38f723c4a220d82724ba4352c9acd745fd2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/module-gui/gui/widgets/TextBlockCursor.hpp b/module-gui/gui/widgets/TextBlockCursor.hpp index 8038b7e6f5347c515dae6267e8221a3c5a138d14..d557b82d9bb662fa1d9d70bda000a4094d5ae3bf 100644 --- a/module-gui/gui/widgets/TextBlockCursor.hpp +++ b/module-gui/gui/widgets/TextBlockCursor.hpp @@ -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 { diff --git a/module-gui/gui/widgets/TextLine.cpp b/module-gui/gui/widgets/TextLine.cpp index cbdd2418a3935e1b948aa556a914add5474460f8..a708f8fbf7355c74d09a7c097d5ec66e8fca2a17 100644 --- a/module-gui/gui/widgets/TextLine.cpp +++ b/module-gui/gui/widgets/TextLine.cpp @@ -51,6 +51,7 @@ namespace gui auto textFormat = localCursor->getFormat(); if (textFormat->getFont() == nullptr) { + lineEnd = true; return; } diff --git a/module-gui/test/test-catch-text/main.cpp b/module-gui/test/test-catch-text/main.cpp index 6e41162144d63070d07b6f3305056aad5ce97625..967c8f690e77d89ebc6b310047cd477f847ec628 100644 --- a/module-gui/test/test-catch-text/main.cpp +++ b/module-gui/test/test-catch-text/main.cpp @@ -3,16 +3,3 @@ #define CATCH_CONFIG_MAIN #include -#include -#include - -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; diff --git a/module-gui/test/test-catch-text/test-gui-Text.cpp b/module-gui/test/test-catch-text/test-gui-Text.cpp index e5463b9f66d4b071e06359c257655be440da120b..234aac106ede6c28daecb3c9434e4c4801449b91 100644 --- a/module-gui/test/test-catch-text/test-gui-Text.cpp +++ b/module-gui/test/test-catch-text/test-gui-Text.cpp @@ -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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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 = - "Test String Test String 1

Test String 2"; 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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 = - "Test String Test String 1

Test String 2"; SECTION("Adding text to 0 line size text") { mockup::fontManager(); using namespace gui; - auto text = new gui::TestText(); + auto text = std::make_unique(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); unsigned int signsLimit = 100; diff --git a/module-gui/test/test-catch-text/test-gui-TextLine.cpp b/module-gui/test/test-catch-text/test-gui-TextLine.cpp index f7f9a6b5baf686eb37a9d9f17c8e230db9d88939..f90274b76a0491901b4d723b1c13e4e7eb3852bd 100644 --- a/module-gui/test/test-catch-text/test-gui-TextLine.cpp +++ b/module-gui/test/test-catch-text/test-gui-TextLine.cpp @@ -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(&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(&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(&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(&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(&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(&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(&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(&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(&document, 0, 0, nullptr); auto text_line = TextLine(*cursor, maxWidth); REQUIRE(text_line.length() > 0); diff --git a/module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp b/module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp index db5e79cd0773ad4433b5bf4ef5f2c2a2c1ebb35b..ac9dfa2bf63be130a5e26daddc70c533cfcbfea1 100644 --- a/module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp +++ b/module-gui/test/test-catch-text/test-gui-TextLineCursor.cpp @@ -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(); 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(); text->setMaximumSize(400, 200); std::tuple 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(); text->setMaximumSize(400, 200); std::tuple selectedLine; @@ -222,7 +222,7 @@ TEST_CASE("TextLineCursor - navigation with scroll") { mockup::fontManager(); - auto text = new gui::TestText(); + auto text = std::make_unique(); 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(); 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(); 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(); 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(); 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(); text->setMaximumSize(400, 90); text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);