tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / shared / org / eclipse / tracecompass / tmf / core / tests / shared / TmfTestTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 É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.tracecompass.tmf.core.tests.shared;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
20 import org.eclipse.core.runtime.FileLocator;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
24 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
25 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
26 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
28 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub2;
29
30 /**
31 * Generic TMF test traces
32 *
33 * @author Geneviève Bastien
34 */
35 public 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
47 private final @NonNull String fPath;
48 private final String fDirectory = "../org.eclipse.tracecompass.tmf.core.tests/testfiles";
49 private ITmfTrace fTrace = null;
50
51 private TmfTestTrace(@NonNull String file) {
52 fPath = file;
53 }
54
55 /**
56 * Get the path of the trace
57 *
58 * @return The path of this trace
59 */
60 public @NonNull String getPath() {
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
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.
80 *
81 * @return A {@link ITmfTrace} reference to this trace
82 */
83 public @NonNull ITmfTrace getTrace() {
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());
90 ITmfTrace trace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null);
91 fTrace = trace;
92 return trace;
93 } catch (URISyntaxException | IOException | TmfTraceException e) {
94 throw new IllegalStateException(e);
95 }
96
97 }
98
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
120 /**
121 * Dispose of the trace
122 */
123 public void dispose() {
124 if (fTrace != null) {
125 fTrace.dispose();
126 fTrace = null;
127 }
128 }
129 }
This page took 0.037517 seconds and 5 git commands to generate.