1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Brent Nicolle.

Added some Interface tests of (IInclude, IMacro, IStructure). 
Made sure all the Test Suites have names in the JUnit hierarchy.
This commit is contained in:
John Camelon 2003-06-10 22:57:05 +00:00
parent 52f06ad88c
commit 362dd49676
19 changed files with 530 additions and 12 deletions

View file

@ -2986,7 +2986,7 @@ c, quickParse);
} catch (EndOfFile e) {
throw e;
} catch (ScannerException e) {
e.printStackTrace();
// e.printStackTrace();
return fetchToken();
}
}

View file

@ -1,3 +1,7 @@
2003-06-10 Brent Nicolle
Added some Interface tests of (IInclude, IMacro, IStructure).
Made sure all the Test Suites have names in the JUnit hierarchy.
2003-06-09 Victor Mozgin
Moved testBug36769() from ACEFailedTest.java to DOMTests.java.
Removed ACEFailedTest.java as it is empty now.

View file

@ -50,7 +50,7 @@ public class AllBuildTests extends TestCase {
}
public static Test suite() {
TestSuite suite = new TestSuite();
TestSuite suite = new TestSuite(AllBuildTests.class.getName());
suite.addTest(new AllBuildTests("testExtensions"));
suite.addTest(new AllBuildTests("testProject"));

View file

@ -49,7 +49,7 @@ public class CModelElementsFailedTests extends TestCase {
private NullProgressMonitor monitor;
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(CModelElementsFailedTests.class.getName());
suite.addTest(new CModelElementsFailedTests("testBug36379"));
return suite;
}

View file

@ -0,0 +1,42 @@
// include
#include <stdio.h>
#include "whatever.h"
#include <src/slash.h>
#include <src\backslash.h>
#include "Program Files/space.h"
#include "../up1dir.h"
#include "./samedir.h"
#include "different_extension1.hpp"
#include "different_extension2.hh"
#include "different_extension3.x"
#include <no_extension>
# include "whitespace_after_hash"
#include "whitespace_before_hash"
// failure cases:
#include garbage
#include "resync_after_bad_parse_1"
#include
#include "resync_after_bad_parse_2"
#include "one" "two" "three"
#include "resync_after_bad_parse_3"
// from the Spec:
// from [C, 6.10.p8]
// should fail
#define EMPTY
EMPTY #include "invalid.h"
// from [C, 6.10.2.p8]:
// should equal #include "myInclude1.h"
#define MYINCFILE "myInclude1.h"
#include MYINCFILE
// from [C, 6.10.3.5.p6]:
// should equal #include "vers2.h"
#define INCFILE(x) vers ## x
#define xstr(x) str(x)
#define str(x) #x
#include xstr(INCFILE(2)).h

View file

@ -0,0 +1,4 @@
// macro
#define SINGLETON
#define NUMBER 1
#define PRINT(string,msg) printf(string, msg)

View file

@ -0,0 +1,4 @@
// IStructure
struct foo {
int bar;
};

View file

@ -25,16 +25,17 @@ public class AllCoreTests {
}
public static Test suite() {
TestSuite suite = new TestSuite();
TestSuite suite = new TestSuite(AllCoreTests.class.getName());
// Just add more test cases here as you create them for
// each class being tested
suite.addTest(AllLanguageInterfaceTests.suite());
suite.addTest(CModelTests.suite());
suite.addTest(CModelExceptionTest.suite());
suite.addTest(FlagTests.suite());
suite.addTest(ArchiveTests.suite());
suite.addTest(TranslationUnitTests.suite());
return suite;
}

View file

@ -0,0 +1,35 @@
/*
* Created on Jun 9, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* LanguageInterfaceTests
* lists all parts of the C/C++ language interface objects
* to be tested.
* @author bnicolle
*
*/
public class AllLanguageInterfaceTests {
/**
*
*/
public static Test suite() {
TestSuite suite = new TestSuite(AllLanguageInterfaceTests.class.getName());
// Just add more test cases here as you create them for
// each class being tested
suite.addTest(IIncludeTests.suite());
suite.addTest(IMacroTests.suite());
suite.addTest(IStructureTests.suite());
return suite;
}
}

View file

@ -59,7 +59,7 @@ public class CModelElementsTests extends TestCase {
private NullProgressMonitor monitor;
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(CModelElementsTests.class.getName());
suite.addTest(new CModelElementsTests("testCModelElements"));
return suite;
}

View file

@ -59,7 +59,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen
}
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(ElementDeltaTests.class.getName());
suite.addTest(new ElementDeltaTests("testElementDeltas"));
return suite;
}

View file

