1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
;
16 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
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
;
31 * Generic TMF test traces
33 * @author Geneviève Bastien
35 public enum TmfTestTrace
{
37 A_TEST_10K("A-Test-10K"),
39 A_TEST_10K2("A-Test-10K-2"),
41 E_TEST_10K("E-Test-10K"),
43 O_TEST_10K("O-Test-10K"),
44 /** And oh! a fifth trace */
45 R_TEST_10K("R-Test-10K");
47 private final @NonNull String fPath
;
48 private final String fDirectory
= "../org.eclipse.tracecompass.tmf.core.tests/testfiles";
49 private ITmfTrace fTrace
= null;
51 private TmfTestTrace(@NonNull String file
) {
56 * Get the path of the trace
58 * @return The path of this trace
60 public @NonNull String
getPath() {
65 * Get the full path of the trace
67 * @return The full path of the trace
69 public String
getFullPath() {
70 return fDirectory
+ File
.separator
+ fPath
;
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
78 * After being used by unit tests, traces must be properly disposed of by
79 * calling the {@link TmfTestTrace#dispose()} method.
81 * @return A {@link ITmfTrace} reference to this trace
83 public @NonNull ITmfTrace
getTrace() {
87 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(fDirectory
+ File
.separator
+ fPath
), null);
89 File test
= new File(FileLocator
.toFileURL(location
).toURI());
90 ITmfTrace trace
= new TmfTraceStub(test
.toURI().getPath(), ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, false, null);
93 } catch (URISyntaxException
| IOException
| TmfTraceException e
) {
94 throw new IllegalStateException(e
);
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.
104 * @return a {@link ITmfTrace} reference to this trace
106 public ITmfTrace
getTraceAsStub2() {
107 ITmfTrace trace
= null;
108 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(fDirectory
+ File
.separator
+ fPath
), null);
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
);
114 } catch (URISyntaxException
| IOException
| TmfTraceException e
) {
115 throw new IllegalStateException(e
);
121 * Dispose of the trace
123 public void dispose() {
124 if (fTrace
!= null) {
This page took 0.03834 seconds and 5 git commands to generate.