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