1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * (Extracted from ImportAndReadSmokeTest.java)
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ctf
.ui
.swtbot
.tests
;
16 import static org
.junit
.Assert
.assertNotNull
;
18 import java
.util
.List
;
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
;
63 * Abstract SWTBot Smoke test class.
65 * @author Matthew Khouzam
66 * @author Bernd Hufmann
68 @RunWith(SWTBotJunit4ClassRunner
.class)
69 public abstract class AbstractImportAndReadSmokeTest
{
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
;
80 protected static Wizard fWizard
;
82 /** The Log4j logger instance. */
83 protected static final Logger fLogger
= Logger
.getRootLogger();
85 /** Test Class setup */
87 public static void init() {
88 SWTBotUtil
.failIfUIThread();
90 /* set up for swtbot */
91 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
92 fLogger
.addAppender(new NullAppender());
93 fBot
= new SWTWorkbenchBot();
95 SWTBotUtil
.closeView("welcome", fBot
);
97 SWTBotUtil
.switchToTracingPerspective();
98 /* finish waiting for eclipse to load */
99 SWTBotUtil
.waitForJobs();
103 * Creates a tracing projects
105 protected void createProject() {
106 SWTBotUtil
.focusMainWindow(fBot
.shells());
107 fBot
.menu("File").menu("New").menu("Project...").click();
109 fBot
.waitUntil(Conditions
.shellIsActive("New Project"));
110 SWTBotTree tree
= fBot
.tree();
112 final String tracingKey
= "Tracing";
113 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
114 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
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
);
122 tracingProject
.select();
123 tracingProject
.click();
125 SWTBotButton nextButton
= fBot
.button("Next >");
126 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
128 fBot
.waitUntil(Conditions
.shellIsActive("Tracing Project"));
130 final SWTBotText text
= fBot
.text();
131 text
.setText(getProjectName());
133 fBot
.button("Finish").click();
134 SWTBotUtil
.waitForJobs();
138 * Opens and get the TmfEventsEditor
139 * @return TmfEventsEditor
141 protected TmfEventsEditor
openEditor() {
142 final SWTBotView projectExplorerBot
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
143 projectExplorerBot
.setFocus();
145 final SWTBotTree tree
= fBot
.tree();
146 final SWTBotTreeItem treeItem
= tree
.getTreeItem(getProjectName());
149 List
<String
> nodes
= treeItem
.getNodes();
150 String nodeName
= "";
151 for (String node
: nodes
) {
152 if (node
.startsWith("Traces")) {
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();
164 final IEditorPart iep
[] = new IEditorPart
[1];
165 UIThreadRunnable
.syncExec(new VoidResult() {
168 IEditorReference
[] ieds
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
171 for (IEditorReference ied
: ieds
) {
172 if (ied
.getTitle().equals(TRACE_NAME
)) {
173 iep
[0] = ied
.getEditor(true);
179 assertNotNull(iep
[0]);
180 return (TmfEventsEditor
) iep
[0];
184 * Deletes the tracing project
186 protected void deleteProject() {
187 // Wait for any analysis to complete because it might create supplementary files
188 SWTBotUtil
.waitForJobs();
190 ResourcesPlugin
.getWorkspace().getRoot().getProject(getProjectName()).refreshLocal(IResource
.DEPTH_INFINITE
, null);
191 } catch (CoreException e
) {
194 SWTBotUtil
.waitForJobs();
196 final SWTBotView projectViewBot
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
197 projectViewBot
.setFocus();
199 SWTBotTree treeBot
= fBot
.tree();
200 SWTBotTreeItem treeItem
= treeBot
.getTreeItem(getProjectName());
201 SWTBotMenu contextMenu
= treeItem
.contextMenu("Delete");
204 String shellText
= "Delete Resources";
205 fBot
.waitUntil(Conditions
.shellIsActive(shellText
));
206 final SWTBotButton okButton
= fBot
.button("OK");
207 fBot
.waitUntil(Conditions
.widgetIsEnabled(okButton
));
210 SWTBotUtil
.waitForJobs();
214 * Finishes the wizard
216 protected void importFinish() {
217 SWTBotShell shell
= fBot
.activeShell();
218 final SWTBotButton finishButton
= fBot
.button("Finish");
219 finishButton
.click();
220 fBot
.waitUntil(Conditions
.shellCloses(shell
));
221 SWTBotUtil
.waitForJobs();
225 * Gets the project Name
226 * @return the project name
228 protected abstract String
getProjectName();
230 // ---------------------------------------------
231 // Helpers for testing views
232 // ---------------------------------------------
235 * Verifies the properties view for a given view part
240 protected void testPropertyView(IViewPart vp
) {
241 PropertySheet pv
= (PropertySheet
) vp
;
246 * Verifies the Histogram View
252 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
253 final CtfTmfEvent desiredEvent1
= getEvent(100);
254 UIThreadRunnable
.syncExec(new VoidResult() {
258 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
262 SWTBotUtil
.waitForJobs();
263 SWTBotUtil
.delay(1000);
265 final CtfTmfEvent desiredEvent2
= getEvent(10000);
266 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
267 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
268 for (SWTBotToolbarButton hvTool
: hvTools
) {
269 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
273 HistogramView hv
= (HistogramView
) vp
;
274 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, desiredEvent1
.getTimestamp());
275 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, desiredEvent2
.getTimestamp());
276 hv
.updateTimeRange(100000);
277 SWTBotUtil
.waitForJobs();
278 hv
.currentTimeUpdated(signal
);
279 hv
.broadcast(signal
);
280 SWTBotUtil
.waitForJobs();
281 SWTBotUtil
.delay(1000);
283 hv
.updateTimeRange(1000000000);
284 SWTBotUtil
.waitForJobs();
285 hv
.currentTimeUpdated(signal2
);
286 hv
.broadcast(signal2
);
287 SWTBotUtil
.waitForJobs();
288 SWTBotUtil
.delay(1000);
293 * Verifies the statistics view
297 protected void testStatisticsView(IViewPart vp
) {
298 TmfStatisticsView sv
= (TmfStatisticsView
) vp
;
302 // ---------------------------------------------
304 // ---------------------------------------------
307 * Gets an event at a given rank
310 * @return the event at given rank
312 protected CtfTmfEvent
getEvent(int rank
) {
313 CtfTmfTrace trace
= fTrace
.getTrace();
317 ITmfContext ctx
= trace
.seekEvent(0);
318 for (int i
= 0; i
< rank
; i
++) {
321 final CtfTmfEvent retVal
= trace
.getNext(ctx
);
327 * Gets a view part based on view title
330 * @return the view part
332 protected IViewPart
getViewPart(final String viewTile
) {
333 final IViewPart
[] vps
= new IViewPart
[1];
334 UIThreadRunnable
.syncExec(new VoidResult() {
337 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
338 for (IViewReference viewRef
: viewRefs
) {
339 IViewPart vp
= viewRef
.getView(true);
340 if (vp
.getTitle().equals(viewTile
)) {