TMF: Add tmf.ui unit tests for project model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / project / model / ProjectModelTraceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.tests.project.model;
14
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20 import static org.junit.Assume.assumeTrue;
21
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
24 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
25 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
26 import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
27 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
28 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * Test suite for the TmfTraceElement class.
35 */
36 public class ProjectModelTraceTest {
37
38 private TmfProjectElement fixture;
39
40 /**
41 * Perform pre-test initialization.
42 */
43 @Before
44 public void setUp() {
45 assumeTrue(CtfTmfTestTraces.tracesExist());
46 try {
47 fixture = ProjectModelTestData.getFilledProject();
48 } catch (CoreException e) {
49 fail(e.getMessage());
50 }
51 }
52
53 /**
54 * Cleans up the project after tests have been executed
55 */
56 @After
57 public void cleanUp() {
58 try {
59 ProjectModelTestData.deleteProject(fixture);
60 } catch (CoreException e) {
61 fail(e.getMessage());
62 }
63 }
64
65 /**
66 * Test the getTrace() and trace opening
67 */
68 @Test
69 public void testOpenTrace() {
70 assertNotNull(fixture);
71
72 final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0);
73
74 /*
75 * Get the trace from the element, it is not opened yet, should be null
76 */
77 ITmfTrace trace = traceElement.getTrace();
78 assertNull(trace);
79
80 TmfOpenTraceHelper.openTraceFromElement(traceElement);
81
82 /* Give the trace a chance to open */
83 ProjectModelTestData.delayThread(5000);
84
85 trace = traceElement.getTrace();
86 assertNotNull(trace);
87
88 /*
89 * Open the trace from project, then get from element, both should be
90 * the exact same element as the active trace
91 */
92 TmfOpenTraceHelper.openTraceFromElement(traceElement);
93 ProjectModelTestData.delayThread(5000);
94
95 ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace();
96
97 /* The trace was reopened, it is not the same as before */
98 assertFalse(trace2 == trace);
99
100 /* Here, the getTrace() should return the same as active trace */
101 trace = traceElement.getTrace();
102 assertTrue(trace2 == trace);
103 }
104
105 }
This page took 0.036239 seconds and 6 git commands to generate.