improved library loading in tests (#4806)
This commit is contained in:
parent
e99d7c6531
commit
3ec4da0f8a
|
@ -102,13 +102,6 @@ static bool isVariableCopyNeeded(const Variable &var, Function::Type type)
|
|||
(var.valueType() && var.valueType()->type >= ValueType::Type::CHAR));
|
||||
}
|
||||
|
||||
static bool isVcl(const Settings *settings)
|
||||
{
|
||||
return std::any_of(settings->libraries.cbegin(), settings->libraries.cend(), [](const std::string& library) {
|
||||
return library == "vcl";
|
||||
});
|
||||
}
|
||||
|
||||
static bool isVclTypeInit(const Type *type)
|
||||
{
|
||||
if (!type)
|
||||
|
@ -141,7 +134,7 @@ void CheckClass::constructors()
|
|||
|
||||
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
|
||||
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
|
||||
if (isVcl(mSettings) && isVclTypeInit(scope->definedType))
|
||||
if (mSettings->hasLib("vcl") && isVclTypeInit(scope->definedType))
|
||||
continue;
|
||||
|
||||
const bool unusedTemplate = Token::simpleMatch(scope->classDef->previous(), ">");
|
||||
|
|
|
@ -116,7 +116,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
|||
return New;
|
||||
}
|
||||
|
||||
if (mSettings_->posix()) {
|
||||
if (mSettings_->hasLib("posix")) {
|
||||
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp|socket (")) {
|
||||
// simple sanity check of function parameters..
|
||||
// TODO: Make such check for all these functions
|
||||
|
@ -237,7 +237,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
|||
if (tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )"))
|
||||
return Malloc;
|
||||
|
||||
if (mSettings_->posix()) {
|
||||
if (mSettings_->hasLib("posix")) {
|
||||
if (tok->str() == "close")
|
||||
return Fd;
|
||||
if (tok->str() == "pclose")
|
||||
|
@ -276,7 +276,7 @@ bool CheckMemoryLeak::isReopenStandardStream(const Token *tok) const
|
|||
|
||||
bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const
|
||||
{
|
||||
if (mSettings_->posix() && tok->str() == "open" && numberOfArguments(tok) == 2) {
|
||||
if (mSettings_->hasLib("posix") && tok->str() == "open" && numberOfArguments(tok) == 2) {
|
||||
const Token* arg = getArguments(tok).at(0);
|
||||
if (Token::simpleMatch(arg, "\"/dev/null\""))
|
||||
return true;
|
||||
|
|
|
@ -417,9 +417,9 @@ public:
|
|||
*/
|
||||
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
|
||||
|
||||
/** Is posix library specified? */
|
||||
bool posix() const {
|
||||
return std::find(libraries.cbegin(), libraries.cend(), "posix") != libraries.cend();
|
||||
/** Is library specified? */
|
||||
bool hasLib(const std::string &lib) const {
|
||||
return std::find(libraries.cbegin(), libraries.cend(), lib) != libraries.cend();
|
||||
}
|
||||
|
||||
/** @brief Request termination of checking */
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
settings.severity.enable(Severity::style);
|
||||
LOAD_LIB_2(settings.library, "std.cfg");
|
||||
LOAD_LIB_2(settings.library, "qt.cfg");
|
||||
settings.libraries.emplace_back("qt");
|
||||
|
||||
TEST_CASE(testautovar1);
|
||||
TEST_CASE(testautovar2);
|
||||
|
|
|
@ -3528,9 +3528,7 @@ private:
|
|||
" <arg nr=\"2\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
// Attempt to get size from Cfg files, no false positives if size is not specified
|
||||
check("void f() {\n"
|
||||
|
@ -4083,9 +4081,7 @@ private:
|
|||
" <arg nr=\"3\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
settings.severity.enable(Severity::warning);
|
||||
settings.sizeof_wchar_t = 4;
|
||||
|
||||
|
@ -4225,9 +4221,7 @@ private:
|
|||
" <arg nr=\"3\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
check("void f() {\n"
|
||||
" char c[7];\n"
|
||||
|
@ -4289,9 +4283,7 @@ private:
|
|||
" </arg>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
// formatstr..
|
||||
check("void f() {\n"
|
||||
|
@ -4403,9 +4395,7 @@ private:
|
|||
" <arg nr=\"4\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
check("void f() {\n"
|
||||
" char c[5];\n"
|
||||
|
@ -5498,6 +5488,7 @@ private:
|
|||
|
||||
Settings settings;
|
||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||
settings.libraries.emplace_back("posix");
|
||||
|
||||
check("void f(){\n"
|
||||
"int pipefd[1];\n" // <-- array of two integers is needed
|
||||
|
|
|
@ -60,10 +60,8 @@ private:
|
|||
" </access>\n"
|
||||
" </container>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings0.library.load(doc);
|
||||
settings1.library.load(doc);
|
||||
ASSERT(settings0.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(settings1.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3390,9 +3388,7 @@ private:
|
|||
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
||||
" <podtype name=\"std::atomic_bool\"/>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
checkNoMemset("class A {\n"
|
||||
" std::array<int, 10> ints;\n"
|
||||
|
|
|
@ -49,6 +49,7 @@ private:
|
|||
PLATFORM(settings1, cppcheck::Platform::Native);
|
||||
|
||||
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||
settings0.libraries.emplace_back("qt");
|
||||
LOAD_LIB_2(settings0.library, "std.cfg");
|
||||
|
||||
settings0.severity.enable(Severity::style);
|
||||
|
@ -58,11 +59,9 @@ private:
|
|||
"<def>\n"
|
||||
" <function name=\"bar\"> <pure/> </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument xmldoc;
|
||||
xmldoc.Parse(cfg, sizeof(cfg));
|
||||
ASSERT(settings1.library.loadxmldata(cfg, sizeof(cfg)));
|
||||
settings1.severity.enable(Severity::style);
|
||||
settings1.severity.enable(Severity::warning);
|
||||
settings1.library.load(xmldoc);
|
||||
|
||||
TEST_CASE(assignAndCompare); // assignment and comparison don't match
|
||||
TEST_CASE(mismatchingBitAnd); // overlapping bitmasks
|
||||
|
|
|
@ -1952,7 +1952,8 @@ private:
|
|||
|
||||
void initvar_smartptr() { // #10237
|
||||
Settings s;
|
||||
s.libraries.emplace_back("std");
|
||||
// TODO: test shuld probably not pass without library
|
||||
//LOAD_LIB_2(s.library, "std.cfg");
|
||||
check("struct S {\n"
|
||||
" explicit S(const std::shared_ptr<S>& sp) {\n"
|
||||
" set(*sp);\n"
|
||||
|
@ -3589,7 +3590,9 @@ private:
|
|||
|
||||
void uninitVarInheritClassInit() {
|
||||
Settings s;
|
||||
s.libraries.emplace_back("vcl");
|
||||
// TODO: test should probably not pass without library
|
||||
//LOAD_LIB_2(s.library, "vcl.cfg");
|
||||
//s.libraries.emplace_back("vcl");
|
||||
|
||||
check("class Fred: public TObject\n"
|
||||
"{\n"
|
||||
|
|
|
@ -249,7 +249,7 @@ private:
|
|||
" <location file=\"foo.cpp\" line=\"5\" column=\"2\"/>\n"
|
||||
"</error>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
ASSERT(doc.Parse(xmldata, sizeof(xmldata)) == tinyxml2::XML_SUCCESS);
|
||||
ErrorMessage msg(doc.FirstChildElement());
|
||||
ASSERT_EQUALS("errorId", msg.id);
|
||||
ASSERT_EQUALS(Severity::error, msg.severity);
|
||||
|
|
|
@ -43,11 +43,11 @@ private:
|
|||
settings.severity.enable(Severity::performance);
|
||||
settings.severity.enable(Severity::portability);
|
||||
settings.certainty.enable(Certainty::inconclusive);
|
||||
settings.libraries.emplace_back("posix");
|
||||
settings.standards.c = Standards::C11;
|
||||
settings.standards.cpp = Standards::CPP11;
|
||||
LOAD_LIB_2(settings.library, "std.cfg");
|
||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||
settings.libraries.emplace_back("posix");
|
||||
|
||||
// Prohibited functions
|
||||
TEST_CASE(prohibitedFunctions_posix);
|
||||
|
@ -1313,9 +1313,7 @@ private:
|
|||
" <arg nr=\"2\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings2.library.load(doc);
|
||||
ASSERT(settings2.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
check("void foo() {\n"
|
||||
" mystrcmp(a, b);\n"
|
||||
|
@ -1468,9 +1466,7 @@ private:
|
|||
" <arg nr=\"2\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings2.library.load(doc);
|
||||
ASSERT(settings2.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
check("void foo() {\n"
|
||||
" mystrcmp(a, b);\n"
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
LOAD_LIB_2(settings.library, "std.cfg");
|
||||
LOAD_LIB_2(settings.library, "windows.cfg");
|
||||
LOAD_LIB_2(settings.library, "qt.cfg");
|
||||
settings.libraries.emplace_back("qt");
|
||||
|
||||
TEST_CASE(coutCerrMisusage);
|
||||
|
||||
|
|
|
@ -65,9 +65,7 @@ private:
|
|||
"<def>\n"
|
||||
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
// Assign
|
||||
TEST_CASE(assign1);
|
||||
|
@ -474,6 +472,7 @@ private:
|
|||
void assign23() {
|
||||
Settings s = settings;
|
||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||
settings.libraries.emplace_back("posix");
|
||||
check("void f() {\n"
|
||||
" int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;\n"
|
||||
" *&n1 = open(\"xx.log\", O_RDONLY);\n"
|
||||
|
@ -1854,6 +1853,7 @@ private:
|
|||
Settings s;
|
||||
LOAD_LIB_2(s.library, "std.cfg");
|
||||
LOAD_LIB_2(s.library, "posix.cfg");
|
||||
s.libraries.emplace_back("posix");
|
||||
|
||||
check("void f() {\n"
|
||||
" char* temp = strdup(\"temp.txt\");\n"
|
||||
|
@ -2594,9 +2594,7 @@ private:
|
|||
" </arg>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settingsFunctionCall.library.load(doc);
|
||||
ASSERT(settingsFunctionCall.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
check("void test_func()\n"
|
||||
"{\n"
|
||||
" char * buf = malloc(4);\n"
|
||||
|
@ -2616,9 +2614,7 @@ private:
|
|||
" <arg nr=\"1\" direction=\"in\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>\n";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settingsLeakIgnore.library.load(doc);
|
||||
ASSERT(settingsLeakIgnore.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
check("void f() {\n"
|
||||
" double* a = new double[1024];\n"
|
||||
" SomeClass::someMethod(a);\n"
|
||||
|
|
|
@ -71,12 +71,6 @@ private:
|
|||
TEST_CASE(loadLibErrors);
|
||||
}
|
||||
|
||||
static Library::Error readLibrary(Library& library, const char* xmldata) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata);
|
||||
return library.load(doc);
|
||||
}
|
||||
|
||||
void isCompliantValidationExpression() const {
|
||||
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("-1"));
|
||||
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("1"));
|
||||
|
@ -103,7 +97,7 @@ private:
|
|||
// Reading an empty library file is considered to be OK
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.functions.empty());
|
||||
}
|
||||
|
||||
|
@ -121,7 +115,7 @@ private:
|
|||
tokenList.front()->next()->astOperand1(tokenList.front());
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||
ASSERT(library.functions.at("foo").argumentChecks.empty());
|
||||
ASSERT(library.isnotnoreturn(tokenList.front()));
|
||||
|
@ -136,7 +130,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
{
|
||||
TokenList tokenList(nullptr);
|
||||
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
|
||||
|
@ -168,7 +162,7 @@ private:
|
|||
tokenList.createAst();
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.isNotLibraryFunction(tokenList.front()));
|
||||
}
|
||||
|
||||
|
@ -182,7 +176,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
{
|
||||
TokenList tokenList(nullptr);
|
||||
|
@ -237,7 +231,7 @@ private:
|
|||
tokenList.front()->next()->varId(1);
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.isNotLibraryFunction(tokenList.front()->next()));
|
||||
}
|
||||
|
||||
|
@ -254,7 +248,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[1].notuninit);
|
||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[2].notnull);
|
||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr);
|
||||
|
@ -273,7 +267,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||
}
|
||||
|
||||
|
@ -287,7 +281,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||
|
||||
TokenList tokenList(nullptr);
|
||||
|
@ -313,7 +307,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
TokenList tokenList(nullptr);
|
||||
std::istringstream istr("foo(a,b,c,d);");
|
||||
|
@ -345,7 +339,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
TokenList tokenList(nullptr);
|
||||
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j,k);");
|
||||
|
@ -487,7 +481,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
TokenList tokenList(nullptr);
|
||||
std::istringstream istr("foo(a,b,c,d,e);");
|
||||
|
@ -546,7 +540,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(library.functions.size(), 2U);
|
||||
ASSERT(library.functions.at("Foo::foo").argumentChecks.empty());
|
||||
ASSERT(library.functions.at("bar").argumentChecks.empty());
|
||||
|
@ -575,7 +569,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||
|
||||
{
|
||||
|
@ -602,7 +596,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
{
|
||||
Tokenizer tokenizer(&settings, nullptr);
|
||||
|
@ -631,7 +625,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
TokenList tokenList(nullptr);
|
||||
std::istringstream istr("a(); b();");
|
||||
|
@ -665,7 +659,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.functions.empty());
|
||||
|
||||
ASSERT(Library::ismemory(library.getAllocFuncInfo("CreateX")));
|
||||
|
@ -708,7 +702,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.functions.empty());
|
||||
|
||||
const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX");
|
||||
|
@ -727,7 +721,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
ASSERT(library.functions.empty());
|
||||
|
||||
ASSERT(Library::isresource(library.allocId("CreateX")));
|
||||
|
@ -744,7 +738,7 @@ private:
|
|||
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
|
||||
"</def>";
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
// s8
|
||||
{
|
||||
const struct Library::PodType * const type = library.podtype("s8");
|
||||
|
@ -822,7 +816,7 @@ private:
|
|||
"</def>";
|
||||
|
||||
Library library;
|
||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
Library::Container& A = library.containers["A"];
|
||||
Library::Container& B = library.containers["B"];
|
||||
|
@ -937,16 +931,14 @@ private:
|
|||
"<def>\n"
|
||||
"</def>";
|
||||
Library library;
|
||||
const Library::Error err = readLibrary(library, xmldata);
|
||||
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
}
|
||||
{
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def format=\"1\">\n"
|
||||
"</def>";
|
||||
Library library;
|
||||
const Library::Error err = readLibrary(library, xmldata);
|
||||
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
||||
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
}
|
||||
{
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||
|
@ -958,6 +950,12 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static Library::Error readLibrary(Library& library, const char* xmldata) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata); // TODO: check result
|
||||
return library.load(doc);
|
||||
}
|
||||
|
||||
void loadLibError(const char xmldata[], Library::ErrorCode errorcode, const char* file, unsigned line) const {
|
||||
Library library;
|
||||
assertEquals(file, line, true, errorcode == readLibrary(library, xmldata).errorcode);
|
||||
|
|
|
@ -151,6 +151,7 @@ private:
|
|||
void run() override {
|
||||
LOAD_LIB_2(settings1.library, "std.cfg");
|
||||
LOAD_LIB_2(settings1.library, "posix.cfg");
|
||||
settings1.libraries.emplace_back("posix");
|
||||
LOAD_LIB_2(settings2.library, "std.cfg");
|
||||
|
||||
TEST_CASE(realloc1);
|
||||
|
@ -1705,6 +1706,7 @@ private:
|
|||
void run() override {
|
||||
LOAD_LIB_2(settings.library, "std.cfg");
|
||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||
settings.libraries.emplace_back("posix");
|
||||
|
||||
// testing that errors are detected
|
||||
TEST_CASE(err);
|
||||
|
@ -2291,11 +2293,11 @@ private:
|
|||
|
||||
void run() override {
|
||||
settings.certainty.setEnabled(Certainty::inconclusive, true);
|
||||
settings.libraries.emplace_back("posix");
|
||||
settings.severity.enable(Severity::warning);
|
||||
|
||||
LOAD_LIB_2(settings.library, "std.cfg");
|
||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||
settings.libraries.emplace_back("posix");
|
||||
|
||||
// pass allocated memory to function..
|
||||
TEST_CASE(functionParameter);
|
||||
|
|
|
@ -5891,9 +5891,7 @@ private:
|
|||
" <arg nr=\"2\"/>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings.library.load(doc);
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
|
||||
check("void foo() {\n"
|
||||
" if (x() || x()) {}\n"
|
||||
|
|
|
@ -45,8 +45,7 @@ private:
|
|||
|
||||
static bool readPlatform(cppcheck::Platform& platform, const char* xmldata) {
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata);
|
||||
return platform.loadFromXmlDocument(&doc);
|
||||
return (doc.Parse(xmldata) == tinyxml2::XML_SUCCESS) && platform.loadFromXmlDocument(&doc);
|
||||
}
|
||||
|
||||
void empty() const {
|
||||
|
|
|
@ -7856,10 +7856,8 @@ private:
|
|||
"<function name=\"g\">\n" \
|
||||
"<returnValue type=\"" #type "\"/>\n" \
|
||||
"</function>\n" \
|
||||
"</def>"; \
|
||||
tinyxml2::XMLDocument doc; \
|
||||
doc.Parse(xmldata, sizeof(xmldata)); \
|
||||
sF.library.load(doc); \
|
||||
"</def>"; \
|
||||
ASSERT(sF.library.loadxmldata(xmldata, sizeof(xmldata))); \
|
||||
ASSERT_EQUALS(#type, typeOf("void f() { auto x = g(); }", "x", "test.cpp", &sF)); \
|
||||
} while (false)
|
||||
// *INDENT-OFF*
|
||||
|
|
|
@ -58,8 +58,11 @@ private:
|
|||
settings_windows.checkUnusedTemplates = true;
|
||||
|
||||
// library=qt
|
||||
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||
settings0.libraries.emplace_back("qt");
|
||||
LOAD_LIB_2(settings1.library, "qt.cfg");
|
||||
settings1.libraries.emplace_back("qt");
|
||||
LOAD_LIB_2(settings2.library, "qt.cfg");
|
||||
settings2.libraries.emplace_back("qt");
|
||||
|
||||
TEST_CASE(tokenize1);
|
||||
|
|
Loading…
Reference in New Issue