diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-02-20 15:51:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-02-20 15:51:27 +0300 |
commit | cf772ab6f9fdfe1647b9b7b79aab685ebc831f31 (patch) | |
tree | 25cdb35a8733efe3a4cb90e36cbb89e8e0c24c10 /src | |
parent | 80ba4766d8ce9861f6d026e791abc741e3fed0f4 (diff) | |
download | manaplus-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.gz manaplus-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.bz2 manaplus-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.xz manaplus-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.zip |
Fix some leaks in unit tests.
Add support for suppression some leaks in asan.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/gui/widgets/browserbox_unittest.cc | 7 | ||||
-rw-r--r-- | src/gui/widgets/widget.h | 3 | ||||
-rw-r--r-- | src/gui/windowmanager_unittest.cc | 12 | ||||
-rw-r--r-- | src/integrity_unittest.cc | 2 | ||||
-rw-r--r-- | src/resources/dye/dye_unittest.cc | 1 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_unittest.cc | 1 | ||||
-rw-r--r-- | src/resources/map/maplayer_unittest.cc | 9 | ||||
-rw-r--r-- | src/resources/map/speciallayer_unittest.cc | 3 | ||||
-rw-r--r-- | src/resources/resourcemanager/resourcemanager_unittest.cc | 5 | ||||
-rw-r--r-- | src/resources/sprite/animatedsprite_unittest.cc | 5 | ||||
-rw-r--r-- | src/utils/chatutils_unittest.cc | 8 | ||||
-rw-r--r-- | src/utils/dumplibs_unittest.cc | 3 | ||||
-rw-r--r-- | src/utils/files_unittest.cc | 7 | ||||
-rw-r--r-- | src/utils/stringutils_unittest.cc | 6 | ||||
-rw-r--r-- | src/utils/translation/poparser_unittest.cc | 1 | ||||
-rw-r--r-- | src/utils/virtfs_unittest.cc | 13 | ||||
-rw-r--r-- | src/utils/xml_unittest.cc | 1 | ||||
-rw-r--r-- | src/utils/xmlutils_unittest.cc | 56 |
19 files changed, 132 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 320809175..7ccb9fd09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,8 @@ AUTOMAKE_OPTIONS = subdir-objects +AM_TESTS_ENVIRONMENT = \ + ASAN_OPTIONS=detect_leaks=1 + if ENABLE_MANAPLUSGAME if ENABLE_DYECMD bin_PROGRAMS = manaplus dyecmd diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index 3978c309d..a3434427f 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -30,6 +30,7 @@ #include "gui/widgets/browserbox.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include "render/sdlgraphics.h" @@ -170,8 +171,10 @@ TEST_CASE("BrowserBox tests", "browserbox") row = "##1%%2"; box->addRow(row); + delete Widget::getGloablFont(); + Widget::setGlobalFont(nullptr); delete box; - delete client; - client = nullptr; + delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h index 4a9957738..92b345cea 100644 --- a/src/gui/widgets/widget.h +++ b/src/gui/widgets/widget.h @@ -641,6 +641,9 @@ class Widget notfinal : public Widget2 */ static void setGlobalFont(Font *const font); + static Font *getGloablFont() + { return mGlobalFont; } + /** * Sets the font for the widget. If NULL is passed, the global font * will be used. diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc index 392e6e872..68fc3852b 100644 --- a/src/gui/windowmanager_unittest.cc +++ b/src/gui/windowmanager_unittest.cc @@ -25,7 +25,7 @@ #include "settings.h" #include "textcommand.h" -#include "being/being.h" +#include "being/localplayer.h" #include "const/resources/currency.h" @@ -159,6 +159,10 @@ TEST_CASE("Windows tests", "windowmanager") config.setValue("fontSize", 16); theme = new Theme; Theme::selectSkin(); + + localPlayer = new LocalPlayer(static_cast<BeingId>(1), + BeingTypeId_zero); + ActorSprite::load(); gui = new Gui(); gui->postInit(mainGraphics); @@ -568,6 +572,7 @@ TEST_CASE("Windows tests", "windowmanager") gui->draw(); mainGraphics->updateScreen(); delete2(dialog); + delete2(textCommand); } SECTION("TextDialog") @@ -677,9 +682,14 @@ TEST_CASE("Windows tests", "windowmanager") delete2(connectionDialog); } + delete2(localPlayer); delete2(userPalette); delete2(client); delete2(serverFeatures); delete2(inventoryHandler); + delete2(charServerHandler); + delete2(playerHandler); + delete2(logger); + // VirtFs::deinit(); } diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc index 31cda2d56..f52e74ed8 100644 --- a/src/integrity_unittest.cc +++ b/src/integrity_unittest.cc @@ -39,6 +39,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/env.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include "utils/virtfsrwops.h" #include "utils/virtfstools.h" @@ -490,5 +491,6 @@ TEST_CASE("integrity tests", "integrity") delete client; client = nullptr; + delete2(logger); // VirtFs::deinit(); } diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc index 57892c3a9..5f38aa77a 100644 --- a/src/resources/dye/dye_unittest.cc +++ b/src/resources/dye/dye_unittest.cc @@ -2391,5 +2391,6 @@ TEST_CASE("Dye real dye") dyeCheck("|A:#0000FFFF,FF000050", "arrow_up_A.png"); } delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc index 88bffe824..9431f0d72 100644 --- a/src/resources/dye/dyepalette_unittest.cc +++ b/src/resources/dye/dyepalette_unittest.cc @@ -381,5 +381,6 @@ TEST_CASE("DyePalette tests") REQUIRE(palette.mColors[0].value[3] == 0x77); } delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc index 75bd20219..5d7f5c258 100644 --- a/src/resources/map/maplayer_unittest.cc +++ b/src/resources/map/maplayer_unittest.cc @@ -28,6 +28,7 @@ #include "gui/theme.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include "render/mockgraphics.h" @@ -1646,6 +1647,7 @@ TEST_CASE("MapLayer draw") TEST_CASE("MapLayer drawSpecialLayer (specialLayer)") { + logger = new Logger; ResourceManager::init(); VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -1990,10 +1992,12 @@ TEST_CASE("MapLayer drawSpecialLayer (specialLayer)") delete map; delete mock; + delete2(logger); } TEST_CASE("MapLayer drawSpecialLayer (tempLayer)") { + logger = new Logger; ResourceManager::init(); VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -2344,14 +2348,15 @@ TEST_CASE("MapLayer drawSpecialLayer (tempLayer)") delete map; delete mock; + delete2(logger); } TEST_CASE("MapLayer drawFringe") { + logger = new Logger; ResourceManager::init(); VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); - logger = new Logger; imageHelper = new SDLImageHelper; #ifdef USE_SDL2 @@ -3220,9 +3225,11 @@ TEST_CASE("MapLayer drawFringe") REQUIRE(mock->mDraws[7].image == img1); } + delete2(localPlayer); delete map; delete img1; delete img2; delete img3; delete mock; + delete2(logger); } diff --git a/src/resources/map/speciallayer_unittest.cc b/src/resources/map/speciallayer_unittest.cc index 6c6772332..70f3d07e1 100644 --- a/src/resources/map/speciallayer_unittest.cc +++ b/src/resources/map/speciallayer_unittest.cc @@ -20,6 +20,7 @@ #include "catch.hpp" #include "client.h" +#include "logger.h" #include "graphicsmanager.h" @@ -40,6 +41,7 @@ TEST_CASE("SpecialLayer updateCache") { + logger = new Logger; client = new Client; ResourceManager::init(); VirtFs::addDirToSearchPath("data", Append_false); @@ -259,4 +261,5 @@ TEST_CASE("SpecialLayer updateCache") delete layer; resourceManager->cleanOrphans(); delete2(client); + delete2(logger); } diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc index 98ed0ca2f..56f055b86 100644 --- a/src/resources/resourcemanager/resourcemanager_unittest.cc +++ b/src/resources/resourcemanager/resourcemanager_unittest.cc @@ -30,6 +30,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/env.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include <unistd.h> @@ -657,7 +658,7 @@ TEST_CASE("resourcemanager", "resourcemanager") delete resourceManager; resourceManager = safeResman; - delete client; - client = nullptr; + delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc index 9505e7d24..8eeb2178d 100644 --- a/src/resources/sprite/animatedsprite_unittest.cc +++ b/src/resources/sprite/animatedsprite_unittest.cc @@ -40,6 +40,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/env.h" +#include "utils/delete2.h" #include "utils/mrand.h" #include "utils/virtfs.h" @@ -179,7 +180,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite") delete sprite2; } - delete client; - client = nullptr; + delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc index b28bd94da..f82fa1549 100644 --- a/src/utils/chatutils_unittest.cc +++ b/src/utils/chatutils_unittest.cc @@ -106,8 +106,6 @@ TEST_CASE("chatutils replaceVars") str = "test <SOMETHING>"; replaceVars(str); REQUIRE(str == "test <SOMETHING>"); - - delete2(localPlayer); } SECTION("player") @@ -123,8 +121,6 @@ TEST_CASE("chatutils replaceVars") str = "test <PLAYER>"; replaceVars(str); REQUIRE(str == "test player1"); - - delete2(localPlayer); } SECTION("monster") @@ -140,8 +136,6 @@ TEST_CASE("chatutils replaceVars") str = "test <MONSTER>"; replaceVars(str); REQUIRE(str == "test monster1"); - - delete2(localPlayer); } SECTION("people") @@ -239,7 +233,9 @@ TEST_CASE("chatutils replaceVars") } delete2(actorManager); + delete2(localPlayer); delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/utils/dumplibs_unittest.cc b/src/utils/dumplibs_unittest.cc index ad408638d..d89dee5fd 100644 --- a/src/utils/dumplibs_unittest.cc +++ b/src/utils/dumplibs_unittest.cc @@ -21,6 +21,7 @@ #include "catch.hpp" #include "logger.h" +#include "utils/delete2.h" #include "utils/stringutils.h" #include <SDL_image.h> @@ -137,4 +138,6 @@ TEST_CASE("dumplibs tests") REQUIRE(build == link); } + + delete2(logger); } diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc index ae2e69a99..78be3d924 100644 --- a/src/utils/files_unittest.cc +++ b/src/utils/files_unittest.cc @@ -23,6 +23,7 @@ #include "catch.hpp" #include "logger.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include "utils/virtfstools.h" @@ -64,6 +65,7 @@ TEST_CASE("Files renameFile") delete [] buf; delete [] buf2; ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -78,6 +80,7 @@ TEST_CASE("Files existsLocal") REQUIRE_FALSE(Files::existsLocal(VirtFs::getPath("help/about1.txt"))); REQUIRE_FALSE(Files::existsLocal(VirtFs::getPath("help1/about.txt"))); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -91,6 +94,7 @@ TEST_CASE("Files loadTextFileString") REQUIRE(VirtFs::loadTextFileString("test/simplefile.txt") == "this is test \nfile."); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -108,6 +112,7 @@ TEST_CASE("Files loadTextFile") REQUIRE(lines[0] == "this is test "); REQUIRE(lines[1] == "file."); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -126,6 +131,7 @@ TEST_CASE("Files saveTextFile") ::remove((dir + "/tempfile.txt").c_str()); REQUIRE(data == "test line\ntext line2\n"); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -155,5 +161,6 @@ TEST_CASE("Files getFilesInDir") REQUIRE(list[3] == "perserver/default/features.xml"); REQUIRE(list[4] == "perserver/default/weapons.xml"); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc index 3354da89c..1356e214b 100644 --- a/src/utils/stringutils_unittest.cc +++ b/src/utils/stringutils_unittest.cc @@ -24,6 +24,8 @@ #include "const/utils/utf8.h" +#include "utils/delete2.h" +#include "utils/dtor.h" #include "utils/virtfs.h" #include "resources/iteminfo.h" @@ -1485,5 +1487,9 @@ TEST_CASE("stringuntils replaceItemLinks") REQUIRE(str == "[[test name 1 ,test name2[] test name 1]"); } ResourceManager::deleteInstance(); + delete2(logger); + delete_all(infos); + infos.clear(); + namedInfos.clear(); // VirtFs::deinit(); } diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc index e7928c8b5..73ef6d396 100644 --- a/src/utils/translation/poparser_unittest.cc +++ b/src/utils/translation/poparser_unittest.cc @@ -122,5 +122,6 @@ TEST_CASE("PoParser tests", "PoParser") delete dict; } delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/utils/virtfs_unittest.cc b/src/utils/virtfs_unittest.cc index af2c22dee..e8af0bb1d 100644 --- a/src/utils/virtfs_unittest.cc +++ b/src/utils/virtfs_unittest.cc @@ -21,6 +21,7 @@ #include "catch.hpp" #include "utils/checkutils.h" +#include "utils/delete2.h" #include "utils/virtfs.h" #include "utils/virtfstools.h" #include "utils/virtlist.h" @@ -75,6 +76,7 @@ TEST_CASE("VirtFs exists") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } static void removeTemp(StringVect &restrict list) @@ -105,6 +107,8 @@ static void removeTemp(StringVect &restrict list) TEST_CASE("VirtFs enumerateFiles") { + logger = new Logger; + VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -134,6 +138,7 @@ TEST_CASE("VirtFs enumerateFiles") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } TEST_CASE("VirtFs isDirectory") @@ -191,6 +196,7 @@ TEST_CASE("VirtFs isDirectory") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } TEST_CASE("VirtFs openRead") @@ -252,6 +258,7 @@ TEST_CASE("VirtFs openRead") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } TEST_CASE("VirtFs addZipToSearchPath") @@ -266,6 +273,7 @@ TEST_CASE("VirtFs removeZipFromSearchPath") TEST_CASE("VirtFs getRealDir") { + logger = new Logger(); REQUIRE(VirtFs::getRealDir(".") == ""); REQUIRE(VirtFs::getRealDir("..") == ""); const bool dir1 = VirtFs::addDirToSearchPath("data", Append_false); @@ -324,10 +332,12 @@ TEST_CASE("VirtFs getRealDir") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } TEST_CASE("VirtFs permitLinks") { + logger = new Logger(); VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -355,10 +365,12 @@ TEST_CASE("VirtFs permitLinks") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } TEST_CASE("VirtFs read") { + logger = new Logger(); VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -389,4 +401,5 @@ TEST_CASE("VirtFs read") VirtFs::removeDirFromSearchPath("data"); VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); } diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc index e6198a597..3076e9f0b 100644 --- a/src/utils/xml_unittest.cc +++ b/src/utils/xml_unittest.cc @@ -358,5 +358,6 @@ TEST_CASE("xml doc") } delete2(theme); delete2(client); + delete2(logger); // VirtFs::deinit(); } diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc index dbb571429..00c850bcc 100644 --- a/src/utils/xmlutils_unittest.cc +++ b/src/utils/xmlutils_unittest.cc @@ -22,13 +22,21 @@ #include "catch.hpp" #include "client.h" +#include "graphicsmanager.h" #include "logger.h" +#include "being/actorsprite.h" + +#include "utils/delete2.h" #include "utils/virtfs.h" #include "utils/xml.h" +#include "render/sdlgraphics.h" + #include "resources/resourcemanager/resourcemanager.h" +#include "resources/sdlimagehelper.h" + #include "debug.h" TEST_CASE("xmlutils readXmlIntVector 1") @@ -38,6 +46,20 @@ TEST_CASE("xmlutils readXmlIntVector 1") XML::initXML(); logger = new Logger(); ResourceManager::init(); + + 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 + + ActorSprite::load(); + VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -57,7 +79,9 @@ TEST_CASE("xmlutils readXmlIntVector 1") REQUIRE(0 == arr[2]); REQUIRE(1 == arr[3]); REQUIRE(1 == arr[4]); + delete2(client); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -68,6 +92,20 @@ TEST_CASE("xmlutils readXmlStringMap 1") XML::initXML(); logger = new Logger(); ResourceManager::init(); + + 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 + + ActorSprite::load(); + VirtFs::addDirToSearchPath("data", Append_false); VirtFs::addDirToSearchPath("../data", Append_false); @@ -86,7 +124,9 @@ TEST_CASE("xmlutils readXmlStringMap 1") REQUIRE(arr["Kitty"] == "0"); REQUIRE(arr["xD"] == "1"); REQUIRE(arr["Metal"] == "26"); + delete2(client); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } @@ -97,6 +137,20 @@ TEST_CASE("xmlutils readXmlIntMap 1") XML::initXML(); logger = new Logger(); ResourceManager::init(); + + 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 + + ActorSprite::load(); + VirtFs::addDirToSearchPath("data/test", Append_false); VirtFs::addDirToSearchPath("../data/test", Append_false); @@ -115,6 +169,8 @@ TEST_CASE("xmlutils readXmlIntMap 1") REQUIRE(arr[1] == 2); REQUIRE(arr[10] == 20); REQUIRE(arr[3] == 0); + delete2(client); ResourceManager::deleteInstance(); + delete2(logger); // VirtFs::deinit(); } |