2008-11-15 17:27:09 +01:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "testsuite.h"
|
|
|
|
#include "tokenize.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
2008-11-20 23:19:26 +01:00
|
|
|
extern std::ostringstream errout;
|
|
|
|
|
2008-11-15 17:27:09 +01:00
|
|
|
class TestSimplifyTokens : public TestFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestSimplifyTokens() : TestFixture("TestSimplifyTokens")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
TEST_CASE( cast0 );
|
2008-11-15 18:21:35 +01:00
|
|
|
TEST_CASE( sizeof1 );
|
2008-11-15 17:27:09 +01:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:19:26 +01:00
|
|
|
std::string tok(const char code[])
|
2008-11-15 17:27:09 +01:00
|
|
|
{
|
|
|
|
std::istringstream istr(code);
|
2008-11-22 20:39:12 +01:00
|
|
|
Tokenizer tokenizer;
|
2008-11-15 17:27:09 +01:00
|
|
|
tokenizer.TokenizeCode( istr );
|
|
|
|
tokenizer.SimplifyTokenList();
|
|
|
|
|
|
|
|
std::string ret;
|
2008-11-16 16:58:52 +01:00
|
|
|
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next )
|
2008-11-15 17:27:09 +01:00
|
|
|
{
|
|
|
|
ret += std::string(tok->str) + " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cast0()
|
|
|
|
{
|
|
|
|
const char code1[] = " if ( p == (char *)0 ) ";
|
|
|
|
const char code2[] = " if ( p == 0 ) ";
|
|
|
|
ASSERT_EQUALS( tok(code1), tok(code2) );
|
|
|
|
}
|
2008-11-15 18:21:35 +01:00
|
|
|
|
|
|
|
void sizeof1()
|
|
|
|
{
|
|
|
|
const char code1[] = " struct ABC *abc = malloc(sizeof(*abc)); ";
|
|
|
|
const char code2[] = " struct ABC *abc = malloc(100); ";
|
|
|
|
ASSERT_EQUALS( tok(code1), tok(code2) );
|
|
|
|
}
|
2008-11-15 17:27:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST( TestSimplifyTokens )
|