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
.BeforeClass
;
54 import org
.junit
.runner
.RunWith
;
57 * Abstract SWTBot Smoke test class.
59 * @author Matthew Khouzam
60 * @author Bernd Hufmann
62 @RunWith(SWTBotJunit4ClassRunner
.class)
63 public abstract class AbstractImportAndReadSmokeTest
{
66 protected static final String TRACE_NAME
= "scp_dest";
68 protected static final String TRACE_FOLDER
= "synctraces";
69 /** Trace type name for generic CTF traces */
70 protected static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
71 /** A Generic CTF Trace*/
72 protected static final CtfTmfTestTrace fTrace
= CtfTmfTestTrace
.SYNC_DEST
;
73 /** SWT BOT workbench reference */
74 protected static SWTWorkbenchBot fBot
;
76 protected static Wizard fWizard
;
78 /** The Log4j logger instance. */
79 protected static final Logger fLogger
= Logger
.getRootLogger();
81 /** Test Class setup */
83 public static void init() {
84 assumeTrue(fTrace
.exists());
85 SWTBotUtils
.failIfUIThread();
87 /* set up for swtbot */
88 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
89 fLogger
.addAppender(new NullAppender());
90 fBot
= new SWTWorkbenchBot();
92 SWTBotUtils
.closeView("welcome", fBot
);
94 SWTBotUtils
.switchToTracingPerspective();
95 /* finish waiting for eclipse to load */
96 SWTBotUtils
.waitForJobs();
100 * Creates a tracing projects
102 protected void createProject() {
103 SWTBotUtils
.focusMainWindow(fBot
.shells());
104 fBot
.menu("File").menu("New").menu("Project...").click();
106 fBot
.shell("New Project").setFocus();
107 SWTBotTree tree
= fBot
.tree();
109 final String tracingKey
= "Tracing";
110 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
111 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
113 tracingNode
.select();
114 final String projectKey
= "Tracing Project";
115 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
116 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
117 assertNotNull(tracingProject
);
119 tracingProject
.select();
120 tracingProject
.click();
122 SWTBotButton nextButton
= fBot
.button("Next >");
123 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
125 fBot
.shell("Tracing Project").setFocus();
127 final SWTBotText text
= fBot
.text();
128 text
.setText(getProjectName());
130 fBot
.button("Finish").click();
131 SWTBotUtils
.waitForJobs();
135 * Finishes the wizard
137 protected void importFinish() {
138 SWTBotShell shell
= fBot
.activeShell();
139 final SWTBotButton finishButton
= fBot
.button("Finish");
140 finishButton
.click();
141 fBot
.waitUntil(Conditions
.shellCloses(shell
));
142 SWTBotUtils
.waitForJobs();
146 * Gets the project Name
147 * @return the project name
149 protected abstract String
getProjectName();
151 // ---------------------------------------------
152 // Helpers for testing views
153 // ---------------------------------------------
156 * Verifies the properties view for a given view part
161 protected void testPropertyView(IViewPart vp
) {
162 PropertySheet pv
= (PropertySheet
) vp
;
167 * Verifies the Histogram View
173 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
174 final CtfTmfEvent desiredEvent1
= getEvent(100);
175 UIThreadRunnable
.syncExec(new VoidResult() {
179 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
183 SWTBotUtils
.waitForJobs();
184 SWTBotUtils
.delay(1000);
186 final CtfTmfEvent desiredEvent2
= getEvent(10000);
187 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
188 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
189 for (SWTBotToolbarButton hvTool
: hvTools
) {
190 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
194 HistogramView hv
= (HistogramView
) vp
;
195 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, desiredEvent1
.getTimestamp());
196 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, desiredEvent2
.getTimestamp());
197 hv
.updateTimeRange(100000);
198 SWTBotUtils
.waitForJobs();
199 hv
.currentTimeUpdated(signal
);
200 hv
.broadcast(signal
);
201 SWTBotUtils
.waitForJobs();
202 SWTBotUtils
.delay(1000);
204 hv
.updateTimeRange(1000000000);
205 SWTBotUtils
.waitForJobs();
206 hv
.currentTimeUpdated(signal2
);
207 hv
.broadcast(signal2
);
208 SWTBotUtils
.waitForJobs();
209 SWTBotUtils
.delay(1000);
214 * Verifies the statistics view
218 protected void testStatisticsView(IViewPart vp
) {
219 TmfStatisticsView sv
= (TmfStatisticsView
) vp
;
223 // ---------------------------------------------
225 // ---------------------------------------------
228 * Gets an event at a given rank
231 * @return the event at given rank
233 protected CtfTmfEvent
getEvent(int rank
) {
234 try (CtfTmfTrace trace
= fTrace
.getTrace()) {
235 ITmfContext ctx
= trace
.seekEvent(0);
236 for (int i
= 0; i
< rank
; i
++) {
239 return trace
.getNext(ctx
);
244 * Gets a view part based on view title
247 * @return the view part
249 protected IViewPart
getViewPart(final String viewTile
) {
250 final IViewPart
[] vps
= new IViewPart
[1];
251 UIThreadRunnable
.syncExec(new VoidResult() {
254 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
255 for (IViewReference viewRef
: viewRefs
) {
256 IViewPart vp
= viewRef
.getView(true);
257 if (vp
.getTitle().equals(viewTile
)) {