tmf: Fix StandardImportGzipTraceTest failing when running from RunAllSWTBotTests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / shared / org / eclipse / tracecompass / tmf / core / tests / shared / TmfTestTrace.java
CommitLineData
9c4d52ee 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
9c4d52ee
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 13package org.eclipse.tracecompass.tmf.core.tests.shared;
9c4d52ee
GB
14
15import java.io.File;
16import java.io.IOException;
17import java.net.URISyntaxException;
18import java.net.URL;
19
20import org.eclipse.core.runtime.FileLocator;
21import org.eclipse.core.runtime.Path;
ca5b04ad 22import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
23import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
24import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
25import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
26import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
28import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub2;
9c4d52ee
GB
29
30/**
4d2857be 31 * Generic TMF test traces
9c4d52ee
GB
32 *
33 * @author Geneviève Bastien
34 */
35public enum TmfTestTrace {
36 /** A test */
37 A_TEST_10K("A-Test-10K"),
38 /** A second trace */
39 A_TEST_10K2("A-Test-10K-2"),
40 /** A third trace */
41 E_TEST_10K("E-Test-10K"),
42 /** A fourth trace */
43 O_TEST_10K("O-Test-10K"),
44 /** And oh! a fifth trace */
45 R_TEST_10K("R-Test-10K");
46
9529060e 47 private final @NonNull String fPath;
642f1a8e 48 private final String fDirectory = "../../tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles";
9c4d52ee
GB
49 private ITmfTrace fTrace = null;
50
9529060e 51 private TmfTestTrace(@NonNull String file) {
9c4d52ee
GB
52 fPath = file;
53 }
54
55 /**
56 * Get the path of the trace
57 *
58 * @return The path of this trace
59 */
9529060e 60 public @NonNull String getPath() {
9c4d52ee
GB
61 return fPath;
62 }
63
64 /**
65 * Get the full path of the trace
66 *
67 * @return The full path of the trace
68 */
69 public String getFullPath() {
70 return fDirectory + File.separator + fPath;
71 }
72
73 /**
74 * Return a ITmfTrace object of this test trace. It will be already
b5ddd705
GB
75 * initTrace()'ed. This method will always return a new trace and dispose of
76 * the old one.
77 *
78 * After being used by unit tests, traces must be properly disposed of by
79 * calling the {@link TmfTestTrace#dispose()} method.
9c4d52ee
GB
80 *
81 * @return A {@link ITmfTrace} reference to this trace
82 */
ca5b04ad 83 public @NonNull ITmfTrace getTrace() {
b5ddd705
GB
84 if (fTrace != null) {
85 fTrace.dispose();
86 }
87 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(fDirectory + File.separator + fPath), null);
88 try {
89 File test = new File(FileLocator.toFileURL(location).toURI());
ca5b04ad
GB
90 ITmfTrace trace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null);
91 fTrace = trace;
92 return trace;
4d2857be
GB
93 } catch (URISyntaxException | IOException | TmfTraceException e) {
94 throw new IllegalStateException(e);
9c4d52ee 95 }
ca5b04ad 96
9c4d52ee 97 }
b5ddd705 98
4d2857be
GB
99 /**
100 * Return a ITmfTrace object that is of type {@link TmfTraceStub2}. It
101 * will be already initTrace()'ed. But the trace will be deregistered from
102 * signal managers and will need to be manually disposed of by the caller.
103 *
104 * @return a {@link ITmfTrace} reference to this trace
105 */
106 public ITmfTrace getTraceAsStub2() {
107 ITmfTrace trace = null;
108 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(fDirectory + File.separator + fPath), null);
109 try {
110 File test = new File(FileLocator.toFileURL(location).toURI());
111 trace = new TmfTraceStub2(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null);
112 TmfSignalManager.deregister(trace);
113
114 } catch (URISyntaxException | IOException | TmfTraceException e) {
115 throw new IllegalStateException(e);
116 }
117 return trace;
118 }
119
b5ddd705
GB
120 /**
121 * Dispose of the trace
122 */
123 public void dispose() {
124 if (fTrace != null) {
125 fTrace.dispose();
126 fTrace = null;
127 }
128 }
9c4d52ee 129}
This page took 0.06273 seconds and 5 git commands to generate.