common: Generalize the BufferedBlockingQueue's concurrent test
[deliverable/tracecompass.git] / org.eclipse.tracecompass.btf.core.tests / src / org / eclipse / tracecompass / btf / core / tests / utils / BtfTestTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.btf.core.tests.utils;
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.tracecompass.btf.core.tests.BtfTestPlugin;
23 import org.eclipse.tracecompass.btf.core.trace.BtfTrace;
24 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
25 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26 import org.osgi.framework.Bundle;
27
28 /**
29 * Wrapper like CtfTestTrace but for BTF, the best trace format
30 * @author Matthew Khouzam
31 */
32 public enum BtfTestTrace {
33
34 /** btf test trace*/
35 BTF_TEST("20140219-123819.btf");
36
37 private final String fPath;
38 private final String fDirectory = "testfiles";
39 private BtfTrace fTrace = null;
40
41 private BtfTestTrace(String file) {
42 fPath = file;
43 }
44
45 /**
46 * Get the path of the trace
47 *
48 * @return The path of this trace
49 */
50 public String getPath() {
51 return fPath;
52 }
53
54 /**
55 * Get the full path of the trace
56 *
57 * @return The full path of the trace
58 */
59 public String getFullPath() {
60 return fDirectory + File.separator + fPath;
61 }
62
63 /**
64 * Return a ITmfTrace object of this test trace. It will be already
65 * initTrace()'ed. This method will always return a new trace and dispose of
66 * the old one.
67 *
68 * After being used by unit tests, traces must be properly disposed of by
69 * calling the {@link BtfTestTrace#dispose()} method.
70 *
71 * @return A {@link ITmfTrace} reference to this trace
72 */
73 public BtfTrace getTrace() {
74 if (fTrace != null) {
75 fTrace.dispose();
76 }
77 Bundle bundle = BtfTestPlugin.getBundle();
78 Path path = new Path(fDirectory + File.separator + fPath);
79 final URL location = FileLocator.find(bundle,path, null);
80 File test;
81 try {
82 test = new File(FileLocator.toFileURL(location).toURI());
83 fTrace = new BtfTrace();
84 fTrace.initTrace(null, test.getAbsolutePath(), null);
85 } catch (URISyntaxException | IOException | TmfTraceException e) {
86 throw new RuntimeException(e);
87 }
88 return fTrace;
89 }
90
91 /**
92 * Dispose of the trace
93 */
94 public void dispose() {
95 if (fTrace != null) {
96 fTrace.dispose();
97 fTrace = null;
98 }
99 }
100 }
This page took 0.045102 seconds and 5 git commands to generate.