summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-08-29 20:26:16 +0300
committerAndrei Karas <akaras@inbox.ru>2016-08-29 20:26:16 +0300
commit9ff7894ef1eeff001f3ddc1a1caec18176428fa1 (patch)
treed6c8dc8dc37d752ac046552ff5e8226fa73a9ed6 /src
parent7e0e97ee7ec31512731cbcef625a040266655062 (diff)
downloadmv-9ff7894ef1eeff001f3ddc1a1caec18176428fa1.tar.gz
mv-9ff7894ef1eeff001f3ddc1a1caec18176428fa1.tar.bz2
mv-9ff7894ef1eeff001f3ddc1a1caec18176428fa1.tar.xz
mv-9ff7894ef1eeff001f3ddc1a1caec18176428fa1.zip
Add some cleanup calls in unit tests.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/browserbox_unittest.cc3
-rw-r--r--src/gui/windowmanager_unittest.cc25
-rw-r--r--src/resources/dye/dye_unittest.cc6
-rw-r--r--src/resources/dye/dyepalette_unittest.cc5
-rw-r--r--src/utils/files_unittest.cc6
-rw-r--r--src/utils/translation/poparser_unittest.cc21
-rw-r--r--src/utils/xml_unittest.cc24
-rw-r--r--src/utils/xmlutils_unittest.cc2
8 files changed, 79 insertions, 13 deletions
diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc
index 9aadeac09..e0ff9e13d 100644
--- a/src/gui/widgets/browserbox_unittest.cc
+++ b/src/gui/widgets/browserbox_unittest.cc
@@ -27,6 +27,8 @@
#include "gui/widgets/browserbox.h"
+#include "resources/resourcemanager/resourcemanager.h"
+
#include "resources/sdlimagehelper.h"
#include <physfs.h>
@@ -43,6 +45,7 @@ TEST_CASE("BrowserBox tests", "browserbox")
logger = new Logger();
imageHelper = new SDLImageHelper();
theme = new Theme;
+ ResourceManager::init();
ActorSprite::load();
Widget::setGlobalFont(new Font("/usr/share/fonts/truetype/"
"ttf-dejavu/DejaVuSans-Oblique.ttf", 18));
diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc
index 37edeb1df..6ae3b0e34 100644
--- a/src/gui/windowmanager_unittest.cc
+++ b/src/gui/windowmanager_unittest.cc
@@ -133,10 +133,10 @@ TEST_CASE("Windows tests", "windowmanager")
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
- delete ResourceManager::instance;
- ResourceManager::instance = nullptr;
+ delete resourceManager;
resourceManager = nullptr;
ResourceManager::init();
+ resourceManager->cleanOrphans(true);
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
branding.setValue("onlineServerFile", "test/serverlistplus.xml");
@@ -228,17 +228,15 @@ TEST_CASE("Windows tests", "windowmanager")
}
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);
-*/
+// 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")
{
@@ -562,6 +560,7 @@ TEST_CASE("Windows tests", "windowmanager")
mainGraphics->updateScreen();
delete2(dialog);
}
+
SECTION("TextDialog")
{
TextDialog *dialog = CREATEWIDGETR(TextDialog,
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index 074854d32..6b6f1719a 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -24,6 +24,8 @@
#include "graphicsmanager.h"
#include "logger.h"
+#include "being/actorsprite.h"
+
#include "resources/sdlimagehelper.h"
#ifdef USE_SDL2
#include "resources/surfaceimagehelper.h"
@@ -38,6 +40,7 @@
#include "resources/resourcemanager/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/env.h"
#include "utils/physfstools.h"
@@ -330,6 +333,8 @@ TEST_CASE("Dye real dye")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif
+ ActorSprite::load();
+
SECTION("B dye")
{
dyeCheck("|B:#FFC88A", "arrow_up_B.png");
@@ -344,4 +349,5 @@ TEST_CASE("Dye real dye")
{
dyeCheck("|A:#0000FFFF,FF000050", "arrow_up_A.png");
}
+ delete2(client);
}
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
index 8689cdf6f..9d9f5fda6 100644
--- a/src/resources/dye/dyepalette_unittest.cc
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -25,6 +25,8 @@
#include "logger.h"
#include "graphicsmanager.h"
+#include "being/actorsprite.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/db/palettedb.h"
@@ -33,6 +35,7 @@
#include "resources/resourcemanager/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/env.h"
#include "utils/physfstools.h"
@@ -65,6 +68,7 @@ TEST_CASE("DyePalette tests")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif
+ ActorSprite::load();
paths.setDefaultValues(getPathsDefaults());
PaletteDB::load();
@@ -367,4 +371,5 @@ TEST_CASE("DyePalette tests")
REQUIRE(palette.mColors[0].value[2] == 46);
REQUIRE(palette.mColors[0].value[3] == 0x77);
}
+ delete2(client);
}
diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc
index 5ccfe0e04..9acd1e059 100644
--- a/src/utils/files_unittest.cc
+++ b/src/utils/files_unittest.cc
@@ -63,6 +63,7 @@ TEST_CASE("Files renameFile")
delete [] buf;
delete [] buf2;
+ ResourceManager::deleteInstance();
}
TEST_CASE("Files existsLocal")
@@ -76,6 +77,7 @@ TEST_CASE("Files existsLocal")
REQUIRE(Files::existsLocal(Files::getPath("help/about.txt")) == true);
REQUIRE_FALSE(Files::existsLocal(Files::getPath("help/about1.txt")));
REQUIRE_FALSE(Files::existsLocal(Files::getPath("help1/about.txt")));
+ ResourceManager::deleteInstance();
}
TEST_CASE("Files loadTextFileString")
@@ -88,6 +90,7 @@ TEST_CASE("Files loadTextFileString")
resourceManager->addToSearchPath("../data", Append_false);
REQUIRE(Files::loadTextFileString("test/simplefile.txt") ==
"this is test \nfile.");
+ ResourceManager::deleteInstance();
}
TEST_CASE("Files loadTextFile")
@@ -104,6 +107,7 @@ TEST_CASE("Files loadTextFile")
REQUIRE(lines.size() == 2);
REQUIRE(lines[0] == "this is test ");
REQUIRE(lines[1] == "file.");
+ ResourceManager::deleteInstance();
}
TEST_CASE("Files saveTextFile")
@@ -121,6 +125,7 @@ TEST_CASE("Files saveTextFile")
std::string data = Files::loadTextFileString("test/tempfile.txt");
::remove((dir + "/tempfile.txt").c_str());
REQUIRE(data == "test line\ntext line2\n");
+ ResourceManager::deleteInstance();
}
TEST_CASE("Files getFilesInDir")
@@ -149,4 +154,5 @@ TEST_CASE("Files getFilesInDir")
REQUIRE(list[2] == "perserver/default/defaultcommands.xml");
REQUIRE(list[3] == "perserver/default/features.xml");
REQUIRE(list[4] == "perserver/default/weapons.xml");
+ ResourceManager::deleteInstance();
}
diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc
index 0fcf2bae5..d75088ee2 100644
--- a/src/utils/translation/poparser_unittest.cc
+++ b/src/utils/translation/poparser_unittest.cc
@@ -20,19 +20,28 @@
#include "catch.hpp"
#include "client.h"
+#include "graphicsmanager.h"
#include "logger.h"
+#include "being/actorsprite.h"
+
#include "utils/translation/podict.h"
#include "utils/translation/poparser.h"
+#include "resources/sdlimagehelper.h"
+
#include "resources/resourcemanager/resourcemanager.h"
+#include "utils/delete2.h"
+#include "utils/env.h"
#include "utils/physfstools.h"
#include "debug.h"
TEST_CASE("PoParser tests", "PoParser")
{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
client = new Client;
PHYSFS_init("manaplus");
dirSeparator = "/";
@@ -41,6 +50,17 @@ TEST_CASE("PoParser tests", "PoParser")
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ imageHelper = new SDLImageHelper();
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif
+
+ ActorSprite::load();
+
SECTION("PoParser empty")
{
PoParser *parser = new PoParser;
@@ -92,4 +112,5 @@ TEST_CASE("PoParser tests", "PoParser")
delete parser;
delete dict;
}
+ delete2(client);
}
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index e2f68181e..d90bfb37d 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -21,16 +21,27 @@
#include "catch.hpp"
#include "client.h"
#include "logger.h"
+#include "graphicsmanager.h"
+#include "being/actorsprite.h"
+
+#include "gui/theme.h"
+
+#include "utils/delete2.h"
+#include "utils/env.h"
#include "utils/physfstools.h"
#include "utils/xml.h"
+#include "resources/sdlimagehelper.h"
+
#include "resources/resourcemanager/resourcemanager.h"
#include "debug.h"
TEST_CASE("xml doc")
{
+ setEnv("SDL_VIDEODRIVER", "dummy");
+
client = new Client;
PHYSFS_init("manaplus");
dirSeparator = "/";
@@ -39,7 +50,19 @@ TEST_CASE("xml doc")
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ imageHelper = new SDLImageHelper();
+#ifdef USE_SDL2
+ SDLImageHelper::setRenderer(graphicsManager.createRenderer(
+ graphicsManager.createWindow(640, 480, 0,
+ SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
+#else
+ graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
+#endif
+
+ theme = new Theme;
+ Theme::selectSkin();
const char *const tempXmlName = "tempxml.xml";
+ ActorSprite::load();
SECTION("load1")
{
@@ -326,4 +349,5 @@ TEST_CASE("xml doc")
// clean again
::remove(tempXmlName);
}
+ delete2(client);
}
diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc
index 4e78d0b0e..3fc27c598 100644
--- a/src/utils/xmlutils_unittest.cc
+++ b/src/utils/xmlutils_unittest.cc
@@ -58,6 +58,7 @@ TEST_CASE("xmlutils readXmlIntVector 1")
REQUIRE(0 == arr[2]);
REQUIRE(1 == arr[3]);
REQUIRE(1 == arr[4]);
+ ResourceManager::deleteInstance();
}
TEST_CASE("xmlutils readXmlStringMap 1")
@@ -86,4 +87,5 @@ TEST_CASE("xmlutils readXmlStringMap 1")
REQUIRE(arr["Kitty"] == "0");
REQUIRE(arr["xD"] == "1");
REQUIRE(arr["Metal"] == "26");
+ ResourceManager::deleteInstance();
}