2008-12-20 20:07:20 +01:00
|
|
|
/*
|
2009-01-21 21:04:20 +01:00
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
2009-03-01 20:52:33 +01:00
|
|
|
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
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/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-01-06 15:18:36 +01:00
|
|
|
#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")
|
|
|
|
{ }
|
|
|
|
|
2009-02-07 21:06:00 +01:00
|
|
|
class OurCheckMemoryLeakClass : public CheckMemoryLeakClass
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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()
|
|
|
|
{
|
2009-01-05 16:49:57 +01:00
|
|
|
TEST_CASE(param1);
|
2008-12-20 20:07:20 +01:00
|
|
|
}
|
|
|
|
|
2008-12-20 22:52:40 +01:00
|
|
|
void param1()
|
2008-12-20 20:07:20 +01:00
|
|
|
{
|
2008-12-20 22:52:40 +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);
|
2009-01-05 16:49:57 +01:00
|
|
|
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-02-07 21:06:00 +01:00
|
|
|
OurCheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this);
|
2009-01-03 21:29:20 +01:00
|
|
|
Token *tok = checkMemoryLeak.functionParameterCode(tokenizer.tokens(), 1);
|
2008-12-20 20:07:20 +01:00
|
|
|
|
2008-12-20 22:52:40 +01:00
|
|
|
// Compare tokens..
|
|
|
|
std::string s;
|
2009-01-05 16:49:57 +01:00
|
|
|
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
2008-12-20 22:52:40 +01:00
|
|
|
s += tok2->str() + " ";
|
2009-01-05 16:49:57 +01:00
|
|
|
ASSERT_EQUALS("; } ", s);
|
2009-03-17 20:59:40 +01:00
|
|
|
Tokenizer::deleteTokens(tok);
|
2008-12-20 20:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-01-05 16:49:57 +01:00
|
|
|
REGISTER_TEST(TestMemleakMultiPass)
|