@ -0,0 +1,116 @@
/*
* Created on Jun 4, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.tests.IntegratedCModelTest;
/**
* @author bnicolle
*
*/
public class IIncludeTests extends IntegratedCModelTest {
/**
* @param string
*/
public IIncludeTests(String string) {
super( string );
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileSubdir() {
return "model/org.eclipse.cdt.core.model.tests.resources/";
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileResource() {
return "IIncludeTest.h";
}
/**
* @returns a test suite named after this class
* containing all its public members named "test*"
*/
public static Test suite() {
TestSuite suite= new TestSuite(IIncludeTests.class);
return suite;
}
public void testGetIncludeName()
{
ITranslationUnit tu = getTU();
IInclude[] theIncludes = null;
try {
theIncludes = tu.getIncludes();
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
}
String getIncludeNameList[] = new String[] {
new String("stdio.h"),
new String("whatever.h"),
new String("src/slash.h"),
new String("src\\backslash.h"), // that's a single backslash, escaped
new String("Program Files/space.h"),
new String("../up1dir.h"),
new String("./samedir.h"),
new String("different_extension1.hpp"),
new String("different_extension2.hh"),
new String("different_extension3.x"),
new String("no_extension"),
new String("whitespace_after_hash"),
new String("whitespace_before_hash"),
new String("resync_after_bad_parse_1"),
new String("resync_after_bad_parse_2"),
new String("one"), // C-spec does not allow this, but that's OK for our present purposes
new String("resync_after_bad_parse_3"),
new String("invalid.h"), // C-spec does not allow this, but that's OK for our present purposes
// TODO: expect new String("MYINCFILE"),
// TODO: expect new String("xstr(INCFILE(2)).h")
};
assertEquals( getIncludeNameList.length, theIncludes.length );
for( int i=0; i<getIncludeNameList.length; i++ )
{
IInclude inc1 = theIncludes[i];
assertEquals( getIncludeNameList[i], inc1.getIncludeName() );
}
// checkLineNumbers((CElement)inc1, 2, 2);
}
public void testIsStandard()
{
ITranslationUnit tu = getTU();
IInclude[] theIncludes = null;
try {
theIncludes = tu.getIncludes();
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
}
boolean isStandardList[] = new boolean[] {
true, false
};
for( int i=0; i<isStandardList.length; i++ )
{
IInclude inc1 = theIncludes[i];
assertEquals( isStandardList[i], inc1.isStandard() );
}
}
}

View file

@ -0,0 +1,106 @@
/*
* Created on Jun 6, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import org.eclipse.cdt.core.model.IMacro;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.tests.IntegratedCModelTest;
/**
* IMacroTest - Class for testing IMacro
*
* @author bnicolle
*
*/
public class IMacroTests extends IntegratedCModelTest {
/**
* @returns a test suite named after this class
* containing all its public members named "test*"
*/
public static Test suite() {
TestSuite suite= new TestSuite( IMacroTests.class.getName() );
suite.addTest( new IMacroTests("testGetElementName"));
// TODO: suite.addTest( new IMacroTest("testGetIdentifierList"));
// TODO: suite.addTest( new IMacroTest("testGetTokenSequence"));
return suite;
}
/**
* @param name
*/
public IMacroTests(String name) {
super(name);
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileSubdir() {
return "model/org.eclipse.cdt.core.model.tests.resources/";
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileResource() {
return "IMacroTest.h";
}
public void testGetElementName() {
ITranslationUnit tu = getTU();
ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO );
String expectedList[] = new String[] {
"SINGLETON",
"NUMBER",
"PRINT"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getElementName() );
}
}
public void testGetIdentifierList() {
ITranslationUnit tu = getTU();
ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO );
String expectedList[] = new String[] {
"",
"",
"string,msg"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getIdentifierList() );
}
}
public void testGetTokenSequence() {
ITranslationUnit tu = getTU();
ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO );
String expectedList[] = new String[] {
"",
"1",
"printf(string, msg)"
};
assertEquals( expectedList.length, arrayElements.size() );
for( int i=0; i<expectedList.length; i++ )
{
IMacro iMacro = (IMacro) arrayElements.get(i);
assertEquals( expectedList[i], iMacro.getTokenSequence() );
}
}
}

View file

