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/utils | |
parent | 80ba4766d8ce9861f6d026e791abc741e3fed0f4 (diff) | |
download | manaverse-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.gz manaverse-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.bz2 manaverse-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.tar.xz manaverse-cf772ab6f9fdfe1647b9b7b79aab685ebc831f31.zip |
Fix some leaks in unit tests.
Add support for suppression some leaks in asan.
Diffstat (limited to 'src/utils')
-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 |
8 files changed, 89 insertions, 6 deletions
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(); } |