cppcheck/test/testmemleakmp.cpp

86 lines
2.4 KiB
C++
Raw Normal View History

2008-12-20 20:07:20 +01:00
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
2008-12-20 20:07:20 +01:00
*
* 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 "../src/tokenize.h"
#include "../src/checkmemoryleak.h"
2008-12-20 20:07:20 +01:00
#include "testsuite.h"
#include <sstream>
extern std::ostringstream errout;
class TestMemleakMultiPass : public TestFixture
{
public:
TestMemleakMultiPass() : TestFixture("TestMemleakMultiPass")
{ }
class OurCheckMemoryLeakClass : public CheckMemoryLeakClass
{
public:
2009-03-20 18:16:21 +01:00
OurCheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: CheckMemoryLeakClass(tokenizer, settings, errorLogger)
{
}
Token *functionParameterCode(const Token *ftok, int parameter)
{
return CheckMemoryLeakClass::functionParameterCode(ftok, parameter);
}
};
2008-12-20 20:07:20 +01:00
private:
void run()
{
TEST_CASE(param1);
2008-12-20 20:07:20 +01:00
}
void param1()
2008-12-20 20:07:20 +01:00
{
const char code[] = "void f(char *s)\n"
"{\n"
" ;\n"
"}\n";
2008-12-20 20:07:20 +01:00
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
2008-12-20 20:07:20 +01:00
tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check..
Settings settings;
2009-03-20 18:16:21 +01:00
OurCheckMemoryLeakClass checkMemoryLeak(&tokenizer, &settings, this);
Token *tok = checkMemoryLeak.functionParameterCode(tokenizer.tokens(), 1);
2008-12-20 20:07:20 +01:00
// Compare tokens..
std::string s;
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
s += tok2->str() + " ";
ASSERT_EQUALS("; } ", s);
2009-03-17 20:59:40 +01:00
Tokenizer::deleteTokens(tok);
2008-12-20 20:07:20 +01:00
}
};
REGISTER_TEST(TestMemleakMultiPass)