ctf: Fix InvalidPathException in CtfTmfTraceValidateTest on Windows
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / trace / CtfTmfTraceValidateTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 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 * Bernd Hufmann - IInitial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ctf.core.tests.trace;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assert.fail;
19
20 import java.net.URI;
21 import java.nio.file.Files;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.LinkedList;
25 import java.util.List;
26
27 import org.eclipse.core.runtime.FileLocator;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
30 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
31 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
32 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.Parameterized;
36 import org.junit.runners.Parameterized.Parameters;
37
38 /**
39 * The class <code>CtfTmfTraceValidateTest</code> contains tests for trace
40 * validation
41 * <code>{@link CtfTmfTrace#validate(org.eclipse.core.resources.IProject, String)}</code>
42 * .
43 *
44 * @author Bernd Hufmann
45 */
46 @RunWith(Parameterized.class)
47 public class CtfTmfTraceValidateTest {
48
49 private static final Path BASE_PATH = Paths.get("../org.eclipse.tracecompass.ctf.core.tests", "traces");
50 private static final Path CTF_SUITE_BASE_PATH = Paths.get("../org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8");
51
52 private String fTrace;
53 private int fServerity;
54 private int fConfidence;
55 private boolean fHasException;
56
57 /**
58 * Gets a list of test case parameters.
59 *
60 * @return The list of CTF traces (directories) to test
61 * @throws Exception in case of error
62 */
63 @Parameters(name = "{index}: {0}")
64 public static Iterable<Object[]> getTracePaths() throws Exception {
65 final List<Object[]> dirs = new LinkedList<>();
66 // text-only metadata, valid CTF trace (lttle-endian)
67 addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "pass", "literal-integers")), IStatus.OK, 10, false);
68 // packet-based metadata, valid CTF trace (lttle-endian)
69 URI tracePath = FileLocator.toFileURL(CtfTestTrace.KERNEL.getTraceURL()).toURI();
70 addDirsFrom(dirs, Paths.get(tracePath), IStatus.OK, 10, false);
71 // text-only metadata, but invalid
72 addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "fail", "enum-empty")), IStatus.WARNING, 1, true);
73 // packet-based metadata, but invalid
74 addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "fail", "lttng-modules-2.0-pre1")), IStatus.WARNING, 1, true);
75 // pass file instead of directory
76 addDirsFrom(dirs, BASE_PATH.resolve(Paths.get("synctraces.tar.gz")), IStatus.ERROR, 1, false);
77
78 return dirs;
79 }
80
81 private static void addDirsFrom(List<Object[]> dirs, Path path, int severity, int confidence, boolean hasException) {
82 if (!Files.exists(path)) {
83 /* Some planned directories may not exist yet in the test suite */
84 return;
85 }
86
87 Object array[] = new Object[] { path.toString(), severity, confidence, hasException };
88 dirs.add(array);
89 }
90
91 /**
92 * @param trace
93 * a trace path
94 * @param severity
95 * severity of validation status expected
96 * @param confidence
97 * confidence of validation status expected
98 * @param hasException
99 * flag whether validation status should contain exception
100 */
101 public CtfTmfTraceValidateTest(String trace, int severity, int confidence, boolean hasException) {
102 fTrace = trace;
103 fServerity = severity;
104 fConfidence = confidence;
105 fHasException = hasException;
106 }
107
108 /**
109 * Main test cases
110 */
111 @Test
112 public void testValidate() {
113 CtfTmfTrace trace = new CtfTmfTrace();
114 IStatus status = trace.validate(null, fTrace);
115 assertEquals(toString(), fServerity, status.getSeverity());
116
117 if (fHasException) {
118 assertNotNull(toString(), status.getException());
119 }
120 switch (status.getSeverity()) {
121 case IStatus.OK: {
122 assertTrue(status instanceof CtfTraceValidationStatus);
123 CtfTraceValidationStatus ctfStatus = (CtfTraceValidationStatus) status;
124 assertEquals(toString(), fConfidence, ctfStatus.getConfidence());
125 assertNotNull(ctfStatus.getEnvironment());
126 break;
127 }
128 case IStatus.WARNING: {
129 assertTrue(status instanceof TraceValidationStatus);
130 TraceValidationStatus ctfStatus = (TraceValidationStatus) status;
131 assertEquals(fConfidence, ctfStatus.getConfidence());
132 break;
133 }
134 case IStatus.ERROR: {
135 // nothing else to check here
136 break;
137 }
138 default:
139 // no other severity should be returned
140 fail();
141 break;
142 }
143 assertEquals(fServerity, status.getSeverity());
144 trace.dispose();
145 }
146
147 }
This page took 0.050905 seconds and 5 git commands to generate.