ctf: Re-enable the CTF parser unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / TestParams.java
CommitLineData
866e5b51
FC
1package org.eclipse.linuxtools.ctf.core.tests;
2
3import java.io.File;
4
5import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
6import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
7
8/**
9 * Here are the definitions common to all the CTF parser tests.
ce2388e0 10 *
866e5b51 11 * @author alexmont
866e5b51 12 */
e5acb357 13@SuppressWarnings("nls")
866e5b51 14public abstract class TestParams {
ce2388e0 15
813ecc8e
AM
16 /*
17 * Path to test traces. Make sure you run the traces/get-traces.sh script
18 * first!
19 */
e5acb357 20 private static final String testTracePath1 = "traces/kernel";
866e5b51
FC
21 private static CTFTrace testTrace1 = null;
22 private static CTFTrace testTraceFromFile1 = null;
e5acb357 23 private static final File testTraceFile1 = new File(testTracePath1 + "/channel0_0");
ce2388e0 24
e5acb357 25 private static final File emptyFile = new File("");
866e5b51 26 private static CTFTrace emptyTrace = null;
ce2388e0 27
e5acb357
AM
28 /**
29 * Return an empty file (new File("");)
30 *
31 * @return An empty file
32 */
866e5b51
FC
33 public static File getEmptyFile() {
34 return emptyFile;
35 }
ce2388e0 36
e5acb357
AM
37 /**
38 * Return a file in test trace #1 (channel0_0).
39 *
40 * Make sure {@link #tracesExist()} before calling this!
41 *
42 * @return A file in a test trace
43 */
024373d7
MK
44 public static File getTraceFile(){
45 return testTraceFile1;
46 }
e5acb357
AM
47
48 /**
49 * Return a trace out of an empty file (new CTFTrace("");)
50 *
51 * @return An empty trace
52 */
866e5b51
FC
53 public static CTFTrace getEmptyTrace() {
54 if (emptyTrace == null) {
55 try {
e5acb357 56 emptyTrace = new CTFTrace("");
866e5b51 57 } catch (CTFReaderException e) {
e5acb357 58 /* Should always work... */
866e5b51 59 throw new RuntimeException(e);
ce2388e0 60 }
866e5b51
FC
61 }
62 return emptyTrace;
63 }
ce2388e0 64
e5acb357
AM
65 /**
66 * Get a CTFTrace reference to test trace #1.
67 *
68 * Make sure {@link #tracesExist()} before calling this!
69 *
70 * @return Reference to test trace #1
71 * @throws CTFReaderException
72 * If the trace cannot be found
73 */
13be1a8f 74 public static CTFTrace createTrace() throws CTFReaderException {
866e5b51 75 if (testTrace1 == null) {
13be1a8f 76 testTrace1 = new CTFTrace(testTracePath1);
866e5b51
FC
77 }
78 return testTrace1;
79 }
80
e5acb357
AM
81 /**
82 * Same as {@link #createTrace()}, except the CTFTrace is create from the
83 * File object and not the path.
84 *
85 * Make sure {@link #tracesExist()} before calling this!
86 *
87 * @return Reference to test trace #1
88 */
866e5b51
FC
89 public static CTFTrace createTraceFromFile() {
90 if (testTraceFromFile1 == null) {
91 try {
92 testTraceFromFile1 = new CTFTrace(new File(testTracePath1));
93 } catch (CTFReaderException e) {
e5acb357 94 /* This trace should exist */
866e5b51
FC
95 throw new RuntimeException(e);
96 }
97 }
98 return testTraceFromFile1;
99 }
e5acb357
AM
100
101 /**
102 * Check if the test traces are present in the tree. If not, you can get
103 * them by running traces/get-traces.sh or traces/get-traces.xml
104 *
105 * @return True if *all* the test files could be found, false otherwise.
106 */
107 public static boolean tracesExist() {
108 if (testTrace1 != null) {
109 return true;
110 }
111 try {
112 createTrace();
113 } catch (CTFReaderException e) {
114 return false;
115 }
116 return true;
117 }
866e5b51 118}
This page took 0.041927 seconds and 5 git commands to generate.