1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fixes occasional NPE in CModelTests

This commit is contained in:
Markus Schorn 2007-04-06 08:44:32 +00:00
parent e239602e33
commit 39e2a19ab7
2 changed files with 19 additions and 17 deletions

View file

@ -16,14 +16,12 @@ import java.util.Stack;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.ExpectedStrings;
import org.eclipse.core.runtime.CoreException;
/**
* @author Peter Graves
@ -87,7 +85,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
* true
*
*/
public void testIsTranslationUnit() throws CoreException,
public void testIsTranslationUnit() throws Exception,
FileNotFoundException {
ITranslationUnit myTranslationUnit;
@ -101,7 +99,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
* Simple sanity tests to make sure TranslationUnit.getChildren seems to
* basicly work
*/
public void testGetChildren() throws CModelException {
public void testGetChildren() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement[] elements;
int x;
@ -126,7 +124,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/***************************************************************************
* Simple sanity tests for the getElement() call
*/
public void testGetElement() throws CModelException {
public void testGetElement() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement myElement;
Stack missing = new Stack();
@ -157,7 +155,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/***************************************************************************
* Simple sanity tests for the getInclude call
*/
public void testBug23478A() throws CModelException {
public void testBug23478A() throws Exception {
IInclude myInclude;
int x;
String includes[] = { "stdio.h", "unistd.h" };
@ -182,7 +180,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/***************************************************************************
* Simple sanity tests for the getIncludes call
*/
public void testBug23478B() throws CModelException {
public void testBug23478B() throws Exception {
IInclude myIncludes[];
String includes[] = { "stdio.h", "unistd.h" };
ExpectedStrings myExp = new ExpectedStrings(includes);
@ -203,7 +201,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/***************************************************************************
* Simple sanity tests for the getElementAtLine() call
*/
public void testGetElementAtLine() throws CoreException {
public void testGetElementAtLine() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement myElement;
Stack missing = new Stack();

View file

@ -259,19 +259,23 @@ public class CProjectHelper {
/**
* Attempts to find a TranslationUnit with the given name in the workspace
* @throws InterruptedException
*/
public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException {
ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[i];
ICElement[] myElements = root.getChildren();
for (int x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) {
if (myElements[x] instanceof ITranslationUnit) {
return ((ITranslationUnit) myElements[x]);
public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException, InterruptedException {
for (int j=0; j<20; j++) {
ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[i];
ICElement[] myElements = root.getChildren();
for (int x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) {
if (myElements[x] instanceof ITranslationUnit) {
return ((ITranslationUnit) myElements[x]);
}
}
}
}
Thread.sleep(100);
}
return null;
}