testcppcheck.cpp file added, test case "linenumbers" added, codeblocks project file updated
This commit is contained in:
parent
05e330ed38
commit
7589dc3d16
6
Makefile
6
Makefile
|
@ -25,6 +25,7 @@ TESTOBJ = test/testbufferoverrun.o \
|
||||||
test/testcharvar.o \
|
test/testcharvar.o \
|
||||||
test/testclass.o \
|
test/testclass.o \
|
||||||
test/testconstructors.o \
|
test/testconstructors.o \
|
||||||
|
test/testcppcheck.o \
|
||||||
test/testdangerousfunctions.o \
|
test/testdangerousfunctions.o \
|
||||||
test/testdivision.o \
|
test/testdivision.o \
|
||||||
test/testfilelister.o \
|
test/testfilelister.o \
|
||||||
|
@ -117,7 +118,7 @@ src/cppcheck.o: src/cppcheck.cpp src/cppcheck.h src/settings.h src/errorlogger.h
|
||||||
src/cppcheckexecutor.o: src/cppcheckexecutor.cpp src/cppcheckexecutor.h src/errorlogger.h src/cppcheck.h src/settings.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
src/cppcheckexecutor.o: src/cppcheckexecutor.cpp src/cppcheckexecutor.h src/errorlogger.h src/cppcheck.h src/settings.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/cppcheckexecutor.o src/cppcheckexecutor.cpp
|
g++ $(CXXFLAGS) -c -o src/cppcheckexecutor.o src/cppcheckexecutor.cpp
|
||||||
|
|
||||||
src/errormessage.o: src/errormessage.cpp src/errormessage.h src/settings.h src/tokenize.h src/errorlogger.h src/token.h
|
src/errormessage.o: src/errormessage.cpp src/errormessage.h src/settings.h src/errorlogger.h src/tokenize.h src/token.h
|
||||||
g++ $(CXXFLAGS) -c -o src/errormessage.o src/errormessage.cpp
|
g++ $(CXXFLAGS) -c -o src/errormessage.o src/errormessage.cpp
|
||||||
|
|
||||||
src/filelister.o: src/filelister.cpp src/filelister.h
|
src/filelister.o: src/filelister.cpp src/filelister.h
|
||||||
|
@ -150,6 +151,9 @@ test/testclass.o: test/testclass.cpp src/tokenize.h src/settings.h src/errorlogg
|
||||||
test/testconstructors.o: test/testconstructors.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
test/testconstructors.o: test/testconstructors.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testconstructors.o test/testconstructors.cpp
|
g++ $(CXXFLAGS) -c -o test/testconstructors.o test/testconstructors.cpp
|
||||||
|
|
||||||
|
test/testcppcheck.o: test/testcppcheck.cpp test/testsuite.h src/errorlogger.h src/cppcheck.h src/settings.h src/checkfunctionusage.h src/tokenize.h src/token.h
|
||||||
|
g++ $(CXXFLAGS) -c -o test/testcppcheck.o test/testcppcheck.cpp
|
||||||
|
|
||||||
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h test/testsuite.h
|
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h test/testsuite.h
|
||||||
g++ $(CXXFLAGS) -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp
|
g++ $(CXXFLAGS) -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
<Unit filename="test/testcharvar.cpp" />
|
<Unit filename="test/testcharvar.cpp" />
|
||||||
<Unit filename="test/testclass.cpp" />
|
<Unit filename="test/testclass.cpp" />
|
||||||
<Unit filename="test/testconstructors.cpp" />
|
<Unit filename="test/testconstructors.cpp" />
|
||||||
|
<Unit filename="test/testcppcheck.cpp" />
|
||||||
<Unit filename="test/testdangerousfunctions.cpp" />
|
<Unit filename="test/testdangerousfunctions.cpp" />
|
||||||
<Unit filename="test/testdivision.cpp" />
|
<Unit filename="test/testdivision.cpp" />
|
||||||
<Unit filename="test/testfilelister.cpp" />
|
<Unit filename="test/testfilelister.cpp" />
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
||||||
|
* Leandro Penz, Kimmo Varis
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// The preprocessor that c++check uses is a bit special. Instead of generating
|
||||||
|
// the code for a known configuration, it generates the code for each configuration.
|
||||||
|
|
||||||
|
|
||||||
|
#include "testsuite.h"
|
||||||
|
#include "../src/cppcheck.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
extern std::ostringstream errout;
|
||||||
|
|
||||||
|
class TestCppcheck : public TestFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestCppcheck() : TestFixture("TestCppcheck")
|
||||||
|
{ }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void check(const std::string &data)
|
||||||
|
{
|
||||||
|
errout.str("");
|
||||||
|
CppCheck cppCheck(*this);
|
||||||
|
cppCheck.addFile("file.cpp", data);
|
||||||
|
cppCheck.check();
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
// TEST_CASE(linenumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
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..
|
||||||
|
ASSERT_EQUALS("[file.cpp:5]: Using \"foo\" after it has been deallocated / released\n", errout.str());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_TEST(TestCppcheck)
|
Loading…
Reference in New Issue