summaryrefslogtreecommitdiff
path: root/src/unittests/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-07 17:05:13 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-07 17:53:24 +0300
commit130f07fd84bfdf781eb42903b3fcbabc26199a3a (patch)
treee4e560c32177e0a64867c5d1584d9bf64b57bbce /src/unittests/gui
parent9bbd191307c97c7589f93a64a4eb9abf3f11c46b (diff)
downloadmv-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.gz
mv-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.bz2
mv-130f07fd84bfdf781eb42903b3fcbabc26199a3a.tar.xz
mv-130f07fd84bfdf781eb42903b3fcbabc26199a3a.zip
Move unit tests into unittests directory.
Diffstat (limited to 'src/unittests/gui')
-rw-r--r--src/unittests/gui/fonts/textchunklist_unittest.cc548
-rw-r--r--src/unittests/gui/widgets/browserbox_unittest.cc211
-rw-r--r--src/unittests/gui/windowmanager_unittest.cc984
3 files changed, 1743 insertions, 0 deletions
diff --git a/src/unittests/gui/fonts/textchunklist_unittest.cc b/src/unittests/gui/fonts/textchunklist_unittest.cc
new file mode 100644
index 000000000..c8df87455
--- /dev/null
+++ b/src/unittests/gui/fonts/textchunklist_unittest.cc
@@ -0,0 +1,548 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "unittests/unittests.h"
+
+#include "gui/fonts/font.h"
+#include "gui/fonts/textchunk.h"
+
+#include "debug.h"
+
+TEST_CASE("TextChunkList empty", "TextChunkList")
+{
+ TextChunkList list;
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList add 1", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 3, 4), nullptr);
+
+ list.insertFirst(chunk);
+
+ REQUIRE(1 == list.size);
+ REQUIRE(chunk == list.start);
+ REQUIRE(chunk == list.end);
+ REQUIRE(nullptr == chunk->prev);
+ REQUIRE(nullptr == chunk->next);
+
+ REQUIRE(1 == list.search.size());
+ REQUIRE(chunk == (*list.search.find(TextChunkSmall(
+ chunk->text, chunk->color, chunk->color2))).second);
+
+ REQUIRE(1 == list.searchWidth.size());
+ REQUIRE(chunk == (*list.searchWidth.find(chunk->text)).second);
+ delete chunk;
+}
+
+TEST_CASE("TextChunkList add 2", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(3, 4, 5), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(2, 3, 4), Color(4, 5, 6), nullptr);
+
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk1);
+
+ REQUIRE(2 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk2 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(chunk2 == chunk1->next);
+ REQUIRE(chunk1 == chunk2->prev);
+ REQUIRE(nullptr == chunk2->next);
+
+ REQUIRE(2 == list.search.size());
+ REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
+ chunk1->text, chunk1->color, chunk1->color2))).second);
+ REQUIRE(chunk2 == (*list.search.find(TextChunkSmall(
+ chunk2->text, chunk2->color, chunk2->color2))).second);
+
+ REQUIRE(1 == list.searchWidth.size());
+ REQUIRE(chunk1 == (*list.searchWidth.find(chunk1->text)).second);
+ delete chunk1;
+ delete chunk2;
+}
+
+TEST_CASE("TextChunkList addRemoveBack 1", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+
+ list.insertFirst(chunk);
+ list.removeBack();
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList addRemoveBack 2", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(1, 2, 4), Color(1, 2, 5), nullptr);
+
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk1);
+ list.removeBack();
+
+ REQUIRE(1 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk1 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(nullptr == chunk1->next);
+
+ REQUIRE(1 == list.search.size());
+ REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
+ chunk1->text, chunk1->color, chunk1->color2))).second);
+
+ REQUIRE(1 == list.searchWidth.size());
+ REQUIRE(chunk1 == (*list.searchWidth.find(chunk1->text)).second);
+ delete chunk1;
+}
+
+TEST_CASE("TextChunkList addRemoveBack 3", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(2, 3, 4), Color(2, 3, 4), nullptr);
+
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk1);
+ list.removeBack(2);
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList addRemoveBack 4", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(2, 3, 4), Color(2, 3, 4), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test",
+ Color(3, 4, 5), Color(3, 4, 5), nullptr);
+
+ list.insertFirst(chunk3);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk1);
+ list.removeBack();
+ list.removeBack();
+
+ REQUIRE(1 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk1 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(nullptr == chunk1->next);
+
+ REQUIRE(1 == list.search.size());
+ REQUIRE(chunk1 == (*list.search.find(TextChunkSmall(
+ chunk1->text, chunk1->color, chunk1->color2))).second);
+
+ REQUIRE(list.searchWidth.empty());
+ delete chunk1;
+}
+
+TEST_CASE("TextChunkList moveToFirst 1", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 3, 4), nullptr);
+
+ list.insertFirst(chunk);
+ list.moveToFirst(chunk);
+
+ REQUIRE(1 == list.size);
+ REQUIRE(chunk == list.start);
+ REQUIRE(chunk == list.end);
+ REQUIRE(nullptr == chunk->prev);
+ REQUIRE(nullptr == chunk->next);
+ delete chunk;
+}
+
+TEST_CASE("TextChunkList moveToFirst 2", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(2, 3, 4), Color(1, 2, 3), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.moveToFirst(chunk1);
+
+ REQUIRE(2 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk2 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(chunk2 == chunk1->next);
+ REQUIRE(chunk1 == chunk2->prev);
+ REQUIRE(nullptr == chunk2->next);
+ delete chunk1;
+ delete chunk2;
+}
+
+TEST_CASE("TextChunkList moveToFirst 3", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(1, 2, 4), Color(1, 2, 3), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test",
+ Color(1, 2, 5), Color(1, 2, 3), nullptr);
+
+ list.insertFirst(chunk3);
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.moveToFirst(chunk1);
+
+ REQUIRE(3 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk3 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(chunk2 == chunk1->next);
+ REQUIRE(chunk1 == chunk2->prev);
+ REQUIRE(chunk3 == chunk2->next);
+ REQUIRE(chunk2 == chunk3->prev);
+ REQUIRE(nullptr == chunk3->next);
+ delete chunk1;
+ delete chunk2;
+ delete chunk3;
+}
+
+TEST_CASE("TextChunkList moveToFirst 4", "TextChunkList")
+{
+ TextChunkList list;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(), Color(), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(), Color(), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test3",
+ Color(), Color(), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk3);
+ list.insertFirst(chunk2);
+ list.moveToFirst(chunk1);
+
+ REQUIRE(3 == list.size);
+ REQUIRE(chunk1 == list.start);
+ REQUIRE(chunk3 == list.end);
+ REQUIRE(nullptr == chunk1->prev);
+ REQUIRE(chunk2 == chunk1->next);
+ REQUIRE(chunk1 == chunk2->prev);
+ REQUIRE(chunk3 == chunk2->next);
+ REQUIRE(chunk2 == chunk3->prev);
+ REQUIRE(nullptr == chunk3->next);
+ delete chunk1;
+ delete chunk2;
+ delete chunk3;
+}
+
+TEST_CASE("TextChunkList clear 1", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk = new TextChunk("test",
+ Color(), Color(), nullptr);
+
+ list.insertFirst(chunk);
+ list.clear();
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+ REQUIRE(chunksLeft == textChunkCnt);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList clear 2", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 0), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 1), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 2), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk3);
+ list.clear();
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+ REQUIRE(chunksLeft == textChunkCnt);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList clear 3", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 0), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 1), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 2), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk3);
+ list.moveToFirst(chunk1);
+ REQUIRE((chunksLeft + 3) == textChunkCnt);
+ REQUIRE(3 == list.search.size());
+ REQUIRE(1 == list.searchWidth.size());
+
+ list.removeBack();
+ REQUIRE((chunksLeft + 2) == textChunkCnt);
+ REQUIRE(2 == list.search.size());
+ REQUIRE(list.searchWidth.empty());
+
+ list.clear();
+ REQUIRE(chunksLeft == textChunkCnt);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList clear 4", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk1 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 0), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test",
+ Color(1, 2, 3), Color(2, 0, 1), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test3",
+ Color(1, 2, 3), Color(2, 0, 2), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk3);
+ list.moveToFirst(chunk2);
+ REQUIRE((chunksLeft + 3) == textChunkCnt);
+ REQUIRE(3 == list.search.size());
+ REQUIRE(2 == list.searchWidth.size());
+
+ list.removeBack(2);
+ REQUIRE((chunksLeft + 1) == textChunkCnt);
+ REQUIRE(1 == list.search.size());
+ REQUIRE(list.searchWidth.empty());
+
+ list.clear();
+ REQUIRE(chunksLeft == textChunkCnt);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList remove 1", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk = new TextChunk("test",
+ Color(), Color(), nullptr);
+
+ list.insertFirst(chunk);
+ list.remove(chunk);
+ delete chunk;
+
+ REQUIRE(0 == list.size);
+ REQUIRE(nullptr == list.start);
+ REQUIRE(nullptr == list.end);
+ REQUIRE(chunksLeft == textChunkCnt);
+ REQUIRE(list.search.empty());
+ REQUIRE(list.searchWidth.empty());
+}
+
+TEST_CASE("TextChunkList remove 2", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk1 = new TextChunk("test1",
+ Color(1, 2, 3), Color(2, 0, 0), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(1, 2, 3), Color(2, 0, 1), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test3",
+ Color(1, 2, 3), Color(2, 0, 2), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk3);
+ list.remove(chunk1);
+ delete chunk1;
+
+ REQUIRE(2 == list.size);
+ REQUIRE(chunk3 == list.start);
+ REQUIRE(chunk2 == list.end);
+ REQUIRE((chunksLeft + 2) == textChunkCnt);
+ REQUIRE(2 == list.search.size());
+ REQUIRE(2 == list.searchWidth.size());
+ delete chunk2;
+ delete chunk3;
+}
+
+TEST_CASE("TextChunkList remove 3", "TextChunkList")
+{
+ TextChunkList list;
+ const int chunksLeft = textChunkCnt;
+
+ TextChunk *const chunk1 = new TextChunk("test1",
+ Color(1, 2, 3), Color(2, 0, 0), nullptr);
+ TextChunk *const chunk2 = new TextChunk("test2",
+ Color(1, 2, 3), Color(2, 0, 1), nullptr);
+ TextChunk *const chunk3 = new TextChunk("test3",
+ Color(1, 2, 3), Color(2, 0, 2), nullptr);
+
+ list.insertFirst(chunk1);
+ list.insertFirst(chunk2);
+ list.insertFirst(chunk3);
+ list.remove(chunk2);
+ delete chunk2;
+
+ REQUIRE(2 == list.size);
+ REQUIRE(chunk3 == list.start);
+ REQUIRE(chunk1 == list.end);
+ REQUIRE((chunksLeft + 2) == textChunkCnt);
+ REQUIRE(2 == list.search.size());
+ REQUIRE(2 == list.searchWidth.size());
+ delete chunk1;
+ delete chunk3;
+}
+
+TEST_CASE("TextChunkList sort 1", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item3("test line2",
+ Color(1, 2, 3), Color(1, 2, 3));
+ REQUIRE(false == (item1 < item2));
+ REQUIRE(false == (item2 < item1));
+ REQUIRE(item1 < item3);
+ REQUIRE(false == (item3 < item1));
+}
+
+TEST_CASE("TextChunkList sort 2", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(2, 3, 4), Color(1, 2, 3));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
+
+TEST_CASE("TextChunkList sort 3", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 3, 4), Color(1, 2, 3));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
+
+TEST_CASE("TextChunkList sort 4", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 2, 4), Color(1, 2, 3));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
+
+TEST_CASE("TextChunkList sort 5", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 2, 3), Color(2, 2, 3));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
+
+TEST_CASE("TextChunkList sort 6", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 2, 3), Color(1, 3, 3));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
+
+TEST_CASE("TextChunkList sort 7", "TextChunkList")
+{
+ TextChunkSmall item1("test line1",
+ Color(1, 2, 3), Color(1, 2, 3));
+ TextChunkSmall item2("test line1",
+ Color(1, 2, 3), Color(1, 2, 4));
+ REQUIRE(item1 < item2);
+ REQUIRE(false == (item2 < item1));
+}
diff --git a/src/unittests/gui/widgets/browserbox_unittest.cc b/src/unittests/gui/widgets/browserbox_unittest.cc
new file mode 100644
index 000000000..128c7a52c
--- /dev/null
+++ b/src/unittests/gui/widgets/browserbox_unittest.cc
@@ -0,0 +1,211 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "unittests/unittests.h"
+
+#include "client.h"
+#include "configuration.h"
+#include "configmanager.h"
+#include "dirs.h"
+#include "graphicsmanager.h"
+
+#include "being/actorsprite.h"
+
+#include "fs/virtfs/fs.h"
+
+#include "gui/gui.h"
+
+#include "gui/fonts/font.h"
+
+#include "gui/widgets/browserbox.h"
+
+#include "utils/delete2.h"
+#include "utils/env.h"
+
+#include "render/sdlgraphics.h"
+
+#include "resources/resourcemanager/resourcemanager.h"
+
+#include "resources/sdlimagehelper.h"
+
+#include "debug.h"
+
+TEST_CASE("BrowserBox leak test1", "")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
+TEST_CASE("BrowserBox tests", "browserbox")
+{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
+ client = new Client;
+ logger = new Logger();
+ VirtFs::mountDirSilent("data", Append_false);
+ VirtFs::mountDirSilent("../data", Append_false);
+
+ mainGraphics = new SDLGraphics;
+ imageHelper = new SDLImageHelper;
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else // USE_SDL2
+
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif // USE_SDL2
+
+ theme = new Theme;
+ Theme::selectSkin();
+
+ Dirs::initRootDir();
+ Dirs::initHomeDir();
+
+ ConfigManager::initConfiguration();
+ getConfigDefaults2(config.getDefaultValues());
+ branding.setDefaultValues(getBrandingDefaults());
+
+ ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
+
+ Widget::setGlobalFont(new Font("/usr/share/fonts/truetype/"
+ "ttf-dejavu/DejaVuSans-Oblique.ttf", 18));
+ BrowserBox *const box = new BrowserBox(nullptr,
+ Opaque_true,
+ "");
+ box->setWidth(100);
+ std::string row = "test";
+ box->addRow(row);
+ REQUIRE(box->hasRows() == true);
+ box->clearRows();
+ row = "@@";
+ box->addRow(row);
+ row = "@@|";
+ box->addRow(row);
+ row = "|@@";
+ box->addRow(row);
+ row = "@@|@@";
+ box->addRow(row);
+ row = "|@@@@";
+ box->addRow(row);
+ row = "@@11|22@@";
+ box->addRow(row);
+ row = "##@@11|22@@";
+ box->addRow(row);
+ row = "@@##|22@@";
+ box->addRow(row);
+ row = "@@11|##22@@";
+ box->addRow(row);
+ row = "@@11|22##@@";
+ box->addRow(row);
+ row = "@@11|22@@##";
+ box->addRow(row);
+ row = "<##@@11|22@@";
+ box->addRow(row);
+ row = "@@<##|22@@";
+ box->addRow(row);
+ row = "@@11|<##22@@";
+ box->addRow(row);
+ row = "@@11|22<##@@";
+ box->addRow(row);
+ row = "@@11|22@@<##";
+ box->addRow(row);
+ row = "<##11|22@@";
+ box->addRow(row);
+ row = "<##|22@@";
+ box->addRow(row);
+ row = "11|<##22@@";
+ box->addRow(row);
+ row = "11|22<##@@";
+ box->addRow(row);
+ row = "11|22@@<##";
+ box->addRow(row);
+ row = "##>@@11|22@@";
+ box->addRow(row);
+ row = "@@##>|22@@";
+ box->addRow(row);
+ row = "@@11|##>22@@";
+ box->addRow(row);
+ row = "@@11|22##>@@";
+ box->addRow(row);
+ row = "@@11|22@@##>";
+ box->addRow(row);
+ row = "<##11|22##>";
+ box->addRow(row);
+ row = "<##|22##>";
+ box->addRow(row);
+ row = "11|<##22##>";
+ box->addRow(row);
+ row = "11|22<####>";
+ box->addRow(row);
+ row = "11|22##><##";
+ box->addRow(row);
+ row = "%%@@11|22@@";
+ box->addRow(row);
+ row = "%%2@@11|22@@";
+ box->addRow(row);
+ row = "<%%11|22@@";
+ box->addRow(row);
+ row = "@@%%>|22@@";
+ box->addRow(row);
+ row = "<%%|22%%>";
+ box->addRow(row);
+ row = "11|22<%%%%>";
+ box->addRow(row);
+ row = "%%";
+ box->addRow(row);
+ row = "%%1";
+ box->addRow(row);
+ row = "%%##";
+ box->addRow(row);
+ row = "%%###";
+ box->addRow(row);
+ row = "##%%";
+ box->addRow(row);
+ row = "##1%%";
+ box->addRow(row);
+ row = "##%%2";
+ box->addRow(row);
+ row = "##1%%2";
+ box->addRow(row);
+
+ delete Widget::getGloablFont();
+ Widget::setGlobalFont(nullptr);
+ delete box;
+ delete2(client);
+ VirtFs::unmountDirSilent("data");
+ VirtFs::unmountDirSilent("../data");
+ delete2(logger);
+// VirtFs::deinit();
+}
+
+TEST_CASE("BrowserBox leak test2", "")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
diff --git a/src/unittests/gui/windowmanager_unittest.cc b/src/unittests/gui/windowmanager_unittest.cc
new file mode 100644
index 000000000..75949fc44
--- /dev/null
+++ b/src/unittests/gui/windowmanager_unittest.cc
@@ -0,0 +1,984 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "unittests/unittests.h"
+
+#include "client.h"
+#include "configmanager.h"
+#include "configuration.h"
+#include "dirs.h"
+#include "graphicsmanager.h"
+#include "main.h"
+#include "settings.h"
+#include "textcommand.h"
+
+#include "being/localplayer.h"
+
+#include "const/resources/currency.h"
+
+#include "fs/virtfs/fs.h"
+
+#include "gui/gui.h"
+#include "gui/mailmessage.h"
+#include "gui/userpalette.h"
+#include "gui/windowmanager.h"
+
+#include "gui/popups/beingpopup.h"
+#include "gui/popups/itempopup.h"
+#include "gui/popups/popupmenu.h"
+#include "gui/popups/skillpopup.h"
+#include "gui/popups/spellpopup.h"
+#include "gui/popups/speechbubble.h"
+#include "gui/popups/statuspopup.h"
+#include "gui/popups/textboxpopup.h"
+#include "gui/popups/textpopup.h"
+
+#include "gui/widgets/desktop.h"
+#include "gui/widgets/emoteshortcutcontainer.h"
+#include "gui/widgets/createwidget.h"
+
+#include "gui/windows/bankwindow.h"
+#include "gui/windows/buydialog.h"
+#include "gui/windows/buyingstoreselldialog.h"
+#include "gui/windows/buyselldialog.h"
+#include "gui/windows/charselectdialog.h"
+#include "gui/windows/changeemaildialog.h"
+#include "gui/windows/changepassworddialog.h"
+#include "gui/windows/chatwindow.h"
+#include "gui/windows/connectiondialog.h"
+#include "gui/windows/confirmdialog.h"
+#include "gui/windows/cutinwindow.h"
+#include "gui/windows/debugwindow.h"
+#include "gui/windows/didyouknowwindow.h"
+#include "gui/windows/editdialog.h"
+#include "gui/windows/editserverdialog.h"
+#include "gui/windows/eggselectiondialog.h"
+#include "gui/windows/emotewindow.h"
+#include "gui/windows/equipmentwindow.h"
+#include "gui/windows/helpwindow.h"
+#include "gui/windows/insertcarddialog.h"
+#include "gui/windows/inventorywindow.h"
+#include "gui/windows/itemamountwindow.h"
+#include "gui/windows/killstats.h"
+#include "gui/windows/logindialog.h"
+#include "gui/windows/maileditwindow.h"
+#include "gui/windows/mailviewwindow.h"
+#include "gui/windows/mailwindow.h"
+#include "gui/windows/minimap.h"
+#include "gui/windows/ministatuswindow.h"
+#include "gui/windows/npcdialog.h"
+#include "gui/windows/npcselldialog.h"
+#include "gui/windows/okdialog.h"
+#include "gui/windows/outfitwindow.h"
+#include "gui/windows/questswindow.h"
+#include "gui/windows/quitdialog.h"
+#include "gui/windows/registerdialog.h"
+#include "gui/windows/serverdialog.h"
+#include "gui/windows/serverinfowindow.h"
+#include "gui/windows/setupwindow.h"
+#include "gui/windows/shopwindow.h"
+#include "gui/windows/shortcutwindow.h"
+#include "gui/windows/skilldialog.h"
+#include "gui/windows/socialwindow.h"
+#include "gui/windows/statuswindow.h"
+#include "gui/windows/textcommandeditor.h"
+#include "gui/windows/textdialog.h"
+#include "gui/windows/textselectdialog.h"
+#include "gui/windows/tradewindow.h"
+#include "gui/windows/updaterwindow.h"
+#include "gui/windows/whoisonline.h"
+#include "gui/windows/worldselectdialog.h"
+
+#include "input/touch/touchmanager.h"
+
+#include "net/logindata.h"
+
+#include "net/eathena/charserverhandler.h"
+#include "net/eathena/inventoryhandler.h"
+#include "net/eathena/serverfeatures.h"
+#include "net/eathena/playerhandler.h"
+
+#include "render/sdlgraphics.h"
+
+#include "resources/sdlimagehelper.h"
+
+#include "resources/db/unitsdb.h"
+
+#include "resources/item/item.h"
+
+#include "resources/map/map.h"
+
+#include "resources/resourcemanager/resourcemanager.h"
+
+#include "utils/delete2.h"
+#include "utils/env.h"
+#include "utils/gettext.h"
+
+#include "utils/translation/translationmanager.h"
+
+#include "debug.h"
+
+extern QuitDialog *quitDialog;
+
+TEST_CASE("windows leak test1", "")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}
+
+TEST_CASE("Windows tests", "windowmanager")
+{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
+ client = new Client;
+ XML::initXML();
+ SDL_Init(SDL_INIT_VIDEO);
+ logger = new Logger();
+ ResourceManager::deleteInstance();
+ ResourceManager::cleanOrphans(true);
+ VirtFs::mountDirSilent("data", Append_false);
+ VirtFs::mountDirSilent("../data", Append_false);
+ VirtFs::mountDirSilent("data/test", Append_false);
+ VirtFs::mountDirSilent("../data/test", Append_false);
+ paths.setDefaultValues(getPathsDefaults());
+ branding.setValue("onlineServerFile", "test/serverlistplus.xml");
+ mainGraphics = new SDLGraphics;
+ imageHelper = new SDLImageHelper;
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else // USE_SDL2
+
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif // USE_SDL2
+
+ userPalette = new UserPalette;
+ config.setValue("fontSize", 16);
+ theme = new Theme;
+ Theme::selectSkin();
+
+ Dirs::initRootDir();
+ Dirs::initHomeDir();
+
+ const std::string cfgName = settings.configDir +
+ "/nonexistserver/config.xml";
+ ::remove(cfgName.c_str());
+
+ ConfigManager::initConfiguration();
+ getConfigDefaults2(config.getDefaultValues());
+ branding.setDefaultValues(getBrandingDefaults());
+ ConfigManager::initServerConfig("nonexistserver");
+
+ localPlayer = new LocalPlayer(static_cast<BeingId>(1),
+ BeingTypeId_zero);
+
+ ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
+ touchManager.init();
+ UnitsDb::loadUnits();
+ charServerHandler = new EAthena::CharServerHandler;
+ serverFeatures = new EAthena::ServerFeatures;
+ inventoryHandler = new EAthena::InventoryHandler;
+ playerHandler = new EAthena::PlayerHandler;
+ paths.setValue("itemIcons", "");
+
+ TranslationManager::init();
+
+ mainGraphics->setVideoMode(640, 480, 1, 8, false, false, false, false);
+
+ SECTION("bankWindow")
+ {
+ CREATEWIDGETV0(bankWindow, BankWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(bankWindow);
+ }
+ SECTION("buyDialog1")
+ {
+ BuyDialog *dialog;
+ CREATEWIDGETV0(dialog, BuyDialog);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("buyDialog2")
+ {
+ BuyDialog *dialog;
+ CREATEWIDGETV(dialog, BuyDialog,
+ BeingId_zero,
+ DEFAULT_CURRENCY);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+#ifdef TMWA_SUPPORT
+ SECTION("buyDialog3")
+ {
+ BuyDialog *dialog;
+ CREATEWIDGETV(dialog, BuyDialog,
+ "user",
+ DEFAULT_CURRENCY);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+#endif // TMWA_SUPPORT
+ SECTION("buyDialog4")
+ {
+ BuyDialog *dialog;
+ BeingTypeId id = static_cast<BeingTypeId>(1);
+ Map *map = new Map("test map",
+ 10, 10,
+ 32, 32);
+ Being *being = Being::createBeing(BeingId_zero,
+ ActorType::Avatar,
+ id,
+ map);
+ CREATEWIDGETV(dialog, BuyDialog,
+ being,
+ DEFAULT_CURRENCY);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(being);
+ }
+ SECTION("BuyingStoreSellDialog")
+ {
+ BuyingStoreSellDialog *dialog;
+ CREATEWIDGETV(dialog, BuyingStoreSellDialog,
+ BeingId_zero, 0);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("BuySellDialog1")
+ {
+ BuySellDialog *dialog;
+ CREATEWIDGETV(dialog, BuySellDialog, BeingId_zero);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("BuySellDialog2")
+ {
+ BuySellDialog *dialog;
+ CREATEWIDGETV(dialog, BuySellDialog, "user");
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("ChangeEmailDialog")
+ {
+ LoginData data;
+ ChangeEmailDialog *dialog;
+ CREATEWIDGETV(dialog, ChangeEmailDialog, data);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("ChangePasswordDialog")
+ {
+ LoginData data;
+ ChangePasswordDialog *dialog;
+ CREATEWIDGETV(dialog, ChangePasswordDialog, data);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("CharSelectDialog")
+ {
+ LoginData data;
+ CharSelectDialog *dialog;
+ CREATEWIDGETV(dialog, CharSelectDialog, data);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("CharCreateDialog")
+ {
+// LoginData data;
+// CharSelectDialog *dialog2;
+// CREATEWIDGETV(dialog2, CharSelectDialog, data);
+// CharCreateDialog *dialog;
+// CREATEWIDGETV(dialog, CharCreateDialog, dialog2, 0);
+// gui->draw();
+// mainGraphics->updateScreen();
+// delete2(dialog);
+// delete2(dialog2);
+ }
+ SECTION("ChatWindow")
+ {
+ CREATEWIDGETV(chatWindow, ChatWindow,
+ "Chat");
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(chatWindow);
+ }
+ SECTION("ConfirmDialog")
+ {
+ ConfirmDialog *dialog;
+ CREATEWIDGETV(dialog, ConfirmDialog,
+ "", "", "", false, Modal_false, nullptr);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("CutinWindow")
+ {
+ CREATEWIDGETV0(cutInWindow, CutInWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(cutInWindow);
+ }
+ SECTION("DebugWindow")
+ {
+ CREATEWIDGETV0(debugWindow, DebugWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(debugWindow);
+ }
+ SECTION("didYouKnowWindow")
+ {
+ CREATEWIDGETV0(didYouKnowWindow, DidYouKnowWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(didYouKnowWindow);
+ }
+ SECTION("EditDialog")
+ {
+ EditDialog *dialog;
+ CREATEWIDGETV(dialog, EditDialog,
+ "", "", "", 100, nullptr, Modal_false);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("EditServerDialog")
+ {
+ ServerInfo mCurrentServer;
+ settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
+ ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
+ &mCurrentServer,
+ settings.configDir);
+ EditServerDialog *editServerDialog = CREATEWIDGETR(EditServerDialog,
+ serverDialog, mCurrentServer, 0);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(editServerDialog);
+ delete2(serverDialog);
+ }
+ SECTION("EggSelectionDialog")
+ {
+ EggSelectionDialog *dialog = CREATEWIDGETR0(EggSelectionDialog);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("EmoteWindow")
+ {
+ EmoteWindow *dialog = CREATEWIDGETR0(EmoteWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("EquipmentWindow")
+ {
+ Equipment *equipment = new Equipment;
+ Map *map = new Map("test", 100, 100, 32, 32);
+ Being *being = Being::createBeing(BeingId_zero,
+ ActorType::Player,
+ BeingTypeId_zero,
+ map);
+ EquipmentWindow *dialog = CREATEWIDGETR(EquipmentWindow,
+ equipment, being, false);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(being);
+ delete2(map);
+ delete2(equipment);
+ }
+ SECTION("helpWindow")
+ {
+ CREATEWIDGETV0(helpWindow, HelpWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(helpWindow);
+ }
+ SECTION("InsertCardDialog")
+ {
+ Item *item = new Item(5000,
+ ItemType::Card,
+ 1,
+ 0,
+ ItemColor_one,
+ Identified_true,
+ Damaged_false,
+ Favorite_false,
+ Equipm_true,
+ Equipped_false);
+ InsertCardDialog *dialog = CREATEWIDGETR(InsertCardDialog,
+ 0, item);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(item);
+ }
+ SECTION("InventoryWindow")
+ {
+ Inventory *inventory = new Inventory(InventoryType::Inventory);
+ InventoryWindow *dialog = CREATEWIDGETR(InventoryWindow,
+ inventory);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(inventory);
+ }
+ SECTION("ItemAmountWindow")
+ {
+ Item *item = new Item(5000,
+ ItemType::Card,
+ 1,
+ 0,
+ ItemColor_one,
+ Identified_true,
+ Damaged_false,
+ Favorite_false,
+ Equipm_true,
+ Equipped_false);
+ ItemAmountWindow *dialog = CREATEWIDGETR(ItemAmountWindow,
+ ItemAmountWindowUsage::ItemDrop, nullptr, item);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(item);
+ }
+ SECTION("KillStats")
+ {
+ CREATEWIDGETV0(killStats, KillStats);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(killStats);
+ }
+ SECTION("loginDialog")
+ {
+ ServerInfo mCurrentServer;
+ LoginDialog *loginDialog = CREATEWIDGETR(LoginDialog,
+ loginData,
+ &mCurrentServer,
+ &settings.options.updateHost);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(loginDialog);
+ }
+ SECTION("MailEditWindow")
+ {
+ CREATEWIDGETV0(mailEditWindow, MailEditWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(mailEditWindow);
+ }
+ SECTION("MailViewWindow")
+ {
+ MailMessage *message = new MailMessage;
+ CREATEWIDGETV(mailViewWindow, MailViewWindow,
+ message);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(mailViewWindow);
+ }
+ SECTION("MailWindow")
+ {
+ CREATEWIDGETV0(mailWindow, MailWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(mailWindow);
+ }
+ SECTION("Minimap")
+ {
+ CREATEWIDGETV0(minimap, Minimap);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(minimap);
+ }
+ SECTION("MiniStatusWindow")
+ {
+ CREATEWIDGETV0(miniStatusWindow, MiniStatusWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(miniStatusWindow);
+ }
+ SECTION("NpcDialog")
+ {
+ NpcDialog *dialog = CREATEWIDGETR(NpcDialog, BeingId_zero);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("NpcSellDialog")
+ {
+ NpcSellDialog *dialog = CREATEWIDGETR(NpcSellDialog, BeingId_zero);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("OkDialog")
+ {
+ OkDialog *dialog = CREATEWIDGETR(OkDialog,
+ "", "", "", DialogType::SILENCE, Modal_false,
+ ShowCenter_true, nullptr, 100);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("OutfitWindow")
+ {
+ CREATEWIDGETV0(outfitWindow, OutfitWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(outfitWindow);
+ }
+ SECTION("QuestsWindow")
+ {
+ CREATEWIDGETV0(questsWindow, QuestsWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(questsWindow);
+ }
+ SECTION("QuitDialog")
+ {
+ CREATEWIDGETV(quitDialog, QuitDialog,
+ &quitDialog);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(quitDialog);
+ }
+ SECTION("RegisterDialog")
+ {
+ RegisterDialog *dialog = CREATEWIDGETR(RegisterDialog,
+ loginData);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("serversDialog")
+ {
+ ServerInfo mCurrentServer;
+ settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml");
+ ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog,
+ &mCurrentServer,
+ settings.configDir);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(serverDialog);
+ }
+ SECTION("serversInfoWindow")
+ {
+ ServerInfo mCurrentServer;
+ CREATEWIDGETV(serverInfoWindow, ServerInfoWindow,
+ mCurrentServer);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(serverInfoWindow);
+ }
+ SECTION("setupWindow")
+ {
+ CREATEWIDGETV0(setupWindow, SetupWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(setupWindow);
+ }
+ SECTION("ShopSellDialog")
+ {
+ // only tmwa skipping
+ }
+ SECTION("ShopWindow")
+ {
+ CREATEWIDGETV0(shopWindow, ShopWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(shopWindow);
+ }
+ SECTION("ShortcutWindow1")
+ {
+ EmoteShortcutContainer *container =
+ new EmoteShortcutContainer(nullptr);
+ CREATEWIDGETV(itemShortcutWindow, ShortcutWindow,
+ "name",
+ container);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(itemShortcutWindow);
+ }
+ SECTION("ShortcutWindow2")
+ {
+ CREATEWIDGETV(itemShortcutWindow, ShortcutWindow, "");
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(itemShortcutWindow);
+ }
+ SECTION("SkillDialog")
+ {
+ CREATEWIDGETV0(skillDialog, SkillDialog);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(skillDialog);
+ }
+ SECTION("SocialWindow")
+ {
+ CREATEWIDGETV0(socialWindow, SocialWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(socialWindow);
+ }
+ SECTION("StatusWindow")
+ {
+ CREATEWIDGETV0(statusWindow, StatusWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(statusWindow);
+ }
+ SECTION("TextCommandEditor")
+ {
+ TextCommand *textCommand = new TextCommand(1, "", "", "",
+ CommandTarget::NoTarget, "");
+ TextCommandEditor *dialog = CREATEWIDGETR(TextCommandEditor,
+ textCommand);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ delete2(textCommand);
+ }
+
+ SECTION("TextDialog")
+ {
+ TextDialog *dialog = CREATEWIDGETR(TextDialog,
+ "", "", nullptr, false);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("TextSelectDialog")
+ {
+ TextSelectDialog *dialog = CREATEWIDGETR(TextSelectDialog,
+ "", "", AllowQuit_false);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("TradeWindow")
+ {
+ CREATEWIDGETV0(tradeWindow, TradeWindow);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(tradeWindow);
+ }
+ SECTION("UpdaterWindow")
+ {
+ CREATEWIDGETV(updaterWindow, UpdaterWindow,
+ "", "", false, UpdateType::Skip);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(updaterWindow);
+ }
+ SECTION("WhoIsOnline")
+ {
+ CREATEWIDGETV0(whoIsOnline, WhoIsOnline);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(whoIsOnline);
+ }
+ SECTION("WorldSelectDialog")
+ {
+ Worlds worlds;
+ WorldSelectDialog *dialog = CREATEWIDGETR(WorldSelectDialog,
+ worlds);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(dialog);
+ }
+ SECTION("popupMenu")
+ {
+ CREATEWIDGETV0(popupMenu, PopupMenu);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(popupMenu);
+ }
+ SECTION("skillPopup")
+ {
+ CREATEWIDGETV0(skillPopup, SkillPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(skillPopup);
+ }
+ SECTION("SpeechBubble")
+ {
+ SpeechBubble *bubble = CREATEWIDGETR0(SpeechBubble);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(bubble);
+ }
+ SECTION("beingPopup")
+ {
+ CREATEWIDGETV0(beingPopup, BeingPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(beingPopup);
+ }
+ SECTION("textPopup")
+ {
+ CREATEWIDGETV0(textPopup, TextPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(textPopup);
+ }
+ SECTION("textBoxPopup")
+ {
+ CREATEWIDGETV0(textBoxPopup, TextBoxPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(textBoxPopup);
+ }
+ SECTION("itemPopup")
+ {
+ CREATEWIDGETV0(itemPopup, ItemPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(itemPopup);
+ }
+ SECTION("spellPopup")
+ {
+ CREATEWIDGETV0(spellPopup, SpellPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(spellPopup);
+ }
+ SECTION("StatusPopup")
+ {
+ StatusPopup *status = CREATEWIDGETR0(StatusPopup);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(status);
+ }
+ SECTION("desktop")
+ {
+ CREATEWIDGETV(desktop, Desktop, nullptr);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(desktop);
+ }
+ SECTION("connectionDialog")
+ {
+ ConnectionDialog *connectionDialog = CREATEWIDGETR(ConnectionDialog,
+ // TRANSLATORS: connection dialog header
+ _("Logging in"),
+ State::SWITCH_SERVER);
+ gui->draw();
+ mainGraphics->updateScreen();
+ delete2(connectionDialog);
+ }
+
+ delete2(localPlayer);
+ delete2(userPalette);
+ delete2(client);
+ delete2(serverFeatures);
+ delete2(inventoryHandler);
+ delete2(charServerHandler);
+ delete2(playerHandler);
+ delete2(gui);
+ ResourceManager::deleteInstance();
+ VirtFs::unmountDirSilent("data");
+ VirtFs::unmountDirSilent("../data");
+ VirtFs::unmountDirSilent("data/test");
+ VirtFs::unmountDirSilent("../data/test");
+ delete2(logger);
+
+// VirtFs::deinit();
+}
+
+TEST_CASE("WindowManager", "create windows")
+{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
+ client = new Client;
+ XML::initXML();
+ SDL_Init(SDL_INIT_VIDEO);
+ logger = new Logger();
+ ResourceManager::deleteInstance();
+ ResourceManager::cleanOrphans(true);
+ VirtFs::mountDirSilent("data", Append_false);
+ VirtFs::mountDirSilent("../data", Append_false);
+ VirtFs::mountDirSilent("data/test", Append_false);
+ VirtFs::mountDirSilent("../data/test", Append_false);
+ paths.setDefaultValues(getPathsDefaults());
+ branding.setValue("onlineServerFile", "test/serverlistplus.xml");
+ mainGraphics = new SDLGraphics;
+ imageHelper = new SDLImageHelper;
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else // USE_SDL2
+
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif // USE_SDL2
+
+ config.setValue("fontSize", 16);
+ theme = new Theme;
+ Theme::selectSkin();
+
+ Dirs::initRootDir();
+ Dirs::initHomeDir();
+
+ const std::string cfgName = settings.configDir +
+ "/nonexistserver/config.xml";
+ ::remove(cfgName.c_str());
+
+ ConfigManager::initConfiguration();
+ getConfigDefaults2(config.getDefaultValues());
+ branding.setDefaultValues(getBrandingDefaults());
+ ConfigManager::initServerConfig("nonexistserver");
+
+ localPlayer = new LocalPlayer(static_cast<BeingId>(1),
+ BeingTypeId_zero);
+
+ ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
+ touchManager.init();
+ UnitsDb::loadUnits();
+ charServerHandler = new EAthena::CharServerHandler;
+ serverFeatures = new EAthena::ServerFeatures;
+ inventoryHandler = new EAthena::InventoryHandler;
+ playerHandler = new EAthena::PlayerHandler;
+ paths.setValue("itemIcons", "");
+
+ TranslationManager::init();
+
+ mainGraphics->setVideoMode(640, 480, 1, 8, false, false, false, false);
+
+ SECTION("create windows")
+ {
+ WindowManager::createWindows();
+ WindowManager::deleteWindows();
+ }
+
+ SECTION("init")
+ {
+ WindowManager::init();
+ }
+
+ SECTION("initTitle")
+ {
+ WindowManager::initTitle();
+ REQUIRE(settings.windowCaption == strprintf("%s %s",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION));
+ }
+
+ SECTION("updateTitle1")
+ {
+ settings.serverName = std::string();
+ settings.login = std::string();
+ WindowManager::updateTitle();
+ REQUIRE(settings.windowCaption == strprintf("%s %s",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION));
+ }
+
+ SECTION("updateTitle2")
+ {
+ settings.serverName = "server";
+ settings.login = std::string();
+ WindowManager::updateTitle();
+ REQUIRE(settings.windowCaption == strprintf("%s %s - %s",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION,
+ settings.serverName.c_str()));
+ }
+
+ SECTION("updateTitle3")
+ {
+ settings.serverName = "server";
+ settings.login = "login";
+ WindowManager::updateTitle();
+ REQUIRE(settings.windowCaption == strprintf("%s %s - %s %s",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION,
+ settings.login.c_str(),
+ settings.serverName.c_str()));
+ }
+
+ SECTION("setFramerate1")
+ {
+ settings.limitFps = true;
+ WindowManager::setFramerate(60);
+ REQUIRE(WindowManager::getFramerate() == 60);
+ WindowManager::setFramerate(10);
+ REQUIRE(WindowManager::getFramerate() == 10);
+ WindowManager::setFramerate(0);
+ REQUIRE(WindowManager::getFramerate() == 10);
+ }
+
+ SECTION("setFramerate2")
+ {
+ settings.limitFps = false;
+ WindowManager::setFramerate(60);
+ REQUIRE(WindowManager::getFramerate() == 0);
+ WindowManager::setFramerate(10);
+ REQUIRE(WindowManager::getFramerate() == 0);
+ WindowManager::setFramerate(0);
+ REQUIRE(WindowManager::getFramerate() == 0);
+ }
+
+ settings.serverName = std::string();
+ settings.login = std::string();
+ settings.limitFps = true;
+
+ delete2(localPlayer);
+ delete2(client);
+ delete2(serverFeatures);
+ delete2(inventoryHandler);
+ delete2(charServerHandler);
+ delete2(playerHandler);
+ delete2(gui);
+ ResourceManager::deleteInstance();
+ VirtFs::unmountDirSilent("data");
+ VirtFs::unmountDirSilent("../data");
+ VirtFs::unmountDirSilent("data/test");
+ VirtFs::unmountDirSilent("../data/test");
+ delete2(logger);
+
+// VirtFs::deinit();
+}
+
+TEST_CASE("windows leak test2", "")
+{
+ logger = new Logger();
+ REQUIRE(gui == nullptr);
+ ResourceManager::cleanOrphans(true);
+ ResourceManager::deleteInstance();
+ delete2(logger);
+}