tmf: Move statevalue unboxing method implementations to the base classes
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / shared / org / eclipse / linuxtools / tmf / core / tests / shared / CtfTmfTestTraces.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.shared;
14
15 import java.io.File;
16
17 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
18 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
19 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
20 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
21
22 /**
23 * Definitions used by all tests using CTF-TMF trace files.
24 *
25 * To run these tests, you will first need to run the "get-traces.sh" script
26 * located under lttng/org.eclipse.linuxtools.ctf.core.tests/traces/ .
27 *
28 * @author Alexandre Montplaisir
29 */
30 public final class CtfTmfTestTraces {
31
32 private CtfTmfTestTraces() {}
33
34 private static final File emptyFile = new File("");
35 private static CtfTmfTrace emptyTrace = new CtfTmfTrace();
36
37 private static CtfTmfTrace[] testTraces = new CtfTmfTrace[3];
38
39 /**
40 * Get an empty File (new File("");)
41 *
42 * @return An empty file
43 */
44 public static File getEmptyFile() {
45 return emptyFile;
46 }
47
48 /**
49 * Get an empty CtfTmfTrace (new CtfTmfTrace();)
50 *
51 * @return An empty trace
52 */
53 public static CtfTmfTrace getEmptyTrace() {
54 return emptyTrace;
55 }
56
57 /**
58 * Get a reference to the test trace used for the kernel event handler unit
59 * tests.
60 *
61 * Make sure you call {@link #tracesExist()} before calling this!
62 *
63 * @param idx
64 * The index of the test trace you want
65 * @return A CtfTmfTrace reference to the test trace
66 */
67 public synchronized static CtfTmfTrace getTestTrace(int idx) {
68 if (testTraces[idx] == null) {
69 String tracePath = CtfTestTraces.getTestTracePath(idx);
70 testTraces[idx] = new CtfTmfTrace();
71 try {
72 testTraces[idx].initTrace(null, tracePath, CtfTmfEvent.class);
73 } catch (TmfTraceException e) {
74 /* Should not happen if tracesExist() passed */
75 testTraces[idx] = null;
76 throw new RuntimeException(e);
77 }
78 }
79 return testTraces[idx];
80 }
81
82 // ------------------------------------------------------------------------
83 // Wrappers around direct CtfTestTraces methods
84 // ------------------------------------------------------------------------
85
86 /**
87 * Get the (string) path to a given test trace.
88 *
89 * You should call {@link #tracesExist()} before calling this if you are
90 * going to use this trace for real.
91 *
92 * @param idx
93 * The index of the trace among all the available ones
94 * @return The path to the test trace
95 */
96 public static String getTestTracePath(int idx) {
97 return CtfTestTraces.getTestTracePath(idx);
98 }
99
100 /**
101 * Check if the test traces are present before trying to open them.
102 *
103 * This should be called in unit tests within a asssumeTrue() call, to skip
104 * the test/test-class if the traces are not available.
105 *
106 * @return True if the trace is available, false if not
107 */
108 public static boolean tracesExist() {
109 return CtfTestTraces.tracesExist();
110 }
111
112 }
This page took 0.03717 seconds and 5 git commands to generate.