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