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; | |
9ac63b5b | 22 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; |
87644443 GB |
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; | |
3d2e4ad3 | 28 | import org.eclipse.linuxtools.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() { | |
9ac63b5b | 47 | assumeTrue(CtfTmfTestTrace.KERNEL.exists()); |
87644443 GB |
48 | try { |
49 | fixture = ProjectModelTestData.getFilledProject(); | |
50 | } catch (CoreException e) { | |
51 | fail(e.getMessage()); | |
52 | } | |
53 | } | |
54 | ||
55 | /** | |
56 | * Cleans up the project after tests have been executed | |
57 | */ | |
58 | @After | |
59 | public void cleanUp() { | |
c068a752 | 60 | ProjectModelTestData.deleteProject(fixture); |
87644443 GB |
61 | } |
62 | ||
63 | /** | |
64 | * Test the getTrace() and trace opening | |
65 | */ | |
66 | @Test | |
67 | public void testOpenTrace() { | |
68 | assertNotNull(fixture); | |
69 | ||
70 | final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0); | |
71 | ||
72 | /* | |
73 | * Get the trace from the element, it is not opened yet, should be null | |
74 | */ | |
75 | ITmfTrace trace = traceElement.getTrace(); | |
76 | assertNull(trace); | |
77 | ||
78 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
79 | ||
80 | /* Give the trace a chance to open */ | |
c068a752 | 81 | ProjectModelTestData.delayThread(500); |
87644443 GB |
82 | |
83 | trace = traceElement.getTrace(); | |
84 | assertNotNull(trace); | |
85 | ||
86 | /* | |
87 | * Open the trace from project, then get from element, both should be | |
88 | * the exact same element as the active trace | |
89 | */ | |
90 | TmfOpenTraceHelper.openTraceFromElement(traceElement); | |
c068a752 | 91 | ProjectModelTestData.delayThread(500); |
87644443 GB |
92 | |
93 | ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace(); | |
94 | ||
67c53011 PT |
95 | /* The trace was reopened, it should be the same as before */ |
96 | assertTrue(trace2 == trace); | |
87644443 GB |
97 | |
98 | /* Here, the getTrace() should return the same as active trace */ | |
99 | trace = traceElement.getTrace(); | |
100 | assertTrue(trace2 == trace); | |
101 | } | |
102 | ||
103 | } |