1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-03-31 11:15:19 -07:00
parent dc19bb3b6b
commit 6b32a922ba

View file

@ -8,7 +8,6 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.model.tests; package org.eclipse.cdt.core.model.tests;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -29,8 +28,7 @@ import org.eclipse.cdt.core.testplugin.util.ExpectedStrings;
* *
* This file contains a set of generic tests for the core C model's * This file contains a set of generic tests for the core C model's
* TranslationUnit class. There is nothing exotic here, mostly just sanity type * TranslationUnit class. There is nothing exotic here, mostly just sanity type
* tests * tests.
*
*/ */
public class TranslationUnitTests extends TranslationUnitBaseTest { public class TranslationUnitTests extends TranslationUnitBaseTest {
/* /*
@ -41,8 +39,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
"globalvar", "myenum", "mystruct_t", "mystruct", "myunion", "globalvar", "myenum", "mystruct_t", "mystruct", "myunion",
"mytype", "func1", "func2", "main", "func3" }; "mytype", "func1", "func2", "main", "func3" };
int[] expectedLines = { 12, 14, 17, 20, 23, 28, 32, 35, 42, 47, 53, 58, 65, int[] expectedLines = { 12, 14, 17, 20, 23, 28, 32, 35, 42, 47, 53, 58, 65, 70 };
70 };
/* /*
* This is a list of that the types of the above list of elements is * This is a list of that the types of the above list of elements is
@ -85,16 +82,11 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/*************************************************************************** /***************************************************************************
* Simple sanity test to make sure TranslationUnit.isTranslationUnit returns * Simple sanity test to make sure TranslationUnit.isTranslationUnit returns
* true * true
*
*/ */
public void testIsTranslationUnit() throws Exception, public void testIsTranslationUnit() throws Exception,
FileNotFoundException { FileNotFoundException {
ITranslationUnit myTranslationUnit; ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject, "exetest.c");
assertNotNull(tu);
myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,
"exetest.c");
assertTrue("A TranslationUnit", myTranslationUnit != null);
} }
/*************************************************************************** /***************************************************************************
@ -102,48 +94,38 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
* basicly work * basicly work
*/ */
public void testGetChildren() throws Exception { public void testGetChildren() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement[] elements;
int x;
ExpectedStrings expectedString = new ExpectedStrings(expectedStringList); ExpectedStrings expectedString = new ExpectedStrings(expectedStringList);
myTranslationUnit = CProjectHelper.findTranslationUnit(testProject, ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject, "exetest.c");
"exetest.c");
if (myTranslationUnit.hasChildren()) { if (tu.hasChildren()) {
elements = myTranslationUnit.getChildren(); ICElement[] elements = tu.getChildren();
for (x = 0; x < elements.length; x++) { for (int x = 0; x < elements.length; x++) {
expectedString.foundString(elements[x].getElementName()); expectedString.foundString(elements[x].getElementName());
} }
} }
assertTrue("PR:23603 " + expectedString.getMissingString(), assertTrue("PR:23603 " + expectedString.getMissingString(),
expectedString.gotAll()); expectedString.gotAll());
assertTrue(expectedString.getExtraString(), !expectedString.gotExtra()); assertTrue(expectedString.getExtraString(), !expectedString.gotExtra());
} }
/*************************************************************************** /***************************************************************************
* Simple sanity tests for the getElement() call * Simple sanity tests for the getElement() call
*/ */
public void testGetElement() throws Exception { public void testGetElement() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement myElement;
Stack missing = new Stack(); Stack missing = new Stack();
int x; ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject,
myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,
"exetest.c"); "exetest.c");
for (x = 0; x < expectedStringList.length; x++) { for (int x = 0; x < expectedStringList.length; x++) {
myElement = myTranslationUnit.getElement(expectedStringList[x]); ICElement myElement = tu.getElement(expectedStringList[x]);
if (myElement == null) if (myElement == null) {
missing.push(expectedStringList[x]); missing.push(expectedStringList[x]);
else { } else {
assertTrue("Expected:" + expectedStringList[x] + " Got:" assertTrue("Expected: \"" + expectedStringList[x] + "\". Got:"
+ myElement.getElementName(), expectedStringList[x] + myElement.getElementName(),
.equals(myElement.getElementName())); expectedStringList[x].equals(myElement.getElementName()));
} }
} }
if (!missing.empty()) { if (!missing.empty()) {
String output = new String("PR:23603 Could not get elements: "); String output = new String("PR:23603 Could not get elements: ");
@ -151,48 +133,40 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
output += missing.pop() + " "; output += missing.pop() + " ";
assertTrue(output, false); assertTrue(output, false);
} }
} }
/*************************************************************************** /***************************************************************************
* Simple sanity tests for the getInclude call * Simple sanity tests for the getInclude call
*/ */
public void testBug23478A() throws Exception { public void testBug23478A() throws Exception {
IInclude myInclude;
int x;
String includes[] = { "stdio.h", "unistd.h" }; String includes[] = { "stdio.h", "unistd.h" };
ITranslationUnit myTranslationUnit = CProjectHelper ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject, "exetest.c");
.findTranslationUnit(testProject, "exetest.c");
for (x = 0; x < includes.length; x++) { for (int x = 0; x < includes.length; x++) {
myInclude = myTranslationUnit.getInclude(includes[x]); IInclude include = tu.getInclude(includes[x]);
if (myInclude == null) if (include == null) {
fail("Unable to get include: " + includes[x]); fail("Unable to get include: " + includes[x]);
else { } else {
// Failed test: Include.getIncludeName() always returns ""; // Failed test: Include.getIncludeName() always returns "";
// assertTrue // assertTrue
assertTrue("PR:23478 Expected:" + new String("") + " Got:" assertTrue("PR:23478 Expected: an empty string. Got: "
+ myInclude.getIncludeName(), includes[x] + include.getIncludeName(),
.equals(myInclude.getIncludeName())); includes[x].equals(include.getIncludeName()));
} }
} }
} }
/*************************************************************************** /***************************************************************************
* Simple sanity tests for the getIncludes call * Simple sanity tests for the getIncludes call
*/ */
public void testBug23478B() throws Exception { public void testBug23478B() throws Exception {
IInclude myIncludes[]; String headers[] = { "stdio.h", "unistd.h" };
String includes[] = { "stdio.h", "unistd.h" }; ExpectedStrings myExp = new ExpectedStrings(headers);
ExpectedStrings myExp = new ExpectedStrings(includes); ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject, "exetest.c");
int x;
ITranslationUnit myTranslationUnit = CProjectHelper
.findTranslationUnit(testProject, "exetest.c");
myIncludes = myTranslationUnit.getIncludes(); IInclude[] includes = tu.getIncludes();
for (x = 0; x < myIncludes.length; x++) { for (int x = 0; x < includes.length; x++) {
myExp.foundString(myIncludes[x].getIncludeName()); myExp.foundString(includes[x].getIncludeName());
} }
// Failed test: Include.getIncludeName() always returns ""; // Failed test: Include.getIncludeName() always returns "";
// assertTrue // assertTrue
@ -204,31 +178,24 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
* Simple sanity tests for the getElementAtLine() call * Simple sanity tests for the getElementAtLine() call
*/ */
public void testGetElementAtLine() throws Exception { public void testGetElementAtLine() throws Exception {
ITranslationUnit myTranslationUnit;
ICElement myElement;
Stack missing = new Stack(); Stack missing = new Stack();
int x; ITranslationUnit tu = CProjectHelper.findTranslationUnit(testProject, "exetest.c");
myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,
"exetest.c");
for (x = 0; x < expectedStringList.length; x++) { for (int x = 0; x < expectedStringList.length; x++) {
myElement = myTranslationUnit.getElementAtLine(expectedLines[x]); ICElement element = tu.getElementAtLine(expectedLines[x]);
if (myElement == null) if (element == null) {
missing.push(expectedStringList[x]); missing.push(expectedStringList[x]);
else { } else {
if (expectedStringList[x].equals("mystruct_t")) { if (expectedStringList[x].equals("mystruct_t")) {
assertTrue("PR:23603 expected:" + expectedStringList[x] assertTrue("PR:23603 expected: " + expectedStringList[x]
+ " Got:" + myElement.getElementName(), + ". Got: " + element.getElementName(),
expectedStringList[x].equals(myElement expectedStringList[x].equals(element.getElementName()));
.getElementName()));
} else { } else {
assertTrue("Expected:" + expectedStringList[x] + " Got:" assertTrue("Expected:" + expectedStringList[x] + " Got: "
+ myElement.getElementName(), expectedStringList[x] + element.getElementName(), expectedStringList[x]
.equals(myElement.getElementName())); .equals(element.getElementName()));
} }
} }
} }
if (!missing.empty()) { if (!missing.empty()) {
String output = new String("PR: 23603 Could not get elements: "); String output = new String("PR: 23603 Could not get elements: ");