summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-01-05 17:00:02 +0300
committerAndrei Karas <akaras@inbox.ru>2017-01-05 17:00:02 +0300
commit855387d2d795c9471587cc7ddf2c66bb676d698e (patch)
tree3dbb1260c219312f36893dfae52f5cd40760aeb5
parent9fefb2942865846ccb7dbdac4ebd4515b8c851a2 (diff)
downloadplus-855387d2d795c9471587cc7ddf2c66bb676d698e.tar.gz
plus-855387d2d795c9471587cc7ddf2c66bb676d698e.tar.bz2
plus-855387d2d795c9471587cc7ddf2c66bb676d698e.tar.xz
plus-855387d2d795c9471587cc7ddf2c66bb676d698e.zip
Fix different issues in unit tests.
Fix crash with some compilers flags. Clean window container to null after it was removed. Init and deinit physfs globally.
-rw-r--r--src/gui/gui.cpp1
-rw-r--r--src/gui/widgets/browserbox_unittest.cc26
-rw-r--r--src/gui/windowmanager_unittest.cc9
-rw-r--r--src/integrity_unittest.cc1
-rw-r--r--src/main.cpp4
-rw-r--r--src/maingui.cpp14
-rw-r--r--src/resources/dye/dye_unittest.cc1
-rw-r--r--src/resources/dye/dyepalette_unittest.cc11
-rw-r--r--src/resources/resourcemanager/resourcemanager_unittest.cc1
-rw-r--r--src/resources/sprite/animatedsprite_unittest.cc12
-rw-r--r--src/utils/chatutils_unittest.cc8
-rw-r--r--src/utils/files_unittest.cc6
-rw-r--r--src/utils/stringutils_unittest.cc5
-rw-r--r--src/utils/translation/poparser_unittest.cc19
-rw-r--r--src/utils/xml_unittest.cc7
-rw-r--r--src/utils/xmlutils_unittest.cc3
16 files changed, 95 insertions, 33 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 7a9e0e29e..fd3f8bd2a 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -279,6 +279,7 @@ Gui::~Gui()
Widget *top = mTop;
if (Widget::widgetExists(mTop))
setTop(nullptr);
+ Window::setWindowContainer(nullptr);
delete top;
delete2(mGuiFont);
diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc
index 665d6de3f..c58f274e0 100644
--- a/src/gui/widgets/browserbox_unittest.cc
+++ b/src/gui/widgets/browserbox_unittest.cc
@@ -20,13 +20,20 @@
#include "catch.hpp"
#include "client.h"
+#include "graphicsmanager.h"
#include "being/actorsprite.h"
+#include "gui/gui.h"
+
#include "gui/fonts/font.h"
#include "gui/widgets/browserbox.h"
+#include "render/sdlgraphics.h"
+
+#include "resources/sdlimagehelper.h"
+
#include "resources/resourcemanager/resourcemanager.h"
#include "resources/sdlimagehelper.h"
@@ -41,16 +48,31 @@ extern const char *dirSeparator;
TEST_CASE("BrowserBox tests", "browserbox")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
client = new Client;
logger = new Logger();
imageHelper = new SDLImageHelper();
- theme = new Theme;
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../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();
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,
diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc
index 0f8c5bc15..048d23550 100644
--- a/src/gui/windowmanager_unittest.cc
+++ b/src/gui/windowmanager_unittest.cc
@@ -127,7 +127,6 @@ TEST_CASE("Windows tests", "windowmanager")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
@@ -138,6 +137,9 @@ TEST_CASE("Windows tests", "windowmanager")
resourceManager->cleanOrphans(true);
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ resourceManager->addToSearchPath("data/test", Append_false);
+ resourceManager->addToSearchPath("../data/test", Append_false);
+ paths.setDefaultValues(getPathsDefaults());
branding.setValue("onlineServerFile", "test/serverlistplus.xml");
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper;
@@ -150,10 +152,11 @@ TEST_CASE("Windows tests", "windowmanager")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif // USE_SDL2
- ActorSprite::load();
userPalette = new UserPalette;
- theme = new Theme;
config.setValue("fontSize", 16);
+ theme = new Theme;
+ Theme::selectSkin();
+ ActorSprite::load();
gui = new Gui();
gui->postInit(mainGraphics);
touchManager.init();
diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc
index 39fa054f1..54137e6b2 100644
--- a/src/integrity_unittest.cc
+++ b/src/integrity_unittest.cc
@@ -66,7 +66,6 @@ TEST_CASE("integrity tests", "integrity")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
diff --git a/src/main.cpp b/src/main.cpp
index 88330451d..936e63c15 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,10 +22,6 @@
#include "maingui.h"
-#ifdef UNITTESTS
-#define CATCH_CONFIG_MAIN
-#include "catch.hpp"
-#endif // UNITTESTS
#include "debug.h"
#if !defined(UNITTESTS) && !defined(ANDROID)
diff --git a/src/maingui.cpp b/src/maingui.cpp
index e3e7012fd..7f4e1950f 100644
--- a/src/maingui.cpp
+++ b/src/maingui.cpp
@@ -49,6 +49,12 @@
#error missing <SDL_version.h>
#endif // SDL_VERSIONNUM
+#ifdef UNITTESTS
+//#define CATCH_CONFIG_MAIN
+#define CATCH_CONFIG_RUNNER
+#include "catch.hpp"
+#endif // UNITTESTS
+
#define SDL_IMAGE_COMPILEDVERSION \
SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, \
SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL)
@@ -135,4 +141,12 @@ int mainGui(int argc, char *argv[])
return ret;
}
+#else // UNITTESTS
+
+int main(int argc, char *argv[])
+{
+ PhysFs::init(argv[0]);
+ return Catch::Session().run(argc, argv);
+}
+
#endif // UNITTESTS
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index ff79fea52..370800675 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -2354,7 +2354,6 @@ TEST_CASE("Dye real dye")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
index 7e652e43f..5296abb33 100644
--- a/src/resources/dye/dyepalette_unittest.cc
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -27,6 +27,11 @@
#include "being/actorsprite.h"
+#include "gui/gui.h"
+#include "gui/theme.h"
+
+#include "render/sdlgraphics.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/db/palettedb.h"
@@ -50,7 +55,6 @@ TEST_CASE("DyePalette tests")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
@@ -59,6 +63,7 @@ TEST_CASE("DyePalette tests")
resourceManager->addToSearchPath("data/test", Append_false);
resourceManager->addToSearchPath("../data/test", Append_false);
+ mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
@@ -69,7 +74,11 @@ TEST_CASE("DyePalette tests")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif // USE_SDL2
+ theme = new Theme;
+ Theme::selectSkin();
ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
paths.setDefaultValues(getPathsDefaults());
PaletteDB::load();
diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc
index a8b1becc1..2019f20d8 100644
--- a/src/resources/resourcemanager/resourcemanager_unittest.cc
+++ b/src/resources/resourcemanager/resourcemanager_unittest.cc
@@ -88,7 +88,6 @@ TEST_CASE("resourcemanager", "resourcemanager")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc
index bf151308c..a46fad9b0 100644
--- a/src/resources/sprite/animatedsprite_unittest.cc
+++ b/src/resources/sprite/animatedsprite_unittest.cc
@@ -28,8 +28,11 @@
#include "being/actorsprite.h"
+#include "gui/gui.h"
#include "gui/theme.h"
+#include "render/sdlgraphics.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/animation/animation.h"
@@ -52,7 +55,6 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
initRand();
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
@@ -60,8 +62,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
- theme = new Theme;
- Theme::selectSkin();
+ mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
@@ -72,7 +73,11 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif // USE_SDL2
+ theme = new Theme;
+ Theme::selectSkin();
ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
SECTION("basic test 1")
{
@@ -92,6 +97,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
REQUIRE(10 == sprite->getFrameTime());
REQUIRE(0 == sprite->getFrameIndex());
delete sprite;
+ logger->log("test4");
}
SECTION("basic test 2")
diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc
index 2077bfe5e..374bf3125 100644
--- a/src/utils/chatutils_unittest.cc
+++ b/src/utils/chatutils_unittest.cc
@@ -27,12 +27,15 @@
#include "being/localplayer.h"
+#include "gui/gui.h"
#include "gui/theme.h"
#include "utils/chatutils.h"
#include "utils/delete2.h"
#include "utils/physfstools.h"
+#include "render/sdlgraphics.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -46,7 +49,6 @@
TEST_CASE("chatutils replaceVars")
{
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
SDL_Init(SDL_INIT_VIDEO);
@@ -57,6 +59,10 @@ TEST_CASE("chatutils replaceVars")
theme = new Theme;
Theme::selectSkin();
imageHelper = new SDLImageHelper();
+ mainGraphics = new SDLGraphics;
+
+ gui = new Gui();
+ gui->postInit(mainGraphics);
#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
graphicsManager.createWindow(640, 480, 0,
diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc
index 77a7017f6..d0d4fdb1e 100644
--- a/src/utils/files_unittest.cc
+++ b/src/utils/files_unittest.cc
@@ -31,7 +31,6 @@
TEST_CASE("Files renameFile")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
@@ -69,7 +68,6 @@ TEST_CASE("Files renameFile")
TEST_CASE("Files existsLocal")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
@@ -84,7 +82,6 @@ TEST_CASE("Files existsLocal")
TEST_CASE("Files loadTextFileString")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
@@ -98,7 +95,6 @@ TEST_CASE("Files loadTextFileString")
TEST_CASE("Files loadTextFile")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
@@ -116,7 +112,6 @@ TEST_CASE("Files loadTextFile")
TEST_CASE("Files saveTextFile")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
@@ -135,7 +130,6 @@ TEST_CASE("Files saveTextFile")
TEST_CASE("Files getFilesInDir")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 481289087..1cc6049f5 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -19,6 +19,7 @@
*/
#include "catch.hpp"
+#include "configuration.h"
#include "logger.h"
#include "utils/physfstools.h"
@@ -623,15 +624,17 @@ TEST_CASE("stringuntils escapeString")
TEST_CASE("stringuntils replaceItemLinks")
{
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ resourceManager->addToSearchPath("data/test", Append_false);
+ resourceManager->addToSearchPath("../data/test", Append_false);
ItemDB::NamedItemInfos &namedInfos = ItemDB::getNamedItemInfosTest();
ItemDB::ItemInfos &infos = ItemDB::getItemInfosTest();
+ paths.setDefaultValues(getPathsDefaults());
ItemInfo *info = new ItemInfo;
info->setId(123456);
info->setName("test name 1");
diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc
index 9a138c67c..77cb4c22d 100644
--- a/src/utils/translation/poparser_unittest.cc
+++ b/src/utils/translation/poparser_unittest.cc
@@ -25,17 +25,22 @@
#include "being/actorsprite.h"
+#include "gui/gui.h"
+#include "gui/theme.h"
+
+#include "utils/delete2.h"
+#include "utils/env.h"
+#include "utils/physfstools.h"
+
#include "utils/translation/podict.h"
#include "utils/translation/poparser.h"
+#include "render/sdlgraphics.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")
@@ -43,13 +48,13 @@ TEST_CASE("PoParser tests", "PoParser")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
@@ -60,7 +65,11 @@ TEST_CASE("PoParser tests", "PoParser")
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
#endif // USE_SDL2
+ theme = new Theme;
+ Theme::selectSkin();
ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
SECTION("PoParser empty")
{
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index 52f234d12..40876e0d2 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -24,12 +24,15 @@
#include "being/actorsprite.h"
+#include "gui/gui.h"
#include "gui/theme.h"
#include "utils/delete2.h"
#include "utils/env.h"
#include "utils/physfstools.h"
+#include "render/sdlgraphics.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -41,13 +44,13 @@ TEST_CASE("xml doc")
setEnv("SDL_VIDEODRIVER", "dummy");
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
logger = new Logger();
ResourceManager::init();
resourceManager->addToSearchPath("data", Append_false);
resourceManager->addToSearchPath("../data", Append_false);
+ mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
@@ -62,6 +65,8 @@ TEST_CASE("xml doc")
Theme::selectSkin();
const char *const tempXmlName = "tempxml.xml";
ActorSprite::load();
+ gui = new Gui();
+ gui->postInit(mainGraphics);
SECTION("load1")
{
diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc
index 5603bf5a8..ebd964262 100644
--- a/src/utils/xmlutils_unittest.cc
+++ b/src/utils/xmlutils_unittest.cc
@@ -34,7 +34,6 @@
TEST_CASE("xmlutils readXmlIntVector 1")
{
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
logger = new Logger();
@@ -65,7 +64,6 @@ TEST_CASE("xmlutils readXmlIntVector 1")
TEST_CASE("xmlutils readXmlStringMap 1")
{
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
logger = new Logger();
@@ -95,7 +93,6 @@ TEST_CASE("xmlutils readXmlStringMap 1")
TEST_CASE("xmlutils readXmlIntMap 1")
{
client = new Client;
- PHYSFS_init("manaplus");
dirSeparator = "/";
XML::initXML();
logger = new Logger();