Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Morgner2016-07-15 11:55:07 +0000
committerThomas Corbat2017-05-15 06:59:54 +0000
commitca1ab7f52dc9174ca42660d5acbe3b634de7ee9e (patch)
tree0e15589348be87761c1a18bc326faaa953a324af /core/org.eclipse.cdt.ui.tests
parent619da2a170183d4fb50272f39407365a8bb7a4b2 (diff)
downloadorg.eclipse.cdt-ca1ab7f52dc9174ca42660d5acbe3b634de7ee9e.tar.gz
org.eclipse.cdt-ca1ab7f52dc9174ca42660d5acbe3b634de7ee9e.tar.xz
org.eclipse.cdt-ca1ab7f52dc9174ca42660d5acbe3b634de7ee9e.zip
Bug 491957. Preferences & save action for choosing const alignment
Conflicts: core/org.eclipse.cdt.core/META-INF/MANIFEST.MF core/org.eclipse.cdt.core/pom.xml core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java core/org.eclipse.cdt.ui/pom.xml Change-Id: I061fa28d2e0b37f6d00232ad619f23b892e13ce6 Signed-off-by: Mario Meili <mmeili@hsr.ch> Signed-off-by: Benny Gaechter <benny.gaechter@hsr.ch> Signed-off-by: Felix Morgner <fmorgner@hsr.ch>
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests')
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/After.cpp28
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/Before.cpp29
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/After.cpp27
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/Before.cpp27
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/After.cpp26
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/Before.cpp27
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/After.cpp29
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/Before.cpp29
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AlignConstActionTest.java130
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java1
10 files changed, 353 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/After.cpp
new file mode 100644
index 00000000000..658556eec44
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/After.cpp
@@ -0,0 +1,28 @@
+
+void f(const int * const);
+
+void f(const int * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ const int &dsa { 2 };
+
+ const int j { 8 };
+
+ const int * const klz;
+
+ const int l { 2 };
+
+ bool yes = false;
+
+ const int k { 42 };
+
+ const volatile int q = 1;
+
+ volatile const int r = 99;
+
+ using const_int = int;
+ const const_int s = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/Before.cpp
new file mode 100644
index 00000000000..71fc943a67f
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftChanged/Before.cpp
@@ -0,0 +1,29 @@
+
+void f(int const * const);
+
+void f(int const * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ int const &dsa { 2 };
+
+ int const j { 8 };
+
+ int const * const klz;
+
+ int const l { 2 };
+
+ bool yes = false;
+
+ int const k { 42 };
+
+ volatile int
+ const q = 1;
+
+ volatile const int r = 99;
+
+ using const_int = int;
+ const_int const s = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/After.cpp
new file mode 100644
index 00000000000..84a0ff7214e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/After.cpp
@@ -0,0 +1,27 @@
+
+void f(const int * const);
+
+void f(const int * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ const int &dsa { 2 };
+
+ const int j { 8 };
+
+ const int * const klz;
+
+ const int l { 2 };
+
+ bool yes = false;
+
+ const int k { 42 };
+
+ volatile const
+ int q = 1;
+
+ using int_const = int;
+ const int_const r = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/Before.cpp
new file mode 100644
index 00000000000..84a0ff7214e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/leftUnchanged/Before.cpp
@@ -0,0 +1,27 @@
+
+void f(const int * const);
+
+void f(const int * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ const int &dsa { 2 };
+
+ const int j { 8 };
+
+ const int * const klz;
+
+ const int l { 2 };
+
+ bool yes = false;
+
+ const int k { 42 };
+
+ volatile const
+ int q = 1;
+
+ using int_const = int;
+ const int_const r = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/After.cpp
new file mode 100644
index 00000000000..d46d4b9ee53
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/After.cpp
@@ -0,0 +1,26 @@
+
+void f(int const * const);
+
+void f(int const * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ int const &dsa { 2 };
+
+ int const j { 8 };
+
+ int const * const klz;
+
+ int const l { 2 };
+
+ bool yes = false;
+
+ int const k { 42 };
+
+ volatile int const q = 1;
+
+ using int_const = int;
+ int_const const r = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/Before.cpp
new file mode 100644
index 00000000000..84a0ff7214e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightChanged/Before.cpp
@@ -0,0 +1,27 @@
+
+void f(const int * const);
+
+void f(const int * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ const int &dsa { 2 };
+
+ const int j { 8 };
+
+ const int * const klz;
+
+ const int l { 2 };
+
+ bool yes = false;
+
+ const int k { 42 };
+
+ volatile const
+ int q = 1;
+
+ using int_const = int;
+ const int_const r = 7;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/After.cpp
new file mode 100644
index 00000000000..1120cb7499e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/After.cpp
@@ -0,0 +1,29 @@
+
+void f(int const * const);
+
+void f(int const * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ int const &dsa { 2 };
+
+ int const j { 8 };
+
+ int const * const klz;
+
+ int const l { 2 };
+
+ bool yes = false;
+
+ int const k { 42 };
+
+ int const volatile m = 21;
+
+ using volatile_int = int;
+ volatile_int const volatile v = 89;
+
+ using const_int = int;
+ const_int const w = 73;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/Before.cpp
new file mode 100644
index 00000000000..1120cb7499e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/constalign/rightUnchanged/Before.cpp
@@ -0,0 +1,29 @@
+
+void f(int const * const);
+
+void f(int const * const) {
+
+}
+
+int main(int argc, char **argv) {
+
+ int const &dsa { 2 };
+
+ int const j { 8 };
+
+ int const * const klz;
+
+ int const l { 2 };
+
+ bool yes = false;
+
+ int const k { 42 };
+
+ int const volatile m = 21;
+
+ using volatile_int = int;
+ volatile_int const volatile v = 89;
+
+ using const_int = int;
+ const_int const w = 73;
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AlignConstActionTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AlignConstActionTest.java
new file mode 100644
index 00000000000..e822e9c9ae1
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AlignConstActionTest.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences.
+ * 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.cdt.ui.tests.text;
+
+import java.util.ListResourceBundle;
+
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.SourceViewer;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.CCorePreferenceConstants;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.testplugin.CProjectHelper;
+import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
+import org.eclipse.cdt.ui.testplugin.ResourceTestHelper;
+
+import org.eclipse.cdt.internal.ui.actions.AlignConstAction;
+import org.eclipse.cdt.internal.ui.editor.CEditor;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test for the const alignment action.
+ */
+public class AlignConstActionTest extends TestCase {
+ private static final String PROJECT = "AlignConstTests";
+
+ private static final class EmptyBundle extends ListResourceBundle {
+ @Override
+ protected Object[][] getContents() {
+ return new Object[0][];
+ }
+ }
+
+ protected static class AlignConstTestSetup extends TestSetup {
+ private ICProject fCProject;
+
+ public AlignConstTestSetup(Test test) {
+ super(test);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ fCProject = EditorTestHelper.createCProject(PROJECT, "resources/constalign");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (fCProject != null)
+ CProjectHelper.delete(fCProject);
+ super.tearDown();
+ }
+ }
+
+ public static Test suite() {
+ return new AlignConstTestSetup(new TestSuite(AlignConstActionTest.class));
+ }
+
+ private CEditor fEditor;
+ private SourceViewer fSourceViewer;
+ private IDocument fDocument;
+
+ @Override
+ protected void setUp() throws Exception {
+ IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
+ prefs.putBoolean(CCorePreferenceConstants.PLACE_CONST_RIGHT_OF_TYPE, getName().startsWith("testRight"));
+ String filename = createFileName("Before");
+ fEditor = (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(filename), true);
+ fSourceViewer = EditorTestHelper.getSourceViewer(fEditor);
+ fDocument = fSourceViewer.getDocument();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ EditorTestHelper.closeEditor(fEditor);
+ IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
+ prefs.putBoolean(CCorePreferenceConstants.PLACE_CONST_RIGHT_OF_TYPE, false);
+ }
+
+ private void assertAlignConstResult() throws Exception {
+ String afterFile = createFileName("After");
+ String expected = ResourceTestHelper.read(afterFile).toString();
+
+ new AlignConstAction(new EmptyBundle(), "prefix", fEditor).run();
+
+ assertEquals(expected, fDocument.get());
+ }
+
+ private String createFileName(String qualifier) {
+ String name = getName();
+ name = name.substring(4, 5).toLowerCase() + name.substring(5);
+ return "/" + PROJECT + "/src/" + name + "/" + qualifier + ".cpp";
+ }
+
+ private void selectAll() {
+ fSourceViewer.setSelectedRange(0, fDocument.getLength());
+ }
+
+ public void testRightUnchanged() throws Exception {
+ selectAll();
+ assertAlignConstResult();
+ }
+
+ public void testRightChanged() throws Exception {
+ selectAll();
+ assertAlignConstResult();
+ }
+
+ public void testLeftUnchanged() throws Exception {
+ selectAll();
+ assertAlignConstResult();
+ }
+
+ public void testLeftChanged() throws Exception {
+ selectAll();
+ assertAlignConstResult();
+ }
+} \ No newline at end of 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 96d650122ee..5e9ee52e523 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
@@ -31,6 +31,7 @@ import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite;
AsmPartitionerTest.class,
// smart edit tests
+ AlignConstActionTest.class,
CAutoIndentTest.class,
CHeuristicScannerTest.class,
BracketInserterTest.class,

Back to the top