Commit | Line | Data |
---|---|---|
2f7b3dd7 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 Ericsson |
2f7b3dd7 BH |
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 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests; |
2f7b3dd7 BH |
15 | |
16 | import static org.junit.Assert.assertNotNull; | |
57adf00d | 17 | import static org.junit.Assume.assumeTrue; |
2f7b3dd7 BH |
18 | |
19 | import java.util.List; | |
20 | ||
21 | import org.apache.log4j.Logger; | |
22 | import org.apache.log4j.varia.NullAppender; | |
2f7b3dd7 BH |
23 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
24 | import org.eclipse.jface.viewers.StructuredSelection; | |
25 | import org.eclipse.jface.wizard.Wizard; | |
2f7b3dd7 BH |
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; | |
2f7b3dd7 BH |
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; | |
2bdf0193 AM |
39 | import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal; |
40 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
9722e5d7 | 41 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
2bdf0193 | 42 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 43 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
2bdf0193 | 44 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
fa24d78b AM |
45 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
46 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
2bdf0193 AM |
47 | import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
48 | import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView; | |
2f7b3dd7 BH |
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; | |
55 | ||
56 | /** | |
57 | * Abstract SWTBot Smoke test class. | |
58 | * | |
59 | * @author Matthew Khouzam | |
60 | * @author Bernd Hufmann | |
61 | */ | |
62 | @RunWith(SWTBotJunit4ClassRunner.class) | |
63 | public abstract class AbstractImportAndReadSmokeTest { | |
64 | ||
65 | /** Trace name */ | |
93c91230 MAL |
66 | protected static final String TRACE_NAME = "scp_dest"; |
67 | /** Trace folder */ | |
68 | protected static final String TRACE_FOLDER = "synctraces"; | |
2f7b3dd7 BH |
69 | /** Trace type name for generic CTF traces */ |
70 | protected static final String TRACE_TYPE_NAME = "Generic CTF Trace"; | |
71 | /** A Generic CTF Trace*/ | |
93c91230 | 72 | protected static final CtfTmfTestTrace fTrace = CtfTmfTestTrace.SYNC_DEST; |
2f7b3dd7 BH |
73 | /** SWT BOT workbench reference */ |
74 | protected static SWTWorkbenchBot fBot; | |
75 | /** Wizard to use */ | |
76 | protected static Wizard fWizard; | |
77 | ||
78 | /** The Log4j logger instance. */ | |
79 | protected static final Logger fLogger = Logger.getRootLogger(); | |
80 | ||
81 | /** Test Class setup */ | |
82 | @BeforeClass | |
83 | public static void init() { | |
57adf00d | 84 | assumeTrue(fTrace.exists()); |
fa24d78b | 85 | SWTBotUtils.failIfUIThread(); |
2f7b3dd7 BH |
86 | |
87 | /* set up for swtbot */ | |
88 | SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */ | |
89 | fLogger.addAppender(new NullAppender()); | |
90 | fBot = new SWTWorkbenchBot(); | |
91 | ||
fa24d78b | 92 | SWTBotUtils.closeView("welcome", fBot); |
2f7b3dd7 | 93 | |
fa24d78b | 94 | SWTBotUtils.switchToTracingPerspective(); |
2f7b3dd7 | 95 | /* finish waiting for eclipse to load */ |
fa24d78b | 96 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
97 | } |
98 | ||
99 | /** | |
100 | * Creates a tracing projects | |
101 | */ | |
102 | protected void createProject() { | |
fa24d78b | 103 | SWTBotUtils.focusMainWindow(fBot.shells()); |
2f7b3dd7 BH |
104 | fBot.menu("File").menu("New").menu("Project...").click(); |
105 | ||
8af624a8 | 106 | fBot.shell("New Project").setFocus(); |
2f7b3dd7 BH |
107 | SWTBotTree tree = fBot.tree(); |
108 | assertNotNull(tree); | |
109 | final String tracingKey = "Tracing"; | |
110 | fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree)); | |
111 | final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey); | |
112 | ||
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); | |
118 | ||
119 | tracingProject.select(); | |
120 | tracingProject.click(); | |
121 | ||
122 | SWTBotButton nextButton = fBot.button("Next >"); | |
123 | fBot.waitUntil(Conditions.widgetIsEnabled(nextButton)); | |
124 | nextButton.click(); | |
8af624a8 | 125 | fBot.shell("Tracing Project").setFocus(); |
2f7b3dd7 BH |
126 | |
127 | final SWTBotText text = fBot.text(); | |
128 | text.setText(getProjectName()); | |
129 | ||
130 | fBot.button("Finish").click(); | |
fa24d78b | 131 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
132 | } |
133 | ||
2f7b3dd7 BH |
134 | /** |
135 | * Finishes the wizard | |
136 | */ | |
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)); | |
fa24d78b | 142 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
143 | } |
144 | ||
145 | /** | |
146 | * Gets the project Name | |
147 | * @return the project name | |
148 | */ | |
149 | protected abstract String getProjectName(); | |
150 | ||
151 | // --------------------------------------------- | |
152 | // Helpers for testing views | |
153 | // --------------------------------------------- | |
154 | ||
155 | /** | |
156 | * Verifies the properties view for a given view part | |
157 | * | |
158 | * @param vp | |
159 | * a view part | |
160 | */ | |
161 | protected void testPropertyView(IViewPart vp) { | |
162 | PropertySheet pv = (PropertySheet) vp; | |
163 | assertNotNull(pv); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Verifies the Histogram View | |
168 | * @param vp | |
169 | * the view part | |
170 | * @param tmfEd | |
171 | * the events editor | |
172 | */ | |
173 | protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) { | |
174 | final CtfTmfEvent desiredEvent1 = getEvent(100); | |
175 | UIThreadRunnable.syncExec(new VoidResult() { | |
176 | @Override | |
177 | public void run() { | |
178 | tmfEd.setFocus(); | |
179 | tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1))); | |
180 | } | |
181 | }); | |
182 | ||
fa24d78b AM |
183 | SWTBotUtils.waitForJobs(); |
184 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
185 | |
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")) { | |
191 | hvTool.click(); | |
192 | } | |
193 | } | |
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); | |
fa24d78b | 198 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
199 | hv.currentTimeUpdated(signal); |
200 | hv.broadcast(signal); | |
fa24d78b AM |
201 | SWTBotUtils.waitForJobs(); |
202 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
203 | |
204 | hv.updateTimeRange(1000000000); | |
fa24d78b | 205 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
206 | hv.currentTimeUpdated(signal2); |
207 | hv.broadcast(signal2); | |
fa24d78b AM |
208 | SWTBotUtils.waitForJobs(); |
209 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
210 | assertNotNull(hv); |
211 | } | |
212 | ||
213 | /** | |
214 | * Verifies the statistics view | |
215 | * @param vp | |
216 | * the view part | |
217 | */ | |
218 | protected void testStatisticsView(IViewPart vp) { | |
219 | TmfStatisticsView sv = (TmfStatisticsView) vp; | |
220 | assertNotNull(sv); | |
221 | } | |
222 | ||
223 | // --------------------------------------------- | |
224 | // Trace helpers | |
225 | // --------------------------------------------- | |
226 | ||
227 | /** | |
228 | * Gets an event at a given rank | |
229 | * @param rank | |
230 | * a rank | |
231 | * @return the event at given rank | |
232 | */ | |
233 | protected CtfTmfEvent getEvent(int rank) { | |
7b3eb8c0 AM |
234 | try (CtfTmfTrace trace = fTrace.getTrace()) { |
235 | ITmfContext ctx = trace.seekEvent(0); | |
236 | for (int i = 0; i < rank; i++) { | |
237 | trace.getNext(ctx); | |
238 | } | |
239 | return trace.getNext(ctx); | |
2f7b3dd7 | 240 | } |
2f7b3dd7 BH |
241 | } |
242 | ||
243 | /** | |
244 | * Gets a view part based on view title | |
245 | * @param viewTile | |
246 | * a view title | |
247 | * @return the view part | |
248 | */ | |
249 | protected IViewPart getViewPart(final String viewTile) { | |
250 | final IViewPart[] vps = new IViewPart[1]; | |
251 | UIThreadRunnable.syncExec(new VoidResult() { | |
252 | @Override | |
253 | public void run() { | |
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)) { | |
258 | vps[0] = vp; | |
259 | return; | |
260 | } | |
261 | } | |
262 | } | |
263 | }); | |
264 | ||
265 | return vps[0]; | |
266 | } | |
267 | } |