|
| 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