Commit | Line | Data |
---|---|---|
9c4d52ee GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 É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.linuxtools.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.linuxtools.tmf.core.exceptions.TmfTraceException; | |
23 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; | |
24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
25 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; | |
26 | ||
27 | /** | |
28 | * Wrapper, imitating the {@link CtfTmfTestTrace} class for the non-ctf traces | |
29 | * | |
30 | * @author Geneviève Bastien | |
31 | */ | |
32 | public enum TmfTestTrace { | |
33 | /** A test */ | |
34 | A_TEST_10K("A-Test-10K"), | |
35 | /** A second trace */ | |
36 | A_TEST_10K2("A-Test-10K-2"), | |
37 | /** A third trace */ | |
38 | E_TEST_10K("E-Test-10K"), | |
39 | /** A fourth trace */ | |
40 | O_TEST_10K("O-Test-10K"), | |
41 | /** And oh! a fifth trace */ | |
42 | R_TEST_10K("R-Test-10K"); | |
43 | ||
44 | ||
45 | private final String fPath; | |
46 | private final String fDirectory = "testfiles"; | |
47 | private ITmfTrace fTrace = null; | |
48 | ||
49 | private TmfTestTrace(String file) { | |
50 | fPath = file; | |
51 | } | |
52 | ||
53 | /** | |
54 | * Get the path of the trace | |
55 | * | |
56 | * @return The path of this trace | |
57 | */ | |
58 | public String getPath() { | |
59 | return fPath; | |
60 | } | |
61 | ||
62 | /** | |
63 | * Get the full path of the trace | |
64 | * | |
65 | * @return The full path of the trace | |
66 | */ | |
67 | public String getFullPath() { | |
68 | return fDirectory + File.separator + fPath; | |
69 | } | |
70 | ||
71 | /** | |
72 | * Return a ITmfTrace object of this test trace. It will be already | |
73 | * initTrace()'ed. | |
74 | * | |
75 | * @return A {@link ITmfTrace} reference to this trace | |
76 | */ | |
77 | public ITmfTrace getTrace() { | |
78 | if (fTrace == null) { | |
79 | TmfTraceStub trace = null; | |
80 | final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(fDirectory + File.separator + fPath), null); | |
81 | try { | |
82 | File test = new File(FileLocator.toFileURL(location).toURI()); | |
ab186fbb | 83 | trace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null); |
9c4d52ee GB |
84 | |
85 | } catch (URISyntaxException e) { | |
86 | throw new RuntimeException(e); | |
87 | } catch (IOException e) { | |
88 | throw new RuntimeException(e); | |
89 | } catch (TmfTraceException e) { | |
90 | throw new RuntimeException(e); | |
91 | } finally { | |
92 | if (trace != null) { | |
93 | trace.dispose(); | |
94 | } | |
95 | } | |
96 | fTrace = trace; | |
97 | } | |
98 | return fTrace; | |
99 | } | |
100 | } |