Skip to content

Commit 7589dc3

Browse files
committed
testcppcheck.cpp file added, test case "linenumbers" added, codeblocks project file updated
1 parent 05e330e commit 7589dc3

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ TESTOBJ = test/testbufferoverrun.o \
2525
test/testcharvar.o \
2626
test/testclass.o \
2727
test/testconstructors.o \
28+
test/testcppcheck.o \
2829
test/testdangerousfunctions.o \
2930
test/testdivision.o \
3031
test/testfilelister.o \
@@ -117,7 +118,7 @@ src/cppcheck.o: src/cppcheck.cpp src/cppcheck.h src/settings.h src/errorlogger.h
117118
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
118119
g++ $(CXXFLAGS) -c -o src/cppcheckexecutor.o src/cppcheckexecutor.cpp
119120

120-
src/errormessage.o: src/errormessage.cpp src/errormessage.h src/settings.h src/tokenize.h src/errorlogger.h src/token.h
121+
src/errormessage.o: src/errormessage.cpp src/errormessage.h src/settings.h src/errorlogger.h src/tokenize.h src/token.h
121122
g++ $(CXXFLAGS) -c -o src/errormessage.o src/errormessage.cpp
122123

123124
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
150151
test/testconstructors.o: test/testconstructors.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkclass.h test/testsuite.h
151152
g++ $(CXXFLAGS) -c -o test/testconstructors.o test/testconstructors.cpp
152153

154+
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
155+
g++ $(CXXFLAGS) -c -o test/testcppcheck.o test/testcppcheck.cpp
156+
153157
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/checkdangerousfunctions.h test/testsuite.h
154158
g++ $(CXXFLAGS) -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp
155159

cppcheck.cbp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<Unit filename="test/testcharvar.cpp" />
6767
<Unit filename="test/testclass.cpp" />
6868
<Unit filename="test/testconstructors.cpp" />
69+
<Unit filename="test/testcppcheck.cpp" />
6970
<Unit filename="test/testdangerousfunctions.cpp" />
7071
<Unit filename="test/testdivision.cpp" />
7172
<Unit filename="test/testfilelister.cpp" />

test/testcppcheck.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
4+
* Leandro Penz, Kimmo Varis
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/
18+
*/
19+
20+
21+
// The preprocessor that c++check uses is a bit special. Instead of generating
22+
// the code for a known configuration, it generates the code for each configuration.
23+
24+
25+
#include "testsuite.h"
26+
#include "../src/cppcheck.h"
27+
28+
#include <map>
29+
#include <string>
30+
31+
extern std::ostringstream errout;
32+
33+
class TestCppcheck : public TestFixture
34+
{
35+
public:
36+
TestCppcheck() : TestFixture("TestCppcheck")
37+
{ }
38+
39+
private:
40+
41+
void check(const std::string &data)
42+
{
43+
errout.str("");
44+
CppCheck cppCheck(*this);
45+
cppCheck.addFile("file.cpp", data);
46+
cppCheck.check();
47+
}
48+
49+
void run()
50+
{
51+
// TEST_CASE(linenumbers);
52+
}
53+
54+
void linenumbers()
55+
{
56+
const char filedata[] = "void f()\n"
57+
"{\n"
58+
" char *foo = new char[10];\n"
59+
" delete [] foo;\n"
60+
" foo[3] = 0;\n"
61+
"}\n";
62+
check(filedata);
63+
64+
// Compare results..
65+
ASSERT_EQUALS("[file.cpp:5]: Using \"foo\" after it has been deallocated / released\n", errout.str());
66+
}
67+
};
68+
69+
REGISTER_TEST(TestCppcheck)

0 commit comments

Comments
 (0)