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

View file

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