| 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.assertNotNull; |
| 16 | import static org.junit.Assert.assertNull; |
| 17 | import static org.junit.Assert.assertTrue; |
| 18 | import static org.junit.Assert.fail; |
| 19 | |
| 20 | import java.util.concurrent.TimeoutException; |
| 21 | |
| 22 | import org.eclipse.core.runtime.CoreException; |
| 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.eclipse.linuxtools.tmf.ui.tests.shared.ProjectModelTestData; |
| 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 | * @author Geneviève Bastien |
| 37 | */ |
| 38 | public class ProjectModelTraceTest { |
| 39 | |
| 40 | private TmfProjectElement fixture; |
| 41 | |
| 42 | /** |
| 43 | * Perform pre-test initialization. |
| 44 | */ |
| 45 | @Before |
| 46 | public void setUp() { |
| 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() { |
| 59 | ProjectModelTestData.deleteProject(fixture); |
| 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 */ |
| 80 | try { |
| 81 | ProjectModelTestData.delayUntilTraceOpened(traceElement); |
| 82 | } catch (TimeoutException e) { |
| 83 | fail("The trace did not open in a reasonable delay"); |
| 84 | } |
| 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); |
| 94 | try { |
| 95 | ProjectModelTestData.delayUntilTraceOpened(traceElement); |
| 96 | } catch (TimeoutException e) { |
| 97 | fail("The trace did not open in a reasonable delay"); |
| 98 | } |
| 99 | |
| 100 | ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace(); |
| 101 | |
| 102 | /* The trace was reopened, it should be the same as before */ |
| 103 | assertTrue(trace2 == trace); |
| 104 | |
| 105 | /* Here, the getTrace() should return the same as active trace */ |
| 106 | trace = traceElement.getTrace(); |
| 107 | assertTrue(trace2 == trace); |
| 108 | } |
| 109 | |
| 110 | } |