@ -0,0 +1,95 @@
/*
* Created on Jun 9, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.IField;
import junit.framework.*;
import java.util.ArrayList;
/**
* @author bnicolle
*
*/
public class IStructureTests extends IntegratedCModelTest {
/**
* @param name
*/
public IStructureTests(String name) {
super(name);
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileSubdir() {
return "model/org.eclipse.cdt.core.model.tests.resources/";
}
/**
* @see org.eclipse.cdt.internal.core.model.IntegratedCModelTest
*/
public String getSourcefileResource() {
return "IStructure.c";
}
/**
* @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() );
// TODO: suite.addTest( new IStructureTests("testGetField"));
// TODO: implement the other tests here once IStructure is properly implemented!
return suite;
}
public void testGetAccessControl() {
// test getAccessControl()
// test getAccessControl(int)
}
public void testGetBaseTypes() {
}
public void testGetField() {
ITranslationUnit tu = getTU();
ArrayList arrayStructs = tu.getChildrenOfType(ITranslationUnit.C_STRUCT);
ArrayList arrayClasses = tu.getChildrenOfType(ITranslationUnit.C_CLASS);
IStructure myIStruct = (IStructure) arrayStructs.get(0);
assertNotNull(myIStruct);
IField myIField = myIStruct.getField("bar");
assertNotNull(myIField);
}
public void testGetFields() {
}
public void testGetInitializer() {
}
public void testGetMethod() {
}
public void testGetMethods() {
}
public void testGetStructureInfo() {
}
public void testGetTypeName() {
}
public void testIsAbstract() {
}
public void testIsClass() {
}
public void testIsConst() {
}
public void testIsStatic() {
}
public void testIsStruct() {
}
public void testIsUnion() {
}
public void testIsVolatile() {
}
}

View file

@ -0,0 +1,104 @@
/*
* Created on Jun 3, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import junit.framework.TestCase;
import java.io.FileInputStream;
import java.util.Map;
import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
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;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
/**
* @author bnicolle
*
*/
public abstract class IntegratedCModelTest extends TestCase {
private ICProject fCProject;
private IFile sourceFile;
private NullProgressMonitor monitor;
/**
*
*/
public IntegratedCModelTest() {
super();
}
/**
* @param name
*/
public IntegratedCModelTest(String name) {
super(name);
}
/**
* @return the subdirectory (from the plugin root) containing the required
* test sourcefile (plus a trailing slash)
*/
abstract public String getSourcefileSubdir();
/**
* @return the name of the test source-file
*/
abstract public String getSourcefileResource();
public void setUp() throws Exception {
monitor = new NullProgressMonitor();
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
sourceFile = fCProject.getProject().getFile( getSourcefileResource() );
if (!sourceFile.exists()) {
try{
FileInputStream fileIn = new FileInputStream(pluginRoot+ getSourcefileSubdir() + getSourcefileResource() );
sourceFile.create(fileIn,false, monitor);
} catch (CoreException e) {
e.printStackTrace();
}
}
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
}
CCorePlugin.getDefault().setUseNewParser(true);
}
protected void tearDown() throws Exception {
CProjectHelper.delete(fCProject);
}
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 ITranslationUnit getTU() {
TranslationUnit tu = new TranslationUnit(fCProject, sourceFile);
// parse the translation unit to get the elements tree
Map newElement = tu.parse(false); // FALSE=require line numbers
return tu;
}
}

View file

@ -157,7 +157,14 @@ public class TranslationUnitTests extends TestCase {
}
public static TestSuite suite() {
return new TestSuite(TranslationUnitTests.class);
TestSuite suite= new TestSuite(TranslationUnitTests.class.getName());
suite.addTest(new TranslationUnitTests("testIsTranslationUnit"));
suite.addTest(new TranslationUnitTests("testGetChildren"));
suite.addTest(new TranslationUnitTests("testGetElement"));
suite.addTest(new TranslationUnitTests("testBug23478A"));
suite.addTest(new TranslationUnitTests("testBug23478B"));
// TODO: suite.addTest(new TranslationUnitTests("testGetElementAtLine"));
return suite;
}
public static void main (String[] args){
@ -183,7 +190,7 @@ public class TranslationUnitTests extends TestCase {
* Simple sanity tests to make sure TranslationUnit.getChildren seems to
* basicly work
*/
public void testGetChildern() {
public void testGetChildren() {
ITranslationUnit myTranslationUnit;
ICElement[] elements;
int x;

View file

@ -48,7 +48,7 @@ public class WorkingCopyTests extends TestCase {
}
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(WorkingCopyTests.class.getName());
suite.addTest(new WorkingCopyTests("testWorkingCopy"));
//suite.addTest(new WorkingCopyTests("testHashing"));
return suite;

View file

@ -24,7 +24,7 @@ import org.eclipse.cdt.core.model.tests.CModelElementsTests;
*/
public class ParserTestSuite extends TestCase {
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
suite.addTestSuite(BranchTrackerTest.class);
suite.addTestSuite(ScannerTestCase.class);
suite.addTestSuite(ExprEvalTest.class);

View file

@ -22,7 +22,7 @@ public class HelloWorld extends TestCase {
}
public static Test suite() {
TestSuite suite= new TestSuite();
TestSuite suite= new TestSuite(HelloWorld.class.getName());
suite.addTest(new HelloWorld("test1"));
return suite;
}