tmf: open files without trace type with eclipse default editors
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / linuxtools / lttng2 / kernel / ui / swtbot / tests / ImportAndReadKernelSmokeTest.java
CommitLineData
ffa8146c
MK
1/*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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 * Matthew Khouzam - Initial API and implementation
11 * Marc-Andre Laperle
977ca87f 12 * Patrick Tasse - Add support for folder elements
ffa8146c
MK
13 *******************************************************************************/
14
15package org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests;
16
17import static org.junit.Assert.assertFalse;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.fail;
20
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.List;
24
25import org.apache.log4j.ConsoleAppender;
26import org.apache.log4j.Logger;
27import org.apache.log4j.SimpleLayout;
977ca87f
PT
28import org.eclipse.core.resources.IProject;
29import org.eclipse.core.resources.ResourcesPlugin;
ffa8146c 30import org.eclipse.core.runtime.CoreException;
ffa8146c
MK
31import org.eclipse.jface.viewers.SelectionChangedEvent;
32import org.eclipse.jface.viewers.StructuredSelection;
33import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow.ControlFlowView;
34import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesView;
ffa8146c
MK
35import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
36import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
ffa8146c 37import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
91e7f946
AM
38import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
39import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
40import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
ffa8146c
MK
41import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
42import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
977ca87f
PT
43import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
44import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
306e18d0 45import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil;
ffa8146c
MK
46import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
47import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView;
ffa8146c
MK
48import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
49import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
50import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
cbbd323f 51import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
ffa8146c
MK
52import org.eclipse.swtbot.swt.finder.results.BoolResult;
53import org.eclipse.swtbot.swt.finder.results.VoidResult;
54import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
55import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
56import org.eclipse.ui.IEditorPart;
57import org.eclipse.ui.IEditorReference;
58import org.eclipse.ui.IViewPart;
59import org.eclipse.ui.IViewReference;
60import org.eclipse.ui.PlatformUI;
61import org.eclipse.ui.WorkbenchException;
62import org.junit.BeforeClass;
63import org.junit.Test;
cbbd323f 64import org.junit.runner.RunWith;
ffa8146c
MK
65
66/**
67 * SWTBot Smoke test for LTTng Kernel UI.
68 *
69 * @author Matthew Khouzam
70 */
cbbd323f 71@RunWith(SWTBotJunit4ClassRunner.class)
ffa8146c
MK
72public class ImportAndReadKernelSmokeTest {
73
74 private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
75 private static final String TRACE_PROJECT_NAME = "test";
76
77 private static SWTWorkbenchBot fBot;
78 private static CtfTmfTestTrace ctt = CtfTmfTestTrace.SYNTHETIC_TRACE;
79 private ITmfEvent fDesired1;
80 private ITmfEvent fDesired2;
81
82 /** The Log4j logger instance. */
83 private static final Logger fLogger = Logger.getRootLogger();
84
85 /**
86 * Test Class setup
87 */
88 @BeforeClass
89 public static void init() {
306e18d0 90 SWTBotUtil.failIfUIThread();
ffa8146c
MK
91
92 /* set up for swtbot */
93 SWTBotPreferences.TIMEOUT = 300000; /* 300 second timeout */
94 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
95 fBot = new SWTWorkbenchBot();
96
97 final List<SWTBotView> openViews = fBot.views();
98 for (SWTBotView view : openViews) {
99 if (view.getTitle().equals("Welcome")) {
100 view.close();
101 fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
102 }
103 }
104 /* Switch perspectives */
105 switchKernelPerspective();
106 /* Finish waiting for eclipse to load */
306e18d0 107 SWTBotUtil.waitForJobs();
ffa8146c
MK
108 }
109
110 private static void switchKernelPerspective() {
111 final Exception retE[] = new Exception[1];
112 if (!UIThreadRunnable.syncExec(new BoolResult() {
113 @Override
114 public Boolean run() {
115 try {
116 PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
117 PlatformUI.getWorkbench().getActiveWorkbenchWindow());
118 } catch (WorkbenchException e) {
119 retE[0] = e;
120 return false;
121 }
122 return true;
123 }
124 })) {
125 fail(retE[0].getMessage());
126 }
127
128 }
129
ffa8146c
MK
130 /**
131 * Main test case
132 */
133 @Test
134 public void test() {
306e18d0 135 SWTBotUtil.createProject(TRACE_PROJECT_NAME);
ffa8146c
MK
136 openTrace();
137 openEditor();
138 testHV(getViewPart("Histogram"));
139 testCFV((ControlFlowView) getViewPart("Control Flow"));
140 testRV((ResourcesView) getViewPart("Resources"));
93c91230
MAL
141
142 fBot.closeAllEditors();
143 SWTBotUtil.deleteProject(TRACE_PROJECT_NAME, fBot);
ffa8146c
MK
144 }
145
146 private static void openTrace() {
147 final Exception exception[] = new Exception[1];
148 exception[0] = null;
149 UIThreadRunnable.syncExec(new VoidResult() {
150 @Override
151 public void run() {
152 try {
977ca87f
PT
153 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
154 TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
155 TmfOpenTraceHelper.openTraceFromPath(destinationFolder, ctt.getPath(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.eclipse.linuxtools.lttng2.kernel.tracetype");
ffa8146c
MK
156 } catch (CoreException e) {
157 exception[0] = e;
158 }
159 }
160 });
161 if (exception[0] != null) {
162 fail(exception[0].getMessage());
163 }
164
306e18d0
MK
165 SWTBotUtil.delay(1000);
166 SWTBotUtil.waitForJobs();
ffa8146c
MK
167 }
168
169 private void openEditor() {
170 final List<IEditorReference> editorRefs = new ArrayList<>();
171 UIThreadRunnable.syncExec(new VoidResult() {
172 @Override
173 public void run() {
174 IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
175 editorRefs.addAll(Arrays.asList(ieds));
176 }
177
178 });
179 assertFalse(editorRefs.isEmpty());
180 IEditorPart iep = null;
181 for (IEditorReference ied : editorRefs) {
182 if (ied.getTitle().equals(ctt.getTrace().getName())) {
183 iep = ied.getEditor(true);
184 break;
185 }
186 }
187 assertNotNull(iep);
188 fDesired1 = getEvent(100);
189 fDesired2 = getEvent(10000);
190 final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
191 UIThreadRunnable.syncExec(new VoidResult() {
192 @Override
193 public void run() {
194 tmfEd.setFocus();
195 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
196 }
197 });
198
306e18d0
MK
199 SWTBotUtil.waitForJobs();
200 SWTBotUtil.delay(1000);
ffa8146c
MK
201 assertNotNull(tmfEd);
202 }
203
ffa8146c
MK
204 private static void testCFV(ControlFlowView vp) {
205 assertNotNull(vp);
206 }
207
208 private void testHV(IViewPart vp) {
209 SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID);
210 List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
211 for (SWTBotToolbarButton hvTool : hvTools) {
212 if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
213 hvTool.click();
214 }
215 }
216 HistogramView hv = (HistogramView) vp;
217 final TmfTimeSynchSignal signal = new TmfTimeSynchSignal(hv, fDesired1.getTimestamp());
218 final TmfTimeSynchSignal signal2 = new TmfTimeSynchSignal(hv, fDesired2.getTimestamp());
219 hv.updateTimeRange(100000);
306e18d0 220 SWTBotUtil.waitForJobs();
ffa8146c
MK
221 hv.currentTimeUpdated(signal);
222 hv.broadcast(signal);
306e18d0
MK
223 SWTBotUtil.waitForJobs();
224 SWTBotUtil.delay(1000);
ffa8146c
MK
225
226 hv.updateTimeRange(1000000000);
306e18d0 227 SWTBotUtil.waitForJobs();
ffa8146c
MK
228 hv.currentTimeUpdated(signal2);
229 hv.broadcast(signal2);
306e18d0
MK
230 SWTBotUtil.waitForJobs();
231 SWTBotUtil.delay(1000);
ffa8146c
MK
232 assertNotNull(hv);
233 }
234
235 private static void testRV(ResourcesView vp) {
236 assertNotNull(vp);
237 }
238
239 private static CtfTmfEvent getEvent(int rank) {
7b3eb8c0
AM
240 try (CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace()) {
241 ITmfContext ctx = trace.seekEvent(0);
242 for (int i = 0; i < rank; i++) {
243 trace.getNext(ctx);
244 }
245 return trace.getNext(ctx);
ffa8146c 246 }
7b3eb8c0 247
ffa8146c
MK
248 }
249
250 private static IViewPart getViewPart(final String viewTile) {
251 final IViewPart[] vps = new IViewPart[1];
252 UIThreadRunnable.syncExec(new VoidResult() {
253 @Override
254 public void run() {
255 IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
256 for (IViewReference viewRef : viewRefs) {
257 IViewPart vp = viewRef.getView(true);
258 if (vp.getTitle().equals(viewTile)) {
259 vps[0] = vp;
260 return;
261 }
262 }
263 }
264 });
265
266 return vps[0];
267 }
268}
This page took 0.04253 seconds and 5 git commands to generate.