2009-02-05 21:06:39 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2010-04-13 21:23:17 +02:00
|
|
|
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
|
2009-02-05 21:06:39 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-05 21:06:39 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-07-05 22:16:43 +02:00
|
|
|
// The preprocessor that Cppcheck uses is a bit special. Instead of generating
|
2009-02-05 21:06:39 +01:00
|
|
|
// the code for a known configuration, it generates the code for each configuration.
|
|
|
|
|
|
|
|
|
2009-10-25 12:49:06 +01:00
|
|
|
#include "cppcheck.h"
|
2010-10-22 17:09:50 +02:00
|
|
|
#include "cppcheckexecutor.h"
|
2009-02-05 21:06:39 +01:00
|
|
|
#include "testsuite.h"
|
2010-07-19 22:02:51 +02:00
|
|
|
#include "path.h"
|
2009-02-05 21:06:39 +01:00
|
|
|
|
2010-05-17 19:18:05 +02:00
|
|
|
#include <algorithm>
|
2009-02-05 21:06:39 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2010-04-11 14:25:30 +02:00
|
|
|
#include <stdexcept>
|
2009-02-05 21:06:39 +01:00
|
|
|
|
2010-05-13 22:14:29 +02:00
|
|
|
// use tinyxml with STL
|
|
|
|
#include "tinyxml/tinyxml.h"
|
|
|
|
|
2009-02-05 21:06:39 +01:00
|
|
|
extern std::ostringstream errout;
|
2010-04-06 21:13:23 +02:00
|
|
|
extern std::ostringstream output;
|
2009-02-05 21:06:39 +01:00
|
|
|
|
|
|
|
class TestCppcheck : public TestFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestCppcheck() : TestFixture("TestCppcheck")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void check(const std::string &data)
|
|
|
|
{
|
|
|
|
errout.str("");
|
2010-04-06 21:13:23 +02:00
|
|
|
output.str("");
|
2009-02-05 21:06:39 +01:00
|
|
|
CppCheck cppCheck(*this);
|
|
|
|
cppCheck.addFile("file.cpp", data);
|
|
|
|
cppCheck.check();
|
|
|
|
}
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
2010-10-22 17:09:50 +02:00
|
|
|
TEST_CASE(nonexistingpath);
|
2009-02-05 21:29:55 +01:00
|
|
|
TEST_CASE(linenumbers);
|
|
|
|
// TEST_CASE(linenumbers2);
|
2009-04-23 21:59:26 +02:00
|
|
|
|
|
|
|
TEST_CASE(xml);
|
2009-05-31 10:12:19 +02:00
|
|
|
|
|
|
|
TEST_CASE(include);
|
2009-09-05 21:01:49 +02:00
|
|
|
TEST_CASE(templateFormat);
|
2010-09-05 10:05:25 +02:00
|
|
|
//TEST_CASE(getErrorMessages);
|
|
|
|
//TEST_CASE(parseOutputtingArgs);
|
|
|
|
//TEST_CASE(parseOutputtingInvalidArgs);
|
|
|
|
//TEST_CASE(parseArgsAndCheck);
|
|
|
|
//TEST_CASE(parseArgsAndCheckSettings);
|
2010-05-16 07:38:29 +02:00
|
|
|
|
2010-09-05 10:05:25 +02:00
|
|
|
//TEST_CASE(userdefines);
|
2010-04-06 21:13:23 +02:00
|
|
|
}
|
|
|
|
|
2010-09-05 10:05:25 +02:00
|
|
|
#if 0
|
2010-04-11 21:53:21 +02:00
|
|
|
bool argCheck(int argc, const char *argv[])
|
2010-04-06 21:13:23 +02:00
|
|
|
{
|
|
|
|
errout.str("");
|
|
|
|
output.str("");
|
|
|
|
CppCheck cppCheck(*this);
|
2010-04-11 21:53:21 +02:00
|
|
|
return cppCheck.parseFromArgs(argc, argv);
|
2010-04-06 21:13:23 +02:00
|
|
|
}
|
|
|
|
|
2010-05-13 22:14:29 +02:00
|
|
|
bool argCheckWithCoutCerrRedirect(int argc, const char * argv[])
|
|
|
|
{
|
|
|
|
// redirect cout and cerr
|
|
|
|
std::stringstream out, err;
|
|
|
|
std::streambuf* oldCout, *oldCerr;
|
|
|
|
|
|
|
|
// flush all old output
|
|
|
|
std::cout.flush();
|
|
|
|
std::cerr.flush();
|
|
|
|
|
|
|
|
oldCout = std::cout.rdbuf(); // back up cout's streambuf
|
|
|
|
oldCerr = std::cerr.rdbuf(); // back up cerr's streambuf
|
|
|
|
|
|
|
|
std::cout.rdbuf(out.rdbuf()); // assign streambuf to cout
|
|
|
|
std::cerr.rdbuf(err.rdbuf()); // assign streambuf to cerr
|
|
|
|
|
|
|
|
bool result = argCheck(argc, argv);
|
|
|
|
|
|
|
|
std::cout.rdbuf(oldCout); // restore cout's original streambuf
|
|
|
|
std::cerr.rdbuf(oldCerr); // restore cerrs's original streambuf
|
|
|
|
|
|
|
|
errout << err.str();
|
|
|
|
output << out.str();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-13 22:52:19 +02:00
|
|
|
bool argCheckWithCheck(int argc, const char *argv[], const std::string &data)
|
|
|
|
{
|
|
|
|
errout.str("");
|
|
|
|
output.str("");
|
|
|
|
CppCheck cppCheck(*this);
|
|
|
|
cppCheck.addFile("file.cpp", data);
|
|
|
|
bool result = cppCheck.parseFromArgs(argc, argv);
|
|
|
|
if (result)
|
|
|
|
cppCheck.check();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-16 17:28:00 +02:00
|
|
|
bool argCheckReturnSettings(int argc, const char *argv[], Settings &settings)
|
|
|
|
{
|
|
|
|
errout.str("");
|
|
|
|
output.str("");
|
|
|
|
CppCheck cppCheck(*this);
|
|
|
|
cppCheck.addFile("file.cpp", "void foo(){}");
|
|
|
|
bool result = cppCheck.parseFromArgs(argc, argv);
|
|
|
|
if (result)
|
|
|
|
settings = cppCheck.settings();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void parseArgsAndCheckSettings()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "gcc"};
|
|
|
|
Settings settings;
|
|
|
|
ASSERT_EQUALS(true, argCheckReturnSettings(3, argv, settings));
|
|
|
|
ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "vs"};
|
|
|
|
Settings settings;
|
|
|
|
ASSERT_EQUALS(true, argCheckReturnSettings(3, argv, settings));
|
|
|
|
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--template", "{file}<->{line}"};
|
|
|
|
Settings settings;
|
|
|
|
ASSERT_EQUALS(true, argCheckReturnSettings(3, argv, settings));
|
|
|
|
ASSERT_EQUALS("{file}<->{line}", settings._outputFormat);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--template"};
|
|
|
|
Settings settings;
|
|
|
|
ASSERT_EQUALS(false, argCheckReturnSettings(2, argv, settings));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: argument to '--template' is missing\n", output.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-13 22:52:19 +02:00
|
|
|
void parseArgsAndCheck()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--showtime=top5"};
|
|
|
|
const char *data = "void foo(){}";
|
|
|
|
ASSERT_EQUALS(true, argCheckWithCheck(2, argv, data));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
// ASSERT_EQUALS(true, output.str().find("Overall time:") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 10:05:25 +02:00
|
|
|
#endif
|
2010-04-13 22:52:19 +02:00
|
|
|
|
2010-05-13 22:14:29 +02:00
|
|
|
void parseErrorList(const char* xmlData)
|
|
|
|
{
|
|
|
|
TiXmlDocument doc;
|
|
|
|
doc.Parse(xmlData);
|
2010-12-15 18:45:53 +01:00
|
|
|
// parsing must be successful
|
2010-05-13 22:14:29 +02:00
|
|
|
ASSERT_EQUALS(false, doc.Error());
|
|
|
|
// root element must be "results"
|
|
|
|
TiXmlElement* root = doc.FirstChildElement();
|
|
|
|
ASSERT_EQUALS("results", root->Value());
|
|
|
|
|
|
|
|
TiXmlElement* error = root->FirstChildElement();
|
|
|
|
std::list<std::string> idList;
|
|
|
|
|
|
|
|
while (error)
|
|
|
|
{
|
|
|
|
// only childs of type "error"
|
|
|
|
ASSERT_EQUALS("error", error->Value());
|
|
|
|
// attributes id, msg, severity
|
|
|
|
ASSERT_EQUALS(error->Attribute("msg") == NULL, false);
|
|
|
|
ASSERT_EQUALS(error->Attribute("severity") == NULL, false);
|
|
|
|
const char* id = error->Attribute("id");
|
|
|
|
ASSERT_EQUALS(id == NULL, false);
|
|
|
|
// no duplicate ids
|
|
|
|
std::stringstream msg;
|
|
|
|
msg << "Duplicate id " << id;
|
|
|
|
ASSERT_EQUALS_MSG(idList.end() == std::find(idList.begin(), idList.end(), id), true, msg.str());
|
|
|
|
idList.push_back(id);
|
|
|
|
error = error->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-05 10:05:25 +02:00
|
|
|
#if 0
|
2010-04-11 14:25:30 +02:00
|
|
|
void parseOutputtingArgs()
|
2010-04-06 21:13:23 +02:00
|
|
|
{
|
2010-05-13 22:14:29 +02:00
|
|
|
{
|
|
|
|
const char *argv[] = { "cppcheck", "--errorlist" };
|
|
|
|
ASSERT_EQUALS(true, argCheckWithCoutCerrRedirect(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
parseErrorList(output.str().c_str());
|
|
|
|
}
|
|
|
|
|
2010-04-06 21:13:23 +02:00
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--help"};
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(true, argCheck(2, argv));
|
2010-04-06 21:13:23 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS(true, output.str().find("Example usage") != std::string::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2010-04-13 19:25:08 +02:00
|
|
|
const char *argv[] = {"cppcheck", "-h"};
|
|
|
|
ASSERT_EQUALS(true, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS(true, output.str().find("Example usage") != std::string::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2010-04-06 21:13:23 +02:00
|
|
|
const char *argv[] = {"cppcheck"};
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(true, argCheck(1, argv));
|
2010-04-06 21:13:23 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS(true, output.str().find("Example usage") != std::string::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--version"};
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(true, argCheck(2, argv));
|
2010-04-06 21:13:23 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS(std::string("Cppcheck ") + CppCheck::version() + "\n", output.str());
|
|
|
|
}
|
2010-04-11 14:25:30 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--doc"};
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(true, argCheck(2, argv));
|
2010-04-11 14:25:30 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(true, output.str().find("===Bounds checking===") != std::string::npos);
|
|
|
|
ASSERT_EQUALS(true, output.str().find("===Unused functions===") != std::string::npos);
|
2010-04-11 14:25:30 +02:00
|
|
|
}
|
2010-04-11 21:53:21 +02:00
|
|
|
}
|
2010-04-11 14:25:30 +02:00
|
|
|
|
2010-04-11 21:53:21 +02:00
|
|
|
void parseOutputtingInvalidArgs()
|
|
|
|
{
|
2010-04-11 14:25:30 +02:00
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--invalidArg"};
|
2010-04-11 21:53:21 +02:00
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--invalidArg\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--suppressions"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: No file specified for the --suppressions option\n", output.str());
|
2010-04-11 14:25:30 +02:00
|
|
|
}
|
2010-04-13 19:25:08 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--exitcode-suppressions"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: No file specified for the --exitcode-suppressions option\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--enable"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--enable\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--append"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--append\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--error-exitcode"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--error-exitcode\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--file-list"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--file-list\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--showtime"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: error: unrecognized command line option \"--showtime\"\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "-I"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: argument to '-I' is missing\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "-j"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: argument to '-j' is missing\n", output.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "--template"};
|
|
|
|
ASSERT_EQUALS(false, argCheck(2, argv));
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("cppcheck: argument to '--template' is missing\n", output.str());
|
|
|
|
}
|
2009-02-05 21:06:39 +01:00
|
|
|
}
|
2010-09-05 10:05:25 +02:00
|
|
|
#endif
|
2009-02-05 21:06:39 +01:00
|
|
|
|
2010-10-22 17:09:50 +02:00
|
|
|
void nonexistingpath()
|
|
|
|
{
|
|
|
|
CppCheckExecutor exec;
|
2010-10-23 16:15:27 +02:00
|
|
|
const char *argv[] = { "", "idontexist" };
|
2010-10-22 17:09:50 +02:00
|
|
|
int retval = exec.check(2, argv);
|
|
|
|
|
|
|
|
ASSERT_EQUALS(retval, EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2009-02-05 21:06:39 +01:00
|
|
|
void linenumbers()
|
|
|
|
{
|
|
|
|
const char filedata[] = "void f()\n"
|
|
|
|
"{\n"
|
|
|
|
" char *foo = new char[10];\n"
|
|
|
|
" delete [] foo;\n"
|
|
|
|
" foo[3] = 0;\n"
|
|
|
|
"}\n";
|
|
|
|
check(filedata);
|
|
|
|
|
|
|
|
// Compare results..
|
2010-04-06 21:13:23 +02:00
|
|
|
ASSERT_EQUALS("Checking file.cpp...\n", output.str());
|
|
|
|
ASSERT_EQUALS("[file.cpp:5]: (error) Dereferencing 'foo' after it is deallocated / released\n", errout.str());
|
2009-02-05 21:06:39 +01:00
|
|
|
}
|
2009-02-05 21:29:55 +01:00
|
|
|
|
|
|
|
void linenumbers2()
|
|
|
|
{
|
|
|
|
const char filedata[] = "void f()\n"
|
|
|
|
"{\n"
|
|
|
|
" char *string;\n"
|
|
|
|
" string = new char[20];\n"
|
|
|
|
" string = new char[30];\n"
|
|
|
|
" delete [] string;\n"
|
|
|
|
"}\n";
|
|
|
|
check(filedata);
|
|
|
|
|
|
|
|
// Compare results..
|
2009-02-05 22:06:32 +01:00
|
|
|
ASSERT_EQUALS("[file.cpp:5]: (error) Memory leak: string\n", errout.str());
|
2009-02-05 21:29:55 +01:00
|
|
|
}
|
2009-04-23 21:59:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
void xml()
|
|
|
|
{
|
|
|
|
// Test the errorlogger..
|
2010-04-09 21:40:37 +02:00
|
|
|
ErrorLogger::ErrorMessage errorMessage;
|
2010-11-11 19:54:43 +01:00
|
|
|
errorMessage.setmsg("ab<cd>ef");
|
2010-12-02 17:32:51 +01:00
|
|
|
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab<cd>ef\"/>", errorMessage.toXML(false,1));
|
2009-04-23 21:59:26 +02:00
|
|
|
}
|
2009-05-31 10:12:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
void include()
|
|
|
|
{
|
2010-04-09 21:40:37 +02:00
|
|
|
ErrorLogger::ErrorMessage errorMessage;
|
2009-05-31 10:12:19 +02:00
|
|
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
2010-07-17 00:27:40 +02:00
|
|
|
loc.setfile("ab/cd/../ef.h");
|
2010-04-09 21:40:37 +02:00
|
|
|
errorMessage._callStack.push_back(loc);
|
2010-07-19 22:02:51 +02:00
|
|
|
const std::string fname(Path::toNativeSeparators("ab/ef.h"));
|
2010-12-02 17:32:51 +01:00
|
|
|
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML(false,1));
|
2010-11-11 19:54:43 +01:00
|
|
|
ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString(false));
|
2009-05-31 10:12:19 +02:00
|
|
|
}
|
|
|
|
|
2009-09-05 21:01:49 +02:00
|
|
|
void templateFormat()
|
|
|
|
{
|
2010-04-09 21:40:37 +02:00
|
|
|
ErrorLogger::ErrorMessage errorMessage;
|
2009-09-05 21:01:49 +02:00
|
|
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
2010-07-17 00:27:40 +02:00
|
|
|
loc.setfile("some/{file}file.cpp");
|
2009-09-05 21:01:49 +02:00
|
|
|
loc.line = 10;
|
2010-04-09 21:40:37 +02:00
|
|
|
errorMessage._callStack.push_back(loc);
|
|
|
|
errorMessage._id = "testId";
|
2010-07-14 19:00:32 +02:00
|
|
|
errorMessage._severity = Severity::fromString("error");
|
2010-11-11 19:54:43 +01:00
|
|
|
errorMessage.setmsg("long testMessage");
|
2010-07-19 22:02:51 +02:00
|
|
|
const std::string fname(Path::toNativeSeparators("some/{file}file.cpp"));
|
2010-12-02 17:32:51 +01:00
|
|
|
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"10\" id=\"testId\" severity=\"error\" msg=\"long testMessage\"/>", errorMessage.toXML(false,1));
|
2010-11-11 19:54:43 +01:00
|
|
|
ASSERT_EQUALS("[" + fname + ":10]: (error) long testMessage", errorMessage.toString(false));
|
|
|
|
ASSERT_EQUALS("testId-" + fname + ",error.10?{long testMessage}", errorMessage.toString(false, "{id}-{file},{severity}.{line}?{{message}}"));
|
2009-09-05 21:01:49 +02:00
|
|
|
}
|
2010-04-03 21:53:06 +02:00
|
|
|
|
|
|
|
void getErrorMessages()
|
|
|
|
{
|
|
|
|
errout.str("");
|
|
|
|
CppCheck cppCheck(*this);
|
|
|
|
cppCheck.getErrorMessages();
|
|
|
|
}
|
2010-05-16 07:38:29 +02:00
|
|
|
|
2010-09-05 10:05:25 +02:00
|
|
|
#if 0
|
2010-05-16 07:38:29 +02:00
|
|
|
void userdefines()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *argv[] = {"cppcheck", "-DA", "-DB"};
|
|
|
|
Settings settings;
|
|
|
|
ASSERT_EQUALS(true, argCheckReturnSettings(3, argv, settings));
|
|
|
|
ASSERT_EQUALS("A;B", settings.userDefines);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT_EQUALS("", output.str());
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 10:05:25 +02:00
|
|
|
#endif
|
2009-02-05 21:06:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestCppcheck)
|