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
.Assume
.assumeTrue
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
24 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
25 import org
.eclipse
.jface
.wizard
.Wizard
;
26 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
28 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
29 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
30 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
31 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
32 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
35 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
36 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
37 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
38 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
41 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
42 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
43 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
45 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
46 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.histogram
.HistogramView
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.statistics
.TmfStatisticsView
;
49 import org
.eclipse
.ui
.IViewPart
;
50 import org
.eclipse
.ui
.IViewReference
;
51 import org
.eclipse
.ui
.PlatformUI
;
52 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
53 import org
.junit
.AfterClass
;
54 import org
.junit
.BeforeClass
;
55 import org
.junit
.runner
.RunWith
;
58 * Abstract SWTBot Smoke test class.
60 * @author Matthew Khouzam
61 * @author Bernd Hufmann
63 @RunWith(SWTBotJunit4ClassRunner
.class)
64 public abstract class AbstractImportAndReadSmokeTest
{
67 protected static final String TRACE_NAME
= "scp_dest";
69 protected static final String TRACE_FOLDER
= "synctraces";
70 /** Trace type name for generic CTF traces */
71 protected static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
72 /** A Generic CTF Trace*/
73 protected static final CtfTmfTestTrace fTrace
= CtfTmfTestTrace
.SYNC_DEST
;
74 /** SWT BOT workbench reference */
75 protected static SWTWorkbenchBot fBot
;
77 protected static Wizard fWizard
;
79 /** The Log4j logger instance. */
80 protected static final Logger fLogger
= Logger
.getRootLogger();
82 /** Test Class setup */
84 public static void init() {
85 assumeTrue(fTrace
.exists());
86 SWTBotUtils
.failIfUIThread();
88 /* set up for swtbot */
89 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
90 fLogger
.removeAllAppenders();
91 fLogger
.addAppender(new NullAppender());
92 fBot
= new SWTWorkbenchBot();
94 SWTBotUtils
.closeView("welcome", fBot
);
96 SWTBotUtils
.switchToTracingPerspective();
97 /* finish waiting for eclipse to load */
98 SWTBotUtils
.waitForJobs();
102 * Test Class teardown
105 public static void terminate() {
106 fLogger
.removeAllAppenders();
110 * Creates a tracing projects
112 protected void createProject() {
113 SWTBotUtils
.focusMainWindow(fBot
.shells());
114 fBot
.menu("File").menu("New").menu("Project...").click();
116 fBot
.shell("New Project").setFocus();
117 SWTBotTree tree
= fBot
.tree();
119 final String tracingKey
= "Tracing";
120 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
121 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
123 tracingNode
.select();
124 final String projectKey
= "Tracing Project";
125 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
126 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
127 assertNotNull(tracingProject
);
129 tracingProject
.select();
130 tracingProject
.click();
132 SWTBotButton nextButton
= fBot
.button("Next >");
133 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
135 fBot
.shell("Tracing Project").setFocus();
137 final SWTBotText text
= fBot
.text();
138 text
.setText(getProjectName());
140 fBot
.button("Finish").click();
141 SWTBotUtils
.waitForJobs();
145 * Finishes the wizard
147 protected void importFinish() {
148 SWTBotShell shell
= fBot
.activeShell();
149 final SWTBotButton finishButton
= fBot
.button("Finish");
150 finishButton
.click();
151 fBot
.waitUntil(Conditions
.shellCloses(shell
));
152 SWTBotUtils
.waitForJobs();
156 * Gets the project Name
157 * @return the project name
159 protected abstract String
getProjectName();
161 // ---------------------------------------------
162 // Helpers for testing views
163 // ---------------------------------------------
166 * Verifies the properties view for a given view part
171 protected void testPropertyView(IViewPart vp
) {
172 PropertySheet pv
= (PropertySheet
) vp
;
177 * Verifies the Histogram View
183 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
184 final CtfTmfEvent desiredEvent1
= getEvent(100);
185 UIThreadRunnable
.syncExec(new VoidResult() {
189 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
193 SWTBotUtils
.waitForJobs();
194 SWTBotUtils
.delay(1000);
196 final CtfTmfEvent desiredEvent2
= getEvent(10000);
197 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
198 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
199 for (SWTBotToolbarButton hvTool
: hvTools
) {
200 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
204 HistogramView hv
= (HistogramView
) vp
;
205 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, desiredEvent1
.getTimestamp());
206 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, desiredEvent2
.getTimestamp());
207 hv
.updateTimeRange(100000);
208 SWTBotUtils
.waitForJobs();
209 hv
.currentTimeUpdated(signal
);
210 hv
.broadcast(signal
);
211 SWTBotUtils
.waitForJobs();
212 SWTBotUtils
.delay(1000);
214 hv
.updateTimeRange(1000000000);
215 SWTBotUtils
.waitForJobs();
216 hv
.currentTimeUpdated(signal2
);
217 hv
.broadcast(signal2
);
218 SWTBotUtils
.waitForJobs();
219 SWTBotUtils
.delay(1000);
224 * Verifies the statistics view
228 protected void testStatisticsView(IViewPart vp
) {
229 TmfStatisticsView sv
= (TmfStatisticsView
) vp
;
233 // ---------------------------------------------
235 // ---------------------------------------------
238 * Gets an event at a given rank
241 * @return the event at given rank
243 protected CtfTmfEvent
getEvent(int rank
) {
244 try (CtfTmfTrace trace
= fTrace
.getTrace()) {
245 ITmfContext ctx
= trace
.seekEvent(0);
246 for (int i
= 0; i
< rank
; i
++) {
249 return trace
.getNext(ctx
);
254 * Gets a view part based on view title
257 * @return the view part
259 protected IViewPart
getViewPart(final String viewTile
) {
260 final IViewPart
[] vps
= new IViewPart
[1];
261 UIThreadRunnable
.syncExec(new VoidResult() {
264 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
265 for (IViewReference viewRef
: viewRefs
) {
266 IViewPart vp
= viewRef
.getView(true);
267 if (vp
.getTitle().equals(viewTile
)) {