Commit | Line | Data |
---|---|---|
87644443 GB |
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 | ||
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; | |
19 | import static org.junit.Assume.assumeTrue; | |
20 | ||
21 | import org.eclipse.core.runtime.CoreException; | |
22 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces; | |
23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
24 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; | |
25 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; | |
26 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; | |
27 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; | |
28 | import org.junit.After; | |
29 | import org.junit.Before; | |
30 | import org.junit.Test; | |
31 | ||
32 | /** | |
33 | * Test suite for the TmfTraceElement class. | |
34 | */ | |
35 | public class ProjectModelTraceTest { | |
36 | ||
37 | private TmfProjectElement fixture; | |
38 | ||
39 | /** | |
40 | * Perform pre-test initialization. | |
41 | */ | |
42 | @Before | |
43 | public void setUp() { | |
44 | assumeTrue(CtfTmfTestTraces.tracesExist()); | |
45 | try { | |
46 | fixture = ProjectModelTestData.getFilledProject(); | |
47 | } catch (CoreException e) { | |
48 | fail(e.getMessage()); | |
49 | } | |
50 | } | |
51 | ||
52 | /** | |
53 | * Cleans up the project after tests have been executed | |
54 | */ | |
55 | @After | |
56 | public void cleanUp() { | |
57 | try { | |
58 | ProjectModelTestData.deleteProject(fixture); | |
59 | } catch (CoreException e) { | |
60 | fail(e.getMessage()); | |
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * Test the getTrace() and trace opening | |
66 | */ | |
67 | @Test | |
68 | public void testOpenTrace() { | |
69 | assertNotNull(fixture); | |
70 | ||
71 | final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0); | |
72 | ||
73 | /* | |
74 | * Get the trace from the element, it is not opened yet, should be null | |
75 | */ | |
76 | ITmfTrace trace = traceElement.getTrace(); | |
77 | assertNull(trace); | |
78 | ||
79 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
80 | ||
81 | /* Give the trace a chance to open */ | |
82 | ProjectModelTestData.delayThread(5000); | |
83 | ||
84 | trace = traceElement.getTrace(); | |
85 | assertNotNull(trace); | |
86 | ||
87 | /* | |
88 | * Open the trace from project, then get from element, both should be | |
89 | * the exact same element as the active trace | |
90 | */ | |
91 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
92 | ProjectModelTestData.delayThread(5000); | |
93 | ||
94 | ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace(); | |
95 | ||
67c53011 PT |
96 | /* The trace was reopened, it should be the same as before */ |
97 | assertTrue(trace2 == trace); | |
87644443 GB |
98 | |
99 | /* Here, the getTrace() should return the same as active trace */ | |
100 | trace = traceElement.getTrace(); | |
101 | assertTrue(trace2 == trace); | |
102 | } | |
103 | ||
104 | } |