Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] CModelElements tests + 2 bug fixes

This patch has:
- Fix for bug 36506: Bad Signature For main
- Fix for bug 36498: outline view signature incorrect for templated
functions/methods 
- JUnit tests for C Model Elements.

Thanks,
Hoda

Index: model/org/eclipse/cdt/core/model/IEnumeration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumeration.java,v
retrieving revision 1.1
diff -u -r1.1 IEnumeration.java
--- model/org/eclipse/cdt/core/model/IEnumeration.java	26 Jun 2002 20:37:14 -0000	1.1
+++ model/org/eclipse/cdt/core/model/IEnumeration.java	16 Apr 2003 19:15:14 -0000
@@ -8,5 +8,5 @@
 /**
  * An Enumeration type.
  */
-public interface IEnumeration extends IVariable {
+public interface IEnumeration extends IVariable, IParent {
 }
Index: model/org/eclipse/cdt/core/model/IEnumerator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumerator.java,v
retrieving revision 1.1
diff -u -r1.1 IEnumerator.java
--- model/org/eclipse/cdt/core/model/IEnumerator.java	31 Mar 2003 20:47:34 -0000	1.1
+++ model/org/eclipse/cdt/core/model/IEnumerator.java	16 Apr 2003 19:15:14 -0000
@@ -10,7 +10,7 @@
  * Contributors: 
  * Rational Software - Initial API and implementation
 ***********************************************************************/
-public interface IEnumerator extends ISourceManipulation{
+public interface IEnumerator extends ICElement, ISourceManipulation{
 
 	/**
 	 * Returns the enumerator constant expression if any.
Index: model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java,v
retrieving revision 1.7
diff -u -r1.7 FunctionDeclaration.java
--- model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java	9 Apr 2003 15:07:55 -0000	1.7
+++ model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java	16 Apr 2003 19:15:14 -0000
@@ -51,6 +51,17 @@
 		
 	public String getSignature(){
 		StringBuffer sig = new StringBuffer(getElementName());
+		sig.append(getParameterClause());
+		if(isConst())
+			sig.append(" const");
+		if(isVolatile())
+			sig.append(" volatile");
+		return sig.toString();
+	}
+	
+	public String getParameterClause(){
+		StringBuffer sig = new StringBuffer();
+		
 		if(getNumberOfParameters() > 0){
 			sig.append("(");
 			String[] paramTypes = getParameterTypes();
@@ -65,13 +76,9 @@
 		else{
 			sig.append("()");
 		}
-		if(isConst())
-			sig.append(" const");
-		if(isVolatile())
-			sig.append(" volatile");
-		return sig.toString();
+		return sig.toString();	
 	}
-		
+	
 	public String getParameterInitializer(int pos) {
 		return "";
 	}
Index: model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java,v
retrieving revision 1.1
diff -u -r1.1 FunctionTemplate.java
--- model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java	11 Apr 2003 14:36:51 -0000	1.1
+++ model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java	16 Apr 2003 19:15:14 -0000
@@ -66,7 +66,12 @@
 		else{
 			sig.append("<>");
 		}
-		sig.append(this.getSignature());
+		sig.append(this.getParameterClause());
+		if(isConst())
+			sig.append(" const");
+		if(isVolatile())
+			sig.append(" volatile");
+
 		if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){ 
 			sig.append(" : ");
 			sig.append(this.getReturnType());
Index: model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java,v
retrieving revision 1.1
diff -u -r1.1 MethodTemplate.java
--- model/org/eclipse/cdt/internal/core/model/MethodTemplate.java	11 Apr 2003 14:36:51 -0000	1.1
+++ model/org/eclipse/cdt/internal/core/model/MethodTemplate.java	16 Apr 2003 19:15:14 -0000
@@ -66,7 +66,12 @@
 		else{
 			sig.append("<>");
 		}
-		sig.append(this.getSignature());
+		sig.append(this.getParameterClause());
+		if(isConst())
+			sig.append(" const");
+		if(isVolatile())
+			sig.append(" volatile");
+
 		if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){ 
 			sig.append(" : ");
 			sig.append(this.getReturnType());
Index: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java,v
retrieving revision 1.12
diff -u -r1.12 CModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java	16 Apr 2003 12:30:47 -0000	1.12
+++ parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java	16 Apr 2003 19:15:14 -0000
@@ -24,6 +24,7 @@
 import org.eclipse.cdt.core.model.IStructure;
 import org.eclipse.cdt.core.model.ITemplate;
 import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
 import org.eclipse.cdt.internal.core.dom.ClassKey;
 import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
 import org.eclipse.cdt.internal.core.dom.DOMBuilder;
@@ -535,7 +536,6 @@
 			if(decl instanceof TemplateParameter){
 				TemplateParameter parameter = (TemplateParameter) decl;
 				if(parameter.getName() != null){
-					paramType.append(" ");
 					paramType.append(parameter.getName().toString());
 				}else {
 					int kind = parameter.getKind();
@@ -577,6 +577,7 @@
 		type.append(getDeclarationType(declaration));
 		// add pointerr or reference from declarator if any
 		type.append(getDeclaratorPointerOperation(declarator));
+		type.append(getDeclaratorArrayQualifiers(declarator));
 		return type.toString();		
 	}
 	
@@ -662,5 +663,18 @@
 			}
 		}
 		return pointerString.toString();
+	}
+	
+	private String getDeclaratorArrayQualifiers(Declarator declarator){		
+		StringBuffer arrayString = new StringBuffer();
+		List arrayQualifiers = declarator.getArrayQualifiers(); 
+		if(arrayQualifiers != null){
+			Iterator i = arrayQualifiers.iterator();
+			while (i.hasNext()){
+				ArrayQualifier q = (ArrayQualifier) i.next();
+				arrayString.append("[]");				
+			}
+		}
+		return arrayString.toString();
 	}
 }
Index: model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java,v
retrieving revision 1.2
diff -u -r1.2 CModelElementsTests.java
--- model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java	16 Apr 2003 12:30:41 -0000	1.2
+++ model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java	16 Apr 2003 19:15:33 -0000
@@ -21,11 +21,25 @@
 import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.IEnumeration;
+import org.eclipse.cdt.core.model.IEnumerator;
 import org.eclipse.cdt.core.model.IField;
+import org.eclipse.cdt.core.model.IFunction;
+import org.eclipse.cdt.core.model.IFunctionDeclaration;
+import org.eclipse.cdt.core.model.IInclude;
+import org.eclipse.cdt.core.model.IMacro;
 import org.eclipse.cdt.core.model.IMember;
 import org.eclipse.cdt.core.model.IMethod;
+import org.eclipse.cdt.core.model.IMethodDeclaration;
 import org.eclipse.cdt.core.model.INamespace;
+import org.eclipse.cdt.core.model.IParent;
 import org.eclipse.cdt.core.model.IStructure;
+import org.eclipse.cdt.core.model.ITypeDef;
+import org.eclipse.cdt.core.model.IVariable;
+import org.eclipse.cdt.core.model.IVariableDeclaration;
+import org.eclipse.cdt.internal.core.model.ClassTemplate;
+import org.eclipse.cdt.internal.core.model.FunctionTemplate;
+import org.eclipse.cdt.internal.core.model.MethodTemplate;
 import org.eclipse.cdt.internal.core.model.TranslationUnit;
 import org.eclipse.cdt.testplugin.CProjectHelper;
 import org.eclipse.cdt.testplugin.TestPluginLauncher;
@@ -75,7 +89,16 @@
 		}
 
 		CCorePlugin.getDefault().setUseNewParser(true);
+	}
 
+	private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
+		IProjectDescription description = proj.getDescription();
+		String[] prevNatures= description.getNatureIds();
+		String[] newNatures= new String[prevNatures.length + 1];
+		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+		newNatures[prevNatures.length]= natureId;
+		description.setNatureIds(newNatures);
+		proj.setDescription(description, monitor);
 	}
 	
 	protected void tearDown() throws Exception {
@@ -87,43 +110,309 @@
 		// parse the translation unit to get the elements tree		
 		tu.parse();
 		
-		// tu ---> namespace MyPackage
+		// tu ---> include
+		checkInclude(tu);
+		
+		// tu ---> macro
+		checkMacro(tu);
+		
+		// tu ---> namespace: MyPackage
 		ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE);
 		INamespace namespace = (INamespace) tuPackages.get(0);
 		assertEquals(namespace.getElementName(), new String("MyPackage"));
 		
-		// MyPackage ---> class Hello
-		ArrayList nsClassChildren = namespace.getChildrenOfType(ICElement.C_CLASS);		
-		IStructure classHello = (IStructure) nsClassChildren.get(0);
+		checkClass(namespace);
+				
+		checkEnums(namespace);	
+		
+		checkVariables(namespace);		
+
+		checkVariableDeclarations(namespace);		
+		
+		checkFunctions(namespace);
+		
+		checkStructs(namespace);
+		
+		checkTemplates(namespace);
+		
+		checkArrays(tu);
+	}
+
+	private void checkInclude(IParent tu){
+		ArrayList tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE);
+		IInclude inc1 = (IInclude) tuIncludes.get(0);
+		assertEquals(inc1.getElementName(), new String("stdio.h"));
+	}
+	
+	private void checkMacro(IParent tu){
+		ArrayList tuMacros = tu.getChildrenOfType(ICElement.C_MACRO);
+		IMacro mac1 = (IMacro) tuMacros.get(0);
+		assertEquals(mac1.getElementName(), new String("PRINT"));
+	}
+	
+	private void checkClass(IParent namespace){
+		// MyPackage ---> class: Hello
+		ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS);		
+		IStructure classHello = (IStructure) nsClasses.get(0);
 		assertEquals(classHello.getElementName(), new String("Hello"));
 		
-		// Hello --> int x
-		ArrayList helloFieldChildren = classHello.getChildrenOfType(ICElement.C_FIELD);
-		IField intX = (IField) helloFieldChildren.get(0);
+		// Hello --> field: int x
+		ArrayList helloFields = classHello.getChildrenOfType(ICElement.C_FIELD);
+		IField intX = (IField) helloFields.get(0);
 		assertEquals(intX.getElementName(), new String("x"));
-		int visibility = intX.getVisibility(); 
-		if (visibility != IMember.V_PROTECTED)
+		assertEquals(intX.getTypeName(), new String("int"));
+		int xVisibility = intX.getVisibility(); 
+		if (xVisibility != IMember.V_PROTECTED)
 			fail("visibility should be protected!");
 		
-		
-		// Hello ---> void setX(int X)
-		ArrayList helloMethodChildren = classHello.getChildrenOfType(ICElement.C_METHOD);
-		IMethod setX = (IMethod) helloMethodChildren.get(0);
+		// Hello ---> method: void setX(int X)
+		ArrayList helloMethods = classHello.getChildrenOfType(ICElement.C_METHOD);
+		IMethod setX = (IMethod) helloMethods.get(0);
 		assertEquals(setX.getElementName(), new String("setX"));
+		assertEquals(setX.getReturnType(), new String("void"));
 		int setXNumOfParam = setX.getNumberOfParameters();
 		if(setXNumOfParam != 1)
 			fail("setX should have one parameter!");
 		String[] setXParamTypes = setX.getParameterTypes();
 		String firstParamType = setXParamTypes[0];
-		assertEquals(firstParamType, new String("int")); 
+		assertEquals(firstParamType, new String("int"));
+		// TODO : check for the inline here
+		
+		checkNestedNamespace(classHello);
 	}
-	private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
-		IProjectDescription description = proj.getDescription();
-		String[] prevNatures= description.getNatureIds();
-		String[] newNatures= new String[prevNatures.length + 1];
-		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
-		newNatures[prevNatures.length]= natureId;
-		description.setNatureIds(newNatures);
-		proj.setDescription(description, monitor);
+	private void checkNestedNamespace(IParent classHello){
+		// Hello ---> namespace: MyNestedPackage 
+		ArrayList helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE);
+		INamespace myNestedPackage = (INamespace) helloNamespaces.get(0);
+		assertEquals(myNestedPackage.getElementName(), new String("MyNestedPackage"));
+	
+		checkParentNestedClass(myNestedPackage);	
+		checkDerivedNestedClass(myNestedPackage);
+	}
+	private void checkParentNestedClass(IParent myNestedPackage){
+		// MyNestedPackage ---> class: Y  
+		ArrayList nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS);		
+		IStructure classY = (IStructure) nestedClasses.get(0);
+		assertEquals(classY.getElementName(), new String("Y"));
+		
+		// Y ---> constructor: Y
+		ArrayList yMethods = classY.getChildrenOfType(ICElement.C_METHOD_DECLARATION);
+		IMethodDeclaration constructor  = (IMethodDeclaration) yMethods.get(0);
+		assertEquals(constructor.getElementName(), new String("Y"));
+		assertTrue (constructor.isConstructor());
+		
+		// Y ---> destructor: ~Y
+		IMethodDeclaration destructor  = (IMethodDeclaration) yMethods.get(1);
+		assertEquals(destructor.getElementName(), new String("~Y"));
+		assertTrue (destructor.isDestructor());
+		// TODO: check for virtual on destructors
+		
+	}
+	
+	private void checkDerivedNestedClass(IParent myNestedPackage){
+		// MyNestedPackage ---> class: X public Y 
+		ArrayList nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS);		
+		IStructure classX = (IStructure) nestedClasses.get(1);
+		assertEquals(classX.getElementName(), new String("X"));
+		// TODO : Check for base classes here
+		
+		// X --> field: B b
+		ArrayList xFieldChildren = classX.getChildrenOfType(ICElement.C_FIELD);
+		IField bB = (IField) xFieldChildren.get(0);
+		assertEquals(bB.getElementName(), new String("b"));
+		assertEquals(bB.getTypeName(), new String("B"));
+		int bVisibility = bB.getVisibility(); 
+		if (bVisibility != IMember.V_PRIVATE)
+			fail("visibility should be private!");
+		
+		// X ---> constructor chain: X 
+		ArrayList xMethodChildren = classX.getChildrenOfType(ICElement.C_METHOD);
+		IMethod xconstructor  = (IMethod) xMethodChildren.get(0);
+		assertEquals(xconstructor.getElementName(), new String("X"));
+		assertTrue (xconstructor.isConstructor());
+
+		// X ---> method declaration: doNothing
+		ArrayList xMethodDeclarations = classX.getChildrenOfType(ICElement.C_METHOD_DECLARATION);
+		IMethodDeclaration xDoNothing = (IMethodDeclaration) xMethodDeclarations.get(0);
+		assertEquals(xDoNothing.getElementName(), new String("doNothing"));
+		assertEquals(xDoNothing.getReturnType(), new String("int"));						
 	}
+	
+	private void checkEnums(IParent namespace){
+		// MyPackage ---> enum: Noname
+		ArrayList nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION);		
+		IEnumeration enum = (IEnumeration) nsEnums.get(0);
+		assertEquals(enum.getElementName(), new String(""));
+	
+		// 	enum ---> enumerator: first
+		ArrayList enumEnumerators = enum.getChildrenOfType(ICElement.C_ENUMERATOR);
+		IEnumerator first = (IEnumerator) enumEnumerators.get(0);
+		assertEquals(first.getElementName(), new String("first"));
+		// 	enum ---> enumerator: second
+		IEnumerator second = (IEnumerator) enumEnumerators.get(1);
+		assertEquals(second.getElementName(), new String("second"));
+		// 	enum ---> enumerator: third
+		IEnumerator third = (IEnumerator) enumEnumerators.get(2);
+		assertEquals(third.getElementName(), new String("third"));		
+
+		// MyPackage ---> enum: MyEnum
+		IEnumeration myEnum = (IEnumeration) nsEnums.get(1);
+		assertEquals(myEnum.getElementName(), new String("MyEnum"));
+	
+		// 	enum ---> enumerator: first
+		ArrayList myEnumEnumerators = myEnum.getChildrenOfType(ICElement.C_ENUMERATOR);
+		IEnumerator f = (IEnumerator) myEnumEnumerators.get(0);
+		assertEquals(f.getElementName(), new String("f"));
+		// 	enum ---> enumerator: second
+		IEnumerator s = (IEnumerator) myEnumEnumerators.get(1);
+		assertEquals(s.getElementName(), new String("s"));
+		// 	enum ---> enumerator: third
+		IEnumerator t = (IEnumerator) myEnumEnumerators.get(2);
+		assertEquals(t.getElementName(), new String("t"));
+	}
+
+	private void checkVariables(IParent namespace){
+		// MyPackage ---> int v
+		ArrayList nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE);
+		IVariable var1 = (IVariable) nsVars.get(0);
+		assertEquals(var1.getElementName(), new String("v"));
+		assertEquals(var1.getTypeName(), new String("int"));
+		
+		// MyPackage ---> unsigned long vuLong
+		IVariable var2 = (IVariable) nsVars.get(1);
+		assertEquals(var2.getElementName(), new String("vuLong"));
+		assertEquals(var2.getTypeName(), new String("unsigned long "));
+		
+		// MyPackage ---> unsigned short vuShort
+		IVariable var3 = (IVariable) nsVars.get(2);
+		assertEquals(var3.getElementName(), new String("vuShort"));
+		assertEquals(var3.getTypeName(), new String("unsigned short "));
+	}
+
+	private void checkVariableDeclarations(IParent namespace){
+		// MyPackage ---> extern int evar
+		ArrayList nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION);
+		IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0);
+		assertEquals(vDecl1.getElementName(), new String("evar"));
+		assertEquals(vDecl1.getTypeName(), new String("int"));
+
+		// 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)"));
+	}
+	
+	private void checkFunctions(IParent namespace){
+		//	MyPackage ---> function: void foo()
+		ArrayList nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION);
+		IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(0);
+		assertEquals(f1.getElementName(), new String("foo"));
+		assertEquals(f1.getReturnType(), new String("void"));
+		
+		//	MyPackage ---> function: char* foo(int&, char**)
+		IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(1);
+		assertEquals(f2.getElementName(), new String("foo"));
+		assertEquals(f2.getReturnType(), new String("char*"));
+		int fooNumOfParam = f2.getNumberOfParameters();
+		if(fooNumOfParam != 2)
+			fail("foo should have two parameter!");
+		String[] paramTypes = f2.getParameterTypes();
+		assertEquals(paramTypes[0], new String("int&"));
+		assertEquals(paramTypes[1], new String("char**"));
+	
+		//	MyPackage ---> function: void boo() {}		
+		ArrayList nsFunctions = namespace.getChildrenOfType(ICElement.C_FUNCTION);
+		IFunction f3 = (IFunction) nsFunctions.get(0);		
+		assertEquals(f3.getElementName(), new String("boo"));
+		assertEquals(f3.getReturnType(), new String("void"));
+	}
+
+	private void checkStructs(IParent namespace){
+		// struct with name
+		ArrayList nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT);
+		IStructure struct1 = (IStructure) nsStructs.get(0);
+		assertEquals(struct1.getElementName(), new String ("MyStruct"));
+		ArrayList struct1Fields = struct1.getChildrenOfType(ICElement.C_FIELD);
+		IField field1 = (IField) struct1Fields.get(0);
+		assertEquals(field1.getElementName(), new String("sint"));
+		assertEquals(field1.getTypeName(), new String("int"));
+		if(field1.getVisibility() != IMember.V_PUBLIC)
+			fail("field visibility should be public!");
+		
+		// struct no name
+		IStructure struct2 = (IStructure) nsStructs.get(1);
+		assertEquals(struct2.getElementName(), new String (""));
+		ArrayList struct2Fields = struct2.getChildrenOfType(ICElement.C_FIELD);
+		IField field2 = (IField) struct2Fields.get(0);
+		assertEquals(field2.getElementName(), new String("ss"));
+		assertEquals(field2.getTypeName(), new String("int"));
+		if(field2.getVisibility() != IMember.V_PUBLIC)
+			fail("field visibility should be public!");
+		
+		// typedefs
+		ArrayList nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF);
+		ITypeDef td1 = (ITypeDef) nsTypeDefs.get(0);
+		assertEquals(td1.getElementName(), new String ("myStruct"));
+		assertEquals(td1.getTypeName(), new String ("struct MyStruct"));
+		ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1);
+		assertEquals(td2.getElementName(), new String ("myTypedef"));
+		assertEquals(td2.getTypeName(), new String (""));
+
+		// union
+		ArrayList nsUnions = namespace.getChildrenOfType(ICElement.C_UNION);
+		IStructure u0 = (IStructure) nsUnions.get(0);
+		assertEquals(u0.getElementName(), new String("U"));		
+		ArrayList u0Fields = u0.getChildrenOfType(ICElement.C_FIELD);
+		IField field3 = (IField) u0Fields.get(0);
+		assertEquals(field3.getElementName(), new String("U1"));
+		assertEquals(field3.getTypeName(), new String("int"));
+		if(field3.getVisibility() != IMember.V_PUBLIC)
+			fail("field visibility should be public!");
+	}
+
+	private void checkTemplates(IParent namespace){
+		// template function
+		ArrayList functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION);
+		FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0);
+		assertEquals(ft.getElementName(), new String("aTemplatedFunction"));
+		assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction<A, B>(B) : A"));
+		
+		// template method
+		ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS);
+		IStructure enclosingClass = (IStructure) nsClasses.get(1);
+		ArrayList methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD);
+		MethodTemplate mt = (MethodTemplate)methodTemplates.get(0);
+		assertEquals(mt.getElementName(), new String("aTemplatedMethod"));
+		assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod<A, B>(B) : A"));
+		assertEquals(mt.getVisibility(), IMember.V_PUBLIC);
+		
+		// template class
+		ArrayList classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS);
+		ClassTemplate ct = (ClassTemplate)classTemplates.get(0);
+		assertEquals(ct.getElementName(), new String("myarray"));
+		assertEquals(ct.getTemplateSignature(), new String("myarray<T, Tibor>"));
+	}
+	
+	private void checkArrays(IParent tu){
+		// array variable
+		ArrayList variables = tu.getChildrenOfType(ICElement.C_VARIABLE);
+		IVariable arrayVar = (IVariable) variables.get(0);
+		assertEquals(arrayVar.getElementName(), new String("myArray"));
+		assertEquals(arrayVar.getTypeName(), new String("int[][]"));
+		
+		// array parameter in function main
+		ArrayList functions = tu.getChildrenOfType(ICElement.C_FUNCTION);
+		IFunction mainFunction  = (IFunction) functions.get(0);
+		assertEquals(mainFunction.getElementName(), new String("main"));
+		assertEquals(mainFunction.getReturnType(), new String("int"));
+		int NumOfParam = mainFunction.getNumberOfParameters();
+		if(NumOfParam != 2)
+			fail("main should have two parameter!");
+		String[] paramTypes = mainFunction.getParameterTypes();
+		assertEquals(paramTypes[0], new String("int"));
+		assertEquals(paramTypes[1], new String("char*[]"));
+		
+	}
+	
+
 }
Index: model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java,v
retrieving revision 1.2
diff -u -r1.2 ElementDeltaTests.java
--- model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java	27 Mar 2003 16:16:46 -0000	1.2
+++ model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java	16 Apr 2003 19:15:33 -0000
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.eclipse.cdt.core.CCProjectNature;
 import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.model.CModelException;
 import org.eclipse.cdt.core.model.ElementChangedEvent;
@@ -35,7 +36,10 @@
 import org.eclipse.cdt.testplugin.CProjectHelper;
 import org.eclipse.cdt.testplugin.TestPluginLauncher;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 
@@ -79,6 +83,9 @@
 				e.printStackTrace();
 			}
 		}
+		if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
+			addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
+		}
 		
 		// register with the model manager to listen to delta changes
 		CModelManager.getDefault().addElementChangedListener(this);
@@ -86,6 +93,15 @@
 		removedElements = new Vector(10);
 		changedElements = new Vector(100);
 		CCorePlugin.getDefault().setUseNewParser(true);
+	}
+	private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
+		IProjectDescription description = proj.getDescription();
+		String[] prevNatures= description.getNatureIds();
+		String[] newNatures= new String[prevNatures.length + 1];
+		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+		newNatures[prevNatures.length]= natureId;
+		description.setNatureIds(newNatures);
+		proj.setDescription(description, monitor);
 	}
 
 	protected void tearDown() throws Exception {
Index: model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java,v
retrieving revision 1.2
diff -u -r1.2 WorkingCopyTests.java
--- model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java	27 Mar 2003 16:16:46 -0000	1.2
+++ model/org/eclipse/cdt/core/model/tests/WorkingCopyTests.java	16 Apr 2003 19:15:34 -0000
@@ -17,6 +17,8 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.model.IBuffer;
 import org.eclipse.cdt.core.model.ICProject;
 import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -25,7 +27,10 @@
 import org.eclipse.cdt.testplugin.CProjectHelper;
 import org.eclipse.cdt.testplugin.TestPluginLauncher;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 
@@ -68,6 +73,20 @@
 				e.printStackTrace();
 			}
 		}
+		if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
+			addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
+		}
+
+		CCorePlugin.getDefault().setUseNewParser(true);		
+	}
+	private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
+		IProjectDescription description = proj.getDescription();
+		String[] prevNatures= description.getNatureIds();
+		String[] newNatures= new String[prevNatures.length + 1];
+		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+		newNatures[prevNatures.length]= natureId;
+		description.setNatureIds(newNatures);
+		proj.setDescription(description, monitor);
 	}
 
 	protected void tearDown() throws Exception {
Index: model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h,v
retrieving revision 1.1
diff -u -r1.1 CModelElementsTestStart.h
--- model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h	3 Apr 2003 15:38:26 -0000	1.1
+++ model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h	16 Apr 2003 19:15:34 -0000
@@ -1,11 +1,118 @@
+// include
 #include <stdio.h>
 
-namespace MyPackage{
-	class Hello{
+// macro
+#define PRINT(string,msg)  printf(string, msg)
+
+//namespace
+namespace MyPackage
+{
+	// check class
+	// class
+	class Hello
+	{
+	// protected visibility
 	protected:
+		// field
 		int x;
-		void setX(int X){
+		// method
+		inline void setX(int X)
+		{
 			x = X;
 		};
+		// check nested pachage
+		// nested namespace
+		namespace MyNestedPackage {
+			// check parent nested class
+			// nested class
+			class Y
+			{	// public visibility
+				public:
+				// constructor
+				Y();
+				//  virtual destructor
+				virtual ~Y();
+			};
+			// check derived nested class
+			// derived class
+			class X : public Y {
+					// private visibility
+					private:
+					// private field
+					B b;
+			        
+					public:
+					// constructor chain
+					X(int x) : yy(x) {
+							cout << "In consturctor\n";
+					}
+			        // method declaration 
+					int doNothing();
+			};
+		}
+	};
+
+	// check enums
+	// enum without name
+	enum { first, second, third };
+	// enum with name
+	enum MyEnum { f, s, t };
+
+	// check variables
+	// variable 
+	int v;
+	// unsigned long variable
+	unsigned long vuLong;
+	// unsigned short variable
+	unsigned short vuShort;
+
+	// check variable declarations
+	// variable declaration 
+	extern int evar;
+	// function pointer
+	static void * (*orig_malloc_hook)(const char *file, int line, size_t size);
+
+	// check functions
+	// simple function declaration
+	void foo();
+	// function declaration with parameters
+	char* foo(int& x, char**y);
+	// simple function definition
+	void boo(){
+		int g = 0;
+	};
+
+	// check Structs
+	// struct 
+	struct MyStruct{
+		int sint;
+	};
+	// typedef and elaborated types
+	typedef struct MyStruct myStruct;
+	// typedef 
+	typedef struct{ int ss; } myTypedef;
+	// unions
+	union U{
+		int U1;
 	};
-};
\ No newline at end of file
+
+
+	// check templates
+	// template function
+	template<class A, typename B=C> A aTemplatedFunction( B bInstance );
+	// template method
+	class enclosing {
+		// public visibility
+		public:
+		template<class A, typename B=C> A aTemplatedMethod( B bInstance );
+	};
+	// template class
+	template<class T, typename Tibor = junk> class myarray { /* */ };
+};
+
+	// check arrays
+	// arrays
+	int myArray [5][];
+	int main(int argc, char * argv[]) { }
+	
+

Back to the top