2010-12-30 09:46:44 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2012-01-01 00:05:37 +01:00
|
|
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
2010-12-30 09:46:44 +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 "testsuite.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "symboldatabase.h"
|
|
|
|
|
2011-01-28 08:33:02 +01:00
|
|
|
#define GET_SYMBOL_DB(code) \
|
|
|
|
errout.str(""); \
|
|
|
|
Settings settings; \
|
|
|
|
Tokenizer tokenizer(&settings, this); \
|
|
|
|
std::istringstream istr(code); \
|
|
|
|
tokenizer.tokenize(istr, "test.cpp"); \
|
|
|
|
const SymbolDatabase *db = tokenizer.getSymbolDatabase();
|
|
|
|
|
2012-01-28 01:24:01 +01:00
|
|
|
#define GET_SYMBOL_DB_C(code) \
|
|
|
|
errout.str(""); \
|
|
|
|
Settings settings; \
|
|
|
|
Tokenizer tokenizer(&settings, this); \
|
|
|
|
std::istringstream istr(code); \
|
|
|
|
tokenizer.tokenize(istr, "test.c"); \
|
|
|
|
const SymbolDatabase *db = tokenizer.getSymbolDatabase();
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
class TestSymbolDatabase: public TestFixture {
|
2010-12-30 09:46:44 +01:00
|
|
|
public:
|
|
|
|
TestSymbolDatabase()
|
|
|
|
:TestFixture("TestSymbolDatabase")
|
|
|
|
,si(NULL, NULL, NULL)
|
|
|
|
,vartok(NULL)
|
2010-12-30 22:57:43 +01:00
|
|
|
,typetok(NULL)
|
2011-01-21 23:48:42 +01:00
|
|
|
,t(NULL)
|
|
|
|
,found(false)
|
2011-02-27 16:21:14 +01:00
|
|
|
,isArray(false)
|
2011-12-17 19:04:03 +01:00
|
|
|
,isPointer(false)
|
2012-01-26 17:04:25 +01:00
|
|
|
,isReference(false)
|
2010-12-30 09:46:44 +01:00
|
|
|
{}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
virtual void reportOut(const std::string &outmsg) {
|
2011-09-29 04:05:26 +02:00
|
|
|
errout << outmsg << std::endl;
|
|
|
|
}
|
|
|
|
|
2010-12-30 09:46:44 +01:00
|
|
|
private:
|
2011-01-17 18:29:19 +01:00
|
|
|
const Scope si;
|
2010-12-30 09:46:44 +01:00
|
|
|
const Token* vartok;
|
2010-12-30 22:57:43 +01:00
|
|
|
const Token* typetok;
|
2011-01-02 00:36:22 +01:00
|
|
|
const Token* t;
|
|
|
|
bool found;
|
2011-02-27 16:21:14 +01:00
|
|
|
bool isArray;
|
2011-12-17 19:04:03 +01:00
|
|
|
bool isPointer;
|
2012-01-26 17:04:25 +01:00
|
|
|
bool isReference;
|
2010-12-30 22:57:43 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void reset() {
|
2010-12-30 22:57:43 +01:00
|
|
|
vartok = NULL;
|
|
|
|
typetok = NULL;
|
2011-01-02 00:36:22 +01:00
|
|
|
t = NULL;
|
|
|
|
found = false;
|
2011-02-27 16:21:14 +01:00
|
|
|
isArray = false;
|
2011-12-17 19:04:03 +01:00
|
|
|
isPointer = false;
|
2012-01-26 17:04:25 +01:00
|
|
|
isReference = false;
|
2010-12-30 22:57:43 +01:00
|
|
|
}
|
2010-12-30 09:46:44 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void run() {
|
2010-12-30 09:46:44 +01:00
|
|
|
TEST_CASE(test_isVariableDeclarationCanHandleNull);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesSimpleDeclaration);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesScopedDeclaration);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesStdDeclaration);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesScopedStdDeclaration);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesManyScopes);
|
2010-12-30 22:57:43 +01:00
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesPointers);
|
2010-12-30 09:46:44 +01:00
|
|
|
TEST_CASE(test_isVariableDeclarationDoesNotIdentifyConstness);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesFirstOfManyVariables);
|
2010-12-30 22:57:43 +01:00
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesScopedPointerDeclaration);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesDeclarationWithIndirection);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection);
|
2011-01-01 01:19:32 +01:00
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesArray);
|
|
|
|
TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers);
|
2011-01-02 00:36:22 +01:00
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable);
|
2011-01-18 08:29:42 +01:00
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable);
|
2011-01-18 10:14:12 +01:00
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable);
|
2011-01-02 00:36:22 +01:00
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable);
|
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator);
|
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
|
2012-01-26 17:04:25 +01:00
|
|
|
TEST_CASE(isVariableDeclarationIdentifiesReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
TEST_CASE(isVariableDeclarationDoesNotIdentifyTemplateClass);
|
|
|
|
TEST_CASE(canFindMatchingBracketsNeedsOpen);
|
|
|
|
TEST_CASE(canFindMatchingBracketsInnerPair);
|
|
|
|
TEST_CASE(canFindMatchingBracketsOuterPair);
|
|
|
|
TEST_CASE(canFindMatchingBracketsWithTooManyClosing);
|
|
|
|
TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
|
2011-01-28 08:33:02 +01:00
|
|
|
|
|
|
|
TEST_CASE(hasRegularFunction);
|
|
|
|
TEST_CASE(hasInlineClassFunction);
|
|
|
|
TEST_CASE(hasMissingInlineClassFunction);
|
|
|
|
TEST_CASE(hasClassFunction);
|
|
|
|
|
|
|
|
TEST_CASE(hasRegularFunctionReturningFunctionPointer);
|
|
|
|
TEST_CASE(hasInlineClassFunctionReturningFunctionPointer);
|
|
|
|
TEST_CASE(hasMissingInlineClassFunctionReturningFunctionPointer);
|
|
|
|
TEST_CASE(hasClassFunctionReturningFunctionPointer);
|
2011-02-25 13:17:55 +01:00
|
|
|
|
2011-11-05 12:23:05 +01:00
|
|
|
TEST_CASE(parseFunctionCorrect);
|
|
|
|
|
2011-02-25 13:17:55 +01:00
|
|
|
TEST_CASE(hasGlobalVariables1);
|
|
|
|
TEST_CASE(hasGlobalVariables2);
|
|
|
|
TEST_CASE(hasGlobalVariables3);
|
2011-04-29 02:53:31 +02:00
|
|
|
|
|
|
|
TEST_CASE(functionArgs1);
|
2011-08-28 19:32:42 +02:00
|
|
|
TEST_CASE(functionArgs2);
|
2011-04-29 03:03:57 +02:00
|
|
|
|
2012-01-07 09:28:26 +01:00
|
|
|
TEST_CASE(namespaces1);
|
|
|
|
TEST_CASE(namespaces2);
|
|
|
|
|
2012-01-26 04:48:18 +01:00
|
|
|
TEST_CASE(tryCatch1);
|
|
|
|
|
2011-04-29 03:03:57 +02:00
|
|
|
TEST_CASE(symboldatabase1);
|
|
|
|
TEST_CASE(symboldatabase2);
|
|
|
|
TEST_CASE(symboldatabase3); // ticket #2000
|
|
|
|
TEST_CASE(symboldatabase4);
|
|
|
|
TEST_CASE(symboldatabase5); // ticket #2178
|
|
|
|
TEST_CASE(symboldatabase6); // ticket #2221
|
|
|
|
TEST_CASE(symboldatabase7); // ticket #2230
|
|
|
|
TEST_CASE(symboldatabase8); // ticket #2252
|
|
|
|
TEST_CASE(symboldatabase9); // ticket #2525
|
|
|
|
TEST_CASE(symboldatabase10); // ticket #2537
|
|
|
|
TEST_CASE(symboldatabase11); // ticket #2539
|
|
|
|
TEST_CASE(symboldatabase12); // ticket #2547
|
|
|
|
TEST_CASE(symboldatabase13); // ticket #2577
|
|
|
|
TEST_CASE(symboldatabase14); // ticket #2589
|
|
|
|
TEST_CASE(symboldatabase15); // ticket #2591
|
|
|
|
TEST_CASE(symboldatabase16); // ticket #2637
|
|
|
|
TEST_CASE(symboldatabase17); // ticket #2657
|
2011-06-27 13:31:10 +02:00
|
|
|
TEST_CASE(symboldatabase18); // ticket #2865
|
2011-08-11 23:57:54 +02:00
|
|
|
TEST_CASE(symboldatabase19); // ticket #2991 (segmentation fault)
|
2011-08-17 01:16:58 +02:00
|
|
|
TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault)
|
2011-09-29 04:05:26 +02:00
|
|
|
TEST_CASE(symboldatabase21);
|
2011-12-22 09:20:37 +01:00
|
|
|
TEST_CASE(symboldatabase22); // ticket #3437 (segmentation fault)
|
2011-12-25 11:05:06 +01:00
|
|
|
TEST_CASE(symboldatabase23); // ticket #3435
|
2012-01-22 19:34:53 +01:00
|
|
|
TEST_CASE(symboldatabase24); // ticket #3508 (constructor, destructor)
|
2012-01-28 01:24:01 +01:00
|
|
|
TEST_CASE(symboldatabase25); // ticket #3561 (throw C++)
|
|
|
|
TEST_CASE(symboldatabase26); // ticket #3561 (throw C)
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationCanHandleNull() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(NULL, vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(false, result);
|
|
|
|
ASSERT(NULL == vartok);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT(NULL == typetok);
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesSimpleDeclaration() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize simpleDeclaration("int x;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("x", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesScopedDeclaration() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize ScopedDeclaration("::int x;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("x", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesStdDeclaration() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize StdDeclaration("std::string x;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("x", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("string", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesScopedStdDeclaration() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize StdDeclaration("::std::string x;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("x", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("string", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesManyScopes() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("x", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("EE", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesPointers() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize pointer("int* p;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(pointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("p", vartok->str());
|
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize constness("const int* cp;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(constness.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(false, result);
|
|
|
|
ASSERT(NULL == vartok);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT(NULL == typetok);
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesFirstOfManyVariables() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
2010-12-30 09:46:44 +01:00
|
|
|
givenACodeSampleToTokenize multipleDeclaration("int first, second;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("first", vartok->str());
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("p", vartok->str());
|
|
|
|
ASSERT_EQUALS("EE", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize pointerToPointer("int** pp;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("pp", vartok->str());
|
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() {
|
2010-12-30 22:57:43 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize pointerToPointer("int***** p;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2010-12-30 22:57:43 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("p", vartok->str());
|
|
|
|
ASSERT_EQUALS("int", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2010-12-30 09:46:44 +01:00
|
|
|
}
|
2011-01-01 01:19:32 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesArray() {
|
2011-01-01 01:19:32 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize array("::std::string v[3];");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-01 01:19:32 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("v", vartok->str());
|
|
|
|
ASSERT_EQUALS("string", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(true == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-01 01:19:32 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void test_isVariableDeclarationIdentifiesOfArrayPointers() {
|
2011-01-01 01:19:32 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize array("A *a[5];");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-01 01:19:32 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("a", vartok->str());
|
|
|
|
ASSERT_EQUALS("A", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(true == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-01 01:19:32 +01:00
|
|
|
}
|
2011-01-02 00:36:22 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesTemplatedPointerVariable() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::set<char>* chars;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("chars", vartok->str());
|
|
|
|
ASSERT_EQUALS("set", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() {
|
2011-01-18 08:29:42 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-18 10:14:12 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("ints", vartok->str());
|
|
|
|
ASSERT_EQUALS("deque", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(true == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-18 10:14:12 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesTemplatedArrayVariable() {
|
2011-01-18 10:14:12 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<int> ints[3];");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-18 10:14:12 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("ints", vartok->str());
|
|
|
|
ASSERT_EQUALS("deque", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(true == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-18 08:29:42 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesTemplatedVariable() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::vector<int> ints;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("ints", vartok->str());
|
|
|
|
ASSERT_EQUALS("vector", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesTemplatedVariableIterator() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::list<int>::const_iterator floats;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("floats", vartok->str());
|
|
|
|
ASSERT_EQUALS("const_iterator", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationIdentifiesNestedTemplateVariable() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT_EQUALS(true, result);
|
|
|
|
ASSERT_EQUALS("intsets", vartok->str());
|
|
|
|
ASSERT_EQUALS("deque", typetok->str());
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
|
|
|
}
|
|
|
|
|
|
|
|
void isVariableDeclarationIdentifiesReference() {
|
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var1("int& foo;");
|
|
|
|
bool result1 = si.isVariableDeclaration(var1.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
|
|
|
ASSERT_EQUALS(true, result1);
|
|
|
|
ASSERT(false == isArray);
|
|
|
|
ASSERT(false == isPointer);
|
|
|
|
ASSERT(true == isReference);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var2("foo*& bar;");
|
|
|
|
bool result2 = si.isVariableDeclaration(var2.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
|
|
|
ASSERT_EQUALS(true, result2);
|
|
|
|
ASSERT(false == isArray);
|
|
|
|
ASSERT(false == isPointer);
|
|
|
|
ASSERT(true == isReference);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var3("std::vector<int>& foo;");
|
|
|
|
bool result3 = si.isVariableDeclaration(var3.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
|
|
|
ASSERT_EQUALS(true, result3);
|
|
|
|
ASSERT(false == isArray);
|
|
|
|
ASSERT(false == isPointer);
|
|
|
|
ASSERT(true == isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void isVariableDeclarationDoesNotIdentifyTemplateClass() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("template <class T> class SomeClass{};");
|
2012-01-26 17:04:25 +01:00
|
|
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT_EQUALS(false, result);
|
2011-02-27 16:21:14 +01:00
|
|
|
ASSERT(false == isArray);
|
2011-12-17 19:04:03 +01:00
|
|
|
ASSERT(false == isPointer);
|
2012-01-26 17:04:25 +01:00
|
|
|
ASSERT(false == isReference);
|
2011-01-02 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void canFindMatchingBracketsNeedsOpen() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
|
|
|
|
|
|
|
found = si.findClosingBracket(var.tokens(), t);
|
|
|
|
ASSERT(! found);
|
|
|
|
ASSERT(! t);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void canFindMatchingBracketsInnerPair() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
|
|
|
|
|
|
|
found = si.findClosingBracket(var.tokens()->tokAt(7), t);
|
|
|
|
ASSERT(found);
|
|
|
|
ASSERT_EQUALS(">", t->str());
|
|
|
|
ASSERT_EQUALS(var.tokens()->strAt(9), t->str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void canFindMatchingBracketsOuterPair() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
|
|
|
|
|
|
|
found = si.findClosingBracket(var.tokens()->tokAt(3), t);
|
|
|
|
ASSERT(found);
|
|
|
|
ASSERT_EQUALS(">", t->str());
|
|
|
|
ASSERT_EQUALS(var.tokens()->strAt(10), t->str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void canFindMatchingBracketsWithTooManyClosing() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("X< 1>2 > x1;\n");
|
|
|
|
|
2011-11-20 15:09:57 +01:00
|
|
|
found = si.findClosingBracket(var.tokens()->next(), t);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT(found);
|
|
|
|
ASSERT_EQUALS(">", t->str());
|
|
|
|
ASSERT_EQUALS(var.tokens()->strAt(3), t->str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void canFindMatchingBracketsWithTooManyOpening() {
|
2011-01-02 00:36:22 +01:00
|
|
|
reset();
|
|
|
|
givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n");
|
|
|
|
|
2011-11-20 15:09:57 +01:00
|
|
|
found = si.findClosingBracket(var.tokens()->next(), t);
|
2011-01-02 00:36:22 +01:00
|
|
|
ASSERT(!found);
|
|
|
|
}
|
2011-01-28 08:33:02 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasRegularFunction() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("void func() { }\n")
|
|
|
|
|
|
|
|
// 2 scopes: Global and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-11-20 15:09:57 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->next());
|
2011-01-28 08:33:02 +01:00
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
2011-11-20 15:09:57 +01:00
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->next());
|
2011-01-28 08:33:02 +01:00
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
2011-11-20 15:09:57 +01:00
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->next());
|
2011-01-28 08:33:02 +01:00
|
|
|
ASSERT(function && function->hasBody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasInlineClassFunction() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void func() { } };\n")
|
|
|
|
|
|
|
|
// 3 scopes: Global, Class, and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 3 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(4));
|
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(4));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(4));
|
|
|
|
ASSERT(function && function->hasBody && function->isInline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasMissingInlineClassFunction() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void func(); };\n")
|
|
|
|
|
|
|
|
// 2 scopes: Global and Class (no Function scope because there is no function implementation)
|
|
|
|
ASSERT(db && db->scopeList.size() == 2 && !tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(4));
|
|
|
|
|
|
|
|
ASSERT(scope == NULL);
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(4));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(4));
|
|
|
|
ASSERT(function && !function->hasBody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasClassFunction() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void func(); }; Fred::func() { }\n")
|
|
|
|
|
|
|
|
// 3 scopes: Global, Class, and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 3 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(12));
|
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(12));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(12));
|
|
|
|
ASSERT(function && function->hasBody && !function->isInline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasRegularFunctionReturningFunctionPointer() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("void (*func(int f))(char) { }\n")
|
|
|
|
|
|
|
|
// 2 scopes: Global and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(3));
|
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(3));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(3));
|
|
|
|
ASSERT(function && function->hasBody && function->retFuncPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasInlineClassFunctionReturningFunctionPointer() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };\n")
|
|
|
|
|
|
|
|
// 3 scopes: Global, Class, and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 3 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(6));
|
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(6));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(6));
|
|
|
|
ASSERT(function && function->hasBody && function->isInline && function->retFuncPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasMissingInlineClassFunctionReturningFunctionPointer() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };\n")
|
|
|
|
|
|
|
|
// 2 scopes: Global and Class (no Function scope because there is no function implementation)
|
|
|
|
ASSERT(db && db->scopeList.size() == 2 && !tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(6));
|
|
|
|
|
|
|
|
ASSERT(scope == NULL);
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(6));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(6));
|
|
|
|
ASSERT(function && !function->hasBody && function->retFuncPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasClassFunctionReturningFunctionPointer() {
|
2011-01-28 08:33:02 +01:00
|
|
|
GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }\n")
|
|
|
|
|
|
|
|
// 3 scopes: Global, Class, and Function
|
|
|
|
ASSERT(db && db->scopeList.size() == 3 && tokenizer.getFunctionTokenByName("func"));
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db) {
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(23));
|
|
|
|
|
|
|
|
ASSERT(scope && scope->className == "func");
|
|
|
|
|
|
|
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(23));
|
|
|
|
|
|
|
|
ASSERT(function && function->token->str() == "func");
|
|
|
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(23));
|
|
|
|
ASSERT(function && function->hasBody && !function->isInline && function->retFuncPtr);
|
|
|
|
}
|
|
|
|
}
|
2011-02-25 13:17:55 +01:00
|
|
|
|
2011-11-05 12:23:05 +01:00
|
|
|
void parseFunctionCorrect() {
|
|
|
|
// ticket 3188 - "if" statement parsed as function
|
|
|
|
GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }\n")
|
|
|
|
ASSERT(db != NULL);
|
|
|
|
|
|
|
|
// 3 scopes: Global, function, if
|
|
|
|
ASSERT_EQUALS(3, db->scopeList.size());
|
|
|
|
|
|
|
|
ASSERT(tokenizer.getFunctionTokenByName("func") != NULL);
|
|
|
|
ASSERT(tokenizer.getFunctionTokenByName("if") == NULL);
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasGlobalVariables1() {
|
2011-02-25 13:17:55 +01:00
|
|
|
GET_SYMBOL_DB("int i;\n")
|
|
|
|
|
|
|
|
ASSERT(db && db->scopeList.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db && db->scopeList.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Scope>::const_iterator it = db->scopeList.begin();
|
|
|
|
ASSERT(it->varlist.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (it->varlist.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Variable>::const_iterator var = it->varlist.begin();
|
2011-02-25 13:17:55 +01:00
|
|
|
ASSERT(var->name() == "i");
|
|
|
|
ASSERT(var->typeStartToken()->str() == "int");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasGlobalVariables2() {
|
2011-02-25 13:17:55 +01:00
|
|
|
GET_SYMBOL_DB("int array[2][2];\n")
|
|
|
|
|
|
|
|
ASSERT(db && db->scopeList.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db && db->scopeList.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Scope>::const_iterator it = db->scopeList.begin();
|
|
|
|
ASSERT(it->varlist.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (it->varlist.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Variable>::const_iterator var = it->varlist.begin();
|
2011-02-25 13:17:55 +01:00
|
|
|
ASSERT(var->name() == "array");
|
|
|
|
ASSERT(var->typeStartToken()->str() == "int");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void hasGlobalVariables3() {
|
2011-02-25 13:17:55 +01:00
|
|
|
GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };\n")
|
|
|
|
|
|
|
|
ASSERT(db && db->scopeList.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (db && db->scopeList.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Scope>::const_iterator it = db->scopeList.begin();
|
|
|
|
ASSERT(it->varlist.size() == 1);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (it->varlist.size() == 1) {
|
2011-03-11 01:43:29 +01:00
|
|
|
std::list<Variable>::const_iterator var = it->varlist.begin();
|
2011-02-25 13:17:55 +01:00
|
|
|
ASSERT(var->name() == "array");
|
|
|
|
ASSERT(var->typeStartToken()->str() == "int");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-29 02:53:31 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void check(const char code[], bool debug = true) {
|
2011-04-29 02:53:31 +02:00
|
|
|
// Clear the error log
|
|
|
|
errout.str("");
|
|
|
|
|
|
|
|
// Check..
|
|
|
|
Settings settings;
|
2011-09-29 04:05:26 +02:00
|
|
|
settings.debugwarnings = debug;
|
2011-04-29 02:53:31 +02:00
|
|
|
|
|
|
|
// Tokenize..
|
|
|
|
Tokenizer tokenizer(&settings, this);
|
|
|
|
std::istringstream istr(code);
|
|
|
|
tokenizer.tokenize(istr, "test.cpp");
|
|
|
|
tokenizer.simplifyTokenList();
|
|
|
|
|
|
|
|
// force symbol database creation
|
|
|
|
tokenizer.getSymbolDatabase();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void functionArgs1() {
|
2011-04-29 02:53:31 +02:00
|
|
|
check("void f(std::vector<std::string s>, const std::vector<int> & v) { }\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("void f(std::map<std::string, std::vector<int> > m) { }\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
2011-04-29 03:03:57 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void functionArgs2() {
|
2011-08-28 19:32:42 +02:00
|
|
|
GET_SYMBOL_DB("void f(int a[][4]) { }");
|
|
|
|
const Variable *a = db->getVariableFromVarId(1);
|
|
|
|
ASSERT_EQUALS("a", a->nameToken()->str());
|
|
|
|
ASSERT_EQUALS(2UL, a->dimensions().size());
|
|
|
|
ASSERT_EQUALS(0UL, a->dimension(0));
|
|
|
|
ASSERT_EQUALS(4UL, a->dimension(1));
|
|
|
|
}
|
|
|
|
|
2012-01-07 09:28:26 +01:00
|
|
|
void namespaces1() {
|
|
|
|
GET_SYMBOL_DB("namespace fred {\n"
|
|
|
|
" namespace barney {\n"
|
|
|
|
" class X { X(int); };\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
"namespace barney { X::X(int) { } }\n");
|
|
|
|
|
|
|
|
// Locate the scope for the class..
|
|
|
|
const Scope *scope = NULL;
|
|
|
|
for (std::list<Scope>::const_iterator it = db->scopeList.begin(); it != db->scopeList.end(); ++it) {
|
|
|
|
if (it->isClassOrStruct()) {
|
|
|
|
scope = &(*it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 10:08:09 +01:00
|
|
|
ASSERT(scope != 0);
|
|
|
|
if (!scope)
|
|
|
|
return;
|
|
|
|
|
2012-01-07 09:28:26 +01:00
|
|
|
ASSERT_EQUALS("X", scope->className);
|
|
|
|
|
2012-01-07 09:37:38 +01:00
|
|
|
// The class has a constructor but the implementation _is not_ seen
|
2012-01-07 09:28:26 +01:00
|
|
|
ASSERT_EQUALS(1U, scope->functionList.size());
|
|
|
|
const Function *function = &(scope->functionList.front());
|
|
|
|
ASSERT_EQUALS(false, function->hasBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
// based on namespaces1 but here the namespaces match
|
|
|
|
void namespaces2() {
|
|
|
|
GET_SYMBOL_DB("namespace fred {\n"
|
|
|
|
" namespace barney {\n"
|
|
|
|
" class X { X(int); };\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
"namespace fred {\n"
|
|
|
|
" namespace barney {\n"
|
|
|
|
" X::X(int) { }\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n");
|
|
|
|
|
|
|
|
// Locate the scope for the class..
|
|
|
|
const Scope *scope = NULL;
|
|
|
|
for (std::list<Scope>::const_iterator it = db->scopeList.begin(); it != db->scopeList.end(); ++it) {
|
|
|
|
if (it->isClassOrStruct()) {
|
|
|
|
scope = &(*it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 10:08:09 +01:00
|
|
|
ASSERT(scope != 0);
|
|
|
|
if (!scope)
|
|
|
|
return;
|
|
|
|
|
2012-01-07 09:28:26 +01:00
|
|
|
ASSERT_EQUALS("X", scope->className);
|
|
|
|
|
2012-01-07 09:37:38 +01:00
|
|
|
// The class has a constructor and the implementation _is_ seen
|
2012-01-07 09:28:26 +01:00
|
|
|
ASSERT_EQUALS(1U, scope->functionList.size());
|
|
|
|
const Function *function = &(scope->functionList.front());
|
|
|
|
ASSERT_EQUALS("X", function->tokenDef->str());
|
|
|
|
ASSERT_EQUALS(true, function->hasBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 04:48:18 +01:00
|
|
|
void tryCatch1() {
|
|
|
|
const std::string str("void foo() {\n"
|
|
|
|
" try { }\n"
|
|
|
|
" catch (const Error1 & x) { }\n"
|
|
|
|
" catch (const X::Error2 & x) { }\n"
|
|
|
|
" catch (Error3 x) { }\n"
|
|
|
|
" catch (X::Error4 x) { }\n"
|
|
|
|
"}\n");
|
|
|
|
GET_SYMBOL_DB(str.c_str())
|
|
|
|
check(str.c_str(), false);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT(db && db->getVariableListSize() == 5); // index 0 + 4 variables
|
|
|
|
ASSERT(db && db->scopeList.size() == 7); // global + function + try + 4 catch
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase1() {
|
2011-04-29 03:03:57 +02:00
|
|
|
check("namespace foo {\n"
|
|
|
|
" class bar;\n"
|
|
|
|
"};");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("class foo : public bar < int, int> {\n"
|
|
|
|
"};");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase2() {
|
2011-04-29 03:03:57 +02:00
|
|
|
check("class foo {\n"
|
|
|
|
"public slots :\n"
|
|
|
|
"foo() { }\n"
|
|
|
|
"};");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("class foo {\n"
|
|
|
|
"class bar;\n"
|
|
|
|
"foo() { }\n"
|
|
|
|
"};");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase3() {
|
2011-04-29 03:03:57 +02:00
|
|
|
check("typedef void (func_type)();\n"
|
|
|
|
"struct A {\n"
|
|
|
|
" friend func_type f : 2;\n"
|
|
|
|
"};\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase4() {
|
2011-04-29 03:03:57 +02:00
|
|
|
check("static void function_declaration_before(void) __attribute__((__used__));\n"
|
|
|
|
"static void function_declaration_before(void) {}\n"
|
|
|
|
"static void function_declaration_after(void) {}\n"
|
|
|
|
"static void function_declaration_after(void) __attribute__((__used__));\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("main(int argc, char *argv[]) { }\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("namespace boost {\n"
|
|
|
|
" std::locale generate_locale()\n"
|
|
|
|
" {\n"
|
|
|
|
" return std::locale();\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("namespace X {\n"
|
|
|
|
" static void function_declaration_before(void) __attribute__((__used__));\n"
|
|
|
|
" static void function_declaration_before(void) {}\n"
|
|
|
|
" static void function_declaration_after(void) {}\n"
|
|
|
|
" static void function_declaration_after(void) __attribute__((__used__));\n"
|
|
|
|
"}\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
check("testing::testing()\n"
|
|
|
|
"{\n"
|
|
|
|
"}\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase5() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2178 - segmentation fault
|
|
|
|
check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n"
|
|
|
|
" return (sign ? cl_I() : 0);\n"
|
|
|
|
"}\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase6() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2221 - segmentation fault
|
|
|
|
check("template<int i> class X { };\n"
|
|
|
|
"X< 1>2 > x1;\n"
|
|
|
|
"X<(1>2)> x2;\n"
|
|
|
|
"template<class T> class Y { };\n"
|
|
|
|
"Y<X<1>> x3;\n"
|
|
|
|
"Y<X<6>>1>> x4;\n"
|
2011-09-29 04:05:26 +02:00
|
|
|
"Y<X<(6>>1)>> x5;\n", false);
|
2011-04-29 03:03:57 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase7() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2230 - segmentation fault
|
|
|
|
check("template<template<class> class E,class D> class C : E<D>\n"
|
|
|
|
"{\n"
|
|
|
|
"public:\n"
|
|
|
|
" int f();\n"
|
|
|
|
"};\n"
|
|
|
|
"class E : C<D,int>\n"
|
|
|
|
"{\n"
|
|
|
|
"public:\n"
|
|
|
|
" int f() { return C< ::D,int>::f(); }\n"
|
|
|
|
"};\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase8() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2252 - segmentation fault
|
|
|
|
check("struct PaletteColorSpaceHolder: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,\n"
|
|
|
|
" PaletteColorSpaceHolder>\n"
|
|
|
|
"{\n"
|
|
|
|
" uno::Reference<rendering::XColorSpace> operator()()\n"
|
|
|
|
" {\n"
|
|
|
|
" return vcl::unotools::createStandardColorSpace();\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase9() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2425 - segmentation fault
|
|
|
|
check("class CHyperlink : public CString\n"
|
|
|
|
"{\n"
|
|
|
|
"public:\n"
|
|
|
|
" const CHyperlink& operator=(LPCTSTR lpsz) {\n"
|
|
|
|
" CString::operator=(lpsz);\n"
|
|
|
|
" return *this;\n"
|
|
|
|
" }\n"
|
2011-09-29 04:05:26 +02:00
|
|
|
"};\n", false);
|
2011-04-29 03:03:57 +02:00
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase10() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2537 - segmentation fault
|
|
|
|
check("class A {\n"
|
|
|
|
"private:\n"
|
|
|
|
" void f();\n"
|
|
|
|
"};\n"
|
|
|
|
"class B {\n"
|
|
|
|
" friend void A::f();\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase11() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2539 - segmentation fault
|
|
|
|
check("int g ();\n"
|
|
|
|
"struct S {\n"
|
|
|
|
" int i : (false ? g () : 1);\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase12() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2547 - segmentation fault
|
|
|
|
check("class foo {\n"
|
|
|
|
" void bar2 () = __null;\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase13() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2577 - segmentation fault
|
|
|
|
check("class foo {\n"
|
|
|
|
" void bar2 () = A::f;\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase14() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2589 - segmentation fault
|
|
|
|
check("struct B : A\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase15() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2591 - segmentation fault
|
|
|
|
check("struct A :\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase16() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2637 - segmentation fault
|
|
|
|
check("{} const const\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase17() {
|
2011-04-29 03:03:57 +02:00
|
|
|
// ticket #2657 - segmentation fault
|
|
|
|
check("return f(){}\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase18() {
|
2011-06-27 13:31:10 +02:00
|
|
|
// ticket #2865 - segmentation fault
|
|
|
|
check("char a[1]\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase19() {
|
2011-08-11 23:57:54 +02:00
|
|
|
// ticket #2991 - segmentation fault
|
|
|
|
check("::y(){x}\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase20() {
|
2011-08-17 01:16:58 +02:00
|
|
|
// ticket #3013 - segmentation fault
|
|
|
|
check("struct x : virtual y\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void symboldatabase21() {
|
2011-09-29 04:05:26 +02:00
|
|
|
check("class Fred {\n"
|
|
|
|
" class Foo { };\n"
|
|
|
|
" void func() const;\n"
|
|
|
|
"};\n"
|
|
|
|
"Fred::func() const {\n"
|
|
|
|
" Foo foo;\n"
|
|
|
|
"}\n");
|
|
|
|
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-12-22 09:20:37 +01:00
|
|
|
// #ticket 3437 (segmentation fault)
|
|
|
|
void symboldatabase22() {
|
|
|
|
check("template <class C> struct A {};\n"
|
|
|
|
"A<int> a;\n");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2011-12-25 11:05:06 +01:00
|
|
|
// #ticket 3435 (std::vector)
|
|
|
|
void symboldatabase23() {
|
|
|
|
GET_SYMBOL_DB("class A { std::vector<int*> ints; };\n");
|
|
|
|
ASSERT_EQUALS(2U, db->scopeList.size());
|
|
|
|
const Scope &scope = db->scopeList.back();
|
|
|
|
ASSERT_EQUALS(1U, scope.varlist.size());
|
|
|
|
const Variable &var = scope.varlist.front();
|
|
|
|
ASSERT_EQUALS(std::string("ints"), var.name());
|
|
|
|
ASSERT_EQUALS(true, var.isClass());
|
|
|
|
}
|
|
|
|
|
2012-01-22 19:34:53 +01:00
|
|
|
// #ticket 3508 (constructor, destructor)
|
|
|
|
void symboldatabase24() {
|
|
|
|
GET_SYMBOL_DB("struct Fred {\n"
|
|
|
|
" ~Fred();\n"
|
|
|
|
" Fred();\n"
|
|
|
|
"};\n"
|
|
|
|
"Fred::Fred() { }\n"
|
|
|
|
"Fred::~Fred() { }");
|
|
|
|
// Global scope, Fred, Fred::Fred, Fred::~Fred
|
|
|
|
ASSERT_EQUALS(4U, db->scopeList.size());
|
|
|
|
|
|
|
|
// Find the scope for the Fred struct..
|
|
|
|
const Scope *fredScope = NULL;
|
|
|
|
for (std::list<Scope>::const_iterator scope = db->scopeList.begin(); scope != db->scopeList.end(); ++scope) {
|
|
|
|
if (scope->isClassOrStruct() && scope->className == "Fred")
|
|
|
|
fredScope = &(*scope);
|
|
|
|
}
|
|
|
|
ASSERT(fredScope != NULL);
|
|
|
|
if (fredScope == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The struct Fred has two functions, a constructor and a destructor
|
|
|
|
ASSERT_EQUALS(2U, fredScope->functionList.size());
|
|
|
|
|
|
|
|
// Get linenumbers where the bodies for the constructor and destructor are..
|
|
|
|
unsigned int constructor = 0;
|
|
|
|
unsigned int destructor = 0;
|
|
|
|
for (std::list<Function>::const_iterator it = fredScope->functionList.begin(); it != fredScope->functionList.end(); ++it) {
|
|
|
|
if (it->type == Function::eConstructor)
|
|
|
|
constructor = it->token->linenr(); // line number for constructor body
|
|
|
|
if (it->type == Function::eDestructor)
|
|
|
|
destructor = it->token->linenr(); // line number for destructor body
|
|
|
|
}
|
|
|
|
|
|
|
|
// The body for the constructor is located at line 5..
|
|
|
|
ASSERT_EQUALS(5U, constructor);
|
|
|
|
|
|
|
|
// The body for the destructor is located at line 6..
|
|
|
|
ASSERT_EQUALS(6U, destructor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-01-28 01:24:01 +01:00
|
|
|
// #ticket #3561 (throw C++)
|
|
|
|
void symboldatabase25() {
|
|
|
|
const std::string str("int main() {\n"
|
|
|
|
" foo bar;\n"
|
|
|
|
" throw bar;\n"
|
|
|
|
"}");
|
|
|
|
GET_SYMBOL_DB(str.c_str());
|
|
|
|
check(str.c_str(), false);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT(db && db->getVariableListSize() == 2); // index 0 + 1 variable
|
|
|
|
}
|
|
|
|
|
|
|
|
// #ticket #3561 (throw C)
|
|
|
|
void symboldatabase26() {
|
|
|
|
const std::string str("int main() {\n"
|
|
|
|
" throw bar;\n"
|
|
|
|
"}");
|
|
|
|
GET_SYMBOL_DB_C(str.c_str());
|
|
|
|
check(str.c_str(), false);
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
ASSERT(db && db->getVariableListSize() == 2); // index 0 + 1 variable
|
|
|
|
}
|
2011-12-25 11:05:06 +01:00
|
|
|
|
2010-12-30 09:46:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestSymbolDatabase)
|
|
|
|
|