2009-02-05 21:06:39 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2011-01-09 20:33:36 +01:00
|
|
|
* Copyright (C) 2007-2011 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 run()
|
|
|
|
{
|
2010-09-05 10:05:25 +02:00
|
|
|
//TEST_CASE(getErrorMessages);
|
2010-04-06 21:13:23 +02:00
|
|
|
}
|
|
|
|
|
2010-09-05 10:05:25 +02:00
|
|
|
#if 0
|
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-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-04-03 21:53:06 +02:00
|
|
|
void getErrorMessages()
|
|
|
|
{
|
|
|
|
errout.str("");
|
|
|
|
CppCheck cppCheck(*this);
|
|
|
|
cppCheck.getErrorMessages();
|
|
|
|
}
|
2010-05-16 07:38:29 +02:00
|
|
|
|
2009-02-05 21:06:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestCppcheck)
|