diff --git a/lib/library.cpp b/lib/library.cpp index 4c886f699..396345ac7 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -187,13 +187,6 @@ Library::Container::Action Library::Container::actionFrom(const std::string& act return Container::Action::NO_ACTION; } -// cppcheck-suppress unusedFunction - only used in unit tests -bool Library::loadxmldata(const char xmldata[], std::size_t len) -{ - tinyxml2::XMLDocument doc; - return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (load(doc).errorcode == ErrorCode::OK); -} - Library::Error Library::load(const tinyxml2::XMLDocument &doc) { const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); diff --git a/lib/library.h b/lib/library.h index ef0e7b3b8..c91079939 100644 --- a/lib/library.h +++ b/lib/library.h @@ -75,9 +75,6 @@ public: Error load(const char exename[], const char path[]); Error load(const tinyxml2::XMLDocument &doc); - /** this is used for unit tests */ - bool loadxmldata(const char xmldata[], std::size_t len); - struct AllocFunc { int groupId; int arg; @@ -134,32 +131,6 @@ public: return af ? af->groupId : 0; } - /** set allocation id for function */ - // cppcheck-suppress unusedFunction - test-only - void setalloc(const std::string &functionname, int id, int arg) { - mAlloc[functionname].groupId = id; - mAlloc[functionname].arg = arg; - } - - // cppcheck-suppress unusedFunction - test-only - void setdealloc(const std::string &functionname, int id, int arg) { - mDealloc[functionname].groupId = id; - mDealloc[functionname].arg = arg; - } - - // cppcheck-suppress unusedFunction - test-only - void setrealloc(const std::string &functionname, int id, int arg, int reallocArg = 1) { - mRealloc[functionname].groupId = id; - mRealloc[functionname].arg = arg; - mRealloc[functionname].reallocArg = reallocArg; - } - - /** add noreturn function setting */ - // cppcheck-suppress unusedFunction - test-only - void setnoreturn(const std::string& funcname, bool noreturn) { - mNoReturn[funcname] = noreturn ? FalseTrueMaybe::True : FalseTrueMaybe::False; - } - static bool isCompliantValidationExpression(const char* p); /** is allocation type memory? */ diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 90458d433..4cb72fc55 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -46,7 +46,7 @@ private: "\n" " \n" ""; - ASSERT(settings1.library.loadxmldata(cfg, sizeof(cfg))); + settings1 = settingsBuilder(settings1).libraryxml(cfg, sizeof(cfg)).build(); TEST_CASE(assignAndCompare); // assignment and comparison don't match TEST_CASE(mismatchingBitAnd); // overlapping bitmasks diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index ea0121769..b07ca4fbf 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -44,27 +44,29 @@ private: Settings settings; void run() override { - int id = 0; - while (!Library::ismemory(++id)); - settings.library.setalloc("malloc", id, -1); - settings.library.setrealloc("realloc", id, -1); - settings.library.setdealloc("free", id, 1); - while (!Library::isresource(++id)); - settings.library.setalloc("socket", id, -1); - settings.library.setdealloc("close", id, 1); - while (!Library::isresource(++id)); - settings.library.setalloc("fopen", id, -1); - settings.library.setrealloc("freopen", id, -1, 3); - settings.library.setdealloc("fclose", id, 1); - settings.library.smartPointers["std::shared_ptr"]; - settings.library.smartPointers["std::unique_ptr"]; - settings.library.smartPointers["std::unique_ptr"].unique = true; - const char xmldata[] = "\n" "\n" " \n" + " \n" + " malloc\n" + " realloc\n" + " free\n" + " \n" + " \n" + " socket\n" + " close\n" + " \n" + " \n" + " fopen\n" + " freopen\n" + " fclose\n" + " \n" + " \n" + " \n" + " \n" + " \n" ""; - ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata))); + settings = settingsBuilder(settings).libraryxml(xmldata, sizeof(xmldata)).build(); // Assign TEST_CASE(assign1); diff --git a/test/testother.cpp b/test/testother.cpp index 681569327..aa09d83ad 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4681,9 +4681,15 @@ private: "}", nullptr, false, false); ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); - Settings settings; - settings.library.setnoreturn("exit", true); - settings.library.functions["exit"].argumentChecks[1] = Library::ArgumentChecks(); + const char xmldata[] = "\n" + "\n" + " \n" + " true\n" + " \n" + " \n" + ""; + Settings settings = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build(); + check("void foo() {\n" " exit(0);\n" " break;\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 55106bade..589a057b7 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -55,7 +55,7 @@ private: " \n" " true \n" // abort is a noreturn function ""; - ASSERT_EQUALS(true, settings.library.loadxmldata(cfg, sizeof(cfg))); + settings = settingsBuilder(settings).libraryxml(cfg, sizeof(cfg)).build(); TEST_CASE(valueFlowNumber); TEST_CASE(valueFlowString);