From 11f05fe7e99d7c5b884e0f4ff1c1961f565854b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 19 Dec 2008 21:15:18 +0000 Subject: [PATCH] Redundant condition: Added a test case when a condition is not redundant --- Makefile | 4 ++- testother.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 testother.cpp diff --git a/Makefile b/Makefile index 34b16b85c..ac1190fa3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SRCS=checkbufferoverrun.cpp checkclass.cpp checkheaders.cpp checkmemoryleak.cpp checkfunctionusage.cpp checkother.cpp filelister.cpp preprocessor.cpp tokenize.cpp cppcheck.cpp settings.cpp token.cpp cppcheckexecutor.cpp OBJS=$(SRCS:%.cpp=%.o) -TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testmemleak.o testpreprocessor.o testredundantif.o testsimplifytokens.o testtokenize.o testtoken.o testunusedprivfunc.o testunusedvar.o testfilelister.o +TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testother.o testmemleak.o testpreprocessor.o testredundantif.o testsimplifytokens.o testtokenize.o testtoken.o testunusedprivfunc.o testunusedvar.o testfilelister.o BIN = ${DESTDIR}/usr/bin all: ${OBJS} main.o @@ -45,6 +45,8 @@ testfunctionusage.o: testfunctionusage.cpp tokenize.h settings.h errorlogger.h t g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp testincompletestatement.o: testincompletestatement.cpp testsuite.h errorlogger.h tokenize.h settings.h token.h checkother.h g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp +testother.o: testother.cpp testsuite.h errorlogger.h tokenize.h settings.h token.h checkother.h + g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp testmemleak.o: testmemleak.cpp tokenize.h settings.h errorlogger.h token.h checkmemoryleak.h testsuite.h g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp testpreprocessor.o: testpreprocessor.cpp testsuite.h errorlogger.h preprocessor.h diff --git a/testother.cpp b/testother.cpp new file mode 100644 index 000000000..9c221a98a --- /dev/null +++ b/testother.cpp @@ -0,0 +1,70 @@ +/* + * c++check - c/c++ syntax checking + * Copyright (C) 2007 Daniel Marjamäki + * + * 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 + +extern std::ostringstream errout; + +class TestOther : public TestFixture +{ +public: + TestOther() : TestFixture("TestOther") + { } + +private: + + + void run() + { + // TODO TEST_CASE( delete1 ); + } + + void check( const char code[] ) + { + // Tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize( istr, "test.cpp" ); + + // Clear the error buffer.. + errout.str(""); + + // Check for redundant code.. + CheckOther checkOther( &tokenizer, this ); + checkOther.WarningRedundantCode(); + } + + void delete1() + { + check( "void foo()\n" + "{\n" + " if (p)\n" + " {\n" + " delete p;\n" + " abc = 123;\n" + " }\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } +}; + +REGISTER_TEST( TestOther ) +