diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java index 466e688d925..0c341f0706c 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -29,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; /** * This is style checker for function name code style. Pattern parameter is * regular expression defining the style. - * */ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker implements ICheckerWithPreferences { private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$ @@ -50,7 +49,7 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker imp public int visit(IASTDeclaration element) { if (element instanceof IASTFunctionDefinition) { IASTName astName = ((IASTFunctionDefinition) element).getDeclarator().getName(); - String name = getSearchibleName(astName); + String name = getSearchableName(astName); if (name != null) { for (Iterator iterator = pts.iterator(); iterator.hasNext();) { IProblem pt = iterator.next(); @@ -68,18 +67,14 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker imp return PROCESS_SKIP; } - public boolean shouldReport(IASTName astName, IProblem pt) { + private boolean shouldReport(IASTName astName, IProblem pt) { if (astName instanceof ICPPASTQualifiedName) { return shouldReportCppMethods(pt); } return true; } - /** - * @param astName - * @return - */ - public String getSearchibleName(IASTName astName) { + private String getSearchableName(IASTName astName) { String name = astName.toString(); if (astName instanceof ICPPASTQualifiedName) { ICPPASTQualifiedName cppAstName = (ICPPASTQualifiedName) astName; @@ -104,13 +99,6 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker imp } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters - * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) - */ @Override public void initPreferences(IProblemWorkingCopy problem) { super.initPreferences(problem); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/ExternalSettingsProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/ExternalSettingsProviderTests.java index b83dcc5967c..98418e57d30 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/ExternalSettingsProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/ExternalSettingsProviderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Intel Corporation and others. + * Copyright (c) 2007, 2012 Intel Corporation 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 @@ -8,12 +8,16 @@ * Contributors: * Intel Corporation - Initial API and implementation * James Blackburn (Broadcom Corp.) - * Christian Walther (Indel AG) - [335344] test for changing language IDs + * Christian Walther (Indel AG) - bug 335344: test for changing language IDs + * Raphael Zulliger (Indel AG) - bug 284699: test having macros with same + * name but different values in same project + * configuration *******************************************************************************/ package org.eclipse.cdt.core.settings.model; import java.util.Arrays; import java.util.HashMap; + import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.IPDOMManager; @@ -29,12 +33,12 @@ import org.eclipse.core.runtime.Path; public class ExternalSettingsProviderTests extends BaseTestCase{ private static final String PROJ_NAME_PREFIX = "espt_"; - ICProject p1, p2, p3, p4, p5; - + ICProject p1, p2, p3, p4, p5, p6; + public static TestSuite suite() { return suite(ExternalSettingsProviderTests.class, "_"); } - + @Override protected void setUp() throws Exception { p1 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "a", IPDOMManager.ID_NO_INDEXER); @@ -42,8 +46,9 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ p3 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "c", IPDOMManager.ID_NO_INDEXER); p4 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "d", IPDOMManager.ID_NO_INDEXER); p5 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "e", IPDOMManager.ID_NO_INDEXER); + p6 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "f", IPDOMManager.ID_NO_INDEXER); } - + /** * Test adding a external setting provider to p1 -- the contributed paths should appear * @throws Exception @@ -52,7 +57,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ TestExtSettingsProvider.setVariantNum(0); CoreModel model = CoreModel.getDefault(); IProject project = p1.getProject(); - + ICProjectDescription des = model.getProjectDescription(project); ICConfigurationDescription cfgDes = des.getConfigurations()[0]; ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); @@ -83,44 +88,44 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ new CSourceEntry(project.getFullPath().append("sp_b"), null, 0), }; assertTrue(Arrays.equals(newExpectedSourceEntries, sourceEntries)); - + // insert entry into the mix; check that the new entry appears ICLanguageSettingEntry[] newEntries = new ICLanguageSettingEntry[3]; newEntries[0] = expectedEntries[1]; newEntries[1] = new CIncludePathEntry("added", 0); newEntries[2] = expectedEntries[0]; - + ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); - + assertEquals(3, entries.length); assertTrue(Arrays.equals(newEntries, entries)); - + newEntries = new ICLanguageSettingEntry[1]; newEntries[0] = expectedEntries[0]; ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); - + assertEquals(1, entries.length); assertTrue(Arrays.equals(newEntries, entries)); - + newEntries = new ICLanguageSettingEntry[0]; ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); - + assertEquals(0, entries.length); - + ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, (ICLanguageSettingEntry[])null); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); assertEquals(2, entries.length); assertTrue(Arrays.equals(expectedEntries, entries)); } - + public void testCreateCfg() throws Exception { TestExtSettingsProvider.setVariantNum(0); CoreModel model = CoreModel.getDefault(); IProject project = p2.getProject(); - + ICProjectDescription des = model.getProjectDescription(project); ICConfigurationDescription cfgDes = des.getConfigurations()[0]; ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); @@ -134,24 +139,24 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedSourceEntries, sourceEntries)); String[] extPIds = new String[]{CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"}; cfgDes.setExternalSettingsProviderIds(extPIds); - + model.setProjectDescription(project, des); - + des = model.getProjectDescription(project, false); cfgDes = des.getConfigurations()[0]; assertEquals(extPIds.length, cfgDes.getExternalSettingsProviderIds().length); assertTrue(Arrays.equals(extPIds, cfgDes.getExternalSettingsProviderIds())); - + des = model.getProjectDescription(project); cfgDes = des.getConfigurations()[0]; assertEquals(extPIds.length, cfgDes.getExternalSettingsProviderIds().length); assertTrue(Arrays.equals(extPIds, cfgDes.getExternalSettingsProviderIds())); - + String newCfgId = CDataUtil.genId(null); ICConfigurationDescription cfgDes2 = des.createConfiguration(newCfgId, "cfg2", cfgDes); assertEquals(extPIds.length, cfgDes2.getExternalSettingsProviderIds().length); assertTrue(Arrays.equals(extPIds, cfgDes2.getExternalSettingsProviderIds())); - + ls = cfgDes2.getLanguageSettingForFile(new Path("a.c"), true); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); ICLanguageSettingEntry[] expectedEntries = new ICLanguageSettingEntry[]{ @@ -161,14 +166,14 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedEntries, entries)); } - + public void testProviderUpdate() throws Exception { TestExtSettingsProvider.setVariantNum(0); CoreModel model = CoreModel.getDefault(); ICProjectDescriptionManager mngr = model.getProjectDescriptionManager(); IProject project = p2.getProject(); - + ICProjectDescription des = model.getProjectDescription(project); ICConfigurationDescription cfgDes = des.getConfigurations()[0]; ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); @@ -182,7 +187,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedSourceEntries, sourceEntries)); String[] extPIds = new String[]{CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"}; cfgDes.setExternalSettingsProviderIds(extPIds); - + ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); @@ -193,19 +198,19 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedEntries, entries)); model.setProjectDescription(project, des); - + des = model.getProjectDescription(project); cfgDes = des.getConfigurations()[0]; ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); assertTrue(Arrays.equals(expectedEntries, entries)); - + ICLanguageSettingEntry[] expectedEntries2 = new ICLanguageSettingEntry[]{ new CIncludePathEntry("ip_a2", 0), new CIncludePathEntry("ip_b2", 0), }; TestExtSettingsProvider.setVariantNum(1); - + mngr.updateExternalSettingsProviders(extPIds, null); des = model.getProjectDescription(project); cfgDes = des.getConfigurations()[0]; @@ -213,14 +218,14 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); assertTrue(Arrays.equals(expectedEntries2, entries)); } - + public void testRestoreDefaults() throws Exception { TestExtSettingsProvider.setVariantNum(0); CoreModel model = CoreModel.getDefault(); ICProjectDescriptionManager mngr = model.getProjectDescriptionManager(); IProject project = p4.getProject(); - + ICProjectDescription des = model.getProjectDescription(project); ICConfigurationDescription cfgDes = des.getConfigurations()[0]; ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); @@ -234,7 +239,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedSourceEntries, sourceEntries)); String[] extPIds = new String[]{CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"}; cfgDes.setExternalSettingsProviderIds(extPIds); - + ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH); @@ -245,7 +250,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedEntries, entries)); model.setProjectDescription(project, des); - + des = model.getProjectDescription(project); cfgDes = des.getConfigurations()[0]; ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true); @@ -259,7 +264,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ cfgDes.setSourceEntries(null); expectedSourceEntries = new ICSourceEntry[]{ new CSourceEntry(project.getFullPath().append("sp_a"), null, 0), - new CSourceEntry(project.getFullPath().append("sp_b"), null, 0), + new CSourceEntry(project.getFullPath().append("sp_b"), null, 0), }; sourceEntries = cfgDes.getSourceEntries(); assertEquals(2, sourceEntries.length); @@ -325,7 +330,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(cfgDes.getSourceEntries(), makeProjectRelativePath(project, provided))); break; default: - fail("Unhandled entry_kind: " + kind); + fail("Unhandled entry_kind: " + kind); } } } @@ -341,11 +346,11 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ for (int i = 0; i < input.length; i ++) { switch (input[i].getKind()) { case ICSettingEntry.OUTPUT_PATH: - out[i] = new COutputEntry(project.getFullPath().append(input[i].getValue()), + out[i] = new COutputEntry(project.getFullPath().append(input[i].getValue()), ((ICOutputEntry)input[i]).getExclusionPatterns(), input[i].getFlags()); break; case ICSettingEntry.SOURCE_PATH: - out[i] = new CSourceEntry(project.getFullPath().append(input[i].getValue()), + out[i] = new CSourceEntry(project.getFullPath().append(input[i].getValue()), ((ICSourceEntry)input[i]).getExclusionPatterns(), input[i].getFlags()); break; } @@ -362,14 +367,14 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ CoreModel model = CoreModel.getDefault(); ICProjectDescriptionManager mngr = model.getProjectDescriptionManager(); IProject project = p5.getProject(); - + // add external settings provider ICProjectDescription des = model.getProjectDescription(project); ICConfigurationDescription cfgDes = des.getConfigurations()[0]; String[] extPIds = new String[]{TestExtSettingsProvider.TEST_EXTERNAL_PROVIDER_ID}; cfgDes.setExternalSettingsProviderIds(extPIds); model.setProjectDescription(project, des); - + // read out the settings it caused des = model.getProjectDescription(project, false); cfgDes = des.getConfigurations()[0]; @@ -378,31 +383,31 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ for (ICLanguageSetting s: root.getLanguageSettings()) { languageSettingsById.put(s.getLanguageId(), s); } - + ICLanguageSetting ls; ICLanguageSettingEntry[] entries; ICLanguageSettingEntry[] expectedEntriesSet = new ICLanguageSettingEntry[]{ new CMacroEntry("m_c", "mv_c", 0) }; ICLanguageSettingEntry[] expectedEntriesUnset = new ICLanguageSettingEntry[] {}; - + // setting should be present for assembly but not for C ls = languageSettingsById.get("org.eclipse.cdt.core.assembly"); assertNotNull(ls); entries = ls.getSettingEntries(ICSettingEntry.MACRO); assertEquals(1, entries.length); assertTrue(Arrays.equals(expectedEntriesSet, entries)); - + ls = languageSettingsById.get("org.eclipse.cdt.core.gcc"); assertNotNull(ls); entries = ls.getSettingEntries(ICSettingEntry.MACRO); assertEquals(0, entries.length); assertTrue(Arrays.equals(expectedEntriesUnset, entries)); - + // update settings provider TestExtSettingsProvider.setVariantNum(3); mngr.updateExternalSettingsProviders(extPIds, null); - + // read out the settings it caused des = model.getProjectDescription(project, false); cfgDes = des.getConfigurations()[0]; @@ -411,14 +416,14 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ for (ICLanguageSetting s: root.getLanguageSettings()) { languageSettingsById.put(s.getLanguageId(), s); } - + // setting should be present for both now ls = languageSettingsById.get("org.eclipse.cdt.core.gcc"); assertNotNull(ls); entries = ls.getSettingEntries(ICSettingEntry.MACRO); assertEquals(1, entries.length); assertTrue(Arrays.equals(expectedEntriesSet, entries)); - + ls = languageSettingsById.get("org.eclipse.cdt.core.assembly"); assertNotNull(ls); entries = ls.getSettingEntries(ICSettingEntry.MACRO); @@ -426,6 +431,40 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ assertTrue(Arrays.equals(expectedEntriesSet, entries)); } + /** + * Test if macros with the same name but different values can coexist when + * they belong to different language ids + */ + public void testSameMacroWithDifferentValuesAndDifferentLanguageIds() throws CoreException { + TestExtSettingsProvider.setVariantNum(4); + + CoreModel model = CoreModel.getDefault(); + ICProjectDescriptionManager mngr = model.getProjectDescriptionManager(); + IProject project = p6.getProject(); + + // add external settings provider + ICProjectDescription des = model.getProjectDescription(project); + ICConfigurationDescription cfgDes = des.getConfigurations()[0]; + String[] extPIds = new String[]{TestExtSettingsProvider.TEST_EXTERNAL_PROVIDER_ID}; + cfgDes.setExternalSettingsProviderIds(extPIds); + ICFolderDescription root = cfgDes.getRootFolderDescription(); + model.setProjectDescription(project, des); + + // read out the settings it caused + des = model.getProjectDescription(project, false); + cfgDes = des.getConfigurations()[0]; + root = cfgDes.getRootFolderDescription(); + for (ICLanguageSetting s: root.getLanguageSettings()) { + if( s.getLanguageId().equals("org.eclipse.cdt.core.assembly") ) { + assertEquals(1, s.getSettingEntries(ICSettingEntry.MACRO).length); + assertEquals("TheValue", s.getSettingEntries(4)[0].getValue()); + } if( s.getLanguageId().equals("org.eclipse.cdt.core.g++") ) { + assertEquals(1, s.getSettingEntries(ICSettingEntry.MACRO).length); + assertEquals("", s.getSettingEntries(ICSettingEntry.MACRO)[0].getValue()); + } + } + } + @Override protected void tearDown() throws Exception { try { @@ -448,5 +487,9 @@ public class ExternalSettingsProviderTests extends BaseTestCase{ p5.getProject().delete(true, null); } catch (CoreException e){ } + try { + p6.getProject().delete(true, null); + } catch (CoreException e){ + } } } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/TestExtSettingsProvider.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/TestExtSettingsProvider.java index 93bb40f1c5e..36d5c3d5f8d 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/TestExtSettingsProvider.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/settings/model/TestExtSettingsProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Intel Corporation and others. + * Copyright (c) 2007, 2012 Intel Corporation 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,7 +7,10 @@ * * Contributors: * Intel Corporation - Initial API and implementation - * Christian Walther (Indel AG) - [335344] test for changing language IDs + * Christian Walther (Indel AG) - bug 335344: test for changing language IDs + * Raphael Zulliger (Indel AG) - bug 284699: test having macros with same + * name but different values in same project + * configuration *******************************************************************************/ package org.eclipse.cdt.core.settings.model; @@ -16,7 +19,7 @@ import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.core.resources.IProject; public class TestExtSettingsProvider extends CExternalSettingProvider { - + public static final String TEST_EXTERNAL_PROVIDER_ID = CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"; private static CExternalSetting[] SETTINGS_1 = new CExternalSetting[]{ @@ -39,7 +42,7 @@ public class TestExtSettingsProvider extends CExternalSettingProvider { new COutputEntry("op_b", null, 0), }) }; - + private static CExternalSetting[] SETTINGS_2 = new CExternalSetting[]{ new CExternalSetting(null, null, null, new ICSettingEntry[]{ new CIncludePathEntry("ip_a2", 0), @@ -72,7 +75,7 @@ public class TestExtSettingsProvider extends CExternalSettingProvider { } ) }; - + private static CExternalSetting[] SETTINGS_4 = new CExternalSetting[]{ new CExternalSetting( new String[]{ @@ -86,26 +89,48 @@ public class TestExtSettingsProvider extends CExternalSettingProvider { ) }; + private static CExternalSetting[] SETTINGS_5 = new CExternalSetting[]{ + new CExternalSetting( + new String[]{ + "org.eclipse.cdt.core.g++" + }, + null, null, + new ICSettingEntry[]{ + new CMacroEntry("THE_MACRO", "", 0) + } + ), + new CExternalSetting( + new String[]{ + "org.eclipse.cdt.core.assembly" + }, + null, null, + new ICSettingEntry[]{ + new CMacroEntry("THE_MACRO", "TheValue", 0) + } + ) + }; + public static final CExternalSetting[][] SETTINGS_VARIANTS = new CExternalSetting[][]{ - SETTINGS_1, + SETTINGS_1, SETTINGS_2, SETTINGS_3, - SETTINGS_4}; + SETTINGS_4, + SETTINGS_5}; private static int variantNum; - + @Override public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfg) { return SETTINGS_VARIANTS[variantNum].clone(); } - + public static void setVariantNum(int num){ if(num < 0 || num >= SETTINGS_VARIANTS.length) throw new IllegalArgumentException(); variantNum = num; } - + public static int getVariantNum(){ return variantNum; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index bae3b12d150..64cb7063c1f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -256,7 +256,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { private ICProject cproject; private StringBuilder[] testData; private IASTTranslationUnit ast; - private boolean cpp; + private final boolean cpp; public SinglePDOMTestFirstASTStrategy(boolean cpp) { this.cpp = cpp; @@ -342,7 +342,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { private ICProject cproject; private StringBuilder[] testData; private IASTTranslationUnit ast; - private boolean cpp; + private final boolean cpp; public SinglePDOMTestStrategy(boolean cpp) { this.cpp = cpp; @@ -392,7 +392,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); if (DEBUG) { - System.out.println("Project PDOM: "+getName()); + System.out.println("Project PDOM: " + getName()); ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } @@ -501,7 +501,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); if (DEBUG) { - System.out.println("Project PDOM: "+getName()); + System.out.println("Project PDOM: " + getName()); ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } @@ -539,7 +539,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { private ICProject cproject, referenced; private StringBuilder[] testData; private IASTTranslationUnit ast; - private boolean cpp; + private final boolean cpp; public ReferencedProject(boolean cpp) { this.cpp = cpp; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java index 2b690924beb..ca8e197a13c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java @@ -67,8 +67,9 @@ public class IndexNamesTests extends BaseTestCase { } public String getComment() throws IOException { - return TestSourceReader.getContentsForTest( - CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1)[0].toString(); + CharSequence[] contents = TestSourceReader.getContentsForTest( + CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1); + return contents[0].toString(); } protected IFile createFile(IContainer container, String fileName, String contents) throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java index 4a89ca2e2f7..b4824233953 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java @@ -21,9 +21,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; - public class CTestPlugin extends Plugin { - public static final String PLUGIN_ID = "org.eclipse.cdt.core.tests"; private static CTestPlugin fgDefault; @@ -55,7 +53,4 @@ public class CTestPlugin extends Plugin { return null; } } - - - } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index 2869a337ba4..c43165b2a58 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -45,8 +46,10 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.osgi.framework.Bundle; /** @@ -247,17 +250,23 @@ public class TestSourceReader { * @throws CoreException * @since 4.0 */ - public static IFile createFile(final IContainer container, final IPath filePath, final String contents) throws CoreException { + public static IFile createFile(final IContainer container, final IPath filePath, + final CharSequence contents) throws CoreException { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IFile result[] = new IFile[1]; ws.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { - //Obtain file handle + // Obtain file handle IFile file = container.getFile(filePath); - InputStream stream = new ByteArrayInputStream(contents.getBytes()); - //Create file input stream + InputStream stream; + try { + stream = new ByteArrayInputStream(contents.toString().getBytes("UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, null, e)); + } + // Create file input stream if (file.exists()) { long timestamp= file.getLocalTimeStamp(); file.setContents(stream, false, false, new NullProgressMonitor()); @@ -290,11 +299,11 @@ public class TestSourceReader { * @param contents the content for the file * @return a file object. * @since 4.0 - */ + */ public static IFile createFile(IContainer container, String filePath, String contents) throws CoreException { return createFile(container, new Path(filePath), contents); } - + /** * Waits until the given file is indexed. Fails if this does not happen within the * given time. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CSettingEntryFactory.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CSettingEntryFactory.java index b82fe3530f1..c611974c6e2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CSettingEntryFactory.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CSettingEntryFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Intel Corporation and others. + * Copyright (c) 2007, 2012 Intel Corporation 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,8 @@ * * Contributors: * Intel Corporation - Initial API and implementation + * Raphael Zulliger (Indel AG) - bug 284699: fixing issues when using same + * macro names with different values *******************************************************************************/ package org.eclipse.cdt.core.settings.model.util; @@ -19,14 +21,18 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.core.runtime.IPath; +/** + * Cache of setting entries stored with multidimentional maps. + * See bug 284699 comment 7 for a possible insight into it. + */ public class CSettingEntryFactory { private static final HashSet EMPTY_SET = new HashSet(0); - + private KindBasedStore> fStore = new KindBasedStore>(false); - - private HashMap> getNameMap(int kind, boolean create, HashMap type){ + + private HashMap> getNameMap(int kind, boolean create){ @SuppressWarnings("unchecked") - HashMap> map = (HashMap>) fStore.get(kind); + HashMap> map = (HashMap>) fStore.get(kind); if(map == null && create){ map = new HashMap>(); fStore.put(kind, map); @@ -34,47 +40,47 @@ public class CSettingEntryFactory { return map; } - private HashMap getValueMap(String name, boolean create, HashMap type){ - HashMap> nameMap = getNameMap(ICSettingEntry.MACRO, create, (HashMap)null); + private HashMap> getValueMap(String name, boolean create){ + HashMap>> nameMap = getNameMap(ICSettingEntry.MACRO, create); if(nameMap != null){ return getMap(nameMap, name, create); } return null; } - private HashMap getFlagMap(int kind, String name, String value, IPath[] exclusionPatters, boolean create){ + private HashMap getFlagMap(int kind, String name, String value, IPath[] exclusionPatterns, boolean create){ switch(kind){ case ICSettingEntry.MACRO: - HashMap> valueMap = getValueMap(name, create, (HashMap>)null); + HashMap> valueMap = getValueMap(name, create); if(valueMap != null){ - return getMap(valueMap, name, create); + return getMap(valueMap, value, create); } return null; case ICSettingEntry.SOURCE_PATH: case ICSettingEntry.OUTPUT_PATH: HashMap, HashMap> excPatternMap = getExclusionPatternsMap(kind, name, create); if(excPatternMap != null){ - HashSet setKey = exclusionPatters == null || exclusionPatters.length == 0 ? EMPTY_SET : new HashSet(Arrays.asList(exclusionPatters)); + HashSet setKey = exclusionPatterns == null || exclusionPatterns.length == 0 ? EMPTY_SET : new HashSet(Arrays.asList(exclusionPatterns)); return getMap(excPatternMap, setKey, create); } return null; default: - HashMap> nameMap = getNameMap(kind, create, (HashMap)null); + HashMap> nameMap = getNameMap(kind, create); if(nameMap != null){ return getMap(nameMap, name, create); } return null; } } - + private HashMap, HashMap> getExclusionPatternsMap(int kind, String name, boolean create){ - HashMap, HashMap>> nameMap = getNameMap(kind, create, (HashMap, HashMap>)null); + HashMap/*exclusionPatterns*/, HashMap>> nameMap = getNameMap(kind, create); if(nameMap != null){ return getMap(nameMap, name, create); } return null; } - + private static HashMap getMap(HashMap> container, Key key, boolean create){ HashMap map = container.get(key); if(map == null && create){ @@ -90,10 +96,10 @@ public class CSettingEntryFactory { case ICSettingEntry.SOURCE_PATH: return getEntry(entry.getKind(), entry.getName(), null, ((ICExclusionPatternPathEntry)entry).getExclusionPatterns(), entry.getFlags(), entry, true); default: - return getLanguageSettingEntry((ICLanguageSettingEntry)entry); + return getLanguageSettingEntry((ICLanguageSettingEntry)entry); } } - + public ICLanguageSettingEntry getLanguageSettingEntry(ICLanguageSettingEntry lEntry){ return (ICLanguageSettingEntry)getEntry(lEntry.getKind(), lEntry.getName(), lEntry.getValue(), null, lEntry.getFlags(), lEntry, true); } @@ -115,7 +121,7 @@ public class CSettingEntryFactory { } return null; } - + public void clear(){ fStore.clear(); } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts deleted file mode 100644 index 1f6f14fa15e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts +++ /dev/null @@ -1,691 +0,0 @@ -//!Extract boolean comparison from if-condition. -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=check - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - bool check(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - if (/*$*/5 == 3 + 2/*$$*/) { - //... - } -} - -//= -#include "test.h" - -bool Test::check() { - return 5 == 3 + 2; -} - -void Test::test() { - if (check()) { - //... - } -} - -//!Extract boolean comparison from if-condition with parameter. -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=check - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - bool check(int num); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - int num = 1; - if (/*$*/5 != 3 + num/*$$*/) { - //... - } -} - -//= -#include "test.h" - -bool Test::check(int num) { - return 5 != 3 + num; -} - -void Test::test() { - int num = 1; - if (check(num)) { - //... - } -} - -//!Extract binary expression that results in a function with the same return type (BasicType) as the LHS. -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=add - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - int add(int five, int six); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - int five = 5; - int six = 6; - int result = /*$*/five + six/*$$*/; -} - -//= -#include "test.h" - -int Test::add(int five, int six) { - return five + six; -} - -void Test::test() { - int five = 5; - int six = 6; - int result = add(five, six); -} - -//!Extract binary expression that results in a function with the same return type (ClassType) as the LHS -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=cat - -//@test.h -struct helper {}; - -class Test { - void test(); -}; - - -//= -struct helper {}; - -class Test { - void test(); - helper cat(helper s1, helper s2); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - helper s1 = "a"; - helper s2 = "b"; - helper result = /*$*/s1 + s2/*$$*/; -} - -//= -#include "test.h" - -helper Test::cat(helper s1, helper s2) { - return s1 + s2; -} - -void Test::test() { - helper s1 = "a"; - helper s2 = "b"; - helper result = cat(s1, s2); -} - -//!Extract binary expression that results in a function with the same return type (Typedef) as the LHS -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=cat - -//@test.h -struct helper {}; -typedef helper new_helper; - -class Test { - void test(); -}; - - -//= -struct helper {}; -typedef helper new_helper; - -class Test { - void test(); - new_helper cat(new_helper s1, new_helper s2); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - new_helper s1 = "a"; - new_helper s2 = "b"; - new_helper result = /*$*/s1 + s2/*$$*/; -} - -//= -#include "test.h" - -new_helper Test::cat(new_helper s1, new_helper s2) { - return s1 + s2; -} - -void Test::test() { - new_helper s1 = "a"; - new_helper s2 = "b"; - new_helper result = cat(s1, s2); -} - -//!Extract new-Expression -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=new_helper - -//@test.cpp - -struct helper {}; - -int main(int argc, char** argv) { - helper* h = /*$*/new helper/*$$*/; - return 0; -} -//= - -struct helper {}; - -helper* new_helper() { - return new helper; -} - -int main(int argc, char** argv) { - helper* h = new_helper(); - return 0; -} -//!Extract function call -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=join_with_world - -//@test.cpp -class string {}; - -string join(string s1, char* s2) { - return s1 + " " + s2; -} - -int main() { - string hello = "Hello"; - cout << /*$*/join(hello, "World")/*$$*/ << endl; -} -//= -class string {}; - -string join(string s1, char* s2) { - return s1 + " " + s2; -} - -string join_with_world(string hello) { - return join(hello, "World"); -} - -int main() { - string hello = "Hello"; - cout << join_with_world(hello) << endl; -} -//!Extract method call -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=value_from - -//@test.cpp -struct other { - bool value() {} -}; - -class Klass { - void set(bool b) { - } - - void test() { - other o; - this->set(/*$*/o.value()/*$$*/); - } -}; - -//= -struct other { - bool value() {} -}; - -class Klass { - void set(bool b) { - } - - bool value_from(other o) { - return o.value(); - } - - void test() { - other o; - this->set(value_from(o)); - } -}; - -//!Extract function call [we only have the declaration] that returns a pointer -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=has - -//@test.cpp -class Cursor{}; - -Cursor* contains(const Cursor& pos); - -int main() { - Cursor c; - contains(/*$*/contains(c)/*$$*/); -} - -//= -class Cursor{}; - -Cursor* contains(const Cursor& pos); - -Cursor* has(Cursor c) { - return contains(c); -} - -int main() { - Cursor c; - contains(has(c)); -} - -//!Extract function call [we have the definition] that returns a pointer -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=has - -//@test.cpp -class Cursor{}; - -Cursor* contains(const Cursor& pos) { - ; -} - -int main() { - Cursor c; - contains(/*$*/contains(c)/*$$*/); -} - -//= -class Cursor{}; - -Cursor* contains(const Cursor& pos) { - ; -} - -Cursor* has(Cursor c) { - return contains(c); -} - -int main() { - Cursor c; - contains(has(c)); -} - -//!Extract string constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=greeting - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - const char greeting(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - char* hi = /*$*/"hello"/*$$*/; -} - -//= -#include "test.h" - -const char Test::greeting() { - return "hello"; -} - -void Test::test() { - char* hi = greeting(); -} - -//!Extract int constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=size - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - int size(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - int i = /*$*/42/*$$*/; -} - -//= -#include "test.h" - -int Test::size() { - return 42; -} - -void Test::test() { - int i = size(); -} - -//!Extract float constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=certainty - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - float certainty(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - float f = /*$*/0.42f/*$$*/; -} - -//= -#include "test.h" - -float Test::certainty() { - return 0.42f; -} - -void Test::test() { - float f = certainty(); -} - -//!Extract char constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=newline - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - char newline(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - char nl = /*$*/'\n'/*$$*/; -} - -//= -#include "test.h" - -char Test::newline() { - return '\n'; -} - -void Test::test() { - char nl = newline(); -} - -//!Extract boolean true constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=valid - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - bool valid(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - bool b = /*$*/true/*$$*/; -} - -//= -#include "test.h" - -bool Test::valid() { - return true; -} - -void Test::test() { - bool b = valid(); -} - -//!Extract boolean false constant -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=invalid - -//@test.h -class Test { - void test(); -}; - - -//= -class Test { - void test(); - bool invalid(); -}; - - -//@test.cpp -#include "test.h" - -void Test::test() { - bool b = /*$*/false/*$$*/; -} - -//= -#include "test.h" - -bool Test::invalid() { - return false; -} - -void Test::test() { - bool b = invalid(); -} - -//!Extract expression with typedef Bug 331985 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=test.cpp -methodname=bar - -//@test.cpp -typedef int& foo; - -int test(foo s) { - int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&' - return a; -} -//= -typedef int& foo; - -int bar(foo s) { - return s + 1; -} - -int test(foo s) { - int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&' - return a; -} -//!Bug 260133 Extract function and extract local variable don't handle type promotion -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - -//@.config -filename=test.cpp -methodname=bar - -//@test.cpp -void foo() { - int x = 3; - double y = /*$*/x + 2.5/*$$*/; -} -//= -double bar(int x) { - return x + 2.5; -} - -void foo() { - int x = 3; - double y = bar(x); -} -//! Extract macro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=test.cpp -methodname=bar -//@test.cpp -#define five 5 -#define ADD(a, b) a + b - -int main() { - int i = five; //comment3 - i = /*$*/ADD(i, five)/*$$*/; - - return i; -} -//= -#define five 5 -#define ADD(a, b) a + b - -int bar(int i) { - return ADD(i, five); -} - -int main() { - int i = five; //comment3 - i = bar(i); - - return i; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts deleted file mode 100644 index b84828e254d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts +++ /dev/null @@ -1,93 +0,0 @@ -//!Extract template function -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.cpp -void test() { -} - -template -int tempFunct() { - T i; - i = 0; - /*$*/i++; - i += 3;/*$$*/ - - return 0; -} -//= -void test() { -} - -template -void exp(T i) { - i++; - i += 3; -} - -template -int tempFunct() { - T i; - i = 0; - exp(i); - return 0; -} -//!Extract template function with template parameter Bug #12 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.cpp -void test() { -} - -template -int tempFunct(T p) { - /*$*/++p; - p + 4;/*$$*/ - return 0; -} - -//= -void test() { -} - -template -void exp(T p) { - ++p; - p + 4; -} - -template -int tempFunct(T p) { - exp(p); - return 0; -} - -//!Extract template function with template type declaration Bug #11 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.cpp -void test() { -} - -template -int tempFunct() { - /*$*/T p; - p = 0; - p + 4;/*$$*/ - p + 2; - return 0; -} -//= -void test() { -} - -template -T exp() { - T p; - p = 0; - p + 4; - return p; -} - -template -int tempFunct() { - T p = exp(); - p + 2; - return 0; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts deleted file mode 100644 index 7e1a136079d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts +++ /dev/null @@ -1,2487 +0,0 @@ -//!Extract function with variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - /*$*/int i = 2; - ++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp() { - int i = 2; - ++i; - help(); - return i; -} - -int A::foo() { - int i = exp(); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - //comment - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - //comment - ++i; - help(); -} - -int A::foo() { - int i = 2; - //comment - exp(i); - return i; -} - -int A::help() { - return 42; -} -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false - -//!Extract function first extracted statement with leading comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@main.cpp -int main() { - int i; - // Comment - /*$*/i= 7;/*$$*/ - return i; -} - -//= -void exp(int& i) { - // Comment - i = 7; -} - -int main() { - int i; - // Comment - exp(i); - return i; -} - -//@.config -filename=main.cpp -methodname=exp -replaceduplicates=false - -//!Extract function last extracted statement with trailling comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@main.cpp -int main() { - int i; - /*$*/i= 7;/*$$*/ // Comment - return i; -} - -//= -void exp(int& i) { - i = 7; // Comment -} - -int main() { - int i; - exp(i); - return i; -} - -//@.config -filename=main.cpp -methodname=exp -replaceduplicates=false - -//!Extract function with two variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -fatalerror=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - /*$*/int o = 1; - int i = 2; - ++i; - o++; - help();/*$$*/ - o++; - return i; -} - -int A::help() { - return 42; -} - -//!Extract function with named typed field -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); - void exp(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::foo() { - /*$*/b = new B(); - help();/*$$*/ -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp() { - b = new B(); - help(); -} - -void A::foo() { - exp(); -} - -int A::help() { - return 42; -} - -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); -}; - -#endif /*B_H_*/ - -//!Extract function with named typed variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); - void exp(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::foo() { - /*$*/b = new B(); - help();/*$$*/ -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp() { - b = new B(); - help(); -} - -void A::foo() { - exp(); -} - -int A::help() { - return 42; -} - -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); -}; - -#endif /*B_H_*/ - -//!Extract function with ObjectStyleMacro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -#define ZWO 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - i += ZWO; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -#define ZWO 2 - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - i += ZWO; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract function with FunctionStyleMacro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -#define ADD(a,b) a + b + 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - i = ADD(i, 42); - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -#define ADD(a,b) a + b + 2 - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - i = ADD(i, 42); - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract method with pointer -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int* i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int* i = new int(2); - /*$*/++*i; - help();/*$$*/ - return *i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - int* i = new int(2); - exp(i); - return *i; -} - -int A::help() { - return 42; -} - -//!Extract method with pointer and comment at the end -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int* i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int* i = new int(2); - /*$*/++*i; - help(); - //A end-comment/*$$*/ - return *i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - int* i = new int(2); - exp(i); - //A end-comment - return *i; -} - -int A::help() { - return 42; -} -//!Extract method with pointer and comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int* i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - //A beautiful comment - int* i = new int(2); - /*$*/++*i; - help();/*$$*/ - return *i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - //A beautiful comment - int* i = new int(2); - exp(i); - return *i; -} - -int A::help() { - return 42; -} -//!Extract function with return value -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp(int i) { - ++i; - help(); - return i; -} - -int A::foo() { - int i = 2; - i = exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value and ref parameter -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, int b); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - int b = i; - /*$*/++i; - i = i + b; - help();/*$$*/ - ++b; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp(int i, int b) { - ++i; - i = i + b; - help(); - return i; -} - -int A::foo() { - int i = 2; - int b = i; - i = exp(i, b); - ++b; - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value and ref parameter and some more not used afterwards -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp(int i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return i; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - ++x; - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value take the second and ref parameter and some more not used aferwards -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnparameterindex=1 -returnvalue=x -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - float exp(int& i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::exp(int& i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return x; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - x = exp(i, b, y, x); - ++x; - return i; -} - -int A::help() { - return 42; -} -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); - void hello(float y); -}; - -#endif /*B_H_*/ -//!Extract function with return value and a lot ref parameter -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp(int i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return i; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); - void hello(float y); -}; - -#endif /*B_H_*/ -//!Extract function with return value take the second and ref parameter -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnparameterindex=1 -returnvalue=b -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - B* exp(int& i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -B* A::exp(int& i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return b; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - b = exp(i, b, y, x); - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); - void hello(float y); -}; - -#endif /*B_H_*/ -//!Extract function with protected visibility -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -visibility=protected -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -protected: - void exp(int& i); - -private: - int help(); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with public visibility -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -visibility=public -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - void exp(int& i); - -private: - int help(); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with const Method Bug # 46 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo() const; - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo() const; - -private: - int help(); - void exp(int& i) const; -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() const { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) const { - ++i; - help(); -} - -int A::foo() const { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Don't return variables that aren't used -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.h -methodname=loop -//@main.h -void method() { - /*$*/for (int var = 0; var < 100; ++var) { - if (var < 50) - continue; - }/*$$*/ -} -//= -void loop() { - for (int var = 0; var < 100; ++var) { - if (var < 50) - continue; - } -} - -void method() { - loop(); -} -//!Don't extract code that contains 'return' -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.h -fatalerror=true -//@main.h -void method() { - /*$*/if (true) - return;/*$$*/ - //unreachable -} -//!Test if we don't allow to extract 'continue' Bug #53 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -fatalerror=true -filename=A.h -//@A.h -void function() { - for (int var = 0; var < 100; ++var) { - /*$*/if (var < 50) - continue;/*$$*/ - } -} -//! Bug #124 Extract function with a Macro call in selected code "forgets" the macro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void testFuerRainer() { - int i = int(); - /*$*/++i; - //Leading Comment - ASSERT(i); - //Trailling Comment - --i;/*$$*/ -} - -//= -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void runTest(int i) { - ++i; - //Leading Comment - ASSERT(i); - //Trailling Comment - --i; -} - -void testFuerRainer() { - int i = int(); - runTest(i); -} - -//! Bug #124 with comments Extract function with a Macro call in selected code "forgets" the macro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void testFuerRainer() { - int i = int(); - /*$*/++i; - ASSERT(i); - --i;/*$$*/ -} - -//= -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void runTest(int i) { - ++i; - ASSERT(i); - --i; -} - -void testFuerRainer() { - int i = int(); - runTest(i); -} - -//! Bug #137 String Array problem in Extract function -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#include - -using namespace std; - -int const INITIAL_CAPACITY = 10; - -int main() { - int m_capacity; - /*$*/m_capacity += INITIAL_CAPACITY; - string* newElements = new string[m_capacity];/*$$*/ - newElements[0] = "s"; -} - -//= -#include - -using namespace std; - -int const INITIAL_CAPACITY = 10; - -string* runTest(int m_capacity) { - m_capacity += INITIAL_CAPACITY; - string* newElements = new string[m_capacity]; - return newElements; -} - -int main() { - int m_capacity; - string* newElements = runTest(m_capacity); - newElements[0] = "s"; -} - -//!Bug 239059: Double & in signature of extracted functions -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(int& a); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(int& a); - -private: - void exp(int& a, int b, int c); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo(int& a) { - int b = 7; - int c = 8; - /*$*/a = b + c;/*$$*/ - return a; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& a, int b, int c) { - a = b + c; -} - -int A::foo(int& a) { - int b = 7; - int c = 8; - exp(a, b, c); - return a; -} -//!Bug 241717: Typedef causes void as return type -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -//@Test.h -#ifndef TEST_H_ -#define TEST_H_ - -class RetValueType { -}; - -typedef RetValueType RetType; - -class Test { -public: - Test(); - virtual ~Test(); -private: - void test(); -}; - -#endif /* TEST_H_ */ -//= -#ifndef TEST_H_ -#define TEST_H_ - -class RetValueType { -}; - -typedef RetValueType RetType; - -class Test { -public: - Test(); - virtual ~Test(); -private: - void test(); - RetType exp(); -}; - -#endif /* TEST_H_ */ -//@Test.cpp -#include "Test.h" - -Test::Test() { -} - -Test::~Test() { -} - -void Test::test() { - RetType v = /*$*/RetType()/*$$*/; -} - -//= -#include "Test.h" - -Test::Test() { -} - -Test::~Test() { -} - -RetType Test::exp() { - return RetType(); -} - -void Test::test() { - RetType v = exp(); -} - -//!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Classtype -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=startTag -//@testString.h -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return /*$*/"<" + name + ">"/*$$*/ + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -test::string startTag(test::string name) { - return "<" + name + ">"; -} - -test::string toXML() { - test::string name; - name = "hello"; - return startTag(name) + ""; -} - -int main() { - return 0; -} -//!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Typedef -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=startTag -//@testString.h - -namespace test { - -class string2 { -public: - friend string2 operator+(const string2& lhs, const string2& rhs) { - return rhs; - } - - string2 operator+(const string2& rhs) { return rhs; } - string2(char* cp) {} - string2() {}; -}; - -typedef string2 string; - -} -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return /*$*/"<" + name + ">"/*$$*/ + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -test::string startTag(test::string name) { - return "<" + name + ">"; -} - -test::string toXML() { - test::string name; - name = "hello"; - return startTag(name) + ""; -} - -int main() { - return 0; -} -//!Bug 248622: Extract function fails to extract several expressions; Selection at the end -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=endTag -//@testString.h - -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} - -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + ">" + /*$*/""/*$$*/; -} - -int main() { - return 0; -} - -//= -#include "testString.h" - -const char endTag(test::string name) { - return ""; -} - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + ">" + endTag(name); -} - -int main() { - return 0; -} - -//!Bug 248622: Extract function fails to extract several expressions; Selection in the middle -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=exp -//@testString.h - -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} - -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + /*$*/">" + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -const char exp() { - return ">" + ""; -} - -int main() { - return 0; -} -//!Bug#262000 Extract function misinterprets artificial blocks -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.cpp -methodname=exp -//@main.cpp -int main(int argc, char** argv) { - /*$*/int a = 0; - { - a++; - }/*$$*/ -} -//= -void exp() { - int a = 0; - { - a++; - } -} - -int main(int argc, char** argv) { - exp(); -} -//!Bug#264712 Refactor extract function deletes comments in header -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=test.cpp -methodname=exp -//@classhelper.h -// Comment -// -// Comment -// Comment -#ifndef utils_classhelper_h_seen -#define utils_classhelper_h_seen -#define IMPORTANT_VALUE 1 -#endif - -//@test.h -/* - * Copyright 2009 - */ -#ifndef test_h_seen -#define test_h_seen - -#include "classhelper.h" - -class Test { - public: - /** - * Small class with some comments - */ - Test(); - - /** Calculate important things. - * @returns the result of the calculation - */ - int calculateStuff(); - - private: - /** - * Retain a value for something. - */ - int m_value; -}; - -#endif -//= -/* - * Copyright 2009 - */ -#ifndef test_h_seen -#define test_h_seen - -#include "classhelper.h" - -class Test { - public: - /** - * Small class with some comments - */ - Test(); - - /** Calculate important things. - * @returns the result of the calculation - */ - int calculateStuff(); - - private: - /** - * Retain a value for something. - */ - int m_value; - - int exp(); -}; - -#endif -//@test.cpp -#include "test.h" - -Test::Test() {} - -int Test::calculateStuff() { - // refactor these lines to a new method: - /*$*/int result = m_value; - result += 10; - result *= 10;/*$$*/ - return result; -} - -//= -#include "test.h" - -Test::Test() {} - -int Test::exp() { - // refactor these lines to a new method: - int result = m_value; - result += 10; - result *= 10; - return result; -} - -int Test::calculateStuff() { - // refactor these lines to a new method: - int result = exp(); - return result; -} - -//!Bug#281564 Extract function fails when catching an unnamed exception -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.cpp -methodname=exp -//@main.cpp - -int myFunc() { - return 5; -} - -int main() { - int a = 0; -/*$*/try { - a = myFunc(); - } catch (const int&) { - a = 3; - }/*$$*/ - return a; -} - -//= - -int myFunc() { - return 5; -} - -void exp(int& a) { - try { - a = myFunc(); - } catch (const int&) { - a = 3; - } -} - -int main() { - int a = 0; - exp(a); - return a; -} - -//!Bug#282004 Extract function in C Project (not C++) won't extract parameters -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=exp -//@main.c -int main() { - int a,b; - /*$*/b=a*2;/*$$*/ - return a; -} -//= -void exp(int b, int a) { - b = a * 2; -} - -int main() { - int a,b; - exp(b, a); - return a; -} -//!Extract function with virtual -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -virtual=true -visibility=public -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - virtual void exp(int& i); - -private: - int help(); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - //comment - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - //comment - ++i; - help(); -} - -int A::foo() { - int i = 2; - //comment - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Bug 288268: c-refactoring creates c++-parameters -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=test -replaceduplicates=false -//@main.c -int main() { - int a, b; - /*$*/a = b * 2;/*$$*/ - return a; -} -//= -void test(int* a, int b) { - a = b * 2; -} - -int main() { - int a, b; - test(a, b); - return a; -} -//!Handling of blank lines -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=fib -replaceduplicates=false -//@main.c -int main() { - int f; - /*$*/int a = 0; - int b = 1; - - for (int i = 0; i < 10; ++i) { - int c = a + b; - a = b; - b = c; - }/*$$*/ - - f = b; -} -//= -int fib() { - int a = 0; - int b = 1; - for (int i = 0; i < 10; ++i) { - int c = a + b; - a = b; - b = c; - } - return b; -} - -int main() { - int f; - int b = fib(); - f = b; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts deleted file mode 100644 index 078efe5bced..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts +++ /dev/null @@ -1,987 +0,0 @@ -//!Extract method with duplicates -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - ++i; - help(); -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - exp(i); -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract method duplicates with different Names -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - ++oo; - help(); -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - exp(oo); -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract method duplicate with field -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=j -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - int i; - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - int i; - -private: - int help(); - int exp(int j, int& a); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int j = 0; - i++; - j++; - help(); -} - -void A::foo() { - int j = 0; - int a = 1; - /*$*/j++; - a++; - help();/*$$*/ - a++; - j++; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int j = 0; - i = exp(i, j); -} - -int A::exp(int j, int& a) { - j++; - a++; - help(); - return j; -} - -void A::foo() { - int j = 0; - int a = 1; - j = exp(j, a); - a++; - j++; -} - -int A::help() { - return 42; -} - -//!Extract method duplicate with field in marked scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=j -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - int i; - int field; - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - int i; - int field; - -private: - int help(); - int exp(int j); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int j = 0; - int a = 1; - a++; - j++; - help(); -} - -void A::foo() { - int j = 0; - - /*$*/field++; - j++; - help();/*$$*/ - field++; - j++; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int j = 0; - int a = 1; - a++; - j++; - help(); -} - -int A::exp(int j) { - field++; - j++; - help(); - return j; -} - -void A::foo() { - int j = 0; - - j = exp(j); - field++; - j++; -} - -int A::help() { - return 42; -} -//!Extract method duplicates with different names and return type -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, float& j); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - float blabla = 0; - ++oo; - blabla += 1; - help(); - blabla += 1; -} - -int A::foo() { - int i = 2; - float j = 8989; - /*$*/++i; - j+=1; - help();/*$$*/ - j++; - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - float blabla = 0; - oo = exp(oo, blabla); - blabla += 1; -} - -int A::exp(int i, float& j) { - ++i; - j += 1; - help(); - return i; -} - -int A::foo() { - int i = 2; - float j = 8989; - i = exp(i, j); - j++; - return i; -} - -int A::help() { - return 42; -} - -//!Extract method duplicates with a lot of different Names an variable not used afterwards in the duplicate -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i, float j); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - float blabla = 0; - ++oo; - blabla += 1; - help(); -} - -int A::foo() { - int i = 2; - float j = 8989; - /*$*/++i; - j+=1; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - float blabla = 0; - exp(oo, blabla); -} - -void A::exp(int& i, float j) { - ++i; - j += 1; - help(); -} - -int A::foo() { - int i = 2; - float j = 8989; - exp(i, j); - return i; -} - -int A::help() { - return 42; -} - -//!Extract method with duplicate name used afterwards in duplicate but not in original selection this is no duplicate -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - void foo(); - -private: - int help(); - void exp(int i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - ++i;// No Duplicate - help(); - ++i;// this is the reason -} - -void A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - ++i;// No Duplicate - help(); - ++i;// this is the reason -} - -void A::exp(int i) { - ++i; - help(); -} - -void A::foo() { - int i = 2; - exp(i); -} - -int A::help() { - return 42; -} - -//!Extract method with return value and a lot ref parameter and a method call -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - ++i; - b->hello(y); - i = i + x; - help(); - b->hello(y); - ++x; - i++; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - b->hello(y); - ++x; - i++; -} - -int A::exp(int i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return i; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - b->hello(y); - ++x; - return i; -} - -int A::help() { - return 42; -} -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); - void hello(float y); -}; - -#endif /*B_H_*/ -//!Extract method with return value and a lot ref parameter and a method call, duplicate is similar -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -returnvalue=i -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - ++i; - b->hello(y); - i = i + x; - help(); - b->hello(y); - ++x; - i++; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - /*$*/++i; - b->hello(y); - i = i + x; - help();/*$$*/ - b->hello(y); - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - b->hello(y); - ++x; - i++; -} - -int A::exp(int i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return i; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - i = exp(i, b, y, x); - b->hello(y); - return i; -} - -int A::help() { - return 42; -} -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); - void hello(float y); -}; - -#endif /*B_H_*/ -//!Extract method with duplicates and comments -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - ++i; - help(); -} - -int A::foo() { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int i = 2; - exp(i); -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts deleted file mode 100644 index d10e5350ec6..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts +++ /dev/null @@ -1,333 +0,0 @@ -//!ExtractFunctionHistoryRefactoringTest variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - ++i; - help(); - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp() { - int i = 2; - ++i; - help(); - return i; -} - -int A::foo() { - int i = exp(); - return i; -} - -int A::help() { - return 42; -} - -//@refScript.xml - - - - - - -//!ExtractFunctionHistoryRefactoringTest -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - //comment - ++i; - help(); - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - //comment - ++i; - help(); -} - -int A::foo() { - int i = 2; - //comment - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//@refScript.xml - - - - - -//!Extract Function History first extracted statement with leading comment -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@main.cpp -int main() { - int i; - // Comment - i = 7; - return i; -} - -//= -void exp(int& i) { - // Comment - i = 7; -} - -int main() { - int i; - // Comment - exp(i); - return i; -} - -//@refScript.xml - - - - - -//!Extract Function History extracted statement with trailing comment -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@main.cpp -int main() { - int i; - i = 7; // Comment - return i; -} - -//= -void exp(int& i) { - i = 7; // Comment -} - -int main() { - int i; - exp(i); - return i; -} - -//@refScript.xml - - - - - -//!ExtractFunctionRefactoringTest duplicates with different Names History Test -//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - ++oo; - help(); -} - -int A::foo() { - int i = 2; - ++i; - help(); - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { - int oo = 99; - exp(oo); -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//@refScript.xml - - - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts deleted file mode 100644 index 34f789a380e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts +++ /dev/null @@ -1,262 +0,0 @@ -//!ExtractFunctionRefactoringTest with FunctionStyleMacro2 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - void exp(int& ii); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -#define ADD(a,ab) a + ab + 2 + a - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int ii = 2; - /*$*/++ii; - ii = ADD(ii, 42); - help();/*$$*/ - return ii; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -#define ADD(a,ab) a + ab + 2 + a - -A::A() { -} - -A::~A() { -} - -void A::exp(int& ii) { - ++ii; - ii = ADD(ii, 42); - help(); -} - -int A::foo() { - int ii = 2; - exp(ii); - return ii; -} - -int A::help() { - return 42; -} - -//!Extract method return value assigned to macro call -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnvalue=b -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int& i, int b); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -#define ADD(b) b = b + 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - int b = 42; - /*$*/++i; - help(); - ADD(b);/*$$*/ - b += 2; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -#define ADD(b) b = b + 2 - -A::A() { -} - -A::~A() { -} - -int A::exp(int& i, int b) { - ++i; - help(); - ADD(b); - return b; -} - -int A::foo() { - int i = 2; - int b = 42; - b = exp(i, b); - b += 2; - return i; -} - -int A::help() { - return 42; -} -//!Extract method with multiple macros -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnvalue=bb -replaceduplicates=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); - int exp(int bb); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -#define ADD(b) b = b + 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - int bb = 42; - ++i; - /*$*/ADD(bb); - ADD(bb);/*$$*/ - bb += 2; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -#define ADD(b) b = b + 2 - -A::A() { -} - -A::~A() { -} - -int A::exp(int bb) { - ADD(bb); - ADD(bb); - return bb; -} - -int A::foo() { - int i = 2; - int bb = 42; - ++i; - bb = exp(bb); - bb += 2; - return i; -} - -int A::help() { - return 42; -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java index c5c02f85a9c..17b353fdd53 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; -import org.eclipse.cdt.core.tests.BaseTestFramework; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.IStatus; @@ -25,10 +24,14 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.text.TextSelection; +import org.eclipse.cdt.core.tests.BaseTestFramework; + /** + * Don't create new tests based on this class. Use RefactoringTestBase instead. + * * @author Guido Zgraggen IFS */ -public abstract class RefactoringBaseTest extends BaseTestFramework implements ILogListener{ +public abstract class RefactoringBaseTest extends BaseTestFramework implements ILogListener { protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); protected TreeMap fileMap = new TreeMap(); @@ -48,7 +51,6 @@ public abstract class RefactoringBaseTest extends BaseTestFramework implements I @Override protected abstract void runTest() throws Throwable; - @Override protected void setUp() throws Exception { @@ -96,14 +98,14 @@ public abstract class RefactoringBaseTest extends BaseTestFramework implements I @Override public void logging(IStatus status, String plugin) { Throwable ex = status.getException(); - StringBuffer stackTrace = new StringBuffer(); - if(ex != null) { + StringBuilder stackTrace = new StringBuilder(); + if (ex != null) { stackTrace.append('\n'); - for(StackTraceElement ste : ex.getStackTrace()) { + for (StackTraceElement ste : ex.getStackTrace()) { stackTrace.append(ste.toString()); } } - fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$ + fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$ } public void setFileWithSelection(String fileWithSelection) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java index 1456f22c0e1..a2ab8fefe9c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software (IFS)- initial API and implementation + * Institute for Software (IFS)- initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring; @@ -18,18 +19,18 @@ import java.util.Properties; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; -import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest; /** * @author Emanuel Graf IFS */ -public class RefactoringHistoryTest extends ExtractFunctionRefactoringTest { +public class RefactoringHistoryTest extends RefactoringTest { private TestSourceFile scriptFile; public RefactoringHistoryTest(String name, Collection files) { @@ -64,4 +65,12 @@ public class RefactoringHistoryTest extends ExtractFunctionRefactoringTest { } } } + + protected void executeRefactoring(Refactoring refactoring) throws Exception { + RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); + assertConditionsOk(finalConditions); + Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); + createChange.perform(NULL_PROGRESS_MONITOR); + compareFiles(fileMap); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java index bef2a1e6ab6..45adc3efb53 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java @@ -35,6 +35,7 @@ public abstract class RefactoringTest extends RefactoringBaseTest { protected String fileName; protected RefactoringASTCache astCache; + protected boolean fatalError; public RefactoringTest(String name, Collection files) { super(name, files); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java new file mode 100644 index 00000000000..5f7f26e8505 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.URI; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; +import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; +import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; +import org.osgi.framework.Bundle; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMManager; +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.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.ui.testplugin.CTestPlugin; + +import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; + +/** + * Common base for refactoring tests. + */ +public abstract class RefactoringTestBase extends BaseTestCase { + private static final int INDEXER_TIMEOUT_SEC = 360; + protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); + + private boolean cpp = true; + private RefactoringASTCache astCache; + private ICProject cproject; + private final Set testFiles = new LinkedHashSet(); + private TestSourceFile selectedFile; + private TextSelection selection; + private TestSourceFile historyScript; + + protected RefactoringTestBase() { + super(); + } + + protected RefactoringTestBase(String name) { + super(name); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + cproject = cpp ? + CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + Bundle bundle = CTestPlugin.getDefault().getBundle(); + CharSequence[] testData = TestSourceReader.getContentsForTest(bundle, "ui", getClass(), getName(), 0); + + for (int i = 0; i < testData.length; i++) { + CharSequence contents = testData[i]; + TestSourceFile testFile = null; + boolean expectedResult = false; + BufferedReader reader = new BufferedReader(new StringReader(contents.toString())); + String line; + while ((line = reader.readLine()) != null) { + if (testFile == null) { + testFile = new TestSourceFile(line.trim()); + } else if (isResultDelimiter(line.trim())) { + expectedResult = true; + } else if (expectedResult) { + testFile.addLineToExpectedSource(line); + } else { + testFile.addLineToSource(line); + } + } + reader.close(); + + if (!testFile.getSource().isEmpty()) { + TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()), + testFile.getSource()); + } + testFiles.add(testFile); + if (testFile.getName().endsWith(".xml")) { + historyScript = testFile; + } else if (selection == null) { + selection = testFile.getSelection(); + if (selection != null) + selectedFile = testFile; + } + } + CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, + NULL_PROGRESS_MONITOR)); + astCache = new RefactoringASTCache(); + } + + @Override + public void tearDown() throws Exception { + astCache.dispose(); + if (cproject != null) { + cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, + NULL_PROGRESS_MONITOR); + } + super.tearDown(); + } + + protected void assertRefactoringSuccess() throws Exception { + executeRefactoring(true); + compareFiles(); + } + + protected void assertRefactoringFailure() throws Exception { + executeRefactoring(false); + } + + private void executeRefactoring(boolean expectedSuccess) throws Exception { + if (historyScript != null) { + executeHistoryRefactoring(expectedSuccess); + return; + } + + Refactoring refactoring = createRefactoring(); + executeRefactoring(refactoring, true, expectedSuccess); + } + + protected void executeRefactoring(Refactoring refactoring, boolean withUserInput, + boolean expectedSuccess) throws CoreException, Exception { + RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); + if (!expectedSuccess) { + assertStatusFatalError(initialStatus); + return; + } + + assertStatusOk(initialStatus); + if (withUserInput) + simulateUserInput(); + RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); + assertStatusOk(finalStatus); + Change change = refactoring.createChange(NULL_PROGRESS_MONITOR); + change.perform(NULL_PROGRESS_MONITOR); + } + + private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception { + URI uri= URIUtil.toURI(cproject.getProject().getLocation()); + String scriptSource = historyScript.getSource().replaceAll("\\$\\{projectPath\\}", uri.getPath()); + RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory( + new ByteArrayInputStream(scriptSource.getBytes()), 0); + for (RefactoringDescriptorProxy proxy : history.getDescriptors()) { + RefactoringStatus status = new RefactoringStatus(); + Refactoring refactoring = + proxy.requestDescriptor(NULL_PROGRESS_MONITOR).createRefactoring(status); + assertTrue(status.isOK()); + executeRefactoring(refactoring, false, expectedSuccess); + } + } + + /** + * Creates a refactoring object. + */ + protected abstract Refactoring createRefactoring(); + + /** + * Subclasses can override to simulate user input. + */ + protected void simulateUserInput() { + } + + protected ICProject getCProject() { + return cproject; + } + + protected TestSourceFile getSelectedTestFile() { + return selectedFile; + } + + protected IFile getSelectedFile() { + if (selectedFile == null) + return null; + return cproject.getProject().getFile(new Path(selectedFile.getName())); + } + + protected TestSourceFile getHistoryScriptFile() { + return historyScript; + } + + protected TextSelection getSelection() { + return selection; + } + + protected boolean isCpp() { + return cpp; + } + + protected void setCpp(boolean cpp) { + this.cpp = cpp; + } + + private boolean isResultDelimiter(String str) { + if (str.isEmpty()) + return false; + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) != '=') + return false; + } + return true; + } + + protected void assertStatusOk(RefactoringStatus status) { + if (!status.isOK()) + fail("Error or warning status: " + status.getEntries()[0].getMessage()); + } + + protected void assertStatusWarning(RefactoringStatus status, int number) { + if (number > 0) { + assertTrue("Warning status expected", status.hasWarning()); + } + RefactoringStatusEntry[] entries = status.getEntries(); + int count = 0; + for (RefactoringStatusEntry entry : entries) { + if (entry.isWarning()) { + ++count; + } + } + assertEquals("Found " + count + " warnings instead of expected " + number, number, count); + } + + protected void assertStatusInfo(RefactoringStatus status, int number) { + if (number > 0) { + assertTrue("Info status expected", status.hasInfo()); + } + RefactoringStatusEntry[] entries = status.getEntries(); + int count = 0; + for (RefactoringStatusEntry entry : entries) { + if (entry.isInfo()) { + ++count; + } + } + assertEquals("Found " + count + " informational messages instead of expected " + number, number, count); + } + + protected void assertStatusError(RefactoringStatus status, int number) { + if (number > 0) { + assertTrue("Error status expected", status.hasError()); + } + RefactoringStatusEntry[] entries = status.getEntries(); + int count = 0; + for (RefactoringStatusEntry entry : entries) { + if (entry.isError()) { + ++count; + } + } + assertEquals("Found " + count + " errors instead of expected " + number, number, count); + } + + protected void assertStatusFatalError(RefactoringStatus status, int number) { + if (number > 0) { + assertTrue("Fatal error status expected", status.hasFatalError()); + } + RefactoringStatusEntry[] entries = status.getEntries(); + int count = 0; + for (RefactoringStatusEntry entry : entries) { + if (entry.isFatalError()) { + ++count; + } + } + assertEquals("Found " + count + " fatal errors instead of expected " + number, number, count); + } + + protected void assertStatusFatalError(RefactoringStatus status) { + assertTrue("Fatal error status expected", status.hasFatalError()); + } + + protected void assertEquals(TestSourceFile testFile, IFile file) throws Exception { + String actualSource = getFileContents(file); + assertEquals(testFile.getExpectedSource(), actualSource); + } + + protected void compareFiles() throws Exception { + for (TestSourceFile testFile : testFiles) { + String expectedSource = testFile.getExpectedSource(); + IFile file = cproject.getProject().getFile(new Path(testFile.getName())); + String actualSource = getFileContents(file); + assertEquals(expectedSource, actualSource); + } + } + + protected String getFileContents(IFile file) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents())); + StringBuilder code = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + code.append(line); + code.append('\n'); + } + reader.close(); + return code.toString(); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java index a7e2db024dd..404b4ddde2b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Tom Ball (Google) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring; @@ -16,7 +17,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantTestSuite; -import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionTestSuite; +import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest; import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableTestSuite; import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTestSuite; import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodTestSuite; @@ -34,7 +35,7 @@ public class RefactoringTestSuite extends TestSuite { TestSuite suite = new RefactoringTestSuite(); suite.addTest(UtilTestSuite.suite()); suite.addTest(RenameRegressionTests.suite()); - suite.addTest(ExtractFunctionTestSuite.suite()); + suite.addTest(ExtractFunctionRefactoringTest.suite()); suite.addTest(ExtractConstantTestSuite.suite()); suite.addTest(HideMethodTestSuite.suite()); suite.addTest(GenerateGettersAndSettersTestSuite.suite()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java index a2ec884cede..b5908e976c2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java index 3c6d5413b34..a5bad1bfaaf 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring; @@ -18,71 +19,77 @@ import org.eclipse.jface.text.TextSelection; /** * @author Emanuel Graf - * */ public class TestSourceFile { + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + private static final String LINE_SEPARATOR = "\n"; //$NON-NLS-1$ + private static final Pattern SELECTION_START = Pattern.compile("/\\*\\$\\*/"); //$NON-NLS-1$ + private static final Pattern SELECTION_END = Pattern.compile("/\\*\\$\\$\\*/"); //$NON-NLS-1$ - private static final String REPLACEMENT = ""; //$NON-NLS-1$ - private String name; - private StringBuffer source = new StringBuffer(); - private StringBuffer expectedSource = new StringBuffer(); - private String separator = "\n"; //$NON-NLS-1$ + private final String name; + private final StringBuilder source = new StringBuilder(); + private final StringBuilder expectedSource = new StringBuilder(); private int selectionStart = -1; private int selectionEnd = -1; - protected static final String selectionStartRegex = "/\\*\\$\\*/"; //$NON-NLS-1$ - protected static final String selectionEndRegex = "/\\*\\$\\$\\*/"; //$NON-NLS-1$ - protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$ - protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$ - public TestSourceFile(String name) { super(); this.name = name; } - public String getExpectedSource() { - String exp = expectedSource.toString(); - if(exp.length() == 0) { - return getSource(); - }else { - return exp; - } - } + public String getName() { return name; } + public String getSource() { return source.toString(); } - public void addLineToSource(String code) { - Matcher start = createMatcherFromString(selectionStartLineRegex, code); - if(start.matches()) { - selectionStart = start.start(2) + source.length(); - code = code.replaceAll(selectionStartRegex, REPLACEMENT); + public String getExpectedSource() { + if (expectedSource.length() == 0) { + return getSource(); } - Matcher end = createMatcherFromString(selectionEndLineRegex, code); - if(end.matches()) { - selectionEnd = end.start(2) + source.length(); - code = code.replaceAll(selectionEndRegex, REPLACEMENT); + return expectedSource.toString(); + } + + public void addLineToSource(String code) { + Matcher start = SELECTION_START.matcher(code); + if (start.find()) { + selectionStart = start.start() + source.length(); + code = start.replaceAll(EMPTY_STRING); + } + Matcher end = SELECTION_END.matcher(code); + if (end.find()) { + selectionEnd = end.start() + source.length(); + code = end.replaceAll(EMPTY_STRING); } source.append(code); - source.append(separator); + source.append(LINE_SEPARATOR); } public void addLineToExpectedSource(String code) { expectedSource.append(code); - expectedSource.append(separator); + expectedSource.append(LINE_SEPARATOR); } public TextSelection getSelection() { - if(selectionStart < 0 || selectionEnd <0 ) { + if (selectionStart < 0 || selectionEnd < selectionStart) return null; - }else { - return new TextSelection(selectionStart, selectionEnd -selectionStart); - } + return new TextSelection(selectionStart, selectionEnd - selectionStart); } - protected static Matcher createMatcherFromString(String pattern, String line) { - return Pattern.compile(pattern).matcher(line); + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + TestSourceFile other = (TestSourceFile) obj; + return name.equals(other.name); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java index 020a2bcc54d..d1aeb10eaa7 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,90 +12,4190 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.extractfunction; -import java.util.Collection; -import java.util.Properties; +import junit.framework.Test; -import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; -import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionInformation; import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; /** - * @author Emanuel Graf + * Tests for Extract Function refactoring. */ -public class ExtractFunctionRefactoringTest extends RefactoringTest { - protected String methodName; - protected boolean replaceDuplicates; - protected String returnValue; - protected int returnParameterIndex; - protected boolean fatalError; - private VisibilityEnum visibility; +public class ExtractFunctionRefactoringTest extends RefactoringTestBase { + private ExtractFunctionInformation refactoringInfo; + private String extractedFunctionName = "extracted"; + private String returnValue; + private VisibilityEnum visibility = VisibilityEnum.v_private; private boolean virtual; - private static int nr = 1; + private boolean replaceDuplicates = true; - public ExtractFunctionRefactoringTest(String name, Collection files) { - super(name, files); + public ExtractFunctionRefactoringTest() { + super(); + } + + public ExtractFunctionRefactoringTest(String name) { + super(name); + } + + public static Test suite() { + return suite(ExtractFunctionRefactoringTest.class); } @Override - protected void runTest() throws Throwable { - IFile refFile = project.getFile(fileName); - ExtractFunctionInformation info = new ExtractFunctionInformation(); - CRefactoring refactoring = new ExtractFunctionRefactoring(refFile, selection, info, cproject); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - - if (fatalError) { - assertConditionsFatalError(checkInitialConditions); - return; - } else { - assertConditionsOk(checkInitialConditions); - setValues(info); - executeRefactoring(refactoring); - } + protected Refactoring createRefactoring() { + refactoringInfo = new ExtractFunctionInformation(); + return new ExtractFunctionRefactoring(getSelectedFile(), getSelection(), refactoringInfo, + getCProject()); } - protected void executeRefactoring(Refactoring refactoring) throws Exception { - RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR); - assertConditionsOk(finalConditions); - Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR); - createChange.perform(NULL_PROGRESS_MONITOR); - compareFiles(fileMap); - } - - private void setValues(ExtractFunctionInformation info) { - info.setMethodName(methodName); - info.setReplaceDuplicates(replaceDuplicates); - if (info.getMandatoryReturnVariable() == null) { + @Override + protected void simulateUserInput() { + refactoringInfo.setMethodName(extractedFunctionName); + refactoringInfo.setReplaceDuplicates(replaceDuplicates); + if (refactoringInfo.getMandatoryReturnVariable() == null) { if (returnValue != null) { - for (NameInformation nameInfo : info.getParameterCandidates()) { + for (NameInformation nameInfo : refactoringInfo.getParameterCandidates()) { if (returnValue.equals(String.valueOf(nameInfo.getName().getSimpleID()))) { - info.setReturnVariable(nameInfo); + refactoringInfo.setReturnVariable(nameInfo); nameInfo.setUserSetIsReference(false); break; } } } } - info.setVisibility(visibility); - info.setVirtual(virtual); + refactoringInfo.setVisibility(visibility); + refactoringInfo.setVirtual(virtual); } - @Override - protected void configureRefactoring(Properties refactoringProperties) { - methodName = refactoringProperties.getProperty("methodname", "exp"); //$NON-NLS-1$ //$NON-NLS-2$ - replaceDuplicates = Boolean.valueOf(refactoringProperties.getProperty("replaceduplicates", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ - returnValue = refactoringProperties.getProperty("returnvalue", null); //$NON-NLS-1$ - fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ - visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_private.toString())); //$NON-NLS-1$ - virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // /*$*/int i = 2; + // ++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = extracted(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testVariableDefinedInside() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // //comment + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // // Comment + // /*$*/i= 7;/*$$*/ + // return i; + //} + //==================== + //void extracted(int& i) { + // // Comment + // i = 7; + //} + // + //int main() { + // int i; + // // Comment + // extracted(i); + // return i; + //} + public void testFirstExtractedStatementWithLeadingComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // /*$*/i= 7;/*$$*/ // Comment + // return i; + //} + //==================== + //void extracted(int& i) { + // i = 7; // Comment + //} + // + //int main() { + // int i; + // extracted(i); + // return i; + //} + public void testLastExtractedStatementWithTraillingComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // /*$*/int o = 1; + // int i = 2; + // ++i; + // o++; + // help();/*$$*/ + // o++; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithTwoVariableDefinedInScope() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + // void extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::foo() { + // /*$*/b = new B(); + // help();/*$$*/ + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted() { + // b = new B(); + // help(); + //} + // + //void A::foo() { + // extracted(); + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + //}; + // + //#endif /*B_H_*/ + public void testWithNamedTypedField() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + // void extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::foo() { + // /*$*/b = new B(); + // help();/*$$*/ + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted() { + // b = new B(); + // help(); + //} + // + //void A::foo() { + // extracted(); + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + //}; + // + //#endif /*B_H_*/ + public void testWithNamedTypedVariableDefinedInScope() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ZWO 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // i += ZWO; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ZWO 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // i += ZWO; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithObjectStyleMacro() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ADD(a,b) a + b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // i = ADD(i, 42); + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ADD(a,b) a + b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // i = ADD(i, 42); + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithFunctionStyleMacro() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int* i = new int(2); + // /*$*/++*i; + // help();/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // int* i = new int(2); + // extracted(i); + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointer() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int* i = new int(2); + // /*$*/++*i; + // help(); + // //A end-comment/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // int* i = new int(2); + // extracted(i); + // //A end-comment + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointerAndCommentAtTheEnd() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // //A beautiful comment + // int* i = new int(2); + // /*$*/++*i; + // help();/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // //A beautiful comment + // int* i = new int(2); + // extracted(i); + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointerAndComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int i) { + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // i = extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValue() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, int b); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // int b = i; + // /*$*/++i; + // i = i + b; + // help();/*$$*/ + // ++b; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int i, int b) { + // ++i; + // i = i + b; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // int b = i; + // i = extracted(i, b); + // ++b; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValueAndRefParameter() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValueAndRefParameterAndSomeMoreNotUsedAfterwards() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // float extracted(int& i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //float A::extracted(int& i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return x; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // x = extracted(i, b, y, x); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + // void hello(float y); + //}; + // + //#endif /*B_H_*/ + public void testWithReturnValueTakeTheSecondAndRefParameterAndSomeMoreNotUsedAferwards() throws Exception { + returnValue = "x"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + // void hello(float y); + //}; + // + //#endif /*B_H_*/ + public void testWithReturnValueAndALotRefParameter() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // B* extracted(int& i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //B* A::extracted(int& i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return b; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // b = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + // void hello(float y); + //}; + // + //#endif /*B_H_*/ + public void testWithReturnValueTakeTheSecondAndRefParameter() throws Exception { + returnValue = "b"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //protected: + // void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithProtectedVisibility() throws Exception { + visibility = VisibilityEnum.v_protected; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPublicVisibility() throws Exception { + visibility = VisibilityEnum.v_public; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo() const; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo() const; + // + //private: + // int help(); + // void extracted(int& i) const; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() const { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) const { + // ++i; + // help(); + //} + // + //int A::foo() const { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithConstMethod() throws Exception { + assertRefactoringSuccess(); + } + + //main.h + //void method() { + // /*$*/for (int var = 0; var < 100; ++var) { + // if (var < 50) + // continue; + // }/*$$*/ + //} + //==================== + //void loop() { + // for (int var = 0; var < 100; ++var) { + // if (var < 50) + // continue; + // } + //} + // + //void method() { + // loop(); + //} + public void testDontReturnVariablesThatArentUsed() throws Exception { + extractedFunctionName = "loop"; + assertRefactoringSuccess(); + } + + //main.h + //void method() { + // /*$*/if (true) + // return;/*$$*/ + // //unreachable + //} + public void testDontExtractCodeThatContainsReturn() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //void function() { + // for (int var = 0; var < 100; ++var) { + // /*$*/if (var < 50) + // continue;/*$$*/ + // } + //} + public void testTestIfWeDontAllowToExtractContinue() throws Exception { + assertRefactoringFailure(); + } + + //Test.cpp + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void testFuerRainer() { + // int i = int(); + // /*$*/++i; + // //Leading Comment + // ASSERT(i); + // //Trailling Comment + // --i;/*$$*/ + //} + //==================== + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void runTest(int i) { + // ++i; + // //Leading Comment + // ASSERT(i); + // //Trailling Comment + // --i; + //} + // + //void testFuerRainer() { + // int i = int(); + // runTest(i); + //} + public void testExtractFunctionWithAMacroCallInSelectedCodeForgetsTheMacro() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //Test.cpp + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void testFuerRainer() { + // int i = int(); + // /*$*/++i; + // ASSERT(i); + // --i;/*$$*/ + //} + //==================== + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void runTest(int i) { + // ++i; + // ASSERT(i); + // --i; + //} + // + //void testFuerRainer() { + // int i = int(); + // runTest(i); + //} + public void testWithCommentsExtractFunctionWithAMacroCallInSelectedCodeForgetsTheMacro() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //Test.cpp + //#include + // + //using namespace std; + // + //int const INITIAL_CAPACITY = 10; + // + //int main() { + // int m_capacity; + // /*$*/m_capacity += INITIAL_CAPACITY; + // string* newElements = new string[m_capacity];/*$$*/ + // newElements[0] = "s"; + //} + //==================== + //#include + // + //using namespace std; + // + //int const INITIAL_CAPACITY = 10; + // + //string* runTest(int m_capacity) { + // m_capacity += INITIAL_CAPACITY; + // string* newElements = new string[m_capacity]; + // return newElements; + //} + // + //int main() { + // int m_capacity; + // string* newElements = runTest(m_capacity); + // newElements[0] = "s"; + //} + public void testStringArrayProblemInExtractFunction() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(int& a); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(int& a); + // + //private: + // void extracted(int& a, int b, int c); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo(int& a) { + // int b = 7; + // int c = 8; + // /*$*/a = b + c;/*$$*/ + // return a; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& a, int b, int c) { + // a = b + c; + //} + // + //int A::foo(int& a) { + // int b = 7; + // int c = 8; + // extracted(a, b, c); + // return a; + //} + public void testBug239059DoubleAmpersandInSignatureOfExtractedFunctions() throws Exception { + assertRefactoringSuccess(); + } + + //Test.h + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class RetValueType { + //}; + // + //typedef RetValueType RetType; + // + //class Test { + //public: + // Test(); + // virtual ~Test(); + //private: + // void test(); + //}; + // + //#endif /* TEST_H_ */ + //==================== + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class RetValueType { + //}; + // + //typedef RetValueType RetType; + // + //class Test { + //public: + // Test(); + // virtual ~Test(); + //private: + // void test(); + // RetType extracted(); + //}; + // + //#endif /* TEST_H_ */ + + //Test.cpp + //#include "Test.h" + // + //Test::Test() { + //} + // + //Test::~Test() { + //} + // + //void Test::test() { + // RetType v = /*$*/RetType()/*$$*/; + //} + //==================== + //#include "Test.h" + // + //Test::Test() { + //} + // + //Test::~Test() { + //} + // + //RetType Test::extracted() { + // return RetType(); + //} + // + //void Test::test() { + // RetType v = extracted(); + //} + public void testBug241717TypedefCausesVoidAsReturnType() throws Exception { + assertRefactoringSuccess(); + } + + //testString.h + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return /*$*/"<" + name + ">"/*$$*/ + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //test::string startTag(test::string name) { + // return "<" + name + ">"; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return startTag(name) + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248238ExtractMethodProducesWrongReturnTypeOrJustFailsClasstype() throws Exception { + extractedFunctionName = "startTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string2 { + //public: + // friend string2 operator+(const string2& lhs, const string2& rhs) { + // return rhs; + // } + // + // string2 operator+(const string2& rhs) { return rhs; } + // string2(char* cp) {} + // string2() {}; + //}; + // + //typedef string2 string; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return /*$*/"<" + name + ">"/*$$*/ + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //test::string startTag(test::string name) { + // return "<" + name + ">"; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return startTag(name) + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248238ExtractMethodProducesWrongReturnTypeOrJustFailsTypedef() throws Exception { + extractedFunctionName = "startTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + ">" + /*$*/""/*$$*/; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //const char endTag(test::string name) { + // return ""; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + ">" + endTag(name); + //} + // + //int main() { + // return 0; + //} + public void testBug248622ExtractFunctionFailsToExtractSeveralExpressionsSelectionAtTheEnd() throws Exception { + extractedFunctionName = "endTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + /*$*/">" + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //const char extracted() { + // return ">" + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248622ExtractFunctionFailsToExtractSeveralExpressionsSelectionInTheMiddle() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main(int argc, char** argv) { + // /*$*/int a = 0; + // { + // a++; + // }/*$$*/ + //} + //==================== + //void extracted() { + // int a = 0; + // { + // a++; + // } + //} + // + //int main(int argc, char** argv) { + // extracted(); + //} + public void testBug262000ExtractFunctionMisinterpretsArtificialBlocks() throws Exception { + assertRefactoringSuccess(); + } + + //classhelper.h + //// Comment + //// + //// Comment + //// Comment + //#ifndef utils_classhelper_h_seen + //#define utils_classhelper_h_seen + //#define IMPORTANT_VALUE 1 + //#endif + + //test.h + ///* + // * Copyright 2009 + // */ + //#ifndef test_h_seen + //#define test_h_seen + // + //#include "classhelper.h" + // + //class Test { + // public: + // /** + // * Small class with some comments + // */ + // Test(); + // + // /** Calculate important things. + // * @returns the result of the calculation + // */ + // int calculateStuff(); + // + // private: + // /** + // * Retain a value for something. + // */ + // int m_value; + //}; + // + //#endif + //==================== + ///* + // * Copyright 2009 + // */ + //#ifndef test_h_seen + //#define test_h_seen + // + //#include "classhelper.h" + // + //class Test { + // public: + // /** + // * Small class with some comments + // */ + // Test(); + // + // /** Calculate important things. + // * @returns the result of the calculation + // */ + // int calculateStuff(); + // + // private: + // /** + // * Retain a value for something. + // */ + // int m_value; + // + // int extracted(); + //}; + // + //#endif + + //test.cpp + //#include "test.h" + // + //Test::Test() {} + // + //int Test::calculateStuff() { + // // refactor these lines to a new method: + // /*$*/int result = m_value; + // result += 10; + // result *= 10;/*$$*/ + // return result; + //} + //==================== + //#include "test.h" + // + //Test::Test() {} + // + //int Test::extracted() { + // // refactor these lines to a new method: + // int result = m_value; + // result += 10; + // result *= 10; + // return result; + //} + // + //int Test::calculateStuff() { + // // refactor these lines to a new method: + // int result = extracted(); + // return result; + //} + public void testBug264712ExtractFunctionDeletesCommentsInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + // + //int myFunc() { + // return 5; + //} + // + //int main() { + // int a = 0; + ///*$*/try { + // a = myFunc(); + // } catch (const int&) { + // a = 3; + // }/*$$*/ + // return a; + //} + //==================== + // + //int myFunc() { + // return 5; + //} + // + //void extracted(int& a) { + // try { + // a = myFunc(); + // } catch (const int&) { + // a = 3; + // } + //} + // + //int main() { + // int a = 0; + // extracted(a); + // return a; + //} + public void testBug281564ExtractFunctionFailsWhenCatchingAnUnnamedException() throws Exception { + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int a,b; + // /*$*/b=a*2;/*$$*/ + // return a; + //} + //==================== + //void extracted(int b, int a) { + // b = a * 2; + //} + // + //int main() { + // int a,b; + // extracted(b, a); + // return a; + //} + public void testBug282004ExtractFunctionInCProjectNotCPPWontExtractParameters() throws Exception { + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int a, b; + // /*$*/a = b * 2;/*$$*/ + // return a; + //} + //==================== + //void extracted(int* a, int b) { + // a = b * 2; + //} + // + //int main() { + // int a, b; + // extracted(a, b); + // return a; + //} + public void testBug288268CRefactoringCreatesCPPParameters() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // virtual void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // //comment + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithVirtual() throws Exception { + visibility = VisibilityEnum.v_public; + virtual = true; + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int f; + // /*$*/int a = 0; + // int b = 1; + // + // for (int i = 0; i < 10; ++i) { + // int c = a + b; + // a = b; + // b = c; + // }/*$$*/ + // + // f = b; + //} + //==================== + //int fib() { + // int a = 0; + // int b = 1; + // for (int i = 0; i < 10; ++i) { + // int c = a + b; + // a = b; + // b = c; + // } + // return b; + //} + // + //int main() { + // int f; + // int b = fib(); + // f = b; + //} + public void testHandlingOfBlankLines() throws Exception { + extractedFunctionName = "fib"; + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct() { + // T i; + // i = 0; + // /*$*/i++; + // i += 3;/*$$*/ + // + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //void extracted(T i) { + // i++; + // i += 3; + //} + // + //template + //int tempFunct() { + // T i; + // i = 0; + // extracted(i); + // return 0; + //} + public void testTemplateFunction() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct(T p) { + // /*$*/++p; + // p + 4;/*$$*/ + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //void extracted(T p) { + // ++p; + // p + 4; + //} + // + //template + //int tempFunct(T p) { + // extracted(p); + // return 0; + //} + public void testTemplateFunctionWithTemplateParameter() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct() { + // /*$*/T p; + // p = 0; + // p + 4;/*$$*/ + // p + 2; + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //T extracted() { + // T p; + // p = 0; + // p + 4; + // return p; + //} + // + //template + //int tempFunct() { + // T p = extracted(); + // p + 2; + // return 0; + //} + public void testTemplateFunctionWithTemplateTypeDeclaration() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // extracted(i); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicates() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // ++oo; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // extracted(oo); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithDifferentNames() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // int i; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // int i; + // + //private: + // int help(); + // int extracted(int j, int& a); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int j = 0; + // i++; + // j++; + // help(); + //} + // + //void A::foo() { + // int j = 0; + // int a = 1; + // /*$*/j++; + // a++; + // help();/*$$*/ + // a++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int j = 0; + // i = extracted(i, j); + //} + // + //int A::extracted(int j, int& a) { + // j++; + // a++; + // help(); + // return j; + //} + // + //void A::foo() { + // int j = 0; + // int a = 1; + // j = extracted(j, a); + // a++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicateWithField() throws Exception { + returnValue = "j"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // int i; + // int field; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // int i; + // int field; + // + //private: + // int help(); + // int extracted(int j); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int j = 0; + // int a = 1; + // a++; + // j++; + // help(); + //} + // + //void A::foo() { + // int j = 0; + // + // /*$*/field++; + // j++; + // help();/*$$*/ + // field++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int j = 0; + // int a = 1; + // a++; + // j++; + // help(); + //} + // + //int A::extracted(int j) { + // field++; + // j++; + // help(); + // return j; + //} + // + //void A::foo() { + // int j = 0; + // + // j = extracted(j); + // field++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicateWithFieldInMarkedScope() throws Exception { + returnValue = "j"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, float& j); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // float blabla = 0; + // ++oo; + // blabla += 1; + // help(); + // blabla += 1; + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // /*$*/++i; + // j+=1; + // help();/*$$*/ + // j++; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // float blabla = 0; + // oo = extracted(oo, blabla); + // blabla += 1; + //} + // + //int A::extracted(int i, float& j) { + // ++i; + // j += 1; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // i = extracted(i, j); + // j++; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithDifferentNamesAndReturnType() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i, float j); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // float blabla = 0; + // ++oo; + // blabla += 1; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // /*$*/++i; + // j+=1; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // float blabla = 0; + // extracted(oo, blabla); + //} + // + //void A::extracted(int& i, float j) { + // ++i; + // j += 1; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // extracted(i, j); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithALotOfDifferentNamesAnVariableNotUsedAfterwardsInTheDuplicate() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // + //private: + // int help(); + // void extracted(int i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // ++i;// No Duplicate + // help(); + // ++i;// this is the reason + //} + // + //void A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // ++i;// No Duplicate + // help(); + // ++i;// this is the reason + //} + // + //void A::extracted(int i) { + // ++i; + // help(); + //} + // + //void A::foo() { + // int i = 2; + // extracted(i); + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicateNameUsedAfterwardsInDuplicateButNotInOriginalSelectionThisIsNoDuplicate() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::extracted(int i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + // void hello(float y); + //}; + // + //#endif /*B_H_*/ + public void testWithReturnValueAndALotRefParameterAndAMethodCall() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // /*$*/++i; + // b->hello(y); + // i = i + x; + // help();/*$$*/ + // b->hello(y); + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::extracted(int i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // i = extracted(i, b, y, x); + // b->hello(y); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + // void hello(float y); + //}; + // + //#endif /*B_H_*/ + public void testWithReturnValueAndALotRefParameterAndAMethodCallDuplicateIsSimilar() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int i = 2; + // extracted(i); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicatesAndComments() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& ii); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ADD(a,ab) a + ab + 2 + a + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int ii = 2; + // /*$*/++ii; + // ii = ADD(ii, 42); + // help();/*$$*/ + // return ii; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ADD(a,ab) a + ab + 2 + a + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& ii) { + // ++ii; + // ii = ADD(ii, 42); + // help(); + //} + // + //int A::foo() { + // int ii = 2; + // extracted(ii); + // return ii; + //} + // + //int A::help() { + // return 42; + //} + public void testExtractFunctionRefactoringTestWithFunctionStyleMacro2() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int& i, int b); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ADD(b) b = b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // int b = 42; + // /*$*/++i; + // help(); + // ADD(b);/*$$*/ + // b += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ADD(b) b = b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int& i, int b) { + // ++i; + // help(); + // ADD(b); + // return b; + //} + // + //int A::foo() { + // int i = 2; + // int b = 42; + // b = extracted(i, b); + // b += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testReturnValueAssignedToMacroCall() throws Exception { + returnValue = "b"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(int bb); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ADD(b) b = b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // int bb = 42; + // ++i; + // /*$*/ADD(bb); + // ADD(bb);/*$$*/ + // bb += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ADD(b) b = b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int bb) { + // ADD(bb); + // ADD(bb); + // return bb; + //} + // + //int A::foo() { + // int i = 2; + // int bb = 42; + // ++i; + // bb = extracted(bb); + // bb += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithMultipleMacros() throws Exception { + returnValue = "bb"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // int extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = extracted(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + // + public void testExtractFunctionHistoryRefactoringTestVariableDefinedInScope() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // //comment + // ++i; + // help(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + public void testExtractFunctionHistoryRefactoringTest() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // // Comment + // i = 7; + // return i; + //} + //==================== + //void extracted(int& i) { + // // Comment + // i = 7; + //} + // + //int main() { + // int i; + // // Comment + // extracted(i); + // return i; + //} + + //refactoringScript.xml + // + // + // + // + public void testHistoryFirstExtractedStatementWithLeadingComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // i = 7; // Comment + // return i; + //} + //==================== + //void extracted(int& i) { + // i = 7; // Comment + //} + // + //int main() { + // int i; + // extracted(i); + // return i; + //} + + //refactoringScript.xml + // + // + // + // + public void testHistoryExtractedStatementWithTrailingComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + // void extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // ++oo; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + // int oo = 99; + // extracted(oo); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + public void testExtractFunctionRefactoringTestDuplicatesWithDifferentNamesHistoryTest() throws Exception { + assertRefactoringSuccess(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java deleted file mode 100644 index 42d36bc0513..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik - * Rapperswil, University of applied sciences 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: - * Institute for Software - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.refactoring.extractfunction; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester; - -/** - * @author Emanuel Graf - */ -public class ExtractFunctionTestSuite extends TestSuite { - - @SuppressWarnings("nls") - public static Test suite() throws Exception { - TestSuite suite = new ExtractFunctionTestSuite(); - suite.addTest(RefactoringTester.suite("ExtractMethod.rts", "resources/refactoring/ExtractMethod.rts")); - suite.addTest(RefactoringTester.suite("ExtractExpression.rts", "resources/refactoring/ExtractExpression.rts")); - suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessor.rts", "resources/refactoring/ExtractMethodPreprocessor.rts")); - suite.addTest(RefactoringTester.suite("ExtractFunctionTemplates.rts", "resources/refactoring/ExtractFunctionTemplates.rts")); - suite.addTest(RefactoringTester.suite("ExtractMethodHistory.rts", "resources/refactoring/ExtractMethodHistory.rts")); - suite.addTest(RefactoringTester.suite("ExtractFunctionDuplicates.rts", "resources/refactoring/ExtractMethodDuplicates.rts")); - return suite; - } -} diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 93187917aaf..6ec55947c06 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -632,3 +632,6 @@ transfer.EditorBehavior.description = Preference related to how the editor proce RefreshExclusionContributor.name = Resources extension-point.name = Refresh Exclusion Contributor + +# New New Project Wizard +newProjectWizard.name = C/C++ Project (new) diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index d8fb40ee3bf..49118077b2c 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -455,6 +455,17 @@ %Cproject.desc + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index d7691a06d7e..6ab5dc189f7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -1241,7 +1241,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC if (IndexerPreferences.KEY_INDEX_ON_OPEN.equals(event.getKey())) { ICElement element= getInputCElement(); ITranslationUnit tu = element != null ? (ITranslationUnit) element : null; - updateIndexInclusion(tu, false); + updateIndexInclusion(tu); } } @@ -1520,32 +1520,25 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC if (element instanceof ITranslationUnit) { ITranslationUnit tu = (ITranslationUnit) element; - updateIndexInclusion(tu, false); + updateIndexInclusion(tu); fBracketMatcher.configure(tu.getLanguage()); } else { - updateIndexInclusion(null, false); + updateIndexInclusion(null); fBracketMatcher.configure(null); } } - private void updateIndexInclusion(ITranslationUnit tu, boolean synchronous) { - if (tu!= null) { + private void updateIndexInclusion(ITranslationUnit tu) { + if (tu != null) { IProject project = tu.getCProject().getProject(); if (!String.valueOf(true).equals(IndexerPreferences.get(project, IndexerPreferences.KEY_INDEX_ON_OPEN, null))) { tu = null; } } - if (tu != null || fTuAddedToIndex != null) { + if ((tu != null || fTuAddedToIndex != null) && tu != fTuAddedToIndex) { IndexUpdateRequestorJob job = new IndexUpdateRequestorJob(tu, fTuAddedToIndex); fTuAddedToIndex = tu; job.schedule(); - if (synchronous) { - try { - job.join(); - } catch (InterruptedException e) { - // Ignore. - } - } } } @@ -2215,7 +2208,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC @Override public void dispose() { fIndexerPreferenceListener.unregister(); - updateIndexInclusion(null, true); + updateIndexInclusion(null); ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java index 80721b725ad..df67cc2f7c8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2012 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 @@ -233,6 +233,14 @@ public abstract class AbstractCompareViewerInformationControl extends org.eclips } } + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + if (!visible) { + setInput(null); + } + } + @Override public void dispose() { if (!fIsSystemBackgroundColor) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java index 0122af6f4cd..d392356e60a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 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 @@ -199,20 +199,21 @@ class CMacroCompareViewer extends CMergeViewer { fLeftViewer.setRedraw(false); fRightViewer.setRedraw(false); } - final ReplaceEdit[] edits; + ReplaceEdit[] edits = null; try { - final IMacroExpansionStep step; - if (fStepIndex < fInput.fExplorer.getExpansionStepCount()) { - step= fInput.fExplorer.getExpansionStep(fStepIndex); - } else { - step= fInput.fExplorer.getFullExpansion(); - } - edits= step.getReplacements(); - - fLeftHighlighter.setReplaceEdits(fPrefixLength, edits); - fRightHighlighter.setReplaceEdits(fPrefixLength, edits); + if (fInput != null) { + final IMacroExpansionStep step; + if (fStepIndex < fInput.fExplorer.getExpansionStepCount()) { + step= fInput.fExplorer.getExpansionStep(fStepIndex); + } else { + step= fInput.fExplorer.getFullExpansion(); + } + edits= step.getReplacements(); + fLeftHighlighter.setReplaceEdits(fPrefixLength, edits); + fRightHighlighter.setReplaceEdits(fPrefixLength, edits); + } super.setInput(input); } finally { @@ -221,7 +222,7 @@ class CMacroCompareViewer extends CMergeViewer { fRightViewer.setRedraw(true); } } - if (edits.length > 0) { + if (edits != null && edits.length > 0) { if (fLeftViewer != null && fRightViewer != null) { final int firstDiffOffset= fPrefixLength + edits[0].getOffset(); fLeftViewer.revealRange(firstDiffOffset, edits[0].getLength()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java index 10b2d813551..2ee273679d5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2012 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 @@ -64,10 +64,19 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr fInput= macroExpansionInput; updateStatusText(); } else { + fInput = null; super.setInput(input); } } + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + if (!visible) { + setInput(null); + } + } + private void updateStatusText() { if (fInput == null) { return; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java index 9b0ee8018c4..888bd2050a5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2012 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 @@ -450,11 +450,14 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo public void setInput(Object input) { if (input instanceof CMacroExpansionInput) { setMacroExpansionInput((CMacroExpansionInput) input); - } else { + } else if (input != null) { if (fMacroCompareViewer != null) { fMacroCompareViewer.setMacroExpansionStep(fIndex); } super.setInput(input); + } else { + setMacroExpansionInput(null); + super.setInput(input); } } @@ -507,6 +510,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo */ private void setMacroExpansionInput(CMacroExpansionInput input) { fInput= input; + if (fMacroCompareViewer != null) { + fMacroCompareViewer.setMacroExpansionInput(input); + } if (fInput != null) { fIndex= fixIndex(input.fStartWithFullExpansion ? getStepCount() : 0); showExpansion(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/Messages.java new file mode 100644 index 00000000000..37a94c7a97a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/Messages.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River 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: + * Doug Schaefer - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.wizards; + +import org.eclipse.osgi.util.NLS; + +class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.wizards.messages"; //$NON-NLS-1$ + public static String NewCDTProjectWizard_mainPageDesc; + public static String NewCDTProjectWizard_mainPageTitle; + public static String NewCDTProjectWizard_refPageDesc; + public static String NewCDTProjectWizard_refPageTitle; + public static String NewCDTProjectWizard_templatePageDesc; + public static String NewCDTProjectWizard_templatePageTitle; + public static String NewCDTProjectWizard_windowTitle; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewCDTProjectWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewCDTProjectWizard.java new file mode 100644 index 00000000000..eb0336db322 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewCDTProjectWizard.java @@ -0,0 +1,84 @@ +package org.eclipse.cdt.ui.wizards; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; +import org.eclipse.ui.dialogs.WizardNewProjectReferencePage; + +/** + * This is the new CDT project wizard. + * + * Without subclassing, it is in it's most generic form. + * + * Subclasses can filter or select the languages and add template filters. + * + * @author Doug Schaefer + * @since 5.4 + */ +public class NewCDTProjectWizard extends Wizard implements INewWizard { + + private IStructuredSelection selection; + private WizardNewProjectCreationPage mainPage; + private TemplateSelectionPage templatePage; + private WizardNewProjectReferencePage referencePage; + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + setNeedsProgressMonitor(true); + setWindowTitle(Messages.NewCDTProjectWizard_windowTitle); + } + + @Override + public boolean performFinish() { + return true; + } + + @Override + public void addPages() { + super.addPages(); + + mainPage = new WizardNewProjectCreationPage("basicNewProjectPage") { //$NON-NLS-1$ + @Override + public void createControl(Composite parent) { + super.createControl(parent); + createWorkingSetGroup( + (Composite) getControl(), + selection, + new String[] { "org.eclipse.ui.resourceWorkingSetPage", //$NON-NLS-1$ + "org.eclipse.cdt.ui.CElementWorkingSetPage" }); //$NON-NLS-1$ + Dialog.applyDialogFont(getControl()); + } + }; + mainPage.setTitle(Messages.NewCDTProjectWizard_mainPageTitle); + mainPage.setDescription(Messages.NewCDTProjectWizard_mainPageDesc); + addPage(mainPage); + + templatePage = new TemplateSelectionPage(); + templatePage.setTitle(Messages.NewCDTProjectWizard_templatePageTitle); + templatePage.setDescription(Messages.NewCDTProjectWizard_templatePageDesc); + addPage(templatePage); + + // only add page if there are already projects in the workspace + if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length > 0) { + referencePage = new WizardNewProjectReferencePage( + "basicReferenceProjectPage");//$NON-NLS-1$ + referencePage.setTitle(Messages.NewCDTProjectWizard_refPageTitle); + referencePage + .setDescription(Messages.NewCDTProjectWizard_refPageDesc); + this.addPage(referencePage); + } + } + + @Override + public boolean canFinish() { + // TODO make sure we have everything in place first. + return false; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java new file mode 100644 index 00000000000..7ca68f75895 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/TemplateSelectionPage.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River 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: + * Doug Schaefer - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.ui.wizards; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.List; + +import org.eclipse.cdt.ui.templateengine.Template; +import org.eclipse.cdt.ui.templateengine.TemplateEngineUI; + +/** + * @author Dad + * @since 5.4 + */ +public class TemplateSelectionPage extends WizardPage { + + public TemplateSelectionPage() { + super("templateSelection"); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout(1, false)); + + List templateList = new List(comp, SWT.BORDER); + templateList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + Template[] templates = TemplateEngineUI.getDefault().getTemplates(); + for (Template template : templates) { + templateList.add(template.getLabel()); + } + + setControl(comp); + } + + @Override + public boolean isPageComplete() { + return true; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/messages.properties new file mode 100644 index 00000000000..e44a79ce2d9 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/messages.properties @@ -0,0 +1,17 @@ +################################################################################# +# Copyright (c) 2012 Wind River 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: +# Doug Schaefer - initial API and implementation +################################################################################# +NewCDTProjectWizard_mainPageDesc=Create a new C/C++ Project +NewCDTProjectWizard_mainPageTitle=Project +NewCDTProjectWizard_refPageDesc=Select referenced projects +NewCDTProjectWizard_refPageTitle=Project References +NewCDTProjectWizard_templatePageDesc=Select a project template for the new project +NewCDTProjectWizard_templatePageTitle=Project Template +NewCDTProjectWizard_windowTitle=New C/C++ Project diff --git a/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF b/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF index dda9260a6e2..2f7d271d536 100644 --- a/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF +++ b/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.launch.remote;singleton:=true -Bundle-Version: 2.3.0.qualifier +Bundle-Version: 2.4.0.qualifier Bundle-Activator: org.eclipse.cdt.internal.launch.remote.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)", diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java index 949bcc36e38..20198fcd040 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2009, 2010 MontaVista Software, Inc. and others. + * Copyright (c) 2009, 2012 MontaVista Software, Inc. and others. * 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 @@ -8,6 +8,7 @@ * Anna Dushistova (MontaVista) - initial API and implementation * Anna Dushistova (Mentor Graphics) - [314659] moved common methods for DSF and CDI launches to this class * Anna Dushistova (Mentor Graphics) - changed spaceEscapify visibility + * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work ********************************************************************************/ package org.eclipse.cdt.launch.remote; @@ -283,6 +284,42 @@ public class RSEHelper { return p; } + public static IHostShell execCmdInRemoteShell(ILaunchConfiguration config, + String prelaunchCmd, String remoteCommandPath, String arguments, + IProgressMonitor monitor) throws Exception { + // The exit command is called to force the remote shell to close after + // our command + // is executed. This is to prevent a running process at the end of the + // debug session. + // See Bug 158786. + monitor.beginTask(NLS.bind(Messages.RemoteRunLaunchDelegate_8, + remoteCommandPath, arguments), 10); + String realRemoteCommand = arguments == null ? spaceEscapify(remoteCommandPath) + : spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$ + + String remoteCommand = realRemoteCommand + CMD_DELIMITER + EXIT_CMD; + + if (!prelaunchCmd.trim().equals("")) //$NON-NLS-1$ + remoteCommand = prelaunchCmd + CMD_DELIMITER + remoteCommand; + + IShellService shellService = null; + shellService = (IShellService) RSEHelper + .getConnectedRemoteShellService(getCurrentConnection(config), + new SubProgressMonitor(monitor, 7)); + + // This is necessary because runCommand does not actually run the + // command right now. + String env[] = new String[0]; + IHostShell hostShell = null; + if (shellService != null) { + hostShell = shellService.launchShell( + "", env, new SubProgressMonitor(monitor, 3)); //$NON-NLS-1$ + hostShell.writeToShell(remoteCommand); + } + monitor.done(); + return hostShell; + } + public static String getRemoteHostname(ILaunchConfiguration config) throws CoreException { IHost currentConnection = getCurrentConnection(config); diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java index b57b929960a..600eac3d7f9 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Mentor Graphics Corporation and others. + * Copyright (c) 2010, 2012 Mentor Graphics Corporation 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 @@ -8,12 +8,21 @@ * Contributors: * Anna Dushistova (Mentor Graphics) - initial API and implementation * Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching + * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work *******************************************************************************/ package org.eclipse.cdt.launch.remote.launching; +import java.util.concurrent.RejectedExecutionException; + import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate; +import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; import org.eclipse.cdt.internal.launch.remote.Activator; import org.eclipse.cdt.internal.launch.remote.Messages; import org.eclipse.cdt.launch.remote.IRemoteConnectionConfigurationConstants; @@ -30,6 +39,8 @@ import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.services.shells.HostShellProcessAdapter; +import org.eclipse.rse.services.shells.IHostShell; public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate { @@ -77,13 +88,56 @@ public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate { if (arguments != null && !arguments.equals("")) //$NON-NLS-1$ commandArguments += " " + arguments; //$NON-NLS-1$ monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9); - remoteShellProcess = RSEHelper.remoteShellExec(config, - prelaunchCmd, gdbserverCommand, commandArguments, - new SubProgressMonitor(monitor, 5)); + // extending HostShellProcessAdapter here + final GdbLaunch l = (GdbLaunch)launch; + IHostShell remoteShell = null; + try { + remoteShell = RSEHelper.execCmdInRemoteShell(config, prelaunchCmd, + gdbserverCommand, commandArguments, + new SubProgressMonitor(monitor, 5)); + } catch (Exception e1) { + RSEHelper.abort(e1.getMessage(), e1, + ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); + + } + try { + remoteShellProcess = new HostShellProcessAdapter(remoteShell) { + + @Override + public synchronized void destroy() { + final DsfSession session = l.getSession(); + if (session != null) { + try { + session.getExecutor().execute(new DsfRunnable() { + public void run() { + DsfServicesTracker tracker = new DsfServicesTracker( + Activator.getBundleContext(), + session.getId()); + IGDBControl control = tracker + .getService(IGDBControl.class); + if (control != null) { + control.terminate(new ImmediateRequestMonitor()); + } + tracker.dispose(); + } + }); + } catch (RejectedExecutionException e) { + // Session disposed. + } + } + super.destroy(); + } + }; + } catch (Exception e) { + if (remoteShellProcess != null) { + remoteShellProcess.destroy(); + } + RSEHelper.abort(Messages.RemoteRunLaunchDelegate_7, e, + ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); + } DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell); - // 3. Let debugger know how gdbserver was started on the remote ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java index 1128c7cb1dd..7feb8327f7e 100644 --- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java +++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 PalmSource, Inc. and others. + * Copyright (c) 2006, 2012 PalmSource, 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 @@ -18,6 +18,7 @@ * Anna Dushistova (MontaVista) - [267951][remotecdt] Support systemTypes without files subsystem * Anna Dushistova (Mentor Graphics) - [314659]Fixed deprecated methods * Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching + * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work *******************************************************************************/ package org.eclipse.cdt.launch.remote.launching; @@ -53,9 +54,13 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.IProcess; import org.eclipse.osgi.util.NLS; import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.services.shells.HostShellProcessAdapter; +import org.eclipse.rse.services.shells.IHostShell; public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { + private ICDISession dsession; + /* * (non-Javadoc) * @@ -103,7 +108,7 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { if (debugMode .equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { Process remoteShellProcess = null; - ICDISession dsession = null; + dsession = null; try { // Download the binary to the remote before debugging. monitor.setTaskName(Messages.RemoteRunLaunchDelegate_2); @@ -127,10 +132,38 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { if (arguments != null && !arguments.equals("")) //$NON-NLS-1$ command_arguments += " " + arguments; //$NON-NLS-1$ monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9); - remoteShellProcess = RSEHelper.remoteShellExec(config, - prelaunchCmd, gdbserver_command, - command_arguments, new SubProgressMonitor( - monitor, 5)); + IHostShell remoteShell = null; + try { + remoteShell = RSEHelper.execCmdInRemoteShell(config, prelaunchCmd, + gdbserver_command, command_arguments, + new SubProgressMonitor(monitor, 5)); + } catch (Exception e1) { + RSEHelper.abort(e1.getMessage(), e1, + ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); + } + + try { + remoteShellProcess = new HostShellProcessAdapter(remoteShell) { + + @Override + public synchronized void destroy() { + ICDISession session = getSession(); + if (session != null) { + try { + session.terminate(); + } catch (CDIException e) { + } + } + super.destroy(); + } + }; + } catch (Exception e) { + if (remoteShellProcess != null) { + remoteShellProcess.destroy(); + } + RSEHelper.abort(Messages.RemoteRunLaunchDelegate_7, e, + ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); + } DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell); @@ -239,4 +272,8 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { protected String getPluginID() { return Activator.PLUGIN_ID; } + + ICDISession getSession(){ + return dsession; + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataReadMemoryInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataReadMemoryInfo.java index 7c3871c5d40..1ba3776c21a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataReadMemoryInfo.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataReadMemoryInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2012 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 @@ -9,6 +9,7 @@ * QNX Software Systems - Initial API and implementation * Ericsson AB - Modified for new DSF Reference Implementation * Ericsson AB - Reverted to byte[] and processed multi-line results + * Harish Dewan (Tensilica Inc) - Bug 369377: Output for command should include value of 'nr-bytes' field *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.output; @@ -139,7 +140,7 @@ public class MIDataReadMemoryInfo extends MIInfo { } // Parse 'nr-bytes="x"', the number of bytes read - if (var.equals("total-bytes")) { //$NON-NLS-1$ + if (var.equals("nr-bytes")) { //$NON-NLS-1$ MIValue value = results[i].getMIValue(); if (value instanceof MIConst) { String size = ((MIConst) value).getCString(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThread.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThread.java index f718950a327..caf4351b5e6 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThread.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThread.java @@ -124,6 +124,7 @@ public class MIThread { private static Pattern fgOsIdPattern1 = Pattern.compile("([Tt][Hh][Rr][Ee][Aa][Dd]\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\([Ll][Ww][Pp]\\s*)(\\d*)", 0); //$NON-NLS-1$ private static Pattern fgOsIdPattern2 = Pattern.compile("[Tt][Hh][Rr][Ee][Aa][Dd]\\s*\\d+\\.(\\d+)", 0); //$NON-NLS-1$ private static Pattern fgOsIdPattern3 = Pattern.compile("[Tt][Hh][Rr][Ee][Aa][Dd]\\s*(\\S+)", 0); //$NON-NLS-1$ + private static Pattern fgOsIdPattern4 = Pattern.compile("[Pp][Rr][Oo][Cc][Ee][Ss][Ss]\\s*(\\S+)", 0); //$NON-NLS-1$ static String parseOsId(String str) { // General format: @@ -132,6 +133,8 @@ public class MIThread { // "Thread 162.32942" // ^^^^^ // "thread abc123" + // + // "process 12345" => Linux without pthread. The process as one thread, the process thread. // ^^^^^^ // PLEASE UPDATE MIThreadTests.java IF YOU TWEAK THIS CODE @@ -150,6 +153,11 @@ public class MIThread { return matcher.group(1); } + matcher = fgOsIdPattern4.matcher(str); + if (matcher.find()) { + return matcher.group(1); + } + return null; } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThreadTests.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThreadTests.java index d0bde2e256c..e057709132f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThreadTests.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIThreadTests.java @@ -12,6 +12,7 @@ public class MIThreadTests { assertEquals("abc123", MIThread.parseOsId("Thread abc123")); assertEquals("abc123", MIThread.parseOsId("thread abc123")); assertEquals("abc123", MIThread.parseOsId("THREAD abc123")); + assertEquals("abc123", MIThread.parseOsId("process abc123")); } @Test diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuites.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuites.java index 11b0e62c9d0..190c8121157 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuites.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuites.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Ericsson and others. + * Copyright (c) 2009, 2012 Ericsson 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 @@ -17,6 +17,7 @@ import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_0.Suite_7_0; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_1.Suite_7_1; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_2.Suite_7_2; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.Suite_7_3; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4.Suite_7_4; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -31,6 +32,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ + Suite_7_4.class, Suite_7_3.class, Suite_7_2.class, Suite_7_1.class, diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuitesRemote.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuitesRemote.java index 95e0000a21c..9ed0cec870f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuitesRemote.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/AllSuitesRemote.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson and others. + * Copyright (c) 2009, 2012 Ericsson 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 @@ -17,6 +17,7 @@ import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_0.Suite_Remote_7_0; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_1.Suite_Remote_7_1; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_2.Suite_Remote_7_2; import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.Suite_Remote_7_3; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4.Suite_Remote_7_4; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -31,6 +32,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ + Suite_Remote_7_4.class, Suite_Remote_7_3.class, Suite_Remote_7_2.class, Suite_Remote_7_1.class, diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/ITestConstants.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/ITestConstants.java index c4a86faabd3..397b33e35cd 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/ITestConstants.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/ITestConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Ericsson and others. + * Copyright (c) 2010, 2012 Ericsson 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: * Ericsson AB - Initial implementation of Test cases + * Marc Khouzam (Ericsson) - Tests for GDB 7.4 *******************************************************************************/ package org.eclipse.cdt.tests.dsf.gdb.tests; @@ -19,4 +20,5 @@ public interface ITestConstants { public static final String SUFFIX_GDB_7_1 = "7.1"; public static final String SUFFIX_GDB_7_2 = "7.2"; public static final String SUFFIX_GDB_7_3 = "7.3"; + public static final String SUFFIX_GDB_7_4 = "7.4"; } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBProcessesTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBProcessesTest_7_4.java new file mode 100644 index 00000000000..44e68f58bb1 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBProcessesTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.GDBProcessesTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class GDBProcessesTest_7_4 extends GDBProcessesTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBRemoteTracepointsTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBRemoteTracepointsTest_7_4.java new file mode 100644 index 00000000000..88685869a63 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/GDBRemoteTracepointsTest_7_4.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.GDBRemoteTracepointsTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class GDBRemoteTracepointsTest_7_4 extends GDBRemoteTracepointsTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/LaunchConfigurationAndRestartTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/LaunchConfigurationAndRestartTest_7_4.java new file mode 100644 index 00000000000..cc8b077ccf7 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/LaunchConfigurationAndRestartTest_7_4.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.LaunchConfigurationAndRestartTest_7_3; +import org.junit.Before; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class LaunchConfigurationAndRestartTest_7_4 extends LaunchConfigurationAndRestartTest_7_3 { + // For the launch config test, we must set the attributes in the @Before method + // instead of the @BeforeClass method. This is because the attributes are overwritten + // by the tests themselves + @Before + public void beforeMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIBreakpointsTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIBreakpointsTest_7_4.java new file mode 100644 index 00000000000..11a8a64f340 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIBreakpointsTest_7_4.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext; +import org.eclipse.cdt.dsf.mi.service.MIBreakpointDMData; +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIBreakpointsTest_7_3; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIBreakpointsTest_7_4 extends MIBreakpointsTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } + + /* + * Starting with GDB 7.4, breakpoints at invalid lines succeed and become + * pending breakpoints. This is because the invalid line for one file, + * may be valid for another file with the same name. + * One could argue that line 0 is an exception, but GDB does not make + * a difference. + * @see org.eclipse.cdt.tests.dsf.gdb.tests.MIBreakpointsTest#insertBreakpoint_InvalidLineNumber() + */ + @Override + @Test + public void insertBreakpoint_InvalidLineNumber() throws Throwable { + + // Create a line breakpoint + Map breakpoint = new HashMap(); + breakpoint.put(BREAKPOINT_TYPE_TAG, BREAKPOINT_TAG); + breakpoint.put(FILE_NAME_TAG, SOURCE_FILE); + breakpoint.put(LINE_NUMBER_TAG, 0); + + // Perform the test + IBreakpointDMContext ref = insertBreakpoint(fBreakpointsDmc, breakpoint); + assertTrue(fWait.getMessage(), fWait.isOK()); + + // Ensure that no BreakpointEvent was received + assertTrue("BreakpointEvent problem: expected " + 1 + " BREAKPOINT event(s), received " + + fBreakpointEventCount, fBreakpointEventCount == 1); + + MIBreakpointDMData bpData = (MIBreakpointDMData) getBreakpoint(ref); + assertTrue("Breakpoint should be pending", bpData.isPending()); + assertTrue("Breakpoint mismatch should be enabled", bpData.isEnabled()); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MICatchpointsTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MICatchpointsTest_7_4.java new file mode 100644 index 00000000000..d2add7c5181 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MICatchpointsTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MICatchpointsTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MICatchpointsTest_7_4 extends MICatchpointsTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIDisassemblyTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIDisassemblyTest_7_4.java new file mode 100644 index 00000000000..2ec30061829 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIDisassemblyTest_7_4.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ + +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIDisassemblyTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + + +@RunWith(BackgroundRunner.class) +public class MIDisassemblyTest_7_4 extends MIDisassemblyTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIExpressionsTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIExpressionsTest_7_4.java new file mode 100644 index 00000000000..cfd0d8364a1 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIExpressionsTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIExpressionsTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIExpressionsTest_7_4 extends MIExpressionsTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIMemoryTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIMemoryTest_7_4.java new file mode 100644 index 00000000000..905fb54d741 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIMemoryTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIMemoryTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIMemoryTest_7_4 extends MIMemoryTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRegistersTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRegistersTest_7_4.java new file mode 100644 index 00000000000..c1b70c304c2 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRegistersTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIRegistersTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIRegistersTest_7_4 extends MIRegistersTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlNonStopTargetAvailableTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlNonStopTargetAvailableTest_7_4.java new file mode 100644 index 00000000000..77c7189be49 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlNonStopTargetAvailableTest_7_4.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIRunControlNonStopTargetAvailableTest_7_4 extends MIRunControlTargetAvailableTest_7_4 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + setLaunchAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_NON_STOP, true); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTargetAvailableTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTargetAvailableTest_7_4.java new file mode 100644 index 00000000000..d94fbfed507 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTargetAvailableTest_7_4.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIRunControlTargetAvailableTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIRunControlTargetAvailableTest_7_4 extends MIRunControlTargetAvailableTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTest_7_4.java new file mode 100644 index 00000000000..9b0aab9a87b --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/MIRunControlTest_7_4.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.MIRunControlTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class MIRunControlTest_7_4 extends MIRunControlTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningNonStopTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningNonStopTest_7_4.java new file mode 100644 index 00000000000..b9ccc2fa7ac --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningNonStopTest_7_4.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class OperationsWhileTargetIsRunningNonStopTest_7_4 extends OperationsWhileTargetIsRunningTest_7_4 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + setLaunchAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_NON_STOP, true); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningTest_7_4.java new file mode 100644 index 00000000000..0c9125389f7 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/OperationsWhileTargetIsRunningTest_7_4.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.OperationsWhileTargetIsRunningTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class OperationsWhileTargetIsRunningTest_7_4 extends OperationsWhileTargetIsRunningTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/PostMortemCoreTest_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/PostMortemCoreTest_7_4.java new file mode 100644 index 00000000000..d84b22e8f2c --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/PostMortemCoreTest_7_4.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3.PostMortemCoreTest_7_3; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +@RunWith(BackgroundRunner.class) +public class PostMortemCoreTest_7_4 extends PostMortemCoreTest_7_3 { + @BeforeClass + public static void beforeClassMethod_7_4() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_4); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_7_4.java new file mode 100644 index 00000000000..791e64e404b --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_7_4.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.dsf.mi.service.command.commands.Suite_Sessionless_Tests; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * This class is meant to be empty. It enables us to define + * the annotations which list all the different JUnit class we + * want to run. When creating a new test class, it should be + * added to the list below. + * + * This suite is for tests to be run with GDB 7.4 + */ + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + // We need specific name for the tests of this suite, because of bug https://bugs.eclipse.org/172256 + MIRegistersTest_7_4.class, + MIRunControlTest_7_4.class, + MIRunControlTargetAvailableTest_7_4.class, + MIRunControlNonStopTargetAvailableTest_7_4.class, + MIExpressionsTest_7_4.class, + MIMemoryTest_7_4.class, + MIBreakpointsTest_7_4.class, + MICatchpointsTest_7_4.class, + MIDisassemblyTest_7_4.class, + GDBProcessesTest_7_4.class, + LaunchConfigurationAndRestartTest_7_4.class, + OperationsWhileTargetIsRunningTest_7_4.class, + OperationsWhileTargetIsRunningNonStopTest_7_4.class, + PostMortemCoreTest_7_4.class, + Suite_Sessionless_Tests.class + /* Add your test class here */ +}) + +public class Suite_7_4 {} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_Remote_7_4.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_Remote_7_4.java new file mode 100644 index 00000000000..ce61ef09780 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_4/Suite_Remote_7_4.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial implementation of Test cases + *******************************************************************************/ +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4; + +import org.eclipse.cdt.dsf.mi.service.command.commands.Suite_Sessionless_Tests; +import org.eclipse.cdt.tests.dsf.gdb.framework.BaseRemoteSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * This class is meant to be empty. It enables us to define + * the annotations which list all the different JUnit class we + * want to run. When creating a new test class, it should be + * added to the list below. + * + * This suite is for tests to be run with GDB 7.4 + */ + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + // We need specific name for the tests of this suite, because of bug https://bugs.eclipse.org/172256 + GDBRemoteTracepointsTest_7_4.class, + MIRegistersTest_7_4.class, + MIRunControlTest_7_4.class, + MIRunControlTargetAvailableTest_7_4.class, + MIRunControlNonStopTargetAvailableTest_7_4.class, + MIExpressionsTest_7_4.class, + MIMemoryTest_7_4.class, + MIBreakpointsTest_7_4.class, + MICatchpointsTest_7_4.class, + MIDisassemblyTest_7_4.class, + GDBProcessesTest_7_4.class, + OperationsWhileTargetIsRunningTest_7_4.class, + OperationsWhileTargetIsRunningNonStopTest_7_4.class, + Suite_Sessionless_Tests.class + /* Add your test class here */ +}) + +public class Suite_Remote_7_4 extends BaseRemoteSuite { +}