Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeneviève Bastien2013-08-15 20:30:18 +0000
committerPatrick Tasse2013-09-04 17:37:20 +0000
commit3c4a557ab5cd627ec344f51d6c6840cb13446578 (patch)
tree3b405c6c228b3f0962c2bf3d1897386f8786e110
parent1e2e55fb43fec778aad975aba5d92a5d93c9a5d4 (diff)
downloadorg.eclipse.linuxtools-3c4a557ab5cd627ec344f51d6c6840cb13446578.tar.gz
org.eclipse.linuxtools-3c4a557ab5cd627ec344f51d6c6840cb13446578.tar.xz
org.eclipse.linuxtools-3c4a557ab5cd627ec344f51d6c6840cb13446578.zip
TMF: Add tmf.ui unit tests for project model
Change-Id: I4524bf0cdc472815d8e9ddf2049469bbaca1b291 Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/15518 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/AllTmfUITests.java1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/AllTests.java27
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTestData.java167
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTraceTest.java105
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF4
5 files changed, 302 insertions, 2 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/AllTmfUITests.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/AllTmfUITests.java
index 743364d56f..34a388725d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/AllTmfUITests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/AllTmfUITests.java
@@ -24,6 +24,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
org.eclipse.linuxtools.tmf.ui.tests.histogram.AllTests.class,
+ org.eclipse.linuxtools.tmf.ui.tests.project.model.AllTests.class,
org.eclipse.linuxtools.tmf.ui.tests.statistics.AllTests.class,
org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.dialogs.AllTests.class,
org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.load.AllTests.class,
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/AllTests.java
new file mode 100644
index 0000000000..57af25c4d4
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/AllTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2013 École Polytechnique de Montréal
+ *
+ * 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:
+ * Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.tests.project.model;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.linuxtools.tmf.ui.project.model
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ ProjectModelTraceTest.class
+})
+public class AllTests {
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTestData.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTestData.java
new file mode 100644
index 0000000000..2aa4c76950
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTestData.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2013 École Polytechnique de Montréal
+ *
+ * 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:
+ * Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.tests.project.model;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
+import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Creates objects used for this package's testing purposes
+ */
+public class ProjectModelTestData {
+
+ /** Default test project name */
+ public static final String PROJECT_NAME = "Test_Project";
+
+ private static final int TRACE_INDEX = 0;
+ private static final String PATH = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
+
+ /**
+ * Gets a project element with traces all initialized
+ *
+ * @return A project stub element
+ * @throws CoreException
+ * If something happened with the project creation
+ */
+ public static TmfProjectElement getFilledProject() throws CoreException {
+
+ IProject project = TmfProjectRegistry.createProject(PROJECT_NAME, null, null);
+ IFolder traceFolder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
+
+ /* Create a trace, if it exist, it will be replaced */
+ File file = new File(PATH);
+ String path = file.getAbsolutePath();
+ final IPath pathString = Path.fromOSString(path);
+ IResource linkedTrace = TmfImportHelper.createLink(traceFolder, pathString, pathString.lastSegment());
+ if (!(linkedTrace != null && linkedTrace.exists())) {
+ return null;
+ }
+ linkedTrace.setPersistentProperty(TmfCommonConstants.TRACETYPE,
+ "org.eclipse.linuxtools.tmf.ui.type.ctf");
+
+ final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
+ TmfTraceElement traceElement = projectElement.getTracesFolder().getTraces().get(0);
+ traceElement.refreshTraceType();
+
+ return projectElement;
+ }
+
+ /**
+ * Get the name of the test trace element
+ *
+ * @return The trace name
+ */
+ public static String getTraceName() {
+ File file = new File(PATH);
+ String path = file.getAbsolutePath();
+ final IPath pathString = Path.fromOSString(path);
+ return pathString.lastSegment();
+ }
+
+ /**
+ * Deletes a project
+ *
+ * @param project
+ * Project to delete
+ * @throws CoreException
+ * Thrown by the resource deletion
+ */
+ public static void deleteProject(TmfProjectElement project) throws CoreException {
+ /* Delete experiments */
+ for (ITmfProjectModelElement element : project.getExperimentsFolder().getChildren()) {
+ if (element instanceof TmfExperimentElement) {
+ TmfExperimentElement experiment = (TmfExperimentElement) element;
+ IResource resource = experiment.getResource();
+
+ /* Close the experiment if open */
+ experiment.closeEditors();
+
+ IPath path = resource.getLocation();
+ if (path != null) {
+ /* Delete supplementary files */
+ experiment.deleteSupplementaryFolder();
+ }
+
+ /* Finally, delete the experiment */
+ resource.delete(true, null);
+ }
+ }
+
+ /* Delete traces */
+ for (ITmfProjectModelElement element : project.getTracesFolder().getChildren()) {
+ if (element instanceof TmfTraceElement) {
+ TmfTraceElement trace = (TmfTraceElement) element;
+ IResource resource = trace.getResource();
+
+ /* Close the trace if open */
+ trace.closeEditors();
+
+ IPath path = resource.getLocation();
+ if (path != null) {
+ /* Delete supplementary files */
+ trace.deleteSupplementaryFolder();
+ }
+
+ /* Finally, delete the trace */
+ resource.delete(true, new NullProgressMonitor());
+ }
+ }
+
+ /* Delete the project itself */
+ project.getResource().delete(true, null);
+ }
+
+ /**
+ * Makes the main display thread sleep, so it gives a chance to other thread
+ * needing the main display to execute
+ *
+ * @param waitTimeMillis
+ * time to wait in millisecond
+ */
+ public static void delayThread(final long waitTimeMillis) {
+ final Display display = Display.getCurrent();
+ if (display != null) {
+ final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
+ while (System.currentTimeMillis() < endTimeMillis) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ display.update();
+ }
+ } else {
+ try {
+ Thread.sleep(waitTimeMillis);
+ } catch (final InterruptedException e) {
+ // Ignored
+ }
+ }
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTraceTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTraceTest.java
new file mode 100644
index 0000000000..42dc258932
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/project/model/ProjectModelTraceTest.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2013 École Polytechnique de Montréal
+ *
+ * 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:
+ * Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.tests.project.model;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfTraceElement class.
+ */
+public class ProjectModelTraceTest {
+
+ private TmfProjectElement fixture;
+
+ /**
+ * Perform pre-test initialization.
+ */
+ @Before
+ public void setUp() {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
+ try {
+ fixture = ProjectModelTestData.getFilledProject();
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Cleans up the project after tests have been executed
+ */
+ @After
+ public void cleanUp() {
+ try {
+ ProjectModelTestData.deleteProject(fixture);
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test the getTrace() and trace opening
+ */
+ @Test
+ public void testOpenTrace() {
+ assertNotNull(fixture);
+
+ final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0);
+
+ /*
+ * Get the trace from the element, it is not opened yet, should be null
+ */
+ ITmfTrace trace = traceElement.getTrace();
+ assertNull(trace);
+
+ TmfOpenTraceHelper.openTraceFromElement(traceElement);
+
+ /* Give the trace a chance to open */
+ ProjectModelTestData.delayThread(5000);
+
+ trace = traceElement.getTrace();
+ assertNotNull(trace);
+
+ /*
+ * Open the trace from project, then get from element, both should be
+ * the exact same element as the active trace
+ */
+ TmfOpenTraceHelper.openTraceFromElement(traceElement);
+ ProjectModelTestData.delayThread(5000);
+
+ ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace();
+
+ /* The trace was reopened, it is not the same as before */
+ assertFalse(trace2 == trace);
+
+ /* Here, the getTrace() should return the same as active trace */
+ trace = traceElement.getTrace();
+ assertTrue(trace2 == trace);
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
index 6316e7d3f2..1c538bd832 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
@@ -21,11 +21,11 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l
org.eclipse.linuxtools.internal.tmf.ui.dialogs;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.editors.handlers;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;x-friends:="org.eclipse.linuxtools.tmf.ui.tests",
- org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;x-friends:="org.eclipse.linuxtools.tmf.ui.tests",
org.eclipse.linuxtools.internal.tmf.ui.preferences;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.project.dialogs;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.project.handlers;x-internal:=true,
- org.eclipse.linuxtools.internal.tmf.ui.project.model;x-friends:="org.eclipse.linuxtools.lttng2.ui",
+ org.eclipse.linuxtools.internal.tmf.ui.project.model;x-friends:="org.eclipse.linuxtools.lttng2.ui,org.eclipse.linuxtools.tmf.ui.tests",
org.eclipse.linuxtools.tmf.ui.editors,
org.eclipse.linuxtools.tmf.ui.project.model,
org.eclipse.linuxtools.tmf.ui.project.wizards,

Back to the top