Commit | Line | Data |
---|---|---|
2f7b3dd7 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 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 - Initial API and implementation | |
11 | * (Extracted from ImportAndReadSmokeTest.java) | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests; | |
15 | ||
16 | import static org.junit.Assert.assertNotNull; | |
17 | ||
18 | import java.util.List; | |
19 | ||
20 | import org.apache.log4j.Logger; | |
21 | import org.apache.log4j.varia.NullAppender; | |
22 | import org.eclipse.core.resources.IResource; | |
23 | import org.eclipse.core.resources.ResourcesPlugin; | |
24 | import org.eclipse.core.runtime.CoreException; | |
25 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
26 | import org.eclipse.jface.viewers.StructuredSelection; | |
27 | import org.eclipse.jface.wizard.Wizard; | |
28 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
29 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; | |
30 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent; | |
31 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; | |
32 | import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace; | |
33 | import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; | |
34 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil; | |
35 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers; | |
36 | import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView; | |
37 | import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsView; | |
38 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
39 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
40 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
41 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
42 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
43 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
44 | import org.eclipse.swtbot.swt.finder.waits.Conditions; | |
45 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; | |
46 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; | |
47 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
48 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; | |
49 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; | |
50 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
51 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
52 | import org.eclipse.ui.IEditorPart; | |
53 | import org.eclipse.ui.IEditorReference; | |
54 | import org.eclipse.ui.IPageLayout; | |
55 | import org.eclipse.ui.IViewPart; | |
56 | import org.eclipse.ui.IViewReference; | |
57 | import org.eclipse.ui.PlatformUI; | |
58 | import org.eclipse.ui.views.properties.PropertySheet; | |
59 | import org.junit.BeforeClass; | |
60 | import org.junit.runner.RunWith; | |
61 | ||
62 | /** | |
63 | * Abstract SWTBot Smoke test class. | |
64 | * | |
65 | * @author Matthew Khouzam | |
66 | * @author Bernd Hufmann | |
67 | */ | |
68 | @RunWith(SWTBotJunit4ClassRunner.class) | |
69 | public abstract class AbstractImportAndReadSmokeTest { | |
70 | ||
71 | /** Trace name */ | |
72 | protected static final String TRACE_NAME = "synthetic-trace"; | |
73 | /** Trace type name for generic CTF traces */ | |
74 | protected static final String TRACE_TYPE_NAME = "Generic CTF Trace"; | |
75 | /** A Generic CTF Trace*/ | |
76 | protected static final CtfTmfTestTrace fTrace = CtfTmfTestTrace.SYNTHETIC_TRACE; | |
77 | /** SWT BOT workbench reference */ | |
78 | protected static SWTWorkbenchBot fBot; | |
79 | /** Wizard to use */ | |
80 | protected static Wizard fWizard; | |
81 | ||
82 | /** The Log4j logger instance. */ | |
83 | protected static final Logger fLogger = Logger.getRootLogger(); | |
84 | ||
85 | /** Test Class setup */ | |
86 | @BeforeClass | |
87 | public static void init() { | |
88 | SWTBotUtil.failIfUIThread(); | |
89 | ||
90 | /* set up for swtbot */ | |
91 | SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */ | |
92 | fLogger.addAppender(new NullAppender()); | |
93 | fBot = new SWTWorkbenchBot(); | |
94 | ||
95 | SWTBotUtil.closeView("welcome", fBot); | |
96 | ||
97 | SWTBotUtil.switchToTracingPerspective(); | |
98 | /* finish waiting for eclipse to load */ | |
99 | SWTBotUtil.waitForJobs(); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Creates a tracing projects | |
104 | */ | |
105 | protected void createProject() { | |
106 | SWTBotUtil.focusMainWindow(fBot.shells()); | |
107 | fBot.menu("File").menu("New").menu("Project...").click(); | |
108 | ||
8af624a8 | 109 | fBot.shell("New Project").setFocus(); |
2f7b3dd7 BH |
110 | SWTBotTree tree = fBot.tree(); |
111 | assertNotNull(tree); | |
112 | final String tracingKey = "Tracing"; | |
113 | fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree)); | |
114 | final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey); | |
115 | ||
116 | tracingNode.select(); | |
117 | final String projectKey = "Tracing Project"; | |
118 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(projectKey, tracingNode)); | |
119 | final SWTBotTreeItem tracingProject = tracingNode.getNode(projectKey); | |
120 | assertNotNull(tracingProject); | |
121 | ||
122 | tracingProject.select(); | |
123 | tracingProject.click(); | |
124 | ||
125 | SWTBotButton nextButton = fBot.button("Next >"); | |
126 | fBot.waitUntil(Conditions.widgetIsEnabled(nextButton)); | |
127 | nextButton.click(); | |
8af624a8 | 128 | fBot.shell("Tracing Project").setFocus(); |
2f7b3dd7 BH |
129 | |
130 | final SWTBotText text = fBot.text(); | |
131 | text.setText(getProjectName()); | |
132 | ||
133 | fBot.button("Finish").click(); | |
134 | SWTBotUtil.waitForJobs(); | |
135 | } | |
136 | ||
137 | /** | |
138 | * Opens and get the TmfEventsEditor | |
139 | * @return TmfEventsEditor | |
140 | */ | |
141 | protected TmfEventsEditor openEditor() { | |
142 | final SWTBotView projectExplorerBot = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER); | |
143 | projectExplorerBot.setFocus(); | |
144 | ||
145 | final SWTBotTree tree = fBot.tree(); | |
146 | final SWTBotTreeItem treeItem = tree.getTreeItem(getProjectName()); | |
147 | treeItem.expand(); | |
148 | ||
149 | List<String> nodes = treeItem.getNodes(); | |
150 | String nodeName = ""; | |
151 | for (String node : nodes) { | |
152 | if (node.startsWith("Traces")) { | |
153 | nodeName = node; | |
154 | } | |
155 | } | |
156 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, treeItem)); | |
157 | treeItem.getNode(nodeName).expand(); | |
158 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(TRACE_NAME, treeItem.getNode(nodeName))); | |
159 | treeItem.getNode(nodeName).getNode(TRACE_NAME).select(); | |
160 | treeItem.getNode(nodeName).getNode(TRACE_NAME).doubleClick(); | |
161 | SWTBotUtil.delay(1000); | |
162 | SWTBotUtil.waitForJobs(); | |
163 | ||
164 | final IEditorPart iep[] = new IEditorPart[1]; | |
165 | UIThreadRunnable.syncExec(new VoidResult() { | |
166 | @Override | |
167 | public void run() { | |
168 | IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); | |
169 | assertNotNull(ieds); | |
170 | iep[0] = null; | |
171 | for (IEditorReference ied : ieds) { | |
172 | if (ied.getTitle().equals(TRACE_NAME)) { | |
173 | iep[0] = ied.getEditor(true); | |
174 | break; | |
175 | } | |
176 | } | |
177 | } | |
178 | }); | |
179 | assertNotNull(iep[0]); | |
180 | return (TmfEventsEditor) iep[0]; | |
181 | } | |
182 | ||
183 | /** | |
184 | * Deletes the tracing project | |
185 | */ | |
186 | protected void deleteProject() { | |
187 | // Wait for any analysis to complete because it might create supplementary files | |
188 | SWTBotUtil.waitForJobs(); | |
189 | try { | |
190 | ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()).refreshLocal(IResource.DEPTH_INFINITE, null); | |
191 | } catch (CoreException e) { | |
192 | } | |
193 | ||
194 | SWTBotUtil.waitForJobs(); | |
195 | ||
196 | final SWTBotView projectViewBot = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER); | |
197 | projectViewBot.setFocus(); | |
198 | ||
199 | SWTBotTree treeBot = fBot.tree(); | |
200 | SWTBotTreeItem treeItem = treeBot.getTreeItem(getProjectName()); | |
201 | SWTBotMenu contextMenu = treeItem.contextMenu("Delete"); | |
202 | contextMenu.click(); | |
203 | ||
8af624a8 | 204 | fBot.shell("Delete Resources").setFocus(); |
2f7b3dd7 BH |
205 | final SWTBotButton okButton = fBot.button("OK"); |
206 | fBot.waitUntil(Conditions.widgetIsEnabled(okButton)); | |
207 | okButton.click(); | |
208 | ||
209 | SWTBotUtil.waitForJobs(); | |
210 | } | |
211 | ||
212 | /** | |
213 | * Finishes the wizard | |
214 | */ | |
215 | protected void importFinish() { | |
216 | SWTBotShell shell = fBot.activeShell(); | |
217 | final SWTBotButton finishButton = fBot.button("Finish"); | |
218 | finishButton.click(); | |
219 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
220 | SWTBotUtil.waitForJobs(); | |
221 | } | |
222 | ||
223 | /** | |
224 | * Gets the project Name | |
225 | * @return the project name | |
226 | */ | |
227 | protected abstract String getProjectName(); | |
228 | ||
229 | // --------------------------------------------- | |
230 | // Helpers for testing views | |
231 | // --------------------------------------------- | |
232 | ||
233 | /** | |
234 | * Verifies the properties view for a given view part | |
235 | * | |
236 | * @param vp | |
237 | * a view part | |
238 | */ | |
239 | protected void testPropertyView(IViewPart vp) { | |
240 | PropertySheet pv = (PropertySheet) vp; | |
241 | assertNotNull(pv); | |
242 | } | |
243 | ||
244 | /** | |
245 | * Verifies the Histogram View | |
246 | * @param vp | |
247 | * the view part | |
248 | * @param tmfEd | |
249 | * the events editor | |
250 | */ | |
251 | protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) { | |
252 | final CtfTmfEvent desiredEvent1 = getEvent(100); | |
253 | UIThreadRunnable.syncExec(new VoidResult() { | |
254 | @Override | |
255 | public void run() { | |
256 | tmfEd.setFocus(); | |
257 | tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1))); | |
258 | } | |
259 | }); | |
260 | ||
261 | SWTBotUtil.waitForJobs(); | |
262 | SWTBotUtil.delay(1000); | |
263 | ||
264 | final CtfTmfEvent desiredEvent2 = getEvent(10000); | |
265 | SWTBotView hvBot = fBot.viewById(HistogramView.ID); | |
266 | List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons(); | |
267 | for (SWTBotToolbarButton hvTool : hvTools) { | |
268 | if (hvTool.getToolTipText().toLowerCase().contains("lost")) { | |
269 | hvTool.click(); | |
270 | } | |
271 | } | |
272 | HistogramView hv = (HistogramView) vp; | |
273 | final TmfTimeSynchSignal signal = new TmfTimeSynchSignal(hv, desiredEvent1.getTimestamp()); | |
274 | final TmfTimeSynchSignal signal2 = new TmfTimeSynchSignal(hv, desiredEvent2.getTimestamp()); | |
275 | hv.updateTimeRange(100000); | |
276 | SWTBotUtil.waitForJobs(); | |
277 | hv.currentTimeUpdated(signal); | |
278 | hv.broadcast(signal); | |
279 | SWTBotUtil.waitForJobs(); | |
280 | SWTBotUtil.delay(1000); | |
281 | ||
282 | hv.updateTimeRange(1000000000); | |
283 | SWTBotUtil.waitForJobs(); | |
284 | hv.currentTimeUpdated(signal2); | |
285 | hv.broadcast(signal2); | |
286 | SWTBotUtil.waitForJobs(); | |
287 | SWTBotUtil.delay(1000); | |
288 | assertNotNull(hv); | |
289 | } | |
290 | ||
291 | /** | |
292 | * Verifies the statistics view | |
293 | * @param vp | |
294 | * the view part | |
295 | */ | |
296 | protected void testStatisticsView(IViewPart vp) { | |
297 | TmfStatisticsView sv = (TmfStatisticsView) vp; | |
298 | assertNotNull(sv); | |
299 | } | |
300 | ||
301 | // --------------------------------------------- | |
302 | // Trace helpers | |
303 | // --------------------------------------------- | |
304 | ||
305 | /** | |
306 | * Gets an event at a given rank | |
307 | * @param rank | |
308 | * a rank | |
309 | * @return the event at given rank | |
310 | */ | |
311 | protected CtfTmfEvent getEvent(int rank) { | |
7b3eb8c0 AM |
312 | try (CtfTmfTrace trace = fTrace.getTrace()) { |
313 | ITmfContext ctx = trace.seekEvent(0); | |
314 | for (int i = 0; i < rank; i++) { | |
315 | trace.getNext(ctx); | |
316 | } | |
317 | return trace.getNext(ctx); | |
2f7b3dd7 | 318 | } |
2f7b3dd7 BH |
319 | } |
320 | ||
321 | /** | |
322 | * Gets a view part based on view title | |
323 | * @param viewTile | |
324 | * a view title | |
325 | * @return the view part | |
326 | */ | |
327 | protected IViewPart getViewPart(final String viewTile) { | |
328 | final IViewPart[] vps = new IViewPart[1]; | |
329 | UIThreadRunnable.syncExec(new VoidResult() { | |
330 | @Override | |
331 | public void run() { | |
332 | IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences(); | |
333 | for (IViewReference viewRef : viewRefs) { | |
334 | IViewPart vp = viewRef.getView(true); | |
335 | if (vp.getTitle().equals(viewTile)) { | |
336 | vps[0] = vp; | |
337 | return; | |
338 | } | |
339 | } | |
340 | } | |
341 | }); | |
342 | ||
343 | return vps[0]; | |
344 | } | |
345 | } |