mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added test.
This commit is contained in:
parent
5995f1cd0f
commit
fb70c25e85
1 changed files with 311 additions and 281 deletions
|
@ -3644,8 +3644,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding();
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(11).resolveBinding();
|
||||
ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1)
|
||||
.resolveBinding();
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(11)
|
||||
.resolveBinding();
|
||||
assertSame(ctor, ctor1);
|
||||
}
|
||||
|
||||
|
@ -3924,7 +3926,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
public void testBug77385() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer( "int main(int argc, char *argv[])\n" ); //$NON-NLS-1$
|
||||
StringBuffer buffer = new StringBuffer(
|
||||
"int main(int argc, char *argv[])\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append(" unsigned long l = 0;\n"); //$NON-NLS-1$
|
||||
buffer.append("char *c;\n"); //$NON-NLS-1$
|
||||
|
@ -3937,7 +3940,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
public void testBug83997() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "namespace { int x; }", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"namespace { int x; }", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
assertNoProblemBindings(col);
|
||||
|
@ -3946,8 +3950,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
protected void assertNoProblemBindings(CPPNameCollector col) {
|
||||
Iterator i = col.nameList.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
while (i.hasNext()) {
|
||||
IASTName n = (IASTName) i.next();
|
||||
assertFalse(n.resolveBinding() instanceof IProblemBinding);
|
||||
}
|
||||
|
@ -3956,8 +3959,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
protected void assertProblemBindings(CPPNameCollector col, int count) {
|
||||
Iterator i = col.nameList.iterator();
|
||||
int sum = 0;
|
||||
while( i.hasNext() )
|
||||
{
|
||||
while (i.hasNext()) {
|
||||
IASTName n = (IASTName) i.next();
|
||||
assertNotNull(n.resolveBinding());
|
||||
if (n.getBinding() instanceof IProblemBinding)
|
||||
|
@ -3967,7 +3969,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
public void testBug85786() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "void f( int ); void foo () { void * p = &f; ( (void (*) (int)) p ) ( 1 ); }", ParserLanguage.C ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse(
|
||||
"void f( int ); void foo () { void * p = &f; ( (void (*) (int)) p ) ( 1 ); }", ParserLanguage.C); //$NON-NLS-1$
|
||||
CPPNameCollector nameResolver = new CPPNameCollector();
|
||||
tu.accept(nameResolver);
|
||||
assertNoProblemBindings(nameResolver);
|
||||
|
@ -4053,7 +4056,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
tu.accept(col);
|
||||
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(1).resolveBinding();
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(1)
|
||||
.resolveBinding();
|
||||
|
||||
ICPPConstructor[] ctors = A.getConstructors();
|
||||
assertEquals(ctors.length, 2);
|
||||
|
@ -4193,13 +4197,13 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertFalse(col.getName(0).isReference());
|
||||
}
|
||||
|
||||
public void testPointerToFunction_CPP() throws Exception
|
||||
{
|
||||
public void testPointerToFunction_CPP() throws Exception {
|
||||
IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
assertEquals(tu.getDeclarations().length, 1);
|
||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals(d.getDeclarators().length, 1);
|
||||
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d
|
||||
.getDeclarators()[0];
|
||||
assertEquals(f.getName().toString(), "");
|
||||
assertNotNull(f.getNestedDeclarator());
|
||||
assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||
|
@ -4220,6 +4224,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
ICPPField bar = (ICPPField) col.getName(1).resolveBinding();
|
||||
assertSame(bar, col.getName(6).resolveBinding());
|
||||
}
|
||||
|
||||
public void testBug95419() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int strcmp( const char * ); \n"); //$NON-NLS-1$
|
||||
|
@ -4250,18 +4255,25 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(2).resolveBinding();
|
||||
ICPPConstructor ctor = (ICPPConstructor) col.getName(2)
|
||||
.resolveBinding();
|
||||
assertSame(ctor, col.getName(15).resolveBinding());
|
||||
}
|
||||
|
||||
public void testBug95768() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void mem( void *, const void * ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" char *x; int offset; \n"); //$NON-NLS-1$
|
||||
buffer.append(" mem( x, \"FUNC\" ); \n"); //$NON-NLS-1$
|
||||
buffer.append(" mem( x + offset, \"FUNC2\" ); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append("void mem( void *, const void * ); \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append(" char *x; int offset; \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append(" mem( x, \"FUNC\" ); \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append(" mem( x + offset, \"FUNC2\" ); \n"); //$NON-NLS-1$
|
||||
buffer
|
||||
.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
@ -4381,8 +4393,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
buffer.append("int s ( t );\n");
|
||||
buffer.append("}\n");
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
IASTDeclarator d = ((IASTSimpleDeclaration)ds.getDeclaration()).getDeclarators()[0];
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
IASTDeclarator d = ((IASTSimpleDeclaration) ds.getDeclaration())
|
||||
.getDeclarators()[0];
|
||||
assertTrue(d.getName().resolveBinding() instanceof IVariable);
|
||||
}
|
||||
|
||||
|
@ -4422,4 +4436,20 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
ICPPField i = (ICPPField) col.getName(1).resolveBinding();
|
||||
assertSame(i, col.getName(7).resolveBinding());
|
||||
}
|
||||
|
||||
public void testBug86849() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int f() {\n");
|
||||
buffer.append(" return 5;\n");
|
||||
buffer.append("}\n");
|
||||
buffer.append("int main() {\n");
|
||||
buffer.append("int a( 5 );\n");
|
||||
buffer.append("int b( f() );\n");
|
||||
buffer.append("return a+b;\n");
|
||||
buffer.append("}\n");
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
assertNoProblemBindings( col );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue