diff options
author | Sergey Prigogin | 2011-12-23 23:57:35 +0000 |
---|---|---|
committer | Sergey Prigogin | 2011-12-23 23:57:35 +0000 |
commit | 2ee14c041ca14ab7e2e8a382f8e4981b51c4cf63 (patch) | |
tree | c91768f79b4b4340b8522ed22d0f7ebf7d106172 /core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt | |
parent | 46e94156ee3e704bd585a3bd84c8f875f13ee356 (diff) | |
download | org.eclipse.cdt-2ee14c041ca14ab7e2e8a382f8e4981b51c4cf63.tar.gz org.eclipse.cdt-2ee14c041ca14ab7e2e8a382f8e4981b51c4cf63.tar.xz org.eclipse.cdt-2ee14c041ca14ab7e2e8a382f8e4981b51c4cf63.zip |
Moved template engine tests to org.eclipse.cdt.ui.tests plug-in since
they fail in headless mode due to loading of
TestExtraPagesProvider.java
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt')
9 files changed, 796 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/AllTemplateEngineTests.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/AllTemplateEngineTests.java new file mode 100644 index 00000000000..3643398cb32 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/AllTemplateEngineTests.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2009 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is a TestSuite, the TestCases created to test Template engine are + * added to testsuite. + * The test suite will execute all the Testcases added to the Suite. + * + * @since 4.0 + */ +public class AllTemplateEngineTests extends TestSuite { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTemplateEngineTests.suite()); + } + + /** + * Since the TemplateEngine consists of UI(Wizard). + * A TestWizard is created to which the dynamically generated + * UIPages are added. The Wizard is launched from here. + * The TestCases created to test the TemplateEngine is initialized here. + * @return + * + * @since 4.0 + */ + public static Test suite() { + TestSuite suite = new TestSuite("Template engine tests"); //$NON-NLS-1$ + //$JUnit-BEGIN$ + + suite.addTestSuite(TestTemplateEngine.class); + suite.addTestSuite(TestTemplateCore.class); + suite.addTestSuite(TestValueStore.class); + suite.addTestSuite(TestSharedDefaults.class); + suite.addTestSuite(TestProcesses.class); + suite.addTestSuite(TestTemplateEngineBugs.class); + + //$JUnit-END$ + return suite; + } +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TemplateEngineTestsHelper.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TemplateEngineTestsHelper.java new file mode 100644 index 00000000000..85c01af5ec7 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TemplateEngineTestsHelper.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateDescriptor; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.core.testplugin.CTestPlugin; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + +/** + * + * All supporting functions which are not part of Testing class. + * + * @since 4.0 +*/ + +public class TemplateEngineTestsHelper { + + public static final String LOGGER_FILE_NAME="TemplateEngineTests"; //$NON-NLS-1$ + + /** + * get the url of a xml template, by passing the xml file name. + * @param templateName + * @return URL + */ + public static URL getTemplateURL(String templateName){ + Bundle bundle = Platform.getBundle(CTestPlugin.PLUGIN_ID); + URL url = FileLocator.find(bundle, new Path("resources/templateengine/"+templateName), null); //$NON-NLS-1$ + if ( url != null ) + { + try { + url = FileLocator.toFileURL(url); + } catch (IOException e) { + e.printStackTrace(); + } + } + return url; + } + + public static TemplateCore[] getTestTemplates() { + TemplateCore[] templates = TemplateEngine.getDefault().getTemplates(); + List testTemplates = new ArrayList(); + for (int i =0; i < templates.length; i++) { + if (templates[i].getTemplateType().equals("TestTemplate")) { + testTemplates.add(templates[i]); + } + } + return (TemplateCore[]) testTemplates.toArray(new TemplateCore[testTemplates.size()]); + } + + public static int getChildCount(TemplateDescriptor templateDescriptor, String propertyGroupID){ + List list = templateDescriptor.getPropertyGroupList(); + for (int i = 0, l = list.size(); i < l; i++) { + Element element = (Element) list.get(i); + NamedNodeMap attributes = element.getAttributes(); + for (int j = 0, l1 = attributes.getLength(); j < l1; j++) { + String value = attributes.item(j).getNodeValue(); + if (value.equals(propertyGroupID)) { + return TemplateEngine.getChildrenOfElement(element).size(); + } + } + } + return 0; + } + + public static boolean failIfErrorStatus(IStatus[] statuses) { + for(int i=0; i<statuses.length; i++) { + IStatus status = statuses[i]; + if (status.getCode() == IStatus.ERROR) { + Assert.fail(status.getMessage()); + return true; + } + IStatus[] children = status.getChildren(); + if (children != null) { + if (failIfErrorStatus(children)) { + return true; + } + } + } + return false; + } + + public static void turnOffAutoBuild() throws CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceDescription workspaceDesc = workspace.getDescription(); + workspaceDesc.setAutoBuilding(false); + workspace.setDescription(workspaceDesc); + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestExtraPagesProvider.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestExtraPagesProvider.java index d7258b5dd13..6be562644ac 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestExtraPagesProvider.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestExtraPagesProvider.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial API and implementation + * Andrew Ferguson (Symbian) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.templateengine; @@ -49,7 +49,7 @@ public class TestExtraPagesProvider implements IPagesAfterTemplateSelectionProvi * An example implementation of {@link IWizardDataPage} for test purposes. */ static class MyPage extends AbstractWizardDataPage implements IWizardDataPage { - String labelText , dataKey, dataValue; + String labelText, dataKey, dataValue; public MyPage(String labelText, String dataKey, String dataValue) { super("CustomTestPageName", "Title", null); @@ -59,7 +59,7 @@ public class TestExtraPagesProvider implements IPagesAfterTemplateSelectionProvi this.dataValue= dataValue; } - public Map getPageData() { + public Map<String, String> getPageData() { return Collections.singletonMap(dataKey, dataValue); } diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestProcesses.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestProcesses.java new file mode 100644 index 00000000000..83842d838e0 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestProcesses.java @@ -0,0 +1,260 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import java.io.File; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; + +public class TestProcesses extends BaseTestCase { + + private static final String workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString(); + private static final String PROJECT_NAME = "TemplateEngineTestsProject"; //$NON-NLS-1$ + private static final String SOURCE_FOLDER = "Source"; //$NON-NLS-1$ + private static final String FILE_NAME = "File"; //$NON-NLS-1$ + private static final String LINK = "Link"; //$NON-NLS-1$ + private static final String CPP_EXT = ".cpp"; //$NON-NLS-1$ + private static final String H_EXT = ".h"; //$NON-NLS-1$ + + private static final String PROJECT_TYPE = "org.eclipse.cdt.core.tests.projectType"; //$NON-NLS-1$ + + protected void setUp() throws Exception { + TemplateEngineTestsHelper.turnOffAutoBuild(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + IPath projectLocation = project.getRawLocation(); + + if (project.exists()) { + project.delete(true, true, null); + } + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProjectDescription description = workspace.newProjectDescription(project.getName()); + + if ((projectLocation != null) && (!projectLocation.equals(Platform.getLocation()))) { + description.setLocation(projectLocation); + } + + CCorePlugin.getDefault().createCDTProject(description, project, null); + if (!project.isOpen()) { + project.open(null); + } + + } + + public void testAddFile() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*AddFile"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + H_EXT); + assertTrue(file.exists()); + } + + public void testAddFiles() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*AddFiles"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + H_EXT); + assertTrue(file.exists()); + } + + public void testAddLink() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*AddLink"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + try { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + project.refreshLocal(1, null); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + LINK + CPP_EXT); + assertTrue(file.exists()); + } catch (CoreException e) { + fail(e.getMessage()); + } + } + + public void testAppend() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*Append"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + valueStore.put("targetSourceName", workspaceLocation + File.separator + PROJECT_NAME + File.separator + FILE_NAME + CPP_EXT); //$NON-NLS-1$ + valueStore.put("targetHeaderName", workspaceLocation + File.separator + PROJECT_NAME + File.separator + FILE_NAME + H_EXT); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + try { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + project.refreshLocal(1, null); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + H_EXT); + assertTrue(file.exists()); + } catch (CoreException e) { + fail(e.getMessage()); + } + } + + public void testAppendCreate() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*AppendCreate"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + valueStore.put("targetSourceName", FILE_NAME + CPP_EXT); //$NON-NLS-1$ + valueStore.put("targetHeaderName", FILE_NAME + H_EXT); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + H_EXT); + assertTrue(file.exists()); + } + + public void testCopy() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*Copy"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("baseName", FILE_NAME); //$NON-NLS-1$ + + valueStore.put("targetSourceName", workspaceLocation + File.separator + PROJECT_NAME + File.separator + FILE_NAME + CPP_EXT); //$NON-NLS-1$ + valueStore.put("targetHeaderName", workspaceLocation + File.separator + PROJECT_NAME + File.separator + FILE_NAME + H_EXT); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + try { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + project.refreshLocal(1, null); + IFile file = project.getFile(FILE_NAME + CPP_EXT); + assertTrue(file.exists()); + file = project.getFile(FILE_NAME + H_EXT); + assertTrue(file.exists()); + } catch (CoreException e) { + fail(e.getMessage()); + } + } + + public void testCreateResourceIdentifier() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*CreateResourceIdentifier"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("valueName1", "baseName1"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("appName1", "Hello"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("valueName2", "baseName2"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("appName2", "He"); //$NON-NLS-1$ //$NON-NLS-2$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + IFile file = project.getFile("HELL" + CPP_EXT); //$NON-NLS-1$ + assertTrue(file.exists()); + file = project.getFile("HEXX" + CPP_EXT); //$NON-NLS-1$ + assertTrue(file.exists()); + } + + public void testCreateSourceFolder() { + TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*CreateSourceFolder"); //$NON-NLS-1$ + Map valueStore = template.getValueStore(); + valueStore.put("projectName", PROJECT_NAME); //$NON-NLS-1$ + valueStore.put("projectType", PROJECT_TYPE); //$NON-NLS-1$ + valueStore.put("location", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("isCProject", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + valueStore.put("sourceDir1", SOURCE_FOLDER + 1); //$NON-NLS-1$ + valueStore.put("sourceDir2", SOURCE_FOLDER + 2); //$NON-NLS-1$ + + if (TemplateEngineTestsHelper.failIfErrorStatus(template.executeTemplateProcesses(null, false))) { + return; + } + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME); + assertTrue(project.exists()); + IFolder folder = project.getFolder(SOURCE_FOLDER + 1); + assertTrue(folder.exists()); + folder = project.getFolder(SOURCE_FOLDER + 2); + assertTrue(folder.exists()); + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestSharedDefaults.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestSharedDefaults.java new file mode 100644 index 00000000000..bbc11e44872 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestSharedDefaults.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.eclipse.cdt.core.templateengine.SharedDefaults; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; + + +/** +* Executes all the test cases of SharedDefaults backend functionality +*/ + +public class TestSharedDefaults extends BaseTestCase { + private SharedDefaults sharedDefaults; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + sharedDefaults = SharedDefaults.getInstance(); + } + + /* + * @see TestCase#tearDown() + */ + + protected void tearDown(){ + sharedDefaults = null; + } + + /** + * This test checks if data gets added to the back end + * New data gets persisted in SharedDefault XML file + */ + + public void testAddToBackEndStorage() { + Map actualSharedDefaults=sharedDefaults.getSharedDefaultsMap(); + + actualSharedDefaults.put("provider.name","eclipse"); //$NON-NLS-1$ //$NON-NLS-2$ + actualSharedDefaults.put("copyright","Symbian Software Ltd."); //$NON-NLS-1$ //$NON-NLS-2$ + actualSharedDefaults.put("author","Bala Torati"); //$NON-NLS-1$ //$NON-NLS-2$ + + Map expectedSharedDefaults=sharedDefaults.getSharedDefaultsMap(); + + assertEquals("Contents are different :", //$NON-NLS-1$ + expectedSharedDefaults, + actualSharedDefaults); + + } + + + /** + * This tests the updateToBackEndStorage of SharedDefaults + * to verify whether the key-value pair gets updated with new value + * New data gets persisted in SharedDefault XML file + */ + + public void testUpdateToBackEndStorage() { + Map actualSharedDefaults = sharedDefaults.getSharedDefaultsMap(); + Set keySet = actualSharedDefaults.keySet(); + Iterator iterator = keySet.iterator(); + + while (iterator.hasNext()) { + Object key = iterator.next(); + Object value = actualSharedDefaults.get(key); + String keyName = (String)key; + String valueName = (String)value; + if (keyName.equals("org.eclipse.cdt.templateengine.project.HelloWorld.basename")){ //$NON-NLS-1$ + valueName = "Astala Vista"; //$NON-NLS-1$ + actualSharedDefaults.put(keyName, valueName); + sharedDefaults.updateToBackEndStorage("org.eclipse.cdt.templateengine.project.HelloWorld.basename", valueName); //$NON-NLS-1$ + } + } + + Map expectedSharedDefaults=sharedDefaults.getSharedDefaultsMap(); + + assertEquals("Contents are different :", //$NON-NLS-1$ + expectedSharedDefaults, + actualSharedDefaults); + } + + /** + * This tests the deleteBackEndStorage of SharedDefaults + * to verify whether the key-value pair gets deleted at the backend + */ + + public void testDeleteBackEndStorage() { + Map actualSharedDefaults=sharedDefaults.getSharedDefaultsMap(); + Set keySet = actualSharedDefaults.keySet(); + Iterator iterator = keySet.iterator(); + String keyName = null; + + while (iterator.hasNext()) { + + Object key = iterator.next(); + keyName = (String)key; + if (keyName.equals("org.eclipse.cdt.templateengine.project.HelloWorld.basename")) { //$NON-NLS-1$ + actualSharedDefaults.remove(keyName); + break; + } + } + + sharedDefaults.deleteBackEndStorage(new String[]{keyName}); + Map expectedSharedDefaults=sharedDefaults.getSharedDefaultsMap(); + + assertEquals("Contents are different :", //$NON-NLS-1$ + expectedSharedDefaults, + actualSharedDefaults); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateCore.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateCore.java new file mode 100644 index 00000000000..c4b53a0ef7c --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateCore.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; + +/** + * Test the functionality of Tempalte Class. + */ +public class TestTemplateCore extends BaseTestCase { + + public TemplateCore[] templates = null; + + protected void setUp() throws Exception { + super.setUp(); + templates = TemplateEngineTestsHelper.getTestTemplates(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Constructor for Template. + * @param name + */ + public TestTemplateCore(String name) { + super(name); + } + + /** + * check that the Template contains a Non Null ValueStore + */ + public void testValueStoreNotNull(){ + for (int i=0; i < templates.length; i++) { + assertNotNull(templates[i].getValueStore()); + } + } + + /** + * Check the IDs to be persisited in SharedDefaults. + */ + public void testPersistTrueIDs(){ + for (int i=0; i < templates.length; i++) { + assertNotNull(templates[i].getPersistTrueIDs()); + } + } + + public void testGetAllMissingMacrosInProcesses(){ + for (int i=0; i < templates.length; i++) { + assertNotNull(templates[i].getAllMissingMacrosInProcesses()); + assertTrue(templates[i].getAllMissingMacrosInProcesses().size() > 0); + } + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngine.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngine.java new file mode 100644 index 00000000000..85cbaab95b0 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngine.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; + +/** + * Test the functionality of TemplateEngine. + */ +public class TestTemplateEngine extends BaseTestCase { + TemplateEngine templateEngine = null; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + templateEngine = TemplateEngine.getDefault(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Constructor for TestTemplateEngine. + * @param name + */ + public TestTemplateEngine(String name) { + super(name); + } + + /** + * check for non null SharedDefaults + * + */ + public void testSharedDefaults() { + assertNotNull(TemplateEngine.getSharedDefaults()); + } + + /** + * check that the instance is created once(Singleton). + */ + public void testSingleton() { + assertSame(templateEngine, TemplateEngine.getDefault()); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngineBugs.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngineBugs.java new file mode 100644 index 00000000000..da1edf430b6 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestTemplateEngineBugs.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Symbian Software Limited and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial Implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.cdt.core.templateengine.process.ProcessHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; + +public class TestTemplateEngineBugs extends BaseTestCase { + + public void testBug215283() { + assertEquals(set("a"), ProcessHelper.getReplaceKeys("$(a)")); + assertEquals(set("a","b"), ProcessHelper.getReplaceKeys("$(a)$(b)")); + assertEquals(set("a","b","cc","ddd"), ProcessHelper.getReplaceKeys("$(a)$(b)$(cc)$(ddd)")); + assertEquals(set("aaa","b","c","dd"), ProcessHelper.getReplaceKeys("$(aaa)$(b)$(c)$(dd)")); + assertEquals(set("a"), ProcessHelper.getReplaceKeys("($(a))")); + assertEquals(set("a","b"), ProcessHelper.getReplaceKeys("$(b)$(a)")); + assertEquals(set("a"), ProcessHelper.getReplaceKeys(" \n$(a)")); + assertEquals(set("a"), ProcessHelper.getReplaceKeys("$(a) ")); + } + + private Set<String> set(String ... s) { + HashSet<String> result= new HashSet<String>(); + result.addAll(Arrays.asList(s)); + return result; + } +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestValueStore.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestValueStore.java new file mode 100644 index 00000000000..739e890d603 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/templateengine/TestValueStore.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Limited 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: + * Bala Torati (Symbian) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.templateengine; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateDescriptor; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; + + +/** + * Test the functionality of the ValueStore class. + */ +public class TestValueStore extends BaseTestCase { + + + /** + * setUp is called before execution of test method. + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /** + * release resources held. + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + public TestValueStore(String name) { + super(name); + } + + /** + * Test ValueStore for Not Null condition. + * + */ + public void testValueStoreNotNull(){ + TemplateCore[] templates = TemplateEngineTestsHelper.getTestTemplates(); + for (int i=0; i <templates.length; i++) { + Map valueStore = templates[i].getValueStore(); + assertNotNull(valueStore); + } + } + + /** + * ValueStore is expected to consist all the IDs from + * FactoryDefaults. Test the same. + */ + public void testCompareValueStoreWithTemplateDefaluts(){ + TemplateCore[] templates = TemplateEngineTestsHelper.getTestTemplates(); + for (int i=0; i <templates.length; i++) { + Map valueStore = templates[i].getValueStore(); + TemplateDescriptor templateDescriptor = templates[i].getTemplateDescriptor(); + Map templateDefaults = templateDescriptor.getTemplateDefaults(templateDescriptor.getRootElement()); + + Iterator defaultsIterator = templateDefaults.keySet().iterator(); + while(defaultsIterator.hasNext()){ + String key = (String)defaultsIterator.next(); + assertNotNull(valueStore.get(key)); + } + } + } + + +} |