From 855387d2d795c9471587cc7ddf2c66bb676d698e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 5 Jan 2017 17:00:02 +0300 Subject: 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. --- src/gui/gui.cpp | 1 + src/gui/widgets/browserbox_unittest.cc | 26 ++++++++++++++++++++++++-- src/gui/windowmanager_unittest.cc | 9 ++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src/gui') 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(); -- cgit v1.2.3-60-g2f50