Added test file for TOKEN class

This commit is contained in:
Reijo Tomperi 2008-12-09 18:13:38 +00:00
parent 2ef955eb65
commit 237dc98ea5
2 changed files with 64 additions and 1 deletions

View File

@ -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 testsimplifytokens.o testtokenize.o testunusedprivfunc.o testunusedvar.o
TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testmemleak.o testpreprocessor.o testsimplifytokens.o testtokenize.o testtoken.o testunusedprivfunc.o testunusedvar.o
BIN = ${DESTDIR}/usr/bin
all: ${OBJS} main.o
@ -55,6 +55,8 @@ testsimplifytokens.o: testsimplifytokens.cpp testsuite.h errorlogger.h tokenize.
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testsuite.o: testsuite.cpp testsuite.h errorlogger.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testtoken.o: testtoken.cpp testsuite.h errorlogger.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testtokenize.o: testtokenize.cpp testsuite.h errorlogger.h tokenize.h settings.h token.h
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
testunusedprivfunc.o: testunusedprivfunc.cpp tokenize.h settings.h errorlogger.h token.h CheckClass.h testsuite.h

61
testtoken.cpp Normal file
View File

@ -0,0 +1,61 @@
/*
* c++check - c/c++ syntax checking
* Copyright (C) 2008 Daniel Marjamäki and Reijo Tomperi
*
* 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/
*/
#include <cstring>
#include "testsuite.h"
#include "token.h"
extern std::ostringstream errout;
class TestTOKEN : public TestFixture
{
public:
TestTOKEN() : TestFixture("TestTOKEN")
{ }
private:
void run()
{
TEST_CASE( nextprevious );
}
void nextprevious()
{
TOKEN *token = new TOKEN;
token->setstr( "1" );
token->insertToken( "2" );
token->next()->insertToken( "3" );
TOKEN *last = token->next()->next();
ASSERT_EQUALS( token->str(), "1" );
ASSERT_EQUALS( token->next()->str(), "2" );
ASSERT_EQUALS( token->next()->next()->str(), "3" );
if( last->next() )
ASSERT_EQUALS( "Null was expected", "" );
ASSERT_EQUALS( last->str(), "3" );
ASSERT_EQUALS( last->previous()->str(), "2" );
ASSERT_EQUALS( last->previous()->previous()->str(), "1" );
if( token->previous() )
ASSERT_EQUALS( "Null was expected", "" );
}
};
REGISTER_TEST( TestTOKEN )