mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Brent Nicolle.
ITemplate tests, further migration of core tests away from ui.tests
This commit is contained in:
parent
3fa62eae94
commit
35a76e8822
13 changed files with 665 additions and 33 deletions
|
@ -36,5 +36,7 @@
|
|||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
2003-06-17 Brent Nicolle
|
||||
Added Interface tests of IStructure.java.
|
||||
|
||||
2003-06-17 Victor Mozgin
|
||||
Added DeclaratorsTests.java (invocation in AllCoreTests).
|
||||
Added DeclaratorsTests.cpp to org.eclipse.cdt.core.model.tests.resources.
|
||||
|
||||
2003-06-16 Victor Mozgin
|
||||
Added testOldKRFunctionDeclarations() to DOMTests.
|
||||
Added testKRFunctionDeclarations() to TranslationUnitTests.
|
||||
|
||||
2003-06-16 Vladimir Hirsl
|
||||
Added /build, /parser, /failures and /suite directories to the library.
|
||||
Copied resources from /model/org.eclipse.cdt.core.model.tests.resources
|
||||
|
@ -8,10 +16,6 @@
|
|||
Added class AISResultPrinter to format test results.
|
||||
Class AutomatedIntegrationSuite now implements IPlatformRunnable.
|
||||
|
||||
2003-06-17 Victor Mozgin
|
||||
Added DeclaratorsTests.java (invocation in AllCoreTests).
|
||||
Added DeclaratorsTests.cpp to org.eclipse.cdt.core.model.tests.resources.
|
||||
|
||||
2003-06-14 Victor Mozgin
|
||||
Moved testBugSingleton192() from LokiFailures to DOMTests.
|
||||
Added testPointersToMembers() and testPointersToMemberFunctions() to DOMTests.
|
||||
|
|
|
@ -14,12 +14,12 @@ import junit.framework.TestSuite;
|
|||
* AllTests.java
|
||||
* This is the main entry point for running this suite of JUnit tests
|
||||
* for all tests within the package "org.eclipse.cdt.core.model"
|
||||
*
|
||||
*
|
||||
* @author Judy N. Green
|
||||
* @since Jul 19, 2002
|
||||
*/
|
||||
public class AllCoreTests {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class AllCoreTests {
|
|||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(AllCoreTests.class.getName());
|
||||
|
||||
// Just add more test cases here as you create them for
|
||||
// Just add more test cases here as you create them for
|
||||
// each class being tested
|
||||
suite.addTest(AllLanguageInterfaceTests.suite());
|
||||
suite.addTest(CModelTests.suite());
|
||||
|
@ -35,9 +35,10 @@ public class AllCoreTests {
|
|||
suite.addTest(FlagTests.suite());
|
||||
suite.addTest(ArchiveTests.suite());
|
||||
suite.addTest(TranslationUnitTests.suite());
|
||||
|
||||
suite.addTest(DeclaratorsTests.suite());
|
||||
|
||||
return suite;
|
||||
|
||||
|
||||
}
|
||||
} // End of AllCoreTests.java
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ public class AllLanguageInterfaceTests {
|
|||
suite.addTest(IIncludeTests.suite());
|
||||
suite.addTest(IMacroTests.suite());
|
||||
suite.addTest(IStructureTests.suite());
|
||||
suite.addTest(ITemplateTests.suite());
|
||||
return suite;
|
||||
|
||||
}
|
||||
|
|
|
@ -304,6 +304,12 @@ public class CModelElementsTests extends TestCase {
|
|||
assertEquals(var3.getElementName(), new String("vuShort"));
|
||||
assertEquals(var3.getTypeName(), new String("unsigned short "));
|
||||
checkLineNumbers((CElement)var3, 75, 75);
|
||||
|
||||
// MyPackage ---> function pointer: orig_malloc_hook
|
||||
IVariable vDecl2 = (IVariable) nsVars.get(3);
|
||||
assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
||||
assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
||||
checkLineNumbers((CElement)vDecl2, 81, 81);
|
||||
}
|
||||
|
||||
private void checkVariableDeclarations(IParent namespace){
|
||||
|
@ -313,12 +319,6 @@ public class CModelElementsTests extends TestCase {
|
|||
assertEquals(vDecl1.getElementName(), new String("evar"));
|
||||
assertEquals(vDecl1.getTypeName(), new String("int"));
|
||||
checkLineNumbers((CElement)vDecl1, 79, 79);
|
||||
|
||||
// // MyPackage ---> function pointer: orig_malloc_hook
|
||||
// IVariableDeclaration vDecl2 = (IVariableDeclaration) nsVarDecls.get(1);
|
||||
// assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
||||
// assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
||||
// checkLineNumbers((CElement)vDecl2, 81, 81);
|
||||
}
|
||||
|
||||
private void checkFunctions(IParent namespace){
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* Created on Jun 9, 2003
|
||||
* by bnicolle
|
||||
*/
|
||||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IFunction;
|
||||
import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ITypeDef;
|
||||
import org.eclipse.cdt.core.model.IVariable;
|
||||
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author bnicolle
|
||||
*
|
||||
*/
|
||||
public class DeclaratorsTests extends IntegratedCModelTest {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public DeclaratorsTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
|
||||
*/
|
||||
public String getSourcefileSubdir() {
|
||||
return "resources/cmodel/";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
|
||||
*/
|
||||
public String getSourcefileResource() {
|
||||
return "DeclaratorsTests.cpp";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns a test suite named after this class
|
||||
* containing all its public members named "test*"
|
||||
*/
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite(DeclaratorsTests.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
public void testDeclarators_0001() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0001");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_FUNCTION_DECLARATION);
|
||||
IFunctionDeclaration decl = (IFunctionDeclaration)element;
|
||||
assertEquals(decl.getSignature(), "decl_0001(char)");
|
||||
assertEquals(decl.getReturnType(), "void");
|
||||
}
|
||||
|
||||
public void testDeclarators_0002() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0002");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_FUNCTION_DECLARATION);
|
||||
IFunctionDeclaration decl = (IFunctionDeclaration)element;
|
||||
assertEquals(decl.getSignature(), "decl_0002(char)");
|
||||
assertEquals(decl.getReturnType(), "void");
|
||||
}
|
||||
|
||||
public void testDeclarators_0003() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0003");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_FUNCTION_DECLARATION);
|
||||
IFunctionDeclaration decl = (IFunctionDeclaration)element;
|
||||
assertEquals(decl.getSignature(), "decl_0003(char)");
|
||||
assertEquals(decl.getReturnType(), "void");
|
||||
}
|
||||
|
||||
public void testDeclarators_0004() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0004");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_FUNCTION_DECLARATION);
|
||||
IFunctionDeclaration decl = (IFunctionDeclaration)element;
|
||||
assertEquals(decl.getSignature(), "decl_0004(char)");
|
||||
assertEquals(decl.getReturnType(), "void*");
|
||||
}
|
||||
|
||||
public void testDeclarators_0005() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0005");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_VARIABLE);
|
||||
IVariable decl = (IVariable)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0006() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0006");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_VARIABLE);
|
||||
IVariable decl = (IVariable)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0007() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0007");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_VARIABLE);
|
||||
IVariable decl = (IVariable)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0011() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0011");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void()(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0012() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0012");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void()(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0013() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0013");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void()(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0014() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0014");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void*()(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0015() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0015");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0016() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0016");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0017() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0017");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_TYPEDEF);
|
||||
ITypeDef decl = (ITypeDef)element;
|
||||
assertEquals(decl.getTypeName(), "void(*)(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0023() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0023");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_FUNCTION);
|
||||
IFunction decl = (IFunction)element;
|
||||
assertEquals(decl.getSignature(), "decl_0023(int)");
|
||||
assertEquals(decl.getReturnType(), "void(*(*))(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0024() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0024");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_VARIABLE);
|
||||
IVariable decl = (IVariable)element;
|
||||
assertEquals(decl.getTypeName(), "void(*(*(*)(int))(float))(char)");
|
||||
}
|
||||
|
||||
public void testDeclarators_0031() throws CModelException {
|
||||
ITranslationUnit tu = getTU();
|
||||
ICElement element = tu.getElement("decl_0031");
|
||||
assertNotNull(element);
|
||||
assertEquals(element.getElementType(), ICElement.C_VARIABLE);
|
||||
IVariable decl = (IVariable)element;
|
||||
assertEquals(decl.getTypeName(), "int(*)(char(*)(bool))");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* Created on Jun 17, 2003
|
||||
* by bnicolle
|
||||
*/
|
||||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import junit.framework.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class for testing ITemplate interface
|
||||
* @author bnicolle
|
||||
*
|
||||
*/
|
||||
public class ITemplateTests extends IntegratedCModelTest {
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public ITemplateTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.tests.IntegratedCModelTest#getSourcefileSubdir()
|
||||
*/
|
||||
public String getSourcefileSubdir() {
|
||||
return "resources/cmodel/";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.tests.IntegratedCModelTest#getSourcefileResource()
|
||||
*/
|
||||
public String getSourcefileResource() {
|
||||
return "ITemplate.cpp";
|
||||
}
|
||||
/**
|
||||
* @returns a test suite named after this class
|
||||
* containing all its public members named "test*"
|
||||
*/
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite( IStructureTests.class.getName() );
|
||||
|
||||
// Interface tests:
|
||||
suite.addTest( new ITemplateTests("testGetChildrenOfTypeTemplate"));
|
||||
suite.addTest( new ITemplateTests("testGetNumberOfTemplateParameters"));
|
||||
suite.addTest( new ITemplateTests("testGetTemplateParameterTypes"));
|
||||
suite.addTest( new ITemplateTests("testGetTemplateSignature"));
|
||||
|
||||
// Language Specification tests:
|
||||
// TBD.
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
public ArrayList getTemplateMethods(ITranslationUnit tu)
|
||||
{
|
||||
IStructure myElem = null;
|
||||
try {
|
||||
myElem = (IStructure) tu.getElement("TemplateContainer");
|
||||
}
|
||||
catch( CModelException c ) {
|
||||
assertNotNull( c );
|
||||
}
|
||||
assertNotNull(myElem);
|
||||
return myElem.getChildrenOfType(ICElement.C_TEMPLATE_METHOD);
|
||||
}
|
||||
|
||||
public void testGetChildrenOfTypeTemplate() {
|
||||
ITranslationUnit tu = getTU();
|
||||
{
|
||||
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT);
|
||||
String[] myExpectedValues = {
|
||||
"Map"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
{
|
||||
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_CLASS);
|
||||
String[] myExpectedValues = {
|
||||
"nonVector"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
{
|
||||
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION);
|
||||
String[] myExpectedValues = {
|
||||
"ArrayOverlay"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
{
|
||||
ArrayList arrayElements = getTemplateMethods(tu);
|
||||
String[] myExpectedValues = {
|
||||
"fum",
|
||||
"scrum"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
{
|
||||
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION);
|
||||
String[] myExpectedValues = {
|
||||
"nonVector<T>::first",
|
||||
"IsGreaterThan",
"Foo::fum"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
{
|
||||
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE);
|
||||
String[] myExpectedValues = {
|
||||
"default_alloc_template<threads,inst>::S_start_free"
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myITemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myITemplate);
|
||||
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testGetNumberOfTemplateParameters()
|
||||
{
|
||||
ITranslationUnit tu = getTU();
|
||||
ArrayList arrayElements = new ArrayList();
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_CLASS ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
|
||||
arrayElements.addAll( getTemplateMethods(tu) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
|
||||
|
||||
int[] myExpectedNumbers = {
|
||||
// 3,1,3,1,1,3
|
||||
3,1,3,1,1,1,1,1,2
|
||||
};
|
||||
assertEquals(myExpectedNumbers.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedNumbers.length; i++) {
|
||||
ITemplate myTemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myTemplate );
|
||||
assertEquals( "Failed on "+i, myExpectedNumbers[i],
|
||||
myTemplate.getNumberOfTemplateParameters());
|
||||
}
|
||||
}
|
||||
public void testGetTemplateParameterTypes()
|
||||
{
|
||||
ITranslationUnit tu = getTU();
|
||||
ArrayList arrayElements = new ArrayList();
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_CLASS ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
|
||||
arrayElements.addAll( getTemplateMethods(tu) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
|
||||
|
||||
String[][] myExpectedValues = {
|
||||
//"Map"
|
||||
{"Key", "Value", "SortAlgorithm"},
|
||||
//"nonVector"
|
||||
{"T"},
|
||||
//"ArrayOverlay"
|
||||
{"X","Y","int"},
|
||||
//"TemplateContainer::fum"
|
||||
{"Bar"},
|
||||
//"TemplateParameter::scrum"
|
||||
{"int"},
|
||||
//"nonVector::first"
|
||||
{"T"},
|
||||
//"IsGreaterThan"
|
||||
{"X"},
|
||||
//"Foo::fum"
|
||||
{"Bar"},
|
||||
//"default_alloc_template::S_start_free"
|
||||
{"bool", "int"},
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myTemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myTemplate );
|
||||
String[] myExpectedParams = myExpectedValues[i];
|
||||
String[] myParams = myTemplate.getTemplateParameterTypes();
|
||||
assertEquals( "Failed on "+i, myExpectedParams.length, myParams.length );
|
||||
for(int j=0; j<myExpectedParams.length; j++) {
|
||||
assertEquals( "Failed on "+i+","+j, myExpectedParams[j], myParams[j] );
|
||||
}
|
||||
}
|
||||
}
|
||||
public void testGetTemplateSignature()
|
||||
{
|
||||
ITranslationUnit tu = getTU();
|
||||
ArrayList arrayElements = new ArrayList();
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_CLASS ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
|
||||
arrayElements.addAll( getTemplateMethods(tu) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
|
||||
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
|
||||
|
||||
String[] myExpectedValues = {
|
||||
"Map<Key, Value, SortAlgorithm>",
|
||||
"nonVector<T>",
|
||||
"ArrayOverlay<X, Y, int>",
|
||||
"fum<Bar>(int) : void",
|
||||
"scrum<int>(void) : void", // TODO: deduce the rules of () versus (void), compare below.
|
||||
"nonVector<T>::first<T>() : const T&", // TODO: where should <T> be?
|
||||
// TODO: shouldn't signature indicate const function as well?
|
||||
"IsGreaterThan<X>(X, X) : bool",
|
||||
"Foo::fum<Bar>(int) : void",
|
||||
"default_alloc_template<threads,inst>::S_start_free<bool, int> : char*",
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
for(int i=0; i<myExpectedValues.length; i++) {
|
||||
ITemplate myTemplate = (ITemplate) arrayElements.get(i);
|
||||
assertNotNull( "Failed on "+i, myTemplate );
|
||||
assertEquals( "Failed on "+i, myExpectedValues[i],
|
||||
myTemplate.getTemplateSignature() );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import junit.framework.TestSuite;
|
|||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IFunction;
|
||||
import org.eclipse.cdt.core.model.IInclude;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
|
@ -51,8 +52,8 @@ public class TranslationUnitTests extends TestCase {
|
|||
*/
|
||||
String[] expectedStringList= {"stdio.h", "unistd.h", "func2p",
|
||||
"globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype",
|
||||
"func1", "func2", "main", "func3"};
|
||||
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65};
|
||||
"func1", "func2", "main", "func3", "KRFunction"};
|
||||
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65,70};
|
||||
/* This is a list of that the types of the above list of elements is
|
||||
* expected to be.
|
||||
*/
|
||||
|
@ -60,7 +61,8 @@ public class TranslationUnitTests extends TestCase {
|
|||
ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE,
|
||||
ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF,
|
||||
ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION,
|
||||
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION};
|
||||
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION,
|
||||
ICElement.C_FUNCTION};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -163,6 +165,7 @@ public class TranslationUnitTests extends TestCase {
|
|||
suite.addTest(new TranslationUnitTests("testGetElement"));
|
||||
suite.addTest(new TranslationUnitTests("testBug23478A"));
|
||||
suite.addTest(new TranslationUnitTests("testBug23478B"));
|
||||
suite.addTest(new TranslationUnitTests("testKRFunctionDeclarations"));
|
||||
// TODO: suite.addTest(new TranslationUnitTests("testGetElementAtLine"));
|
||||
return suite;
|
||||
}
|
||||
|
@ -359,4 +362,15 @@ public class TranslationUnitTests extends TestCase {
|
|||
assertTrue(myExp.getExtraString(), !myExp.gotExtra());
|
||||
}
|
||||
*/
|
||||
/***
|
||||
* Simple sanity test for old K&R-style C function declaration
|
||||
*/
|
||||
public void testKRFunctionDeclarations() throws CModelException {
|
||||
ITranslationUnit myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
assertTrue(myTranslationUnit.getElement("KRFunction") instanceof IFunction);
|
||||
IFunction myKRFunction = (IFunction)myTranslationUnit.getElement("KRFunction");
|
||||
assertEquals(myKRFunction.getSignature(), "KRFunction(const char*, int(*)(float), parm3)");
|
||||
assertEquals(myKRFunction.getReturnType(), "bool");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.internal.core.dom.Inclusion;
|
|||
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
|
||||
import org.eclipse.cdt.internal.core.dom.Macro;
|
||||
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
||||
import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause;
|
||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
||||
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
||||
|
@ -2159,4 +2160,78 @@ public class DOMTests extends BaseDOMTest {
|
|||
parse("template <class B,C> A::nested::operator int() {} ");
|
||||
}
|
||||
|
||||
public void testOldKRFunctionDeclarations() throws Exception
|
||||
{
|
||||
// Parse and get the translaton unit
|
||||
Writer code = new StringWriter();
|
||||
code.write("bool myFunction( parm1, parm2, parm3 )\n");
|
||||
code.write("const char* parm1;\n");
|
||||
code.write("int (*parm2)(float);\n");
|
||||
code.write("{}");
|
||||
TranslationUnit translationUnit = parse(code.toString());
|
||||
|
||||
// Get the declaration
|
||||
List declarations = translationUnit.getDeclarations();
|
||||
assertEquals(1, declarations.size());
|
||||
SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0);
|
||||
assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool );
|
||||
List declarators = simpleDeclaration.getDeclarators();
|
||||
assertEquals( 1, declarators.size() );
|
||||
Declarator functionDeclarator = (Declarator)declarators.get( 0 );
|
||||
assertEquals( functionDeclarator.getName().toString(), "myFunction" );
|
||||
|
||||
ParameterDeclarationClause pdc = functionDeclarator.getParms();
|
||||
assertNotNull( pdc );
|
||||
List parameterDecls = pdc.getDeclarations();
|
||||
assertEquals( 3, parameterDecls.size() );
|
||||
ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 );
|
||||
assertNotNull( parm1.getDeclSpecifier().getName() );
|
||||
assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() );
|
||||
List parm1Decls = parm1.getDeclarators();
|
||||
assertEquals( 1, parm1Decls.size() );
|
||||
|
||||
ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 );
|
||||
assertNotNull( parm2.getDeclSpecifier().getName() );
|
||||
assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() );
|
||||
List parm2Decls = parm2.getDeclarators();
|
||||
assertEquals( 1, parm2Decls.size() );
|
||||
|
||||
ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 );
|
||||
assertNotNull( parm3.getDeclSpecifier().getName() );
|
||||
assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() );
|
||||
List parm3Decls = parm3.getDeclarators();
|
||||
assertEquals( 1, parm3Decls.size() );
|
||||
|
||||
OldKRParameterDeclarationClause clause = pdc.getOldKRParms();
|
||||
assertNotNull( clause );
|
||||
assertEquals( clause.getDeclarations().size(), 2 );
|
||||
SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0);
|
||||
assertEquals( decl1.getDeclarators().size(), 1 );
|
||||
assertTrue(decl1.getDeclSpecifier().isConst());
|
||||
assertFalse(decl1.getDeclSpecifier().isVolatile());
|
||||
assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char);
|
||||
Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 );
|
||||
assertEquals( declarator1.getName().toString(), "parm1" );
|
||||
Expression initValue1 = declarator1.getExpression();
|
||||
List ptrOps1 = declarator1.getPointerOperators();
|
||||
assertNotNull( ptrOps1 );
|
||||
assertEquals( 1, ptrOps1.size() );
|
||||
PointerOperator po1 = (PointerOperator)ptrOps1.get(0);
|
||||
assertNotNull( po1 );
|
||||
assertFalse( po1.isConst() );
|
||||
assertFalse( po1.isVolatile() );
|
||||
assertEquals( po1.getType(), PointerOperator.t_pointer );
|
||||
|
||||
SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1);
|
||||
assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int );
|
||||
assertEquals( declaration.getDeclarators().size(), 1);
|
||||
assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() );
|
||||
assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() );
|
||||
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" );
|
||||
ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms();
|
||||
assertEquals( clause2.getDeclarations().size(), 1 );
|
||||
assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 );
|
||||
assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() );
|
||||
assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,3 +66,9 @@ void func3()
|
|||
{
|
||||
printf("This is not really here\n");
|
||||
}
|
||||
|
||||
bool KRFunction( parm1, parm2, parm3 )
|
||||
const char* parm1;
|
||||
int (*parm2)(float);
|
||||
{
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
void decl_0001(char);
|
||||
void (decl_0002)(char);
|
||||
void ((decl_0003))(char);
|
||||
|
||||
void *decl_0004(char);
|
||||
void (*decl_0005)(char);
|
||||
void (*(decl_0006))(char);
|
||||
void ((*decl_0007))(char);
|
||||
|
||||
typedef void decl_0011(char);
|
||||
typedef void (decl_0012)(char);
|
||||
typedef void ((decl_0013))(char);
|
||||
|
||||
typedef void *decl_0014(char);
|
||||
typedef void (*decl_0015)(char);
|
||||
typedef void (*(decl_0016))(char);
|
||||
typedef void ((*decl_0017))(char);
|
||||
|
||||
typedef void decl_0021(char);
|
||||
void (*decl_0022)(char);
|
||||
void (*(*decl_0023(int a)))(char) { return &decl_0021; }
|
||||
void (*(*(*((decl_0024)))(int))(float))(char);
|
||||
|
||||
int (*decl_0031)(char(*yyy)(bool));
|
|
@ -1,15 +0,0 @@
|
|||
int z;
|
||||
|
||||
template<T> class nonVector {
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
|
||||
T* head;
|
||||
vector<T>() { head =new T(); }
|
||||
int length() { return 1; }
|
||||
T& first() { return *head; }
|
||||
const T& first() const { return *head; }
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// TEMPLATE_STRUCT
|
||||
template<class Key, class Value, class SortAlgorithm=DefaultSort>
|
||||
struct Map
|
||||
{
|
||||
Key* keys;
|
||||
Value* values;
|
||||
SortAlgorithm* sortAlgorithm;
|
||||
Map();
|
||||
};
|
||||
|
||||
// TEMPLATE_CLASS
|
||||
template<class T> class nonVector {
|
||||
private:
|
||||
T* head;
|
||||
|
||||
public:
|
||||
nonVector() { head =new T(); }
|
||||
int length() { return 1; }
|
||||
T& first() { return *head; }
|
||||
const T& first() const;
|
||||
};
|
||||
|
||||
// TEMPLATE_UNION
|
||||
template<class X, class Y, int size=16>
|
||||
union ArrayOverlay {
|
||||
public:
|
||||
X x[size];
|
||||
Y y[size];
|
||||
|
||||
static int<X,Y> numArrays;
|
||||
};
|
||||
|
||||
|
||||
// TEMPLATE_METHODS
|
||||
class TemplateContainer {
|
||||
// these are in an enclosing class
|
||||
template<class Bar> void fum(int i);
|
||||
template<int> void scrum(void) {};
|
||||
};
|
||||
|
||||
// TEMPLATE_FUNCTION
|
||||
template<class T> const T& nonVector<T>::first() const
|
||||
{
|
||||
return *head;
|
||||
}
|
||||
|
||||
template<class X> bool IsGreaterThan(X,X);
|
||||
|
||||
template<class Bar> void Foo::fum(int i) {}
|
||||
|
||||
// TEMPLATE_VARIABLES
|
||||
template <bool threads, int inst> char* default_alloc_template<threads, inst>::S_start_free = 0;
|
||||
|
||||
// an instantiation, not a template:
|
||||
complex<float> cf(0,0);
|
||||
//template<class Language, class CharacterSet, class SortAlgorithm<CharacterSet> >
|
||||
//Dictionary* TheSpellCheckDictionary;
|
||||
|
||||
int success;
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue