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

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-11-06 18:31:03 -08:00
parent a85d7aea25
commit c5bdc34618
19 changed files with 140 additions and 169 deletions

View file

@ -27,7 +27,6 @@ import org.eclipse.jface.text.TextSelection;
/**
* @author Guido Zgraggen IFS
*
*/
public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener{
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
@ -50,7 +49,6 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
@Override
protected abstract void runTest() throws Throwable;
@Override
protected void setUp() throws Exception {
super.setUp();
@ -62,7 +60,7 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
}
protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
StringBuffer code = getCodeFromIFile(file2);
StringBuilder code = getCodeFromFile(file2);
assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
}
@ -70,14 +68,15 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
for (String fileName : testResourceFiles.keySet()) {
TestSourceFile file = testResourceFiles.get(fileName);
IFile iFile = project.getFile(new Path(fileName));
StringBuffer code = getCodeFromIFile(iFile);
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
StringBuilder code = getCodeFromFile(iFile);
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()),
TestHelper.unifyNewLines(code.toString()));
}
}
protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
protected StringBuilder getCodeFromFile(IFile file) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
StringBuffer code = new StringBuffer();
StringBuilder code = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
code.append(line);
@ -96,7 +95,7 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
public void logging(IStatus status, String plugin) {
Throwable ex = status.getException();
StringBuffer stackTrace = new StringBuffer();
StringBuilder stackTrace = new StringBuilder();
if (ex != null) {
stackTrace.append('\n');
for (StackTraceElement ste : ex.getStackTrace()) {

View file

@ -33,10 +33,8 @@ import org.osgi.framework.Bundle;
/**
* @author Emanuel Graf
*
*/
public class RewriteTester extends TestSuite {
enum MatcherState{skip, inTest, inSource, inExpectedResult}
private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
@ -60,7 +58,6 @@ public class RewriteTester extends TestSuite{
}
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
String line;
Vector<TestSourceFile> files = new Vector<TestSourceFile>();
TestSourceFile actFile = null;
@ -71,7 +68,6 @@ public class RewriteTester extends TestSuite{
boolean bevorFirstTest = true;
while ((line = inputReader.readLine()) != null) {
if (lineMatchesBeginOfTest(line)) {
if (!bevorFirstTest) {
RewriteBaseTest test = createTestClass(className, testName, files);
@ -117,11 +113,8 @@ public class RewriteTester extends TestSuite{
return testCases;
}
private static RewriteBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
private static RewriteBaseTest createTestClass(String className, String testName,
Vector<TestSourceFile> files) throws Exception {
try {
Class<?> refClass = Class.forName(className);
Class<?> paratypes[] = new Class[2];
@ -142,7 +135,8 @@ public class RewriteTester extends TestSuite{
}
return test;
} catch (ClassNotFoundException e) {
throw new Exception("Unknown TestClass: " + e.getMessage() + ". Make sure the test's sourcefile specifies a valid test class.");
throw new Exception("Unknown TestClass: " + e.getMessage() +
". Make sure the test's sourcefile specifies a valid test class.");
} catch (SecurityException e) {
throw new Exception("Security Exception during Test creation", e);
} catch (NoSuchMethodException e) {
@ -162,7 +156,6 @@ public class RewriteTester extends TestSuite{
Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
if (matcherBeginOfTest.find())
return matcherBeginOfTest.group(1);
else
return null;
}
@ -170,7 +163,6 @@ public class RewriteTester extends TestSuite{
Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
if (matcherBeginOfTest.find())
return matcherBeginOfTest.group(1);
else
return null;
}
@ -194,7 +186,6 @@ public class RewriteTester extends TestSuite{
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
if (matcherBeginOfTest.find())
return matcherBeginOfTest.group(1);
else
return "Not Named";
}

View file

@ -18,10 +18,8 @@ import org.eclipse.jface.text.TextSelection;
/**
* @author Emanuel Graf
*
*/
public class TestSourceFile {
private static final String REPLACEMENT = ""; //$NON-NLS-1$
private String name;
private StringBuffer source = new StringBuffer();
@ -39,6 +37,7 @@ public class TestSourceFile {
super();
this.name = name;
}
public String getExpectedSource() {
String exp = expectedSource.toString();
if (exp.length() == 0) {
@ -47,9 +46,11 @@ public class TestSourceFile {
return exp;
}
}
public String getName() {
return name;
}
public String getSource() {
return source.toString();
}
@ -75,12 +76,10 @@ public class TestSourceFile {
}
public TextSelection getSelection() {
if(selectionStart < 0 || selectionEnd <0 ) {
if (selectionStart < 0 || selectionEnd <0 )
return null;
}else {
return new TextSelection(selectionStart, selectionEnd -selectionStart);
}
}
protected static Matcher createMatcherFromString(String pattern, String line) {
return Pattern.compile(pattern).matcher(line);

View file

@ -84,7 +84,7 @@ public class ASTWriterTest extends RewriteBaseTest {
ASTModificationMap map = new ASTModificationMap();
map.getModificationsForNode(unit.getDeclarations()[0]);
ASTWriter writer = new ASTWriter();
return writer.write(unit, null, commentMap);
return writer.write(unit, commentMap);
}
protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
@ -120,20 +120,14 @@ public class ASTWriterTest extends RewriteBaseTest {
}
private boolean getGNUExtension(TestSourceFile file) {
if(file instanceof ASTWriterTestSourceFile) {
if (file instanceof ASTWriterTestSourceFile)
return ((ASTWriterTestSourceFile) file).isUseGNUExtensions();
}
else {
return false;
}
}
private ParserLanguage getLanguage(TestSourceFile file) {
if(file instanceof ASTWriterTestSourceFile) {
if (file instanceof ASTWriterTestSourceFile)
return ((ASTWriterTestSourceFile) file).getParserLanguage();
}
else {
return ParserLanguage.CPP;
}
}
}

View file

@ -16,7 +16,6 @@ import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
/**
* @author Guido Zgraggen IFS
*
*/
public class ASTWriterTestSourceFile extends TestSourceFile {
private ParserLanguage parserLanguage = ParserLanguage.CPP;

View file

@ -5,7 +5,8 @@
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Pascal Kesseli (HSR) - Initial API and implementation
* Contributors:
* Pascal Kesseli (HSR) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
@ -182,8 +183,7 @@ public class ExpressionWriterTest extends TestCase {
ICPPASTLambdaExpression lambda = new CPPASTLambdaExpression();
CPPASTCompoundStatement stmt = new CPPASTCompoundStatement();
stmt.addStatement(new CPPASTReturnStatement(new CPPASTLiteralExpression(
IASTLiteralExpression.lk_integer_constant,
new char[] { '7' })));
IASTLiteralExpression.lk_integer_constant, new char[] { '7' })));
lambda.setBody(stmt);
return lambda;
}

View file

@ -31,7 +31,6 @@ import org.eclipse.jface.text.TextSelection;
import org.osgi.framework.Bundle;
public class SourceRewriteTester extends TestSuite {
private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
private static final String codeTypeRegexp = "//%(C|CPP)( GNU)?$"; //$NON-NLS-1$
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
@ -77,11 +76,12 @@ public class SourceRewriteTester extends TestSuite {
protected static String getNameOfTest(String line) {
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
if(matcherBeginOfTest.find())
if (matcherBeginOfTest.find()) {
return matcherBeginOfTest.group(1);
else
} else {
return "Not Named";
}
}
protected static boolean lineMatchesBeginOfResult(String line) {
return createMatcherFromString(resultRegexp, line).find();

View file

@ -38,6 +38,10 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
super();
}
public ChangeGeneratorTest(String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
@ -65,8 +69,7 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
changegenartor.generateChange(unit);
Document doc = new Document(source);
for (Change curChange : ((CompositeChange) changegenartor.getChange())
.getChildren()) {
for (Change curChange : ((CompositeChange) changegenartor.getChange()).getChildren()) {
if (curChange instanceof TextFileChange) {
TextFileChange textChange = (TextFileChange) curChange;
textChange.getEdit().apply(doc);
@ -77,10 +80,6 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
protected abstract ASTVisitor createModificator(ASTModificationStore modStore);
public ChangeGeneratorTest(String name) {
super(name);
}
@Override
protected void tearDown() throws Exception {
System.gc();

View file

@ -21,7 +21,6 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.Replace
/**
* @author Thomas Corbat
*
*/
public class ChangeGeneratorTestSuite{

View file

@ -33,9 +33,12 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
import org.eclipse.core.runtime.CoreException;
/**
* This test tests the behavoir of the class ASTCommenter. It checks if the ASTCommenter assigns the comments contained in an AST to the right ASTNodes.<br>
* The source for the CommentHandling tests is located at /resources/rewrite/CommentHandlingTestSource.rts.<br>
* This file contains the source code and the expected output for all the tests. Following a little example how such a test looks like:<br><br>
* This test tests the behavior of the class ASTCommenter. It checks if the ASTCommenter assigns
* the comments contained in an AST to the right ASTNodes.<br>
* The source for the CommentHandling tests is located at
* /resources/rewrite/CommentHandlingTestSource.rts.<br>
* This file contains the source code and the expected output for all the tests.
* Following a little example how such a test looks like:<br><br>
*
* <code><pre>
* //!NameOfTheTest - will be used as JUnit test name
@ -62,12 +65,13 @@ import org.eclipse.core.runtime.CoreException;
*
* The second line (//#org.eclipse.cdt...) indicates the test class (in this case this class).<br>
* The "//=" indicates the beginning of the expected test result.<br>
* The test result contains three sections (separated by "=>leading", "=>trailing" and "=>freestanding").<br>
* Each section contains the raw signature of the node to which a comment is assigned plus " = " and the comment. If there are several comments
* assigned to the same node they are concatenated with a " , ".
* The test result contains three sections (separated by "=>leading", "=>trailing" and
* "=>freestanding").<br>
* Each section contains the raw signature of the node to which a comment is assigned plus " = "
* and the comment. If there are several comments assigned to the same node they are concatenated
* with a " , ".
*
* @author Guido Zgraggen IFS, Lukas Felber IFS
*
*/
public class CommentHandlingTest extends RewriteBaseTest {
@ -88,7 +92,6 @@ public class CommentHandlingTest extends RewriteBaseTest {
@Override
protected void runTest() throws Throwable {
if (fileMap.size() == 0) {
fail("No file for testing"); //$NON-NLS-1$
}
@ -105,8 +108,8 @@ public class CommentHandlingTest extends RewriteBaseTest {
}
private StringBuilder buildExpectedResult(TestSourceFile file) {
Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(), Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(),
Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
if (!matcher.find()) {
fail("Missing expected section. Expected result code must be of the following format:\n\"=>leading\n...\n=>trailing\n...\n=>freestanding\""); //$NON-NLS-1$
}
@ -143,7 +146,6 @@ public class CommentHandlingTest extends RewriteBaseTest {
StringBuilder output = new StringBuilder();
for (IASTNode actNode : keyTree) {
ArrayList<IASTComment> comments = map.get(actNode);
output.append(getSignature(actNode) + " = "); //$NON-NLS-1$
boolean first = true;
for (IASTComment actComment : comments) {
@ -170,11 +172,13 @@ public class CommentHandlingTest extends RewriteBaseTest {
}
private static String getSeparatingRegexp() {
return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR +
ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
}
private IASTTranslationUnit getUnit(String fileName) throws CoreException {
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(project.getFile(fileName));
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(
project.getFile(fileName));
return tu.getAST();
}

View file

@ -18,18 +18,14 @@ import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTester;
/**
* @author Guido Zgraggen IFS
*
*/
public class CommentHandlingTestSuite extends TestSuite {
public static Test suite() throws Exception {
TestSuite suite = new TestSuite(CommentHandlingTestSuite.class.getName());
suite.addTest(RewriteTester.suite("CommentTests", "resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
suite.addTest(RewriteTester.suite("CommentTests",
"resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
suite.addTestSuite(NodeCommentMapTest.class);
return suite;
}
}

View file

@ -21,10 +21,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/**
* @author Guido Zgraggen IFS
*
*/
public class NodeCommentMapTest extends TestCase {
private NodeCommentMap map;
@Override
@ -39,7 +37,6 @@ public class NodeCommentMapTest extends TestCase {
public void testNoComment(){
ASTNode node = new CPPASTName();
assertEquals(0, map.getLeadingCommentsForNode(node).size());
assertEquals(0, map.getTrailingCommentsForNode(node).size());
assertEquals(0, map.getFreestandingCommentsForNode(node).size());
@ -51,7 +48,6 @@ public class NodeCommentMapTest extends TestCase {
IASTComment comm2 = new Comment();
IASTComment comm3 = new Comment();
map.addLeadingCommentToNode(node, comm1);
map.addTrailingCommentToNode(node, comm2);
map.addFreestandingCommentToNode(node, comm3);
@ -89,7 +85,6 @@ public class NodeCommentMapTest extends TestCase {
assertEquals(com2, map.getFreestandingCommentsForNode(node).get(1));
}
public void testCommentOnDifferentNodes(){
ASTNode node1 = new CPPASTName();
ASTNode node2 = new CPPASTName();
@ -129,7 +124,6 @@ public class NodeCommentMapTest extends TestCase {
assertEquals(com3, map.getFreestandingCommentsForNode(node1).get(1));
}
//=== InternalComment class for testing
private class Comment extends ASTNode implements IASTComment {
private char[] comment;
@ -137,11 +131,15 @@ public class NodeCommentMapTest extends TestCase {
public char[] getComment() {
return comment;
}
public void setComment(char[] comment) {
this.comment = comment;
}
// not used
public boolean isBlockComment() {return false;}
public boolean isBlockComment() {
return false;
}
public IASTNode copy() {
return null;

View file

@ -21,8 +21,7 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoringC
public class MockToggleRefactoringTest extends ToggleRefactoring {
public MockToggleRefactoringTest(IFile file, TextSelection selection,
ICProject proj) {
public MockToggleRefactoringTest(IFile file, TextSelection selection, ICProject proj) {
super(file, selection, proj);
}

View file

@ -19,10 +19,8 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleNodeHelper;
/**
* @author egraf
*
*/
public class ToggleNodeHelperTest extends TestCase {
/**
* Test method for {@link org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleNodeHelper#getFilenameWithoutExtension(java.lang.String)}.
*/
@ -38,5 +36,4 @@ public class ToggleNodeHelperTest extends TestCase {
public void testGetFilenameWithoutExtension2() {
assertEquals("My.Class", ToggleNodeHelper.getFilenameWithoutExtension("My.Class.h"));
}
}

View file

@ -26,7 +26,6 @@ import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
public class ToggleRefactoringTest extends RefactoringTest {
private boolean fatalError;
private boolean newFileCreation;
private String[] newfiles;
@ -117,5 +116,4 @@ public class ToggleRefactoringTest extends RefactoringTest {
changes.perform(NULL_PROGRESS_MONITOR);
compareFiles(fileMap);
}
}

View file

@ -32,7 +32,7 @@ public class ToggleRefactoringTestSuite extends TestSuite {
"resources/refactoring/ToggleSimpleFunctionRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleTemplateRefactoringTest",
"resources/refactoring/ToggleTemplateRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleNamespaceRefacotringTest",
suite.addTest(RefactoringTester.suite("ToggleNamespaceRefactoringTest",
"resources/refactoring/ToggleNamespaceRefactoring.rts"));
suite.addTest(RefactoringTester.suite("ToggleTryCatchRefactoringTest",
"resources/refactoring/ToggleTryCatchRefactoring.rts"));
@ -49,7 +49,7 @@ public class ToggleRefactoringTestSuite extends TestSuite {
"resources/refactoring/ToggleFreeFunction.rts"));
suite.addTest(RefactoringTester.suite("ToggleVirtualFunctionTest",
"resources/refactoring/ToggleVirtualFunction.rts"));
suite.addTest(RefactoringTester.suite("ToggleOrderintTest",
suite.addTest(RefactoringTester.suite("ToggleOrderingTest",
"resources/refactoring/ToggleOrdering.rts"));
suite.addTest(RefactoringTester.suite("ToggleCommentsClassToHeader",
"resources/refactoring/ToggleCommentsClassToHeader.rts"));
@ -62,5 +62,4 @@ public class ToggleRefactoringTestSuite extends TestSuite {
suite.addTestSuite(ToggleNodeHelperTest.class);
return suite;
}
}