diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 155af950c..4be511e1b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -125,16 +125,14 @@ public: } private: + Settings settings1; + void check(const char code[], const Settings *settings = nullptr) { // Clear the error buffer.. errout.str(""); - Settings settings1; - if (!settings) { - LOAD_LIB("gtk.cfg"); - settings1.library = _lib; + if (!settings) settings = &settings1; - } // Tokenize.. Tokenizer tokenizer(settings, this); @@ -150,6 +148,8 @@ private: void run() { + LOAD_LIB_2(settings1.library, "gtk.cfg"); + // Check that getcode works correctly.. TEST_CASE(testgetcode); @@ -4241,9 +4241,8 @@ private: // Test that posix.cfg is configured correctly void posixcfg() { - LOAD_LIB("posix.cfg"); Settings settings; - settings.library = _lib; + LOAD_LIB_2(settings.library, "posix.cfg"); const char code[] = "void leaks() {\n" " void* leak1 = fdopendir();\n" @@ -4255,17 +4254,19 @@ private: " void *p2 = opendir(); closedir(p2);\n" " void *p3 = socket(); close(p3);\n" "}"; - check(code,&settings); + check(code, &settings); ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: leak1\n" "[test.cpp:5]: (error) Resource leak: leak2\n" "[test.cpp:5]: (error) Resource leak: leak3\n", errout.str()); + LOAD_LIB_2(settings.library, "gtk.cfg"); + check("void f(char *a) {\n" " char *s = g_strdup(a);\n" " mkstemp(s);\n" " mkdtemp(s);\n" " mktemp(s);\n" - "}"); + "}", &settings); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: s\n", errout.str()); } }; @@ -6115,26 +6116,12 @@ public: } private: + Settings settings; + void check(const char code[]) { // Clear the error buffer.. errout.str(""); - Settings settings; - settings.standards.posix = true; - - LOAD_LIB("gtk.cfg"); - settings.library = _lib; - - // Add some test allocation functions to the library. - // When not run as a unit test, these are read from - // an XML file (e.g. cfg/posix.cfg). - int id = 0; - while (!settings.library.ismemory(++id)) - continue; - settings.library.setalloc("malloc", id); - settings.library.setalloc("calloc", id); - settings.library.setalloc("strdup", id); - // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -6147,6 +6134,21 @@ private: } void run() { + settings.standards.posix = true; + + LOAD_LIB_2(settings.library, "gtk.cfg"); + + // Add some test allocation functions to the library. + // When not run as a unit test, these are read from + // an XML file (e.g. cfg/posix.cfg). + int id = 0; + while (!settings.library.ismemory(++id)) + continue; + settings.library.setalloc("malloc", id); + settings.library.setalloc("calloc", id); + settings.library.setalloc("strdup", id); + + // pass allocated memory to function.. TEST_CASE(functionParameter); // never use leakable resource @@ -6304,14 +6306,12 @@ public: } private: + Settings settings; + void check(const char code[]) { // Clear the error buffer.. errout.str(""); - Settings settings; - LOAD_LIB("gtk.cfg"); - settings.library = _lib; - // Preprocess... Preprocessor preprocessor(&settings, this); std::istringstream istrpreproc(code); @@ -6331,6 +6331,8 @@ private: } void run() { + LOAD_LIB_2(settings.library, "gtk.cfg"); + TEST_CASE(glib1); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index b47b6de3a..5bfc80eb0 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -29,9 +29,11 @@ public: } private: - + Settings settings; void run() { + LOAD_LIB_2(settings.library, "std.cfg"); + TEST_CASE(nullpointerAfterLoop); TEST_CASE(nullpointer1); TEST_CASE(nullpointer2); @@ -86,12 +88,8 @@ private: // Clear the error buffer.. errout.str(""); - Settings settings; settings.addEnabled("warning"); settings.inconclusive = inconclusive; - _lib = Library(); - LOAD_LIB("std.cfg"); - settings.library = _lib; // Tokenize.. Tokenizer tokenizer(&settings, this); diff --git a/test/testother.cpp b/test/testother.cpp index 268bebd10..8e895746c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4874,9 +4874,8 @@ private: ASSERT_EQUALS("", errout.str()); { - LOAD_LIB("std.cfg"); Settings settings; - settings.library = _lib; + LOAD_LIB_2(settings.library, "std.cfg"); check("void foo() {\n" " if ((strcmp(a, b) == 0) || (strcmp(a, b) == 0)) {}\n" "}", "test.cpp", false, false, false, true, &settings); diff --git a/test/testsuite.h b/test/testsuite.h index 4d1f76830..ddc055a23 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -85,10 +85,10 @@ public: #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; } #ifdef _WIN32 -#define REQUIRE_LIB( NAME ) { if (!_lib.load("./testrunner", "../cfg/" NAME) && !_lib.load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } } +#define LOAD_LIB_2( LIB, NAME ) { if (!(LIB).load("./testrunner", "../cfg/" NAME) && !(LIB).load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } } #else -#define REQUIRE_LIB( NAME ) { if (!_lib.load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } } +#define LOAD_LIB_2( LIB, NAME ) { if (!(LIB).load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } } #endif -#define LOAD_LIB( NAME ) { REQUIRE_LIB(NAME); } +#define LOAD_LIB( NAME ) { LOAD_LIB_2(_lib, NAME); } #endif diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index fa102f6aa..2a9e7a6ba 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1840,7 +1840,6 @@ private: //ASSERT(db && db->findScopeByName("InfiniteA") && !db->findScopeByName("InfiniteA")->functionList.front().isImplicitlyVirtual()); TODO_ASSERT_EQUALS(1, 0, db->findScopeByName("InfiniteA")->functionList.size()); } - } void garbage() { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 92e11fd07..600b90d55 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -29,9 +29,11 @@ public: } private: - + Settings settings; void run() { + LOAD_LIB_2(settings.library, "std.cfg"); + TEST_CASE(uninitvar1); TEST_CASE(uninitvar_bitop); // using uninitialized operand in bit operation TEST_CASE(uninitvar_alloc); // data is allocated but not initialized @@ -76,10 +78,6 @@ private: // Clear the error buffer.. errout.str(""); - Settings settings; - LOAD_LIB("std.cfg"); - settings.library = _lib; - // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code);