Commit | Line | Data |
---|---|---|
87644443 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
87644443 GB |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.tests.project.model; |
87644443 | 14 | |
87644443 GB |
15 | import static org.junit.Assert.assertNotNull; |
16 | import static org.junit.Assert.assertNull; | |
17 | import static org.junit.Assert.assertTrue; | |
18 | import static org.junit.Assert.fail; | |
87644443 | 19 | |
bc5f2035 GB |
20 | import java.util.concurrent.TimeoutException; |
21 | ||
87644443 | 22 | import org.eclipse.core.runtime.CoreException; |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
24 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
25 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper; | |
26 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
27 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
28 | import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData; | |
87644443 GB |
29 | import org.junit.After; |
30 | import org.junit.Before; | |
31 | import org.junit.Test; | |
32 | ||
33 | /** | |
34 | * Test suite for the TmfTraceElement class. | |
c068a752 GB |
35 | * |
36 | * @author Geneviève Bastien | |
87644443 GB |
37 | */ |
38 | public class ProjectModelTraceTest { | |
39 | ||
40 | private TmfProjectElement fixture; | |
41 | ||
42 | /** | |
43 | * Perform pre-test initialization. | |
44 | */ | |
45 | @Before | |
46 | public void setUp() { | |
87644443 GB |
47 | try { |
48 | fixture = ProjectModelTestData.getFilledProject(); | |
49 | } catch (CoreException e) { | |
50 | fail(e.getMessage()); | |
51 | } | |
52 | } | |
53 | ||
54 | /** | |
55 | * Cleans up the project after tests have been executed | |
56 | */ | |
57 | @After | |
58 | public void cleanUp() { | |
c068a752 | 59 | ProjectModelTestData.deleteProject(fixture); |
87644443 GB |
60 | } |
61 | ||
62 | /** | |
63 | * Test the getTrace() and trace opening | |
64 | */ | |
65 | @Test | |
66 | public void testOpenTrace() { | |
67 | assertNotNull(fixture); | |
68 | ||
69 | final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0); | |
70 | ||
71 | /* | |
72 | * Get the trace from the element, it is not opened yet, should be null | |
73 | */ | |
74 | ITmfTrace trace = traceElement.getTrace(); | |
75 | assertNull(trace); | |
76 | ||
77 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
78 | ||
79 | /* Give the trace a chance to open */ | |
bc5f2035 GB |
80 | try { |
81 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
82 | } catch (TimeoutException e) { | |
83 | fail("The trace did not open in a reasonable delay"); | |
84 | } | |
87644443 GB |
85 | |
86 | trace = traceElement.getTrace(); | |
87 | assertNotNull(trace); | |
88 | ||
89 | /* | |
90 | * Open the trace from project, then get from element, both should be | |
91 | * the exact same element as the active trace | |
92 | */ | |
93 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
bc5f2035 GB |
94 | try { |
95 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
96 | } catch (TimeoutException e) { | |
97 | fail("The trace did not open in a reasonable delay"); | |
98 | } | |
87644443 GB |
99 | |
100 | ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace(); | |
101 | ||
67c53011 PT |
102 | /* The trace was reopened, it should be the same as before */ |
103 | assertTrue(trace2 == trace); | |
87644443 GB |
104 | |
105 | /* Here, the getTrace() should return the same as active trace */ | |
106 | trace = traceElement.getTrace(); | |
107 | assertTrue(trace2 == trace); | |
108 | } | |
109 | ||
110 | } |