tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / ImportAndReadKernelSmokeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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
12 * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
16
17 import static org.junit.Assert.assertNotNull;
18
19 import java.util.List;
20
21 import org.eclipse.jface.viewers.SelectionChangedEvent;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
24 import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
25 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
26 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
27 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
28 import org.eclipse.swtbot.swt.finder.results.VoidResult;
29 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
30 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowView;
31 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources.ResourcesView;
32 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
33 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
34 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
35 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
36 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
37 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
38 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
39 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
40 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
41 import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
42 import org.eclipse.ui.IEditorPart;
43 import org.eclipse.ui.IEditorReference;
44 import org.eclipse.ui.IViewPart;
45 import org.eclipse.ui.IViewReference;
46 import org.eclipse.ui.PlatformUI;
47 import org.hamcrest.Matcher;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50
51 /**
52 * SWTBot Smoke test for LTTng Kernel UI.
53 *
54 * @author Matthew Khouzam
55 */
56 @RunWith(SWTBotJunit4ClassRunner.class)
57 public class ImportAndReadKernelSmokeTest extends KernelTestBase {
58
59 private ITmfEvent fDesired1;
60 private ITmfEvent fDesired2;
61
62 /**
63 * Main test case
64 */
65 @Test
66 public void test() {
67 CtfTmfTrace trace = CtfTmfTestTraceUtils.getSyntheticTrace();
68 Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(trace.getName());
69 IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true);
70 final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
71
72 fDesired1 = getEvent(trace, 100);
73 fDesired2 = getEvent(trace, 10000);
74
75 UIThreadRunnable.syncExec(new VoidResult() {
76 @Override
77 public void run() {
78 tmfEd.setFocus();
79 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
80 }
81 });
82 testHV(getViewPart("Histogram"));
83 testCFV((ControlFlowView) getViewPart("Control Flow"));
84 testRV((ResourcesView) getViewPart("Resources"));
85 trace.dispose();
86 }
87
88 private static void testCFV(ControlFlowView vp) {
89 assertNotNull(vp);
90 }
91
92 private void testHV(IViewPart vp) {
93 SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID);
94 List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
95 for (SWTBotToolbarButton hvTool : hvTools) {
96 if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
97 hvTool.click();
98 }
99 }
100 HistogramView hv = (HistogramView) vp;
101 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp());
102 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp());
103 hv.updateTimeRange(100000);
104 WaitUtils.waitForJobs();
105 hv.selectionRangeUpdated(signal);
106 hv.broadcast(signal);
107 WaitUtils.waitForJobs();
108 SWTBotUtils.delay(1000);
109
110 hv.updateTimeRange(1000000000);
111 WaitUtils.waitForJobs();
112 hv.selectionRangeUpdated(signal2);
113 hv.broadcast(signal2);
114 WaitUtils.waitForJobs();
115 SWTBotUtils.delay(1000);
116 assertNotNull(hv);
117 }
118
119 private static void testRV(ResourcesView vp) {
120 assertNotNull(vp);
121 }
122
123 private static CtfTmfEvent getEvent(CtfTmfTrace trace, int rank) {
124 ITmfContext ctx = trace.seekEvent(0);
125 for (int i = 0; i < rank; i++) {
126 trace.getNext(ctx);
127 }
128 return trace.getNext(ctx);
129 }
130
131 private static IViewPart getViewPart(final String viewTile) {
132 final IViewPart[] vps = new IViewPart[1];
133 UIThreadRunnable.syncExec(new VoidResult() {
134 @Override
135 public void run() {
136 IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
137 for (IViewReference viewRef : viewRefs) {
138 IViewPart vp = viewRef.getView(true);
139 if (vp.getTitle().equals(viewTile)) {
140 vps[0] = vp;
141 return;
142 }
143 }
144 }
145 });
146
147 return vps[0];
148 }
149 }
This page took 0.033882 seconds and 5 git commands to generate.