aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2008-11-11 17:26:54 (EST)
committersefftinge2008-11-11 17:26:54 (EST)
commit6eee3adaf179cd21d106270d66ea0b2cdc28541c (patch)
tree86a884bbb248c080b3d7f07db87348f5def3229e
parent08fd787c3554b47c28117b3daf59532b9a1f4db4 (diff)
downloadorg.eclipse.xtext-6eee3adaf179cd21d106270d66ea0b2cdc28541c.zip
org.eclipse.xtext-6eee3adaf179cd21d106270d66ea0b2cdc28541c.tar.gz
org.eclipse.xtext-6eee3adaf179cd21d106270d66ea0b2cdc28541c.tar.bz2
add: starting with UI tests
-rw-r--r--tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF9
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/META-INF/MANIFEST.MF9
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java98
3 files changed, 114 insertions, 2 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
index a2e52bf..97e1731 100644
--- a/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
@@ -16,4 +16,11 @@ Require-Bundle: org.eclipse.xtext,
org.eclipse.xtend.typesystem.emf,
org.eclipse.xtend.util.stdlib,
org.easymock;bundle-version="2.3.0"
-Export-Package: org.eclipse.xtext
+Export-Package: org.eclipse.xtext,
+ org.eclipse.xtext.crossrefs,
+ org.eclipse.xtext.testlanguages,
+ org.eclipse.xtext.testlanguages.parser,
+ org.eclipse.xtext.testlanguages.parser.internal,
+ org.eclipse.xtext.testlanguages.parsetree.reconstr,
+ org.eclipse.xtext.testlanguages.services,
+ org.eclipse.xtext.tests
diff --git a/tests/org.eclipse.xtext.ui.common.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.xtext.ui.common.tests/META-INF/MANIFEST.MF
index 096c1c1..b5a3122 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.xtext.ui.common.tests/META-INF/MANIFEST.MF
@@ -9,6 +9,13 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.xtext.ui.core.tests;bundle-version="0.7.0",
org.junit;bundle-version="3.8.2",
- org.eclipse.ui.views;bundle-version="3.3.0"
+ org.eclipse.ui.views;bundle-version="3.3.0",
+ org.eclipse.xtext.generator.tests;bundle-version="0.7.0",
+ org.eclipse.xtext.common.ui;bundle-version="0.7.0",
+ org.eclipse.xtext;bundle-version="0.7.0",
+ org.eclipse.xtext.ui.common;bundle-version="0.7.0",
+ org.easymock;bundle-version="2.3.0",
+ org.eclipse.jface.text;bundle-version="3.4.0",
+ org.eclipse.xtext.ui.core;bundle-version="0.7.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
new file mode 100644
index 0000000..88ed2bf
--- /dev/null
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * __ ___ _
+ * \ \/ / |_ _____ __ |_
+ * \ /| __/ _ \ \/ / __|
+ * / \| |_ __/> <| |_
+ * /_/\_\\__\___/_/\_\\__|
+ *
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.ui.common.editor.codecompletion;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.xtext.parsetree.CompositeNode;
+import org.eclipse.xtext.testlanguages.ReferenceGrammarStandaloneSetup;
+import org.eclipse.xtext.tests.AbstractGeneratorTest;
+import org.eclipse.xtext.ui.core.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
+
+
+/**
+ * Unit test for class <code>DefaultContentAssistProcessor</code>.
+ *
+ * @author Michael Clay - Initial contribution and API
+ * @see org.eclipse.xtext.ui.common.editor.codecompletion.DefaultContentAssistProcessor
+ */
+public class DefaultContentAssistProcessorTest extends AbstractGeneratorTest
+{
+
+ private DefaultContentAssistProcessor defaultContentAssistProcessor;
+ private ITextViewer textViewerMock;
+ private IXtextDocument xtextDocumentMock;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(ReferenceGrammarStandaloneSetup.class);
+ textViewerMock = createMock(ITextViewer.class);
+ xtextDocumentMock = createMock(IXtextDocument.class);
+ defaultContentAssistProcessor = new DefaultContentAssistProcessor();
+ defaultContentAssistProcessor.setProposalProvider(new AbstractProposalProvider(){
+ @Override
+ protected String getDefaultImageFilePath() {
+ return "JUNIT";
+ }
+
+ @Override
+ protected String getPluginId() {
+ return "JUNIT";
+ }}
+ );
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testComputeCompletionProposalsCount() throws Exception {
+
+ final String testDslModel = "spielplatz ";
+
+ CompositeNode rootNode = getRootNode(testDslModel);
+ expect(textViewerMock.getDocument()).andReturn(xtextDocumentMock);
+ expect(xtextDocumentMock.readOnly((UnitOfWork<CompositeNode>) anyObject()))
+ .andReturn(rootNode);
+ expect(textViewerMock.getTextWidget()).andReturn(newStyledTextWidgetMock(testDslModel));
+ replay(textViewerMock);
+ replay(xtextDocumentMock);
+
+ ICompletionProposal[] computeCompletionProposals = defaultContentAssistProcessor.computeCompletionProposals(textViewerMock, testDslModel.length());
+
+ assertEquals("expect only 1 ICompletionProposal item",1,computeCompletionProposals.length);
+ }
+
+ private StyledText newStyledTextWidgetMock(final String testDslModel) {
+ return new StyledText(new Shell(), SWT.NONE) {
+ @Override
+ public int getCharCount() {
+ return testDslModel.length();
+ }
+
+ @Override
+ public String getText(int start, int end) {
+ return testDslModel.substring(start, end);
+ }
+ };
+ }
+
+} \ No newline at end of file