Commit | Line | Data |
---|---|---|
2470d687 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 | *******************************************************************************/ | |
12 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events; | |
13 | ||
14 | import static org.junit.Assert.assertEquals; | |
15 | import static org.junit.Assert.assertNotNull; | |
16 | ||
17 | import java.io.File; | |
18 | import java.io.IOException; | |
19 | ||
20 | import org.apache.log4j.ConsoleAppender; | |
21 | import org.apache.log4j.Logger; | |
22 | import org.apache.log4j.SimpleLayout; | |
6941941d MAL |
23 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
24 | import org.eclipse.core.runtime.preferences.InstanceScope; | |
2470d687 MK |
25 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
26 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
27 | import org.eclipse.swtbot.swt.finder.SWTBot; | |
9afd04ae | 28 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
2470d687 MK |
29 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; |
30 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo; | |
31 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; | |
665990bb | 32 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; |
2470d687 MK |
33 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; |
34 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
35 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
6941941d | 36 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
2470d687 | 37 | import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile; |
6941941d | 38 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants; |
9bb4b61e | 39 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimePreferences; |
6941941d | 40 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; |
2470d687 MK |
41 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
42 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
f0beeb4a | 43 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
2470d687 | 44 | import org.eclipse.tracecompass.tmf.ui.views.filter.FilterView; |
2470d687 MK |
45 | import org.junit.After; |
46 | import org.junit.AfterClass; | |
47 | import org.junit.Before; | |
48 | import org.junit.BeforeClass; | |
49 | import org.junit.Test; | |
9afd04ae | 50 | import org.junit.runner.RunWith; |
2470d687 MK |
51 | |
52 | /** | |
53 | * Test for filter views in trace compass | |
54 | */ | |
9afd04ae | 55 | @RunWith(SWTBotJunit4ClassRunner.class) |
2470d687 MK |
56 | public class FilterViewerTest { |
57 | ||
58 | ||
59 | private static final String COMPARE = "COMPARE"; | |
60 | private static final String CONTAINS = "CONTAINS"; | |
61 | private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub"; | |
62 | private static final String TRACETYPE = "Test trace : XML Trace Stub"; | |
63 | private static final String AND = "AND"; | |
64 | private static final String WITH_TRACETYPE = "WITH TRACETYPE " + TRACETYPE; | |
65 | private static final String FILTER_TEST = "FILTER "; | |
11a4b9ac PT |
66 | private static final String TIMESTAMP = "Timestamp"; |
67 | private static final String CONTENTS = "Contents"; | |
2470d687 MK |
68 | |
69 | private static final String TRACE_START = "<trace>"; | |
70 | private static final String EVENT_BEGIN = "<event timestamp=\""; | |
71 | private static final String EVENT_MIDDLE = " \" name=\"event\"><field name=\"field\" value=\""; | |
72 | private static final String EVENT_END = "\" type=\"int\" />" + "</event>"; | |
73 | private static final String TRACE_END = "</trace>"; | |
74 | ||
2470d687 MK |
75 | private static final String PROJECT_NAME = "TestForFiltering"; |
76 | ||
77 | /** The Log4j logger instance. */ | |
78 | private static final Logger fLogger = Logger.getRootLogger(); | |
79 | private static final String OR = "OR"; | |
80 | private static SWTWorkbenchBot fBot; | |
81 | ||
82 | private static String makeEvent(int ts, int val) { | |
83 | return EVENT_BEGIN + Integer.toString(ts) + EVENT_MIDDLE + Integer.toString(val) + EVENT_END + "\n"; | |
84 | } | |
85 | ||
86 | private static File fFileLocation; | |
87 | ||
88 | /** | |
89 | * Initialization, creates a temp trace | |
90 | * | |
91 | * @throws IOException | |
92 | * should not happen | |
93 | */ | |
94 | @BeforeClass | |
95 | public static void init() throws IOException { | |
6941941d MAL |
96 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); |
97 | defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00"); | |
98 | TmfTimestampFormat.updateDefaultFormats(); | |
99 | ||
5785ab49 | 100 | SWTBotUtils.initialize(); |
2470d687 MK |
101 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger |
102 | /* set up for swtbot */ | |
103 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
f10c30a0 | 104 | fLogger.removeAllAppenders(); |
2470d687 MK |
105 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); |
106 | fBot = new SWTWorkbenchBot(); | |
107 | ||
108 | SWTBotUtils.closeView("welcome", fBot); | |
109 | ||
110 | SWTBotUtils.switchToTracingPerspective(); | |
111 | /* finish waiting for eclipse to load */ | |
f0beeb4a | 112 | WaitUtils.waitForJobs(); |
2470d687 MK |
113 | fFileLocation = File.createTempFile("sample", ".xml"); |
114 | try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) { | |
115 | braf.writeBytes(TRACE_START); | |
116 | for (int i = 0; i < 100; i++) { | |
117 | braf.writeBytes(makeEvent(i * 100, i % 4)); | |
118 | } | |
119 | braf.writeBytes(TRACE_END); | |
120 | } | |
121 | } | |
122 | ||
123 | /** | |
124 | * Open a trace in an editor | |
125 | */ | |
126 | @Before | |
127 | public void beforeTest() { | |
128 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
129 | SWTBotUtils.createProject(PROJECT_NAME); | |
130 | SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(bot, PROJECT_NAME); | |
131 | assertNotNull(treeItem); | |
132 | SWTBotUtils.openTrace(PROJECT_NAME, fFileLocation.getAbsolutePath(), XMLSTUB_ID); | |
133 | SWTBotUtils.openView(FilterView.ID); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Delete the file | |
138 | */ | |
139 | @AfterClass | |
140 | public static void cleanUp() { | |
141 | fFileLocation.delete(); | |
142 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); | |
f10c30a0 | 143 | fLogger.removeAllAppenders(); |
e4d15418 | 144 | SWTBotUtils.closeViewById(FilterView.ID, fBot); |
6941941d MAL |
145 | |
146 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
9bb4b61e | 147 | defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, TmfTimePreferences.getDefaultPreferenceMap().get(ITmfTimePreferencesConstants.TIME_ZONE)); |
6941941d | 148 | TmfTimestampFormat.updateDefaultFormats(); |
2470d687 MK |
149 | } |
150 | ||
151 | /** | |
152 | * Close the editor | |
153 | */ | |
154 | @After | |
155 | public void tearDown() { | |
156 | fBot.closeAllEditors(); | |
157 | } | |
158 | ||
159 | /** | |
160 | * Return all timestamps ending with 100... for reasons | |
161 | */ | |
162 | @Test | |
163 | public void testTimestampFilter() { | |
164 | SWTBotView viewBot = fBot.viewById(FilterView.ID); | |
165 | viewBot.setFocus(); | |
166 | SWTBot filterBot = viewBot.bot(); | |
167 | SWTBotTree treeBot = filterBot.tree(); | |
168 | ||
169 | viewBot.toolbarButton("Add new filter").click(); | |
170 | treeBot.getTreeItem("FILTER <name>").select(); | |
171 | SWTBotText textBot = filterBot.text(); | |
172 | textBot.setFocus(); | |
173 | String filterName = "timestamp"; | |
174 | textBot.setText(filterName); | |
175 | SWTBotTreeItem filterNodeBot = treeBot.getTreeItem(FILTER_TEST + filterName); | |
176 | filterNodeBot.click(); | |
177 | filterNodeBot.contextMenu("TRACETYPE").click(); | |
178 | filterNodeBot.expand(); | |
179 | SWTBotCombo comboBot = filterBot.comboBox(); | |
180 | comboBot.setSelection(TRACETYPE); | |
181 | filterNodeBot.getNode(WITH_TRACETYPE).expand(); | |
182 | ||
183 | // -------------------------------------------------------------------- | |
184 | // add AND | |
185 | // -------------------------------------------------------------------- | |
186 | ||
187 | filterNodeBot.getNode(WITH_TRACETYPE).contextMenu(AND).click(); | |
188 | ||
189 | // -------------------------------------------------------------------- | |
190 | // add CONTAINS "100" | |
191 | // -------------------------------------------------------------------- | |
192 | ||
193 | filterNodeBot.getNode(WITH_TRACETYPE).getNode(AND).contextMenu(CONTAINS).click(); | |
194 | filterNodeBot.getNode(WITH_TRACETYPE).getNode(AND).expand(); | |
11a4b9ac PT |
195 | comboBot = filterBot.comboBox(1); // aspect |
196 | comboBot.setSelection(TIMESTAMP); | |
2470d687 MK |
197 | textBot = filterBot.text(); |
198 | textBot.setFocus(); | |
199 | textBot.setText("100"); | |
200 | filterNodeBot.getNode(WITH_TRACETYPE).getNode(AND).getNode("Timestamp CONTAINS \"100\"").select(); | |
201 | filterNodeBot.getNode(WITH_TRACETYPE).getNode(AND).select(); | |
202 | ||
203 | viewBot.toolbarButton("Save filters").click(); | |
204 | ||
205 | String ret = applyFilter(fBot, filterName); | |
206 | assertEquals("10/100", ret); | |
207 | } | |
208 | ||
209 | /** | |
210 | * Return all timestamps ending with 100... for reasons | |
211 | */ | |
212 | @Test | |
213 | public void testTimestampEqualsOr() { | |
214 | SWTBotView viewBot = fBot.viewById(FilterView.ID); | |
215 | viewBot.setFocus(); | |
216 | SWTBot filterBot = viewBot.bot(); | |
217 | SWTBotTree treeBot = filterBot.tree(); | |
218 | ||
219 | viewBot.toolbarButton("Add new filter").click(); | |
220 | treeBot.getTreeItem("FILTER <name>").select(); | |
221 | SWTBotText textBot = filterBot.text(); | |
222 | textBot.setFocus(); | |
223 | String filterName = "matchAndEquals"; | |
224 | textBot.setText(filterName); | |
225 | SWTBotTreeItem filterNodeBot = treeBot.getTreeItem(FILTER_TEST + filterName); | |
226 | filterNodeBot.click(); | |
227 | filterNodeBot.contextMenu("TRACETYPE").click(); | |
228 | filterNodeBot.expand(); | |
229 | SWTBotCombo comboBot = filterBot.comboBox(); | |
230 | comboBot.setSelection(TRACETYPE); | |
231 | filterNodeBot.getNode(WITH_TRACETYPE).expand(); | |
232 | ||
233 | // -------------------------------------------------------------------- | |
234 | // add OR | |
235 | // -------------------------------------------------------------------- | |
236 | ||
237 | filterNodeBot.getNode(WITH_TRACETYPE).contextMenu(OR).click(); | |
238 | ||
239 | // -------------------------------------------------------------------- | |
240 | // add EQUALS "19...300" | |
241 | // -------------------------------------------------------------------- | |
242 | ||
243 | SWTBotTreeItem orNode = filterNodeBot.getNode(WITH_TRACETYPE).getNode(OR); | |
244 | orNode.contextMenu("EQUALS").click(); | |
245 | orNode.expand(); | |
246 | orNode.getNode(0).select(); | |
11a4b9ac PT |
247 | comboBot = filterBot.comboBox(1); // aspect |
248 | comboBot.setSelection(TIMESTAMP); | |
2470d687 MK |
249 | textBot = filterBot.text(); |
250 | textBot.setFocus(); | |
251 | textBot.setText("19:00:00.000 000 300"); | |
252 | ||
253 | // -------------------------------------------------------------------- | |
254 | // add MATCHES "1" | |
255 | // -------------------------------------------------------------------- | |
256 | orNode.contextMenu("MATCHES").click(); | |
257 | orNode.expand(); | |
258 | orNode.getNode(1).select(); | |
11a4b9ac PT |
259 | comboBot = filterBot.comboBox(1); // aspect |
260 | comboBot.setSelection(CONTENTS); | |
261 | textBot = filterBot.text(0); // field | |
2470d687 MK |
262 | textBot.setFocus(); |
263 | textBot.setText("field"); | |
11a4b9ac | 264 | textBot = filterBot.text(1); // value |
2470d687 MK |
265 | textBot.setFocus(); |
266 | textBot.setText("1"); | |
267 | ||
268 | viewBot.toolbarButton("Save filters").click(); | |
269 | ||
270 | String ret = applyFilter(fBot, filterName); | |
271 | assertEquals("26/100", ret); | |
6941941d | 272 | // filterNodeBot.contextMenu().menu("Delete").click(); |
2470d687 MK |
273 | } |
274 | ||
275 | /** | |
276 | * test compare field >= 2 | |
277 | */ | |
278 | @Test | |
279 | public void testField01() { | |
280 | SWTBotView viewBot = fBot.viewById(FilterView.ID); | |
281 | viewBot.setFocus(); | |
282 | SWTBot filterBot = viewBot.bot(); | |
283 | SWTBotTree treeBot = filterBot.tree(); | |
284 | ||
285 | viewBot.toolbarButton("Add new filter").click(); | |
286 | treeBot.getTreeItem("FILTER <name>").select(); | |
287 | SWTBotText textBot = filterBot.text(); | |
288 | textBot.setFocus(); | |
289 | String filterName = "field"; | |
290 | textBot.setText(filterName); | |
291 | SWTBotTreeItem filterNodeBot = treeBot.getTreeItem(FILTER_TEST + filterName); | |
292 | filterNodeBot.click(); | |
293 | filterNodeBot.contextMenu("TRACETYPE").click(); | |
294 | filterNodeBot.expand(); | |
295 | SWTBotCombo comboBot = filterBot.comboBox(); | |
296 | comboBot.setSelection(TRACETYPE); | |
297 | filterNodeBot.getNode(WITH_TRACETYPE).expand(); | |
298 | ||
299 | // -------------------------------------------------------------------- | |
300 | // add Compare > 1.5 | |
301 | // -------------------------------------------------------------------- | |
302 | ||
303 | filterNodeBot.getNode(WITH_TRACETYPE).contextMenu(COMPARE).click(); | |
304 | SWTBotTreeItem contentNode = filterNodeBot.getNode(WITH_TRACETYPE).getNode("<select aspect> " + "=" + " <value>"); | |
305 | contentNode.expand(); | |
11a4b9ac PT |
306 | comboBot = filterBot.comboBox(1); // aspect |
307 | comboBot.setSelection(CONTENTS); | |
308 | textBot = filterBot.text(0); // field | |
2470d687 MK |
309 | textBot.setFocus(); |
310 | textBot.setText(filterName); | |
311 | ||
11a4b9ac | 312 | textBot = filterBot.text(1); // value |
2470d687 MK |
313 | textBot.setFocus(); |
314 | textBot.setText("1.5"); | |
11a4b9ac | 315 | filterBot.radio(">").click(); |
2470d687 MK |
316 | |
317 | // -------------------------------------------------------------------- | |
318 | // apply | |
319 | // -------------------------------------------------------------------- | |
320 | viewBot.toolbarButton("Save filters").click(); | |
321 | ||
322 | String ret = applyFilter(fBot, filterName); | |
6941941d | 323 | // filterNodeBot.contextMenu().menu("Delete").click(); |
2470d687 MK |
324 | assertEquals("50/100", ret); |
325 | } | |
326 | ||
327 | private static String applyFilter(SWTWorkbenchBot bot, final String filterName) { | |
f0beeb4a | 328 | WaitUtils.waitForJobs(); |
11a4b9ac PT |
329 | final SWTBotTable eventsTable = SWTBotUtils.activeEventsEditor(bot).bot().table(); |
330 | SWTBotTableItem tableItem = eventsTable.getTableItem(2); | |
665990bb | 331 | tableItem.contextMenu(filterName).click(); |
11a4b9ac PT |
332 | fBot.waitUntil(ConditionHelpers.isTableCellFilled(eventsTable, "/100", 1, 1)); |
333 | return eventsTable.cell(1, 1); | |
2470d687 | 334 | } |
2470d687 | 335 | } |