Commit | Line | Data |
---|---|---|
b373d07b MK |
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 | * Matthew Khouzam - Initial API and implementation | |
11 | * Patrick Tasse - Fix editor handling | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests; | |
15 | ||
16 | import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertContains; | |
17 | ||
18 | import java.io.File; | |
19 | import java.io.IOException; | |
20 | import java.nio.file.FileVisitResult; | |
21 | import java.nio.file.FileVisitor; | |
22 | import java.nio.file.Files; | |
23 | import java.nio.file.Path; | |
24 | import java.nio.file.Paths; | |
25 | import java.nio.file.SimpleFileVisitor; | |
26 | import java.nio.file.attribute.BasicFileAttributes; | |
27 | import java.util.HashMap; | |
28 | import java.util.LinkedList; | |
29 | import java.util.List; | |
30 | import java.util.Map; | |
31 | ||
32 | import org.apache.log4j.ConsoleAppender; | |
33 | import org.apache.log4j.Logger; | |
34 | import org.apache.log4j.SimpleLayout; | |
35 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
36 | import org.eclipse.swtbot.swt.finder.SWTBot; | |
37 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
38 | import org.eclipse.swtbot.swt.finder.waits.Conditions; | |
39 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
40 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
41 | import org.junit.After; | |
a0f54826 MAL |
42 | import org.junit.AfterClass; |
43 | import org.junit.BeforeClass; | |
b373d07b MK |
44 | import org.junit.Test; |
45 | import org.junit.runner.RunWith; | |
46 | import org.junit.runners.Parameterized; | |
47 | import org.junit.runners.Parameterized.Parameters; | |
48 | ||
49 | /** | |
50 | * Test invalid trace openning | |
51 | * | |
52 | * @author Matthew Khouzam | |
53 | */ | |
54 | @RunWith(Parameterized.class) | |
55 | public class TestInvalidCtfTrace { | |
56 | ||
57 | private static final String PROJET_NAME = "TestInvalidCtfTraces"; | |
3e6e367c | 58 | private static final Path BASE_PATH = Paths.get("../../ctf/org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8"); |
b373d07b MK |
59 | |
60 | /** The Log4j logger instance. */ | |
61 | private static final Logger fLogger = Logger.getRootLogger(); | |
62 | ||
63 | private static SWTWorkbenchBot fBot; | |
64 | ||
65 | private final File fLocation; | |
66 | ||
67 | private final String fExpectedMessage; | |
68 | ||
69 | private static final Map<String, String> ERRORS = new HashMap<>(); | |
70 | static { | |
71 | // metadata | |
73511e67 | 72 | ERRORS.put("array-redefinition", "MismatchedTokenException(56!=71)"); |
b373d07b | 73 | ERRORS.put("array-size-identifier", "Is not an integer: x"); |
73511e67 | 74 | ERRORS.put("array-size-keyword", "NoViableAltException(74@[])"); |
b373d07b | 75 | ERRORS.put("array-size-negative", "Array length is negative"); |
73511e67 | 76 | ERRORS.put("array-size-not-present", "NoViableAltException(13@[])"); |
b373d07b MK |
77 | ERRORS.put("array-size-string", "Is not an integer: x"); |
78 | ERRORS.put("array-size-type-field", "Is not an integer: uint32_t"); | |
79 | ERRORS.put("array-size-type", "Is not an integer: uint32_t"); | |
80 | ERRORS.put("integer-encoding-as-string", "Invalid value for encoding"); | |
81 | ERRORS.put("integer-encoding-invalid", "Invalid value for encoding"); | |
82 | ERRORS.put("integer-negative-bit-size", "Invalid value for size"); | |
83 | ERRORS.put("integer-range", "Invalid integer format: 23452397856348975623897562893746589237465289374658923764598237645897234658723648579236"); | |
b1ea73b5 | 84 | ERRORS.put("integer-signed-as-string", "Invalid boolean value"); |
b373d07b MK |
85 | ERRORS.put("integer-signed-invalid", "Invalid boolean value svp"); |
86 | ERRORS.put("integer-size-as-string", "Invalid value for size"); | |
b1ea73b5 | 87 | ERRORS.put("integer-size-missing", "Invalid boolean value"); |
b373d07b MK |
88 | ERRORS.put("struct-align-enum", "Invalid value for alignment"); |
89 | ERRORS.put("struct-align-huge", "Invalid integer format: 0xFFFFFFFFU"); | |
90 | ERRORS.put("struct-align-negative", "Invalid value for alignment : -8"); | |
91 | ERRORS.put("struct-align-string", "Invalid value for alignment"); | |
92 | ERRORS.put("struct-align-zero", "Invalid value for alignment : 0"); | |
93 | ERRORS.put("struct-duplicate-field-name", "Identifier has already been defined:xxx"); | |
94 | ERRORS.put("struct-duplicate-struct-name", "struct a already defined."); | |
73511e67 | 95 | ERRORS.put("struct-field-name-keyword", "NoViableAltException(72@[])"); |
b373d07b MK |
96 | // streams |
97 | ERRORS.put("content-size-larger-than-packet-size", "UNKNOWN"); //FIXME | |
98 | ERRORS.put("cross-packet-event-alignment-empty-struct", "UNKNOWN"); //FIXME | |
99 | ERRORS.put("cross-packet-event-alignment-integer", "UNKNOWN"); //FIXME | |
100 | ERRORS.put("cross-packet-event-array-of-integers", "UNKNOWN"); //FIXME | |
101 | ERRORS.put("cross-packet-event-float", "UNKNOWN"); //FIXME | |
102 | ERRORS.put("cross-packet-event-integer", "UNKNOWN"); //FIXME | |
103 | ERRORS.put("cross-packet-event-len-of-sequence", "UNKNOWN"); //FIXME | |
104 | ERRORS.put("cross-packet-event-sequence-between-elements", "UNKNOWN"); //FIXME | |
105 | ERRORS.put("cross-packet-event-sequence-start", "UNKNOWN"); //FIXME | |
106 | ERRORS.put("out-of-bound-empty-event-with-aligned-struct", "UNKNOWN"); //FIXME | |
107 | ERRORS.put("out-of-bound-float", "UNKNOWN"); //FIXME | |
108 | ERRORS.put("out-of-bound-integer", "UNKNOWN"); //FIXME | |
109 | ERRORS.put("out-of-bound-large-sequence-length", "UNKNOWN"); //FIXME | |
110 | ERRORS.put("out-of-bound-len-of-sequence", "UNKNOWN"); //FIXME | |
111 | ERRORS.put("out-of-bound-packet-header", "UNKNOWN"); //FIXME | |
112 | ERRORS.put("out-of-bound-sequence-between-elements", "UNKNOWN"); //FIXME | |
113 | ERRORS.put("out-of-bound-sequence-start", "UNKNOWN"); //FIXME | |
114 | ERRORS.put("out-of-bound-sequence-within-element", "UNKNOWN"); //FIXME | |
115 | ||
116 | } | |
117 | ||
118 | /** | |
119 | * Populate the parameters | |
120 | * | |
121 | * @return the parameters. Basically all the errors with lookuped paths | |
122 | */ | |
123 | @Parameters(name = "{index}: {0}") | |
124 | public static Iterable<Object[]> getTracePaths() { | |
125 | final List<Object[]> dirs = new LinkedList<>(); | |
126 | ||
127 | FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { | |
128 | @Override | |
129 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { | |
130 | final Path fileName = dir.getFileName(); | |
131 | String res = ERRORS.get(fileName.toString()); | |
132 | if (res != null) { | |
133 | dirs.add(new Object[] { dir.toFile(), res }); | |
134 | return FileVisitResult.SKIP_SUBTREE; | |
135 | } | |
136 | return FileVisitResult.CONTINUE; | |
137 | } | |
138 | ||
139 | }; | |
140 | /* TODO: add way of handling an error in a trace during a run */ | |
141 | /* when that is done, we can add regression/stream/fail */ | |
142 | ||
143 | Path badMetadata = BASE_PATH.resolve(Paths.get("regression", "metadata", "fail")); | |
144 | try { | |
145 | Files.walkFileTree(badMetadata, visitor); | |
146 | } catch (IOException e) { | |
147 | e.printStackTrace(); | |
148 | } | |
149 | return dirs; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Constructor | |
154 | * | |
155 | * @param location | |
156 | * trace file | |
157 | * @param errorMessage | |
158 | * error message | |
159 | */ | |
160 | public TestInvalidCtfTrace(File location, String errorMessage) { | |
161 | fLocation = location; | |
162 | fExpectedMessage = errorMessage; | |
163 | } | |
164 | ||
165 | /** | |
166 | * Initialization | |
167 | */ | |
a0f54826 MAL |
168 | @BeforeClass |
169 | public static void beforeClass() { | |
5785ab49 | 170 | SWTBotUtils.initialize(); |
b373d07b MK |
171 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger |
172 | /* set up for swtbot */ | |
173 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
174 | fLogger.removeAllAppenders(); | |
175 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
176 | fBot = new SWTWorkbenchBot(); | |
177 | ||
178 | SWTBotUtils.closeView("welcome", fBot); | |
179 | ||
180 | SWTBotUtils.switchToTracingPerspective(); | |
181 | /* finish waiting for eclipse to load */ | |
182 | SWTBotUtils.waitForJobs(); | |
183 | SWTBotUtils.createProject(PROJET_NAME); | |
184 | ||
185 | } | |
186 | ||
187 | /** | |
a0f54826 | 188 | * Delete traces |
b373d07b MK |
189 | */ |
190 | @After | |
a0f54826 MAL |
191 | public void teardown() { |
192 | SWTBotUtils.clearTracesFolder(fBot, PROJET_NAME); | |
1dfcd42b | 193 | SWTBotUtils.closeSecondaryShells(fBot); |
a0f54826 MAL |
194 | } |
195 | ||
196 | /** | |
197 | * Delete project | |
198 | */ | |
199 | @AfterClass | |
200 | public static void afterClass() { | |
b373d07b MK |
201 | SWTBotUtils.deleteProject(PROJET_NAME, fBot); |
202 | fLogger.removeAllAppenders(); | |
203 | } | |
204 | ||
205 | /** | |
206 | * Open an invalid trace and see the message | |
207 | */ | |
208 | @Test | |
209 | public void testOpen() { | |
210 | SWTBotUtils.selectTracesFolder(fBot, PROJET_NAME); | |
a0f54826 | 211 | SWTBotUtils.openTrace(PROJET_NAME, fLocation.getAbsolutePath(), "org.eclipse.linuxtools.tmf.ui.type.ctf", false); |
b373d07b MK |
212 | fBot.waitUntil(Conditions.shellIsActive("Open Trace")); |
213 | final SWTBotShell shell = fBot.activeShell(); | |
214 | final SWTBot dialogBot = shell.bot(); | |
215 | String text = dialogBot.label(1).getText(); | |
216 | dialogBot.button().click(); | |
217 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
218 | assertContains(fExpectedMessage, text); | |
219 | ||
220 | } | |
221 | ||
222 | } |