1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.jface
.wizard
.Wizard
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
29 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
30 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
31 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
32 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
33 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
35 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
36 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
37 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
38 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
39 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
40 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.views
.statistics
.TmfStatisticsViewImpl
;
41 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
44 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
45 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
46 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.histogram
.HistogramView
;
51 import org
.eclipse
.ui
.IViewPart
;
52 import org
.eclipse
.ui
.IViewReference
;
53 import org
.eclipse
.ui
.PlatformUI
;
54 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
55 import org
.junit
.AfterClass
;
56 import org
.junit
.BeforeClass
;
57 import org
.junit
.runner
.RunWith
;
60 * Abstract SWTBot Smoke test class.
62 * @author Matthew Khouzam
63 * @author Bernd Hufmann
65 @RunWith(SWTBotJunit4ClassRunner
.class)
66 public abstract class AbstractImportAndReadSmokeTest
{
69 protected static final String TRACE_NAME
= "scp_dest";
71 protected static final String TRACE_FOLDER
= "synctraces";
72 /** Trace type name for generic CTF traces */
73 protected static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
74 /** A Generic CTF Trace */
75 protected static final @NonNull CtfTestTrace fTrace
= CtfTestTrace
.SYNC_DEST
;
76 /** SWT BOT workbench reference */
77 protected static SWTWorkbenchBot fBot
;
79 protected static Wizard fWizard
;
81 /** The Log4j logger instance. */
82 protected static final Logger fLogger
= Logger
.getRootLogger();
84 /** Test Class setup */
86 public static void init() {
87 SWTBotUtils
.initialize();
89 /* set up for swtbot */
90 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
91 fLogger
.removeAllAppenders();
92 fLogger
.addAppender(new NullAppender());
93 fBot
= new SWTWorkbenchBot();
95 SWTBotUtils
.closeView("welcome", fBot
);
97 SWTBotUtils
.switchToTracingPerspective();
98 /* finish waiting for eclipse to load */
99 SWTBotUtils
.waitForJobs();
103 * Test Class teardown
106 public static void terminate() {
107 fLogger
.removeAllAppenders();
111 * Creates a tracing projects
113 * @param traceProjectName
114 * the name of the test project
116 protected static void createProject(String traceProjectName
) {
117 SWTBotUtils
.focusMainWindow(fBot
.shells());
118 fBot
.menu("File").menu("New").menu("Project...").click();
120 fBot
.shell("New Project").setFocus();
121 SWTBotTree tree
= fBot
.tree();
123 final String tracingKey
= "Tracing";
124 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
125 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
127 tracingNode
.select();
128 final String projectKey
= "Tracing Project";
129 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
130 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
131 assertNotNull(tracingProject
);
133 tracingProject
.select();
134 tracingProject
.click();
136 SWTBotButton nextButton
= fBot
.button("Next >");
137 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
139 fBot
.shell("Tracing Project").setFocus();
141 final SWTBotText text
= fBot
.text();
142 text
.setText(traceProjectName
);
144 fBot
.button("Finish").click();
145 SWTBotUtils
.waitForJobs();
149 * Finishes the wizard
151 protected void importFinish() {
152 SWTBotShell shell
= fBot
.activeShell();
153 final SWTBotButton finishButton
= fBot
.button("Finish");
154 finishButton
.click();
155 fBot
.waitUntil(Conditions
.shellCloses(shell
));
156 SWTBotUtils
.waitForJobs();
160 * Checks finish button enablement
163 * state to check against
166 protected void checkFinishButton(boolean isEnabled
) {
167 final SWTBotButton finishButton
= fBot
.button("Finish");
168 assertTrue(finishButton
.isEnabled() == isEnabled
);
171 // ---------------------------------------------
172 // Helpers for testing views
173 // ---------------------------------------------
176 * Verifies the properties view for a given view part
181 protected void testPropertyView(IViewPart vp
) {
182 PropertySheet pv
= (PropertySheet
) vp
;
187 * Verifies the Histogram View
194 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
195 final CtfTmfEvent desiredEvent1
= getEvent(100);
196 UIThreadRunnable
.syncExec(new VoidResult() {
200 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
204 SWTBotUtils
.waitForJobs();
205 SWTBotUtils
.delay(1000);
207 final CtfTmfEvent desiredEvent2
= getEvent(10000);
208 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
209 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
210 for (SWTBotToolbarButton hvTool
: hvTools
) {
211 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
215 HistogramView hv
= (HistogramView
) vp
;
216 final TmfSelectionRangeUpdatedSignal signal
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent1
.getTimestamp());
217 final TmfSelectionRangeUpdatedSignal signal2
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent2
.getTimestamp());
218 hv
.updateTimeRange(100000);
219 SWTBotUtils
.waitForJobs();
220 hv
.selectionRangeUpdated(signal
);
221 hv
.broadcast(signal
);
222 SWTBotUtils
.waitForJobs();
223 SWTBotUtils
.delay(1000);
225 hv
.updateTimeRange(1000000000);
226 SWTBotUtils
.waitForJobs();
227 hv
.selectionRangeUpdated(signal2
);
228 hv
.broadcast(signal2
);
229 SWTBotUtils
.waitForJobs();
230 SWTBotUtils
.delay(1000);
235 * Verifies the statistics view
240 protected void testStatisticsView(IViewPart vp
) {
241 TmfStatisticsViewImpl sv
= (TmfStatisticsViewImpl
) vp
;
245 // ---------------------------------------------
247 // ---------------------------------------------
250 * Gets an event at a given rank
254 * @return the event at given rank
256 protected CtfTmfEvent
getEvent(int rank
) {
257 CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(fTrace
);
258 ITmfContext ctx
= trace
.seekEvent(rank
);
259 CtfTmfEvent ret
= trace
.getNext(ctx
);
265 * Gets a view part based on view title
269 * @return the view part
271 protected IViewPart
getViewPart(final String viewTile
) {
272 final IViewPart
[] vps
= new IViewPart
[1];
273 UIThreadRunnable
.syncExec(new VoidResult() {
276 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
277 for (IViewReference viewRef
: viewRefs
) {
278 IViewPart vp
= viewRef
.getView(true);
279 if (vp
.getTitle().equals(viewTile
)) {