1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

225534: add unit tests

This commit is contained in:
Andrew Ferguson 2008-04-03 11:40:52 +00:00
parent 0ba4cad18d
commit 307bcca6a5
2 changed files with 78 additions and 4 deletions

View file

@ -406,9 +406,11 @@ public class AST2BaseTest extends BaseTestCase {
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections);
}
protected static void assertInstance(Object o, Class c) {
assertNotNull("Expected object of "+c.getName()+" but got a null value", o);
assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
protected static void assertInstance(Object o, Class... cs) {
for(Class c : cs) {
assertNotNull("Expected object of "+c.getName()+" but got a null value", o);
assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
}
}
protected static void assertField(IBinding binding, String fieldName, String ownerName) throws DOMException {
@ -441,10 +443,11 @@ public class AST2BaseTest extends BaseTestCase {
return binding;
}
public <T extends IBinding> T assertNonProblem(String section, int len, Class<T> type) {
public <T extends IBinding> T assertNonProblem(String section, int len, Class<T> type, Class... cs) {
IBinding binding= binding(section, len);
assertTrue("Binding is a ProblemBinding for name: "+section, !(binding instanceof IProblemBinding));
assertInstance(binding, type);
assertInstance(binding, cs);
return type.cast(binding);
}

View file

@ -74,6 +74,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
@ -5845,4 +5846,74 @@ public class AST2CPPTests extends AST2BaseTest {
final String code = getContents(1)[0].toString();
parseAndCheckBindings(code);
}
// long x= 10L;
public void _testLongLiteral_225534() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
IASTDeclarator decltor= ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0];
IASTInitializerExpression init= (IASTInitializerExpression) decltor.getInitializer();
ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getExpression();
ICPPBasicType type= (ICPPBasicType) CPPVisitor.getExpressionType(exp);
assertEquals(ICPPBasicType.IS_LONG, type.getType());
}
// void foo/*_a*/(int x) {}
// void foo/*_b*/(unsigned int) {}
// void foo/*_c*/(short x) {}
// void foo/*_d*/(unsigned short x) {}
// void foo/*_e*/(long x) {}
// void foo/*_f*/(unsigned long x) {}
// void foo/*_g*/(long long x) {}
// void foo/*_h*/(unsigned long long x) {}
// void foo/*_i*/(float x) {}
// void foo/*_j*/(double x) {}
// void foo/*_k*/(long double x) {}
//
// int main() {
// foo/*a1*/(1);
// foo/*a2*/(010);
// foo/*a3*/(0x010);
//
// foo/*b1*/(1U);
// foo/*b2*/(010U);
// foo/*b3*/(0x010U);
//
// /*c*/ /*d*/
//
// foo/*e1*/(1L);
// foo/*e2*/(010L);
// foo/*e3*/(0x010L);
//
// foo/*f1*/(1UL);
// foo/*f2*/(010UL);
// foo/*f3*/(0x010UL);
//
// foo/*g1*/(100000000000000000L);
// foo/*g2*/(0100000000000L);
// foo/*g3*/(0x01000000000L);
//
// foo/*h1*/(100000000000000000UL);
// foo/*h2*/(0100000000000UL);
// foo/*h3*/(0x01000000000UL);
//
// foo/*i1*/(11.1F);
// foo/*i2*/(11E1F);
//
// foo/*j1*/(11.1);
// foo/*j2*/(11.1E1);
//
// foo/*k1*/(11.1L);
// foo/*k2*/(11.1E1L);
// }
public void _testLiteralsViaOverloads_225534() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
char[] cs= {'a','b','e','f','g','h','i','j','k'};
for(char c : cs) {
for(int i=1; i<(c < 'i' ? 4 : 3); i++) {
ICPPFunction def= ba.assertNonProblem("foo/*_"+c+"*/", 3, ICPPFunction.class);
ICPPFunction ref= ba.assertNonProblem("foo/*"+c+""+i+"*/", 3, ICPPFunction.class);
assertSame("function ref: "+c+""+i, def, ref);
}
}
}
}