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 GB |
19 | |
20 | import org.eclipse.core.runtime.CoreException; | |
2bdf0193 AM |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
22 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
23 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper; | |
24 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
25 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
26 | import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData; | |
6db82092 | 27 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException; |
87644443 GB |
28 | import org.junit.After; |
29 | import org.junit.Before; | |
30 | import org.junit.Test; | |
31 | ||
32 | /** | |
33 | * Test suite for the TmfTraceElement class. | |
c068a752 GB |
34 | * |
35 | * @author Geneviève Bastien | |
87644443 GB |
36 | */ |
37 | public class ProjectModelTraceTest { | |
38 | ||
39 | private TmfProjectElement fixture; | |
40 | ||
41 | /** | |
42 | * Perform pre-test initialization. | |
43 | */ | |
44 | @Before | |
45 | public void setUp() { | |
87644443 GB |
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() { | |
c068a752 | 58 | ProjectModelTestData.deleteProject(fixture); |
87644443 GB |
59 | } |
60 | ||
61 | /** | |
62 | * Test the getTrace() and trace opening | |
63 | */ | |
64 | @Test | |
65 | public void testOpenTrace() { | |
66 | assertNotNull(fixture); | |
67 | ||
68 | final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0); | |
69 | ||
70 | /* | |
71 | * Get the trace from the element, it is not opened yet, should be null | |
72 | */ | |
73 | ITmfTrace trace = traceElement.getTrace(); | |
74 | assertNull(trace); | |
75 | ||
76 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
77 | ||
78 | /* Give the trace a chance to open */ | |
bc5f2035 GB |
79 | try { |
80 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
6db82092 | 81 | } catch (WaitTimeoutException e) { |
bc5f2035 GB |
82 | fail("The trace did not open in a reasonable delay"); |
83 | } | |
87644443 GB |
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); | |
bc5f2035 GB |
93 | try { |
94 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
6db82092 | 95 | } catch (WaitTimeoutException e) { |
bc5f2035 GB |
96 | fail("The trace did not open in a reasonable delay"); |
97 | } | |
87644443 GB |
98 | |
99 | ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace(); | |
100 | ||
67c53011 PT |
101 | /* The trace was reopened, it should be the same as before */ |
102 | assertTrue(trace2 == trace); | |
87644443 GB |
103 | |
104 | /* Here, the getTrace() should return the same as active trace */ | |
105 | trace = traceElement.getTrace(); | |
106 | assertTrue(trace2 == trace); | |
107 | } | |
108 | ||
109 | } |