diff options
author | Andrew Ferguson | 2008-02-09 12:23:25 +0000 |
---|---|---|
committer | Andrew Ferguson | 2008-02-09 12:23:25 +0000 |
commit | c113b004769eb979b72cd7c859462ecc0050224e (patch) | |
tree | c2e0b3f66396d6c17403e62943a4714d9ef410bb /core/org.eclipse.cdt.ui.tests | |
parent | 14b1bbaf1eedda0978cd79b5a4bc838d10528dc7 (diff) | |
download | org.eclipse.cdt-c113b004769eb979b72cd7c859462ecc0050224e.tar.gz org.eclipse.cdt-c113b004769eb979b72cd7c859462ecc0050224e.tar.xz org.eclipse.cdt-c113b004769eb979b72cd7c859462ecc0050224e.zip |
178386: check-in documentation tool framework plus doxygen implementation
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests')
15 files changed, 1955 insertions, 206 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs index f683c141712..19476feb871 100644 --- a/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs +++ b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,8 @@ -#Wed Nov 28 11:16:20 CET 2007 +#Tue Jan 29 13:30:09 GMT 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.doc.comment.support=disabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning org.eclipse.jdt.core.compiler.problem.autoboxing=ignore @@ -11,6 +12,8 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod= org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning @@ -19,16 +22,34 @@ org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled @@ -41,13 +62,17 @@ org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning org.eclipse.jdt.core.compiler.problem.unusedLocal=ignore org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.4 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml index 4a378d1304d..72140c1c76f 100644 --- a/core/org.eclipse.cdt.ui.tests/plugin.xml +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -32,10 +32,10 @@ <perspectiveExtension targetID="org.eclipse.ui.resourcePerspective"> <view + id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST" ratio="0.5" - relative="org.eclipse.ui.views.TaskList" relationship="right" - id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST"> + relative="org.eclipse.ui.views.TaskList"> </view> </perspectiveExtension> </extension> @@ -115,5 +115,87 @@ projectType="org.eclipse.cdt.build.core.buildArtefactType.exe"> </template> </extension> - + + + <!-- documentation tool comment test owners --> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner id="org.cdt.test.DCOM1" + name="Test comment owner1" + singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration" + multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration" + /> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner id="org.cdt.test.DCOM2" + name="Test comment owner1" + singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration" + multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration" + /> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.DCOM3" + multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration" + name="Test comment owner1" + singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerA" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A" + name="name_A" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerB" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B" + name="name_B" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerC" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C" + name="name_C" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerABC" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC" + name="name_ABC" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerBDFG" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG" + name="name_BDFG" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG"> + </owner> + </extension> + <extension + point="org.eclipse.cdt.ui.DocCommentOwner"> + <owner + id="org.cdt.test.ownerPUNC" + multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC" + name="name_PUNC" + singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC"> + </owner> + </extension> + </plugin> diff --git a/core/org.eclipse.cdt.ui.tests/resources/docComments/this.cpp b/core/org.eclipse.cdt.ui.tests/resources/docComments/this.cpp new file mode 100644 index 00000000000..b24e4f4814e --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/docComments/this.cpp @@ -0,0 +1,24 @@ +// N.B: Character positions in this file are hard-coded into expected results in +// DocCommentHightlightTest. + +/* normal0 */ +/*A comment1___ */ +/*B comment2__ */ +/*C comment3_ *//*D comment4___ */ +/*E comment5____ *//*F comment6_ */ +/*G comment7 +*//*F comment8_ *//*! __comment9 */ +/** +comment10 +*/ + +// snormal0 +//A scomment1__ +//B scomment2_ +//C scomment3__ +//! _scomment4 +//* scomment5___ + +/*# comment11_ #*/ // scomment6__ +/*# comment12__ #*/ //# __scomment7 + diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java new file mode 100644 index 00000000000..10cb5cb0430 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Sergey Prigogin, Google + * Andrew Ferguson (Symbian) + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.TextUtilities; + +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.ui.testplugin.CTestPlugin; + +/** + * IAutoEditStrategy related tests + */ +public class AbstractAutoEditTest extends BaseTestCase { + + protected AbstractAutoEditTest(String name) { + super(name); + } + + /** + * Helper class to test the auto-edit strategies on a document. + * Split out from CAutoIndentTest. + */ + protected static class AutoEditTester { + + private Map fStrategyMap = new HashMap(); + IDocument fDoc; + private String fPartitioning; + private int fCaretOffset; + + public AutoEditTester(IDocument doc, String partitioning) { + super(); + fDoc = doc; + fPartitioning = partitioning; + } + + public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) { + fStrategyMap.put(contentType, aes); + } + + public IAutoEditStrategy getAutoEditStrategy(String contentType) { + return (IAutoEditStrategy)fStrategyMap.get(contentType); + } + + /** + * Empties the document, and returns the caret to the origin (0,0) + * @return <code>this</code> for method chaining + */ + public AutoEditTester reset() { + try { + goTo(0,0); + fDoc.set(""); + } catch(BadLocationException ble) { + fail(ble.getMessage()); + } + return this; + } + + public void type(String text) throws BadLocationException { + for (int i = 0; i < text.length(); ++i) { + type(text.charAt(i)); + } + } + + public void type(char c) throws BadLocationException { + TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c })); + customizeDocumentCommand(command); + fCaretOffset = command.exec(fDoc); + } + + private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException { + IAutoEditStrategy aes = getAutoEditStrategy(getContentType(command.offset)); + if (aes != null) { + aes.customizeDocumentCommand(fDoc, command); + } + } + + public void type(int offset, String text) throws BadLocationException { + fCaretOffset = offset; + type(text); + } + + public void type(int offset, char c) throws BadLocationException { + fCaretOffset = offset; + type(c); + } + + public void paste(String text) throws BadLocationException { + TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text); + customizeDocumentCommand(command); + fCaretOffset = command.exec(fDoc); + } + + public void paste(int offset, String text) throws BadLocationException { + fCaretOffset = offset; + paste(text); + } + + public void backspace(int n) throws BadLocationException { + for (int i = 0; i < n; ++i) { + backspace(); + } + } + + public void backspace() throws BadLocationException { + TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$ + customizeDocumentCommand(command); + fCaretOffset = command.exec(fDoc); + } + + public int getCaretOffset() { + return fCaretOffset; + } + + public int setCaretOffset(int offset) { + fCaretOffset = offset; + if (fCaretOffset < 0) + fCaretOffset = 0; + else if (fCaretOffset > fDoc.getLength()) + fCaretOffset = fDoc.getLength(); + return fCaretOffset; + } + + /** + * Moves caret right or left by the given number of characters. + * + * @param shift Move distance. + * @return New caret offset. + */ + public int moveCaret(int shift) { + return setCaretOffset(fCaretOffset + shift); + } + + public int goTo(int line) throws BadLocationException { + fCaretOffset = fDoc.getLineOffset(line); + return fCaretOffset; + } + + public int goTo(int line, int column) throws BadLocationException { + if (column < 0 || column > fDoc.getLineLength(line)) { + throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$ + } + fCaretOffset = fDoc.getLineOffset(line) + column; + return fCaretOffset; + } + + public int getCaretLine() throws BadLocationException { + return fDoc.getLineOfOffset(fCaretOffset); + } + + public int getCaretColumn() throws BadLocationException { + IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset); + return fCaretOffset - region.getOffset(); + } + + public char getChar() throws BadLocationException { + return getChar(0); + } + + public char getChar(int i) throws BadLocationException { + return fDoc.getChar(fCaretOffset+i); + } + + public String getLine() throws BadLocationException { + return getLine(0); + } + + public String getLine(int i) throws BadLocationException { + IRegion region = fDoc.getLineInformation(getCaretLine() + i); + return fDoc.get(region.getOffset(), region.getLength()); + } + + public String getContentType(int offset) throws BadLocationException { + return TextUtilities.getContentType(fDoc, fPartitioning, offset, true); + } + } + + /** + * A DocumentCommand with public constructor and exec method. + */ + protected static class TestDocumentCommand extends DocumentCommand { + + public TestDocumentCommand(int offset, int length, String text) { + super(); + doit = true; + this.text = text; + + this.offset = offset; + this.length = length; + + owner = null; + caretOffset = -1; + } + + /** + * @param doc + * @return the new caret position. + * @throws BadLocationException + */ + public int exec(IDocument doc) throws BadLocationException { + doc.replace(offset, length, text); + return caretOffset != -1 ? + caretOffset : + offset + (text == null ? 0 : text.length()); + } + } + + protected StringBuffer[] getTestContents() { + try { + return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 2); + } catch(IOException ioe) { + fail(ioe.getMessage()); + } + return null; + } + + protected StringBuffer[] getTestContents1() { + try { + return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 1); + } catch(IOException ioe) { + fail(ioe.getMessage()); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java index 8ab9167eeb9..cf9a40b6af6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java @@ -8,6 +8,7 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation * Sergey Prigogin, Google + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text; @@ -16,7 +17,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; @@ -26,214 +26,22 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.TextUtilities; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy; import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions; import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy; -import org.eclipse.cdt.internal.ui.text.CCommentAutoIndentStrategy; import org.eclipse.cdt.internal.ui.text.CTextTools; /** * Testing the auto indent strategies. */ -public class CAutoIndentTest extends BaseTestCase { - - /** - * Helper class to test the auto-edit strategies on a document. - */ - static class AutoEditTester { - - private Map fStrategyMap = new HashMap(); - private IDocument fDoc; - private String fPartitioning; - private int fCaretOffset; - - public AutoEditTester(IDocument doc, String partitioning) { - super(); - fDoc = doc; - fPartitioning = partitioning; - } - - public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) { - fStrategyMap.put(contentType, aes); - } - - public IAutoEditStrategy getAutoEditStrategy(String contentType) { - return (IAutoEditStrategy)fStrategyMap.get(contentType); - } - - /** - * Empties the document, and returns the caret to the origin (0,0) - */ - public void reset() { - try { - goTo(0,0); - fDoc.set(""); - } catch(BadLocationException ble) { - fail(ble.getMessage()); - } - } - - public void type(String text) throws BadLocationException { - for (int i = 0; i < text.length(); ++i) { - type(text.charAt(i)); - } - } - - public void type(char c) throws BadLocationException { - TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c })); - customizeDocumentCommand(command); - fCaretOffset = command.exec(fDoc); - } - - private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException { - IAutoEditStrategy aes = getAutoEditStrategy(getContentType()); - if (aes != null) { - aes.customizeDocumentCommand(fDoc, command); - } - } - - public void type(int offset, String text) throws BadLocationException { - fCaretOffset = offset; - type(text); - } - - public void type(int offset, char c) throws BadLocationException { - fCaretOffset = offset; - type(c); - } - - public void paste(String text) throws BadLocationException { - TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text); - customizeDocumentCommand(command); - fCaretOffset = command.exec(fDoc); - } - - public void paste(int offset, String text) throws BadLocationException { - fCaretOffset = offset; - paste(text); - } - - public void backspace(int n) throws BadLocationException { - for (int i = 0; i < n; ++i) { - backspace(); - } - } - - public void backspace() throws BadLocationException { - TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$ - customizeDocumentCommand(command); - fCaretOffset = command.exec(fDoc); - } - - public int getCaretOffset() { - return fCaretOffset; - } - - public int setCaretOffset(int offset) { - fCaretOffset = offset; - if (fCaretOffset < 0) - fCaretOffset = 0; - else if (fCaretOffset > fDoc.getLength()) - fCaretOffset = fDoc.getLength(); - return fCaretOffset; - } - - /** - * Moves caret right or left by the given number of characters. - * - * @param shift Move distance. - * @return New caret offset. - */ - public int moveCaret(int shift) { - return setCaretOffset(fCaretOffset + shift); - } - - public int goTo(int line) throws BadLocationException { - fCaretOffset = fDoc.getLineOffset(line); - return fCaretOffset; - } - - public int goTo(int line, int column) throws BadLocationException { - if (column < 0 || column > fDoc.getLineLength(line)) { - throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$ - } - fCaretOffset = fDoc.getLineOffset(line) + column; - return fCaretOffset; - } - - public int getCaretLine() throws BadLocationException { - return fDoc.getLineOfOffset(fCaretOffset); - } - - public int getCaretColumn() throws BadLocationException { - IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset); - return fCaretOffset - region.getOffset(); - } - - public char getChar() throws BadLocationException { - return getChar(0); - } - - public char getChar(int i) throws BadLocationException { - return fDoc.getChar(fCaretOffset+i); - } - - public String getLine() throws BadLocationException { - return getLine(0); - } - - public String getLine(int i) throws BadLocationException { - IRegion region = fDoc.getLineInformation(getCaretLine() + i); - return fDoc.get(region.getOffset(), region.getLength()); - } - - public String getContentType() throws BadLocationException { - return getContentType(0); - } - - public String getContentType(int i) throws BadLocationException { - return TextUtilities.getContentType(fDoc, fPartitioning, fCaretOffset + i, false); - } - } - - /** - * A DocumentCommand with public constructor and exec method. - */ - static class TestDocumentCommand extends DocumentCommand { - - public TestDocumentCommand(int offset, int length, String text) { - super(); - doit = true; - this.text = text; - - this.offset = offset; - this.length = length; - - owner = null; - caretOffset = -1; - } - - /** - * Returns new caret position. - */ - public int exec(IDocument doc) throws BadLocationException { - doc.replace(offset, length, text); - return caretOffset != -1 ? - caretOffset : - offset + (text == null ? 0 : text.length()); - } - } +public class CAutoIndentTest extends AbstractAutoEditTest { private HashMap fOptions; private List fStatusLog; @@ -289,8 +97,9 @@ public class CAutoIndentTest extends BaseTestCase { IDocument doc = new Document(); textTools.setupCDocument(doc); AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING); + tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); - tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new CCommentAutoIndentStrategy()); + tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy()); tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); return tester; } @@ -385,7 +194,7 @@ public class CAutoIndentTest extends BaseTestCase { public void testCCommentAutoIndent() throws BadLocationException { AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$ tester.type("/*\n"); //$NON-NLS-1$ - assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(-1)); + assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(tester.getCaretOffset()-1)); assertEquals(1, tester.getCaretLine()); assertEquals(3, tester.getCaretColumn()); assertEquals(" * ", tester.getLine()); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java index 8a63d15d8a1..7ad9a314cdc 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text; @@ -49,7 +50,7 @@ public class CPartitionerTest extends TestCase { fTextTools= new CTextTools(new PreferenceStore()); fDocument= new Document(); - IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner(); + IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner(null); partitioner.connect(fDocument); fDocument.setDocumentPartitioner(partitioner); fDocument.set("xxx\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nxxx\n/***/\nxxx"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 1d5eecde1a2..c5f7a2d684a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text; @@ -209,7 +210,7 @@ public class CodeFormatterTest extends BaseUITestCase { //int verylooooooooooooooooooooooooooooooooooongname = 0000000000000000000000000000000; - //int verylooooooooooooooooooooooooooooooooooongname = + //int verylooooooooooooooooooooooooooooooooooongname = // 0000000000000000000000000000000; public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception { assertFormatterResult(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/DefaultCCommentAutoEditStrategyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/DefaultCCommentAutoEditStrategyTest.java new file mode 100644 index 00000000000..88bff2d97bc --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/DefaultCCommentAutoEditStrategyTest.java @@ -0,0 +1,609 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Sergey Prigogin, Google + * Andrew Ferguson (Symbian) + *******************************************************************************/ + +package org.eclipse.cdt.ui.tests.text; + +import java.util.HashMap; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy; + +import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy; +import org.eclipse.cdt.internal.ui.text.CTextTools; + + +/** + * Testing the auto indent strategies. + */ +public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest { + private HashMap fOptions; + + /** + * @param name + */ + public DefaultCCommentAutoEditStrategyTest(String name) { + super(name); + } + + public static Test suite() { + return suite(DefaultCCommentAutoEditStrategyTest.class); + } + + /* + * @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + fOptions= CCorePlugin.getOptions(); + } + + /* + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + CCorePlugin.setOptions(fOptions); + super.tearDown(); + } + + private AutoEditTester createAutoEditTester() { + CTextTools textTools = CUIPlugin.getDefault().getTextTools(); + IDocument doc = new Document(); + textTools.setupCDocument(doc); + AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING); + + + tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); + tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy()); + tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); + return tester; + } + + public void testIsMultilineNew() throws BadLocationException { + DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy(); + CTextTools textTools = CUIPlugin.getDefault().getTextTools(); + IDocument doc = new Document(); + textTools.setupCDocument(doc); + + doc.set(" /* "); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + assertTrue(ds.shouldCloseMultiline(doc, 5)); + doc.set(" /* \n "); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + assertTrue(ds.shouldCloseMultiline(doc, 6)); + doc.set(" /* */"); + assertFalse(ds.shouldCloseMultiline(doc, 5)); + doc.set(" /* */ "); + assertFalse(ds.shouldCloseMultiline(doc, 5)); + doc.set(" /* \n\n */ "); + assertFalse(ds.shouldCloseMultiline(doc, 5)); + doc.set(" /* \n\n */ \n /*"); + assertTrue(ds.shouldCloseMultiline(doc, 14)); + doc.set(" /* \n\n */ \n /* "); + assertTrue(ds.shouldCloseMultiline(doc, 14)); + doc.set(" /* \n\n */ \n /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 14)); + doc.set(" /* /* \n\n */ \n /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /* \n/* \n\n */ \n /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /* \n\n/* \n\n */ \n /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /* \n\n/* \n\n */ \n /* \n"); + assertTrue(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /* \n\n */ /* \n\n */ \n /* \n"); + assertFalse(ds.shouldCloseMultiline(doc, 3)); + doc.set(" /*\n /*\n * \n * \n */\n"); + assertFalse(ds.shouldCloseMultiline(doc, 8)); + } + + // /*X + + // /* + // * X + // */ + public void testInsertNewLine1() { + assertNewLineBehaviour(); + } + + // /*X + + // /* + // * X + // */ + public void testInsertNewLine2() { + assertNewLineBehaviour(); + } + + // class A {}; /*X + + // class A {}; /* + // X + public void testInsertNewLine3() { + assertNewLineBehaviour(); + } + + // class A { + // /*X + // }; + + // class A { + // /* + // * X + // */ + // }; + public void testInsertNewLine4() { + assertNewLineBehaviour(); + } + + // class A { + // /* X + // }; + + // class A { + // /* + // * X + // */ + // }; + public void testInsertNewLine5() { + assertNewLineBehaviour(); + } + + + + // class A { + // /*X + // * + // */ + // }; + + // class A { + // /* + // * X + // * + // */ + // }; + public void testInsertNewLine6() { + assertNewLineBehaviour(); + } + + // class A { + // /* + // *X + // */ + // }; + + // class A { + // /* + // * + // *X + // */ + // }; + public void testInsertNewLine7() { + assertNewLineBehaviour(); + } + + // class A { + // /* + // *X + // */ + // }; + + // class A { + // /* + // * + // *X + // */ + // }; + public void testInsertNewLine8() { + assertNewLineBehaviour(); + } + + // class A { + // /* + // * abcd def ghiX + // */ + // }; + + // class A { + // /* + // * abcd def ghi + // * X + // */ + // }; + public void testInsertNewLine9() { + assertNewLineBehaviour(); + } + + // class A { + // /* + // * abcd deXf ghi + // */ + // }; + + // class A { + // /* + // * abcd de + // * Xf ghi + // */ + // }; + public void testInsertNewLine10() { + assertNewLineBehaviour(); + } + + // class A { + // /* + // * + // */X + // }; + + // class A { + // /* + // * + // */ + // X + // }; + public void _testInsertNewLine11() { // this is correct - we're not in a dccaes partition + assertNewLineBehaviour(); + } + + // /*X*/ + + // /* + // * X + // */ + public void _testInsertNewLine12() { + assertNewLineBehaviour(); + } + + // class A { + // /*Xfoo + // }; + + // class A { + // /* + // * X + // */foo + // }; + public void testInsertNewLine13() { + assertNewLineBehaviour(); + } + + // class A { + // /*fooX + // }; + + // class A { + // /*foo + // * X + // */ + // }; + public void testInsertNewLine14() { + assertNewLineBehaviour(); + } + + + // /* + // * + // *X + + // /* + // * + // * + // *X + public void testInsertNewLine15() { + assertNewLineBehaviour(); + } + + // /* + // * + // *Xxx + + // /* + // * + // * + // *Xxx + public void testInsertNewLine16() { + assertNewLineBehaviour(); + } + + // /* + // X + + // /* + // + // X + public void testInsertNewLine17() { + assertNewLineBehaviour(); + } + + // /* + // X + // */ + + // /* + // + // X + // */ + public void testInsertNewLine18() { + assertNewLineBehaviour(); + } + + // /* + // * + // */ /*X + + // /* + // * + // */ /* + // * X + // */ + public void _testInsertNewLine19() { + assertNewLineBehaviour(); + } + + // /* + // /*X + // * + // */ + + // /* + // /* + // * X + // * + // */ + public void testInsertNewLine20() { + assertNewLineBehaviour(); + } + + + // + // X + // + // void foo() {} + public void testFollowingDeclaration1() { + assertDeclarationFollowingX("void foo() {}"); + } + + // X + // + // void foo() {} + // void bar() {} + public void testFollowingDeclaration1b() { + assertDeclarationFollowingX("void foo() {}"); + } + + + // + // X + // class C { + // void foo() {} + // }; + public void testFollowingDeclaration2() { + assertDeclarationFollowingX("class C {\n void foo() {}\n };"); + } + + // class C { + // X + // void foo() {} + // }; + public void testFollowingDeclaration3() { + assertDeclarationFollowingX("void foo() {}"); + } + + // class C { + // void foo() {X} + // void bar(int x); + // }; + public void testFollowingDeclaration4() { + assertDeclarationFollowingX(null); + } + + // class C { + // void foo() {} X + // void bar(int x); + // }; + public void testFollowingDeclaration4a() { + assertDeclarationFollowingX("void bar(int x);"); + } + + // class C { + // void foo()X{} + // void bar(int x); + // }; + public void _testFollowingDeclaration4b() { // XXX - this is likely invalid anyhow + assertDeclarationFollowingX("void foo(){}"); // (X is just the cursor position) + } + + // class C { + // void foo() + // X + // { + // int x; + // } + // void bar(int x); + // }; + public void _testFollowingDeclaration4c() { // XXX - this is likely invalid anyhow + assertDeclarationFollowingX("void foo()\n {\n int x;\n }\n"); // (X is just the cursor position) + } + + // namespace n1 { X + // namespace n2 { + // void foo() {} + // void bar(int x) {} + // class C { + // int y; + // void baz(int x) {} + // }; + // } + // } + public void _testFollowingDeclaration5() { + assertDeclarationFollowingX("namespace n2 {\n void foo() {}\n void bar(int x) {}\n class C {\n int y;\n void baz(int x) {}\n };\n }"); + } + + // namespace n1 { + // namespace n2 {X + // void foo() {} + // void bar(int x) {} + // class C { + // int y; + // void baz(int x) {} + // }; + // } + // } + public void testFollowingDeclaration6() { + assertDeclarationFollowingX("void foo() {}"); + } + + // namespace n1 { + // namespace n2 { + // void foo() {}X + // void bar(int x) {} + // class C { + // int y; + // void baz(int x) {} + // }; + // } + // } + public void testFollowingDeclaration7() { + assertDeclarationFollowingX("void bar(int x) {}"); + } + + // namespace n1 { + // namespace n2 { + // void foo() {} + // void bar(int x) {} + // class C {X + // int y; + // void baz(int x) {} + // }; + // } + // } + public void testFollowingDeclaration8() { + assertDeclarationFollowingX("int y;"); + } + + // namespace n1 { + // namespace n2 { + // void foo() {} + // void bar(int x) {} + // class C { + // int y;X + // void baz(int x) {} + // }; + // } + // } + public void testFollowingDeclaration9() { + assertDeclarationFollowingX("void baz(int x) {}"); + } + + // #define MM void foo() + // X + // MM {} + public void testFollowingDeclaration10() { + assertDeclarationFollowingX("MM {}"); + } + + // #define NAME foo + // #define MM(V) void V(int y) + // X + // MM(NAME) {} + public void testFollowingDeclaration11() { + assertDeclarationFollowingX("MM(NAME) {}"); + } + + // #define MAKEFUNC(V) void V() + // #define B(V) V + // #define C(V) foo ## x + // X + // MAKEFUNC(B(C(y))) {} + public void testFollowingDeclaration12() { + assertDeclarationFollowingX("MAKEFUNC(B(C(y))) {}"); + } + + /** + * @param rs - the raw signature of the declaration that should be returned + * or <code>null</code> if no declaration should be returned. + */ + protected void assertDeclarationFollowingX(String rs) { + try { + ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), "bin"); + try { + String init= getTestContents1()[0].toString(); + int caretInit= init.indexOf('X'); + init= init.replaceFirst("X", ""); + IFile file= TestSourceReader.createFile(cproject.getProject(), "this.cpp", init); + IASTTranslationUnit ast= TestSourceReader.createIndexBasedAST(null, cproject, file); + assertNotNull(ast); + IASTDeclaration decl= DefaultMultilineCommentAutoEditStrategy.findFollowingDeclaration(ast, caretInit); + if(rs!=null) { + assertNotNull(decl); + assertEquals(rs, decl.getRawSignature()); + } else { + assertNull(decl); + } + } finally { + if(cproject!=null) { + cproject.getProject().delete(true, NPM); + } + } + } catch(CoreException ce) { + fail(ce.getMessage()); + } + } + + protected void assertNewLineBehaviour() { + DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy(); + CTextTools textTools = CUIPlugin.getDefault().getTextTools(); + IDocument doc = new Document(); + textTools.setupCDocument(doc); + + StringBuffer[] raw= getTestContents(); + String init= raw[0].toString(), expected= raw[1].toString(); + + int caretInit= init.indexOf('X'); + init= init.replaceFirst("X", ""); + + int caretExpected= expected.indexOf('X'); + expected= expected.replaceFirst("X", ""); + + doc.set(init); + int caretActual= -1; + try { + TestDocumentCommand dc= new TestDocumentCommand(caretInit, 0, "\n"); + ds.customizeDocumentCommand(doc, dc); + caretActual= dc.exec(doc); + } catch(BadLocationException ble) { + fail(ble.getMessage()); + } + String actual= doc.get(); + assertEquals(expected, actual); + assertEquals(caretExpected, caretActual); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java index c4242948865..69fdae9f21d 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 QNX Software Systems and others. + * Copyright (c) 2005, 2008 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text; @@ -41,7 +42,7 @@ public class PartitionTokenScannerTest extends TestCase { protected void setUp() { fReference= new CPartitionScanner(); - fTestee= new FastCPartitionScanner(true); + fTestee= new FastCPartitionScanner(true, null); } // read sample C file diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java index e19bb822035..42bcdbf6af5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java @@ -7,12 +7,15 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text; import junit.framework.TestSuite; +import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite; + public class TextTestSuite extends TestSuite { public static TestSuite suite() { @@ -22,6 +25,9 @@ public class TextTestSuite extends TestSuite { public TextTestSuite() { super(TextTestSuite.class.getName()); + // documentation tool extension tests + addTest(DocCommentTestSuite.suite()); + // partitioning tests addTest(PartitionTokenScannerTest.suite()); addTest(CPartitionerTest.suite()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java new file mode 100644 index 00000000000..d442d4af5e7 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.doctools; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; + +import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; +import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner; + +/** + * Test comment ownership mapping + */ +public class CommentOwnerManagerTests extends BaseTestCase { + IDocCommentOwner OWNER_1; + IDocCommentOwner OWNER_2; + IDocCommentOwner OWNER_3; + DocCommentOwnerManager manager; + + ICProject projectA, projectB, projectC; + + protected void setUp() throws Exception { + manager= DocCommentOwnerManager.getInstance(); + + projectA= CProjectHelper.createCCProject("projectA", null); + projectB= CProjectHelper.createCCProject("projectB", null); + projectC= CProjectHelper.createCCProject("projectC", null); + + IDocCommentOwner[] owners= manager.getRegisteredOwners(); + OWNER_1= manager.getOwner("org.cdt.test.DCOM1"); + OWNER_2= manager.getOwner("org.cdt.test.DCOM2"); + OWNER_3= manager.getOwner("org.cdt.test.DCOM3"); + } + + protected void tearDown() throws Exception { + if(projectA != null) { + CProjectHelper.delete(projectA); + } + if(projectB != null) { + CProjectHelper.delete(projectB); + } + if(projectC != null) { + CProjectHelper.delete(projectC); + } + } + + public static Test suite() { + return new TestSuite(CommentOwnerManagerTests.class); + } + + public void testProjectLevel() throws Exception { + manager.setCommentOwner(projectA.getProject(), OWNER_3, true); + manager.setCommentOwner(projectB.getProject(), OWNER_2, true); + manager.setCommentOwner(projectC.getProject(), OWNER_1, true); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setCommentOwner(projectA.getProject(), OWNER_2, true); + manager.setCommentOwner(projectB.getProject(), OWNER_1, true); + manager.setCommentOwner(projectC.getProject(), OWNER_3, true); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + projectA.getProject().close(NPM); + projectB.getProject().close(NPM); + projectC.getProject().close(NPM); + + projectA.getProject().open(NPM); + projectB.getProject().open(NPM); + projectC.getProject().open(NPM); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + } + + public void testBoundaryConditions1() throws Exception { + DocCommentOwnerManager manager= DocCommentOwnerManager.getInstance(); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(null).getID()); + } + + public void testBoundaryConditions2() throws Exception { + try { + manager.setWorkspaceCommentOwner(null); + fail(); + } catch(Exception e) { + // expected + } + } + + public void testWorkspaceRootLevel() throws Exception { + manager.setCommentOwner(projectA.getProject(), null, true); + manager.setCommentOwner(projectB.getProject(), null, true); + manager.setCommentOwner(projectC.getProject(), null, true); + + manager.setWorkspaceCommentOwner(OWNER_1); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setWorkspaceCommentOwner(OWNER_2); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setWorkspaceCommentOwner(OWNER_3); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setCommentOwner(projectA.getProject(), OWNER_3, true); + manager.setCommentOwner(projectB.getProject(), OWNER_2, true); + manager.setCommentOwner(projectC.getProject(), OWNER_1, true); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setWorkspaceCommentOwner(NullDocCommentOwner.INSTANCE); + + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setCommentOwner(projectA.getProject(), null, true); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setCommentOwner(projectC.getProject(), null, true); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setCommentOwner(projectB.getProject(), null, true); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + + manager.setWorkspaceCommentOwner(OWNER_1); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID()); + + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID()); + assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID()); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java new file mode 100644 index 00000000000..1397afb756a --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.doctools; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.AbstractTextEditor; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.ui.tests.BaseUITestCase; +import org.eclipse.cdt.ui.tests.text.Accessor; +import org.eclipse.cdt.ui.tests.text.EditorTestHelper; +import org.eclipse.cdt.ui.tests.text.ResourceTestHelper; + +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; + +/** + * + */ +public class DocCommentHighlightingTest extends BaseUITestCase { + private static final DocCommentOwnerManager DCMAN= DocCommentOwnerManager.getInstance(); + private static final String LINKED_FOLDER= "resources/docComments"; + private static final String PROJECT= "DocCommentTests"; + + // ordered by occurrence + private static final int[] normal0= {114, 13}; + private static final int[] comment1= {129, 18}; + private static final int[] comment2= {149, 17}; + private static final int[] comment3= {168, 16}; + private static final int[] comment4= {184, 18}; + private static final int[] comment5= {204, 19}; + private static final int[] comment6= {223, 16}; + private static final int[] comment7= {241, 17}; + private static final int[] comment8= {258, 16}; + private static final int[] comment9= {274, 17}; + private static final int[] comment10= {293, 18}; + private static final int[] snormal0= {315, 13}; + private static final int[] scomment1= {328, 17}; + private static final int[] scomment2= {345, 16}; + private static final int[] scomment3= {361, 17}; + private static final int[] scomment4= {378, 16}; + private static final int[] scomment5= {394, 18}; + private static final int[] comment11= {414, 18}; + private static final int[] scomment6= {433, 16}; + private static final int[] comment12= {449, 19}; + private static final int[] scomment7= {469, 17}; + + + private ICProject fCProject; + private final String fTestFilename= "/"+PROJECT+"/src/this.cpp"; + + private static SourceViewer fSourceViewer; + + public static Test suite() { + return new TestSuite(DocCommentHighlightingTest.class); + } + + public DocCommentHighlightingTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + fCProject= EditorTestHelper.createCProject(PROJECT, LINKED_FOLDER); + + AbstractTextEditor fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(fTestFilename), true); + fSourceViewer= EditorTestHelper.getSourceViewer(fEditor); + assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100)); + } + + protected void tearDown () throws Exception { + EditorTestHelper.closeAllEditors(); + + if (fCProject != null) + CProjectHelper.delete(fCProject); + + super.tearDown(); + } + + protected List/*<Position>*/ findRangesColored(RGB rgb) { + List result= new ArrayList(); + IEditorPart p= get(); + ISourceViewer vw= ((CEditor)p).getViewer(); + Accessor a= new Accessor(vw, TextViewer.class); + StyledText st= (StyledText) a.get("fTextWidget"); + StyleRange[] rgs= st.getStyleRanges(); + for(int i=0; i<rgs.length; i++) { + if(rgs[i].foreground != null && rgs[i].foreground.getRGB().equals(rgb)) { + result.add(new Position(rgs[i].start, rgs[i].length)); + } + } + return result; + } + + protected IEditorPart get(){ + IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if(window!=null) { + if(window.getActivePage()!=null) { + IEditorReference[] es= window.getActivePage().getEditorReferences(); + for(int i=0; i<es.length; i++) { + IEditorPart part= es[i].getEditor(false); + if(part != null) + return part; + } + } + } + return null; + } + + private List/*<Position>*/ mkPositions(int[][] raw) { + List result= new ArrayList(); + for(int i=0; i<raw.length; i++) { + Assert.assertEquals(2, raw[i].length); + result.add(new Position(raw[i][0], raw[i][1])); + } + return result; + } + + public void testDCOM_A() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerA"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment1, scomment1}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } + + public void testDCOM_B() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerB"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment2, scomment2}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } + + public void testDCOM_C() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerC"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment3, scomment3}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } + + public void testDCOM_ABC() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerABC"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment1, comment2, comment3, scomment1, scomment2, scomment3}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } + + public void testDCOM_BDFG() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerBDFG"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment2, comment4, comment6, comment7, comment8, scomment2}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } + + public void testDCOM_PUNC() throws BadLocationException, InterruptedException { + DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerPUNC"), true); + runEventQueue(1000); + List/*<Position>*/ expected= mkPositions(new int[][] {comment9, comment10, scomment4, scomment5, comment11, comment12, scomment7}); + assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB)); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentTestSuite.java new file mode 100644 index 00000000000..651f431cdca --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentTestSuite.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.doctools; + +import org.eclipse.cdt.ui.tests.text.doctools.doxygen.DoxygenCCommentAutoEditStrategyTest; + +import junit.framework.TestSuite; + +public class DocCommentTestSuite extends TestSuite { + + public static TestSuite suite() { + return new DocCommentTestSuite(); + } + + public DocCommentTestSuite() { + super(DocCommentTestSuite.class.getName()); + + addTest(CommentOwnerManagerTests.suite()); + addTest(DocCommentHighlightingTest.suite()); + addTest(DoxygenCCommentAutoEditStrategyTest.suite()); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/TestGenericTagConfiguration.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/TestGenericTagConfiguration.java new file mode 100644 index 00000000000..bfde81e1d3d --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/TestGenericTagConfiguration.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.doctools; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.graphics.RGB; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration; +import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag; + +public class TestGenericTagConfiguration extends AbstractGenericTagDocCommentViewerConfiguration { + public static final RGB DEFAULTRGB= new RGB(63, 95, 191); + + protected char[] fCommentMarkers; + + public TestGenericTagConfiguration(String commentMarkers, String tags, String tagMarkers, String defaultToken, String tagToken) { + super(mkTags(tags.split("(\\s)*,(\\s)*")), tagMarkers.toCharArray(), defaultToken, tagToken); + IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore(); + PreferenceConverter.setDefault(cuis, defaultToken, DEFAULTRGB); + PreferenceConverter.setDefault(cuis, tagToken, new RGB(127, 159, 191)); + fCommentMarkers= commentMarkers.toCharArray(); + } + + public IAutoEditStrategy createAutoEditStrategy() { + return null; + } + + private static GenericDocTag[] mkTags(String[] tagNames) { + GenericDocTag[] tags= new GenericDocTag[tagNames.length]; + for(int i=0; i<tagNames.length; i++) { + tags[i]= new GenericDocTag(tagNames[i], "no description"); + } + return tags; + } + + public boolean isDocumentationComment(IDocument doc, int offset, int length) { + try { + if(offset+2 < doc.getLength()) { + char c= doc.getChar(offset+2); + for(int i=0; i<fCommentMarkers.length; i++) + if(c == fCommentMarkers[i]) + return true; + return false; + } + } catch(BadLocationException ble) { + CUIPlugin.getDefault().log(ble); + } + return false; + } + + public static class A extends TestGenericTagConfiguration { + public A() {super("A", "", "@", "test.token.A.default", "test.token.A.tag");} + } + + public static class B extends TestGenericTagConfiguration { + public B() {super("B", "", "@", "test.token.B.default", "test.token.B.tag");} + } + + public static class C extends TestGenericTagConfiguration { + public C() {super("C", "", "@", "test.token.C.default", "test.token.C.tag");} + } + + public static class ABC extends TestGenericTagConfiguration { + public ABC() {super("ABC", "", "@", "test.token.ABC.default", "test.token.ABC.tag");} + } + + public static class BDFG extends TestGenericTagConfiguration { + public BDFG() {super("BDFG", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");} + } + + public static class PUNC extends TestGenericTagConfiguration { + public PUNC() {super("!*#", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");} + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java new file mode 100644 index 00000000000..e6a7a6c479f --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java @@ -0,0 +1,378 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Sergey Prigogin, Google + * Andrew Ferguson (Symbian) + *******************************************************************************/ + +package org.eclipse.cdt.ui.tests.text.doctools.doxygen; + +import java.util.HashMap; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.tests.text.DefaultCCommentAutoEditStrategyTest; +import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy; +import org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineAutoEditStrategy; + +import org.eclipse.cdt.internal.core.model.TranslationUnit; + +import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy; +import org.eclipse.cdt.internal.ui.text.CTextTools; + + +/** + * Testing the auto indent strategies. + */ +public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest { + private HashMap fOptions; + protected ICProject fCProject; + + /** + * @param name + */ + public DoxygenCCommentAutoEditStrategyTest(String name) { + super(name); + } + + public static Test suite() { + return suite(DoxygenCCommentAutoEditStrategyTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null); + fOptions= CCorePlugin.getOptions(); + } + + /* + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + CProjectHelper.delete(fCProject); + CCorePlugin.setOptions(fOptions); + super.tearDown(); + } + + private AutoEditTester createAutoEditTester() { + CTextTools textTools = CUIPlugin.getDefault().getTextTools(); + IDocument doc = new Document(); + textTools.setupCDocument(doc); + AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING); + + + tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); + tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy()); + tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null)); + return tester; + } + + // /**X + // void foo() {} + + // /** + // * X + // */ + // void foo() {} + public void testAutoDocCommentContent1() throws CoreException { + assertAutoEditBehaviour(); + } + + // /** X + // void foo() {} + + // /** + // * X + // */ + // void foo() {} + public void testAutoDocCommentContent2() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // int foo_bar() {} + + // /** + // * X + // * @return + // */ + // int foo_bar() {} + public void testAutoDocCommentContent3() throws CoreException { + assertAutoEditBehaviour(); + } + + // /** X + // int foo_bar() {} + + // /** + // * X + // * @return + // */ + // int foo_bar() {} + public void testAutoDocCommentContent4() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // * + // */ + // int foo_bar() {} + + // /** + // * X + // * + // */ + // int foo_bar() {} + public void testAutoDocCommentContent5() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // void foo_bar(int x) {} + + // /** + // * X + // * @param x + // */ + // void foo_bar(int x) {} + public void testAutoDocCommentContent6() throws CoreException { + assertAutoEditBehaviour(); + } + + // class A {}; class B {}; + // /**X + // C* bar_baz(A a, B b, int c) {} + + // class A {}; class B {}; + // /** + // * X + // * @param a + // * @param b + // * @param c + // * @return + // */ + // C* bar_baz(A a, B b, int c) {} + public void testAutoDocCommentContent7() throws CoreException { + assertAutoEditBehaviour(); + } + + // /** + // * namespace + // */ + // namespace NS { + // class A { + // private: + // /* + // * TODO + // */ + // /*! + // * class + // */ + // class B { + // public: + // /** + // * + // */ + // void foo() {} + // /*!X + // A bar(A as[], B bs[]) {} + // }; + // }; + // } + + // /** + // * namespace + // */ + // namespace NS { + // class A { + // private: + // /* + // * TODO + // */ + // /*! + // * class + // */ + // class B { + // public: + // /** + // * + // */ + // void foo() {} + // /*! + // * X + // * @param as + // * @param bs + // * @return + // */ + // A bar(A as[], B bs[]) {} + // }; + // }; + // } + public void testAutoDocCommentContent8() throws CoreException { + assertAutoEditBehaviour(); + } + + // void foo_bar(int x) + // /**X + // {} + + // void foo_bar(int x) + // /** + // * X + // * @param x + // */ + // {} + public void _testAutoDocCommentContent9() throws CoreException { + assertAutoEditBehaviour(); + // TODO - desired behaviour when there is a comment preceding the declaration + // needs defining + } + + // void foo_bar(int x) + // { + // /**X + // } + + // void foo_bar(int x) + // { + // /** + // * X + // * @param x + // */ + // } + public void _testAutoDocCommentContent10() throws CoreException { + assertAutoEditBehaviour(); + // TODO - desired behaviour when there is a comment preceding the declaration + // or when there is a comment after the signature but before the brace, both need defining + } + + // /*!X + // enum A { B, C }; + + // /*! + // * X + // */ + // enum A { B, C }; + public void testAutoDocCommentContent11() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // enum A { B, + // C }; + + // /** + // * X + // */ + // enum A { B,//!< B + // C }; //!< C + public void testAutoDocCommentContent13() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // enum A { B, + // C };//!< C + + // /** + // * X + // */ + // enum A { B,//!< B + // C };//!< C + public void testAutoDocCommentContent14() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // enum A { B,//!< B + // C }; + + // /** + // * X + // */ + // enum A { B,//!< B + // C };//!< C + public void testAutoDocCommentContent15() throws CoreException { + assertAutoEditBehaviour(); + } + + // /**X + // enum A { B, + // C }; + + // /** + // * X + // */ + // enum A { B,//!< B + // C }; //!< C + public void _testAutoDocCommentContent16() throws CoreException { + /* + * Indenting in the presence of tabs is not handled at the moment. + */ + assertAutoEditBehaviour(); + } + + protected void assertAutoEditBehaviour() throws CoreException { + CTextTools textTools = CUIPlugin.getDefault().getTextTools(); + final IDocument doc = new Document(); + textTools.setupCDocument(doc); + + StringBuffer[] raw= getTestContents(); + String init= raw[0].toString(), expected= raw[1].toString(); + + int caretInit= init.indexOf('X'); + init= init.replaceFirst("X", ""); + + int caretExpected= expected.indexOf('X'); + expected= expected.replaceFirst("X", ""); + + + DoxygenMultilineAutoEditStrategy ds= new DoxygenMultilineAutoEditStrategy() { + public IASTTranslationUnit getAST() { + final IFile file= fCProject.getProject().getFile("testContent.cpp"); + try { + TestSourceReader.createFile(fCProject.getProject(), "testContent.cpp", doc.get()); + String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName()); + return new TranslationUnit(fCProject, file, id).getAST(); + } catch(CoreException ce) { + assertTrue("Could not get test content AST", false); + return null; + } + } + }; + + + doc.set(init); + int caretActual= -1; + try { + TestDocumentCommand dc= new TestDocumentCommand(caretInit, 0, "\n"); + ds.customizeDocumentCommand(doc, dc); + caretActual= dc.exec(doc); + } catch(BadLocationException ble) { + fail(ble.getMessage()); + } + String actual= doc.get(); + assertEquals(expected, actual); + assertEquals(caretExpected, caretActual); + } +} |