ctf: Lose reference to StreamInputReader in EventDefinition
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / AbstractImportAndReadSmokeTest.java
CommitLineData
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 14package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
2f7b3dd7
BH
15
16import static org.junit.Assert.assertNotNull;
57adf00d 17import static org.junit.Assume.assumeTrue;
2f7b3dd7
BH
18
19import java.util.List;
20
21import org.apache.log4j.Logger;
22import org.apache.log4j.varia.NullAppender;
2f7b3dd7
BH
23import org.eclipse.jface.viewers.SelectionChangedEvent;
24import org.eclipse.jface.viewers.StructuredSelection;
25import org.eclipse.jface.wizard.Wizard;
2f7b3dd7
BH
26import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
27import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
28import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
29import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
30import org.eclipse.swtbot.swt.finder.results.VoidResult;
31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32import org.eclipse.swtbot.swt.finder.waits.Conditions;
33import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
2f7b3dd7
BH
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
36import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
37import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
38import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
97c71024 39import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
2bdf0193 40import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
9722e5d7 41import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 42import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 43import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
2bdf0193 44import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
fa24d78b
AM
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
46import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
2bdf0193
AM
47import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
48import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView;
2f7b3dd7
BH
49import org.eclipse.ui.IViewPart;
50import org.eclipse.ui.IViewReference;
51import org.eclipse.ui.PlatformUI;
52import org.eclipse.ui.views.properties.PropertySheet;
f10c30a0 53import org.junit.AfterClass;
2f7b3dd7
BH
54import org.junit.BeforeClass;
55import org.junit.runner.RunWith;
56
57/**
58 * Abstract SWTBot Smoke test class.
59 *
60 * @author Matthew Khouzam
61 * @author Bernd Hufmann
62 */
63@RunWith(SWTBotJunit4ClassRunner.class)
64public abstract class AbstractImportAndReadSmokeTest {
65
66 /** Trace name */
93c91230
MAL
67 protected static final String TRACE_NAME = "scp_dest";
68 /** Trace folder */
69 protected static final String TRACE_FOLDER = "synctraces";
2f7b3dd7
BH
70 /** Trace type name for generic CTF traces */
71 protected static final String TRACE_TYPE_NAME = "Generic CTF Trace";
72 /** A Generic CTF Trace*/
93c91230 73 protected static final CtfTmfTestTrace fTrace = CtfTmfTestTrace.SYNC_DEST;
2f7b3dd7
BH
74 /** SWT BOT workbench reference */
75 protected static SWTWorkbenchBot fBot;
76 /** Wizard to use */
77 protected static Wizard fWizard;
78
79 /** The Log4j logger instance. */
80 protected static final Logger fLogger = Logger.getRootLogger();
81
82 /** Test Class setup */
83 @BeforeClass
84 public static void init() {
57adf00d 85 assumeTrue(fTrace.exists());
fa24d78b 86 SWTBotUtils.failIfUIThread();
2f7b3dd7
BH
87
88 /* set up for swtbot */
89 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
f10c30a0 90 fLogger.removeAllAppenders();
2f7b3dd7
BH
91 fLogger.addAppender(new NullAppender());
92 fBot = new SWTWorkbenchBot();
93
fa24d78b 94 SWTBotUtils.closeView("welcome", fBot);
2f7b3dd7 95
fa24d78b 96 SWTBotUtils.switchToTracingPerspective();
2f7b3dd7 97 /* finish waiting for eclipse to load */
fa24d78b 98 SWTBotUtils.waitForJobs();
2f7b3dd7
BH
99 }
100
f10c30a0
MK
101 /**
102 * Test Class teardown
103 */
104 @AfterClass
105 public static void terminate() {
106 fLogger.removeAllAppenders();
107 }
108
2f7b3dd7
BH
109 /**
110 * Creates a tracing projects
111 */
112 protected void createProject() {
fa24d78b 113 SWTBotUtils.focusMainWindow(fBot.shells());
2f7b3dd7
BH
114 fBot.menu("File").menu("New").menu("Project...").click();
115
8af624a8 116 fBot.shell("New Project").setFocus();
2f7b3dd7
BH
117 SWTBotTree tree = fBot.tree();
118 assertNotNull(tree);
119 final String tracingKey = "Tracing";
120 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree));
121 final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey);
122
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);
128
129 tracingProject.select();
130 tracingProject.click();
131
132 SWTBotButton nextButton = fBot.button("Next >");
133 fBot.waitUntil(Conditions.widgetIsEnabled(nextButton));
134 nextButton.click();
8af624a8 135 fBot.shell("Tracing Project").setFocus();
2f7b3dd7
BH
136
137 final SWTBotText text = fBot.text();
138 text.setText(getProjectName());
139
140 fBot.button("Finish").click();
fa24d78b 141 SWTBotUtils.waitForJobs();
2f7b3dd7
BH
142 }
143
2f7b3dd7
BH
144 /**
145 * Finishes the wizard
146 */
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));
fa24d78b 152 SWTBotUtils.waitForJobs();
2f7b3dd7
BH
153 }
154
155 /**
156 * Gets the project Name
157 * @return the project name
158 */
159 protected abstract String getProjectName();
160
161 // ---------------------------------------------
162 // Helpers for testing views
163 // ---------------------------------------------
164
165 /**
166 * Verifies the properties view for a given view part
167 *
168 * @param vp
169 * a view part
170 */
171 protected void testPropertyView(IViewPart vp) {
172 PropertySheet pv = (PropertySheet) vp;
173 assertNotNull(pv);
174 }
175
176 /**
177 * Verifies the Histogram View
178 * @param vp
179 * the view part
180 * @param tmfEd
181 * the events editor
182 */
183 protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
184 final CtfTmfEvent desiredEvent1 = getEvent(100);
185 UIThreadRunnable.syncExec(new VoidResult() {
186 @Override
187 public void run() {
188 tmfEd.setFocus();
189 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
190 }
191 });
192
fa24d78b
AM
193 SWTBotUtils.waitForJobs();
194 SWTBotUtils.delay(1000);
2f7b3dd7
BH
195
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")) {
201 hvTool.click();
202 }
203 }
204 HistogramView hv = (HistogramView) vp;
97c71024
AM
205 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent1.getTimestamp());
206 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent2.getTimestamp());
2f7b3dd7 207 hv.updateTimeRange(100000);
fa24d78b 208 SWTBotUtils.waitForJobs();
97c71024 209 hv.selectionRangeUpdated(signal);
2f7b3dd7 210 hv.broadcast(signal);
fa24d78b
AM
211 SWTBotUtils.waitForJobs();
212 SWTBotUtils.delay(1000);
2f7b3dd7
BH
213
214 hv.updateTimeRange(1000000000);
fa24d78b 215 SWTBotUtils.waitForJobs();
97c71024 216 hv.selectionRangeUpdated(signal2);
2f7b3dd7 217 hv.broadcast(signal2);
fa24d78b
AM
218 SWTBotUtils.waitForJobs();
219 SWTBotUtils.delay(1000);
2f7b3dd7
BH
220 assertNotNull(hv);
221 }
222
223 /**
224 * Verifies the statistics view
225 * @param vp
226 * the view part
227 */
228 protected void testStatisticsView(IViewPart vp) {
229 TmfStatisticsView sv = (TmfStatisticsView) vp;
230 assertNotNull(sv);
231 }
232
233 // ---------------------------------------------
234 // Trace helpers
235 // ---------------------------------------------
236
237 /**
238 * Gets an event at a given rank
239 * @param rank
240 * a rank
241 * @return the event at given rank
242 */
243 protected CtfTmfEvent getEvent(int rank) {
7b3eb8c0
AM
244 try (CtfTmfTrace trace = fTrace.getTrace()) {
245 ITmfContext ctx = trace.seekEvent(0);
246 for (int i = 0; i < rank; i++) {
247 trace.getNext(ctx);
248 }
249 return trace.getNext(ctx);
2f7b3dd7 250 }
2f7b3dd7
BH
251 }
252
253 /**
254 * Gets a view part based on view title
255 * @param viewTile
256 * a view title
257 * @return the view part
258 */
259 protected IViewPart getViewPart(final String viewTile) {
260 final IViewPart[] vps = new IViewPart[1];
261 UIThreadRunnable.syncExec(new VoidResult() {
262 @Override
263 public void run() {
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)) {
268 vps[0] = vp;
269 return;
270 }
271 }
272 }
273 });
274
275 return vps[0];
276 }
277}
This page took 0.064907 seconds and 5 git commands to generate.