diff options
author | Andrew Ferguson | 2008-04-03 11:40:52 +0000 |
---|---|---|
committer | Andrew Ferguson | 2008-04-03 11:40:52 +0000 |
commit | 307bcca6a5503e51c0f7ac1891317c8eb71f2201 (patch) | |
tree | b76f7febc93d5c2852e492fb444136648c216fe1 | |
parent | 0ba4cad18dea3415787a448f27902ea747605514 (diff) | |
download | org.eclipse.cdt-307bcca6a5503e51c0f7ac1891317c8eb71f2201.tar.gz org.eclipse.cdt-307bcca6a5503e51c0f7ac1891317c8eb71f2201.tar.xz org.eclipse.cdt-307bcca6a5503e51c0f7ac1891317c8eb71f2201.zip |
225534: add unit tests
2 files changed, 78 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 8fe5e590a73..c70de27a89b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -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); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 283e67e2b5e..7f23ad5101e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -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); + } + } + } } |