48b606c8241fc9a2891b75775963fe02e4a026a7
[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.views.histogram.HistogramView;
41 import org.eclipse.ui.IEditorPart;
42 import org.eclipse.ui.IEditorReference;
43 import org.eclipse.ui.IViewPart;
44 import org.eclipse.ui.IViewReference;
45 import org.eclipse.ui.PlatformUI;
46 import org.hamcrest.Matcher;
47 import org.junit.Test;
48 import org.junit.runner.RunWith;
49
50 /**
51 * SWTBot Smoke test for LTTng Kernel UI.
52 *
53 * @author Matthew Khouzam
54 */
55 @RunWith(SWTBotJunit4ClassRunner.class)
56 public class ImportAndReadKernelSmokeTest extends KernelTestBase {
57
58 private ITmfEvent fDesired1;
59 private ITmfEvent fDesired2;
60
61 /**
62 * Main test case
63 */
64 @Test
65 public void test() {
66 CtfTmfTrace trace = CtfTmfTestTraceUtils.getSyntheticTrace();
67 Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(trace.getName());
68 IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true);
69 final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
70
71 fDesired1 = getEvent(trace, 100);
72 fDesired2 = getEvent(trace, 10000);
73
74 UIThreadRunnable.syncExec(new VoidResult() {
75 @Override
76 public void run() {
77 tmfEd.setFocus();
78 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1)));
79 }
80 });
81 testHV(getViewPart("Histogram"));
82 testCFV((ControlFlowView) getViewPart("Control Flow"));
83 testRV((ResourcesView) getViewPart("Resources"));
84 trace.dispose();
85 }
86
87 private static void testCFV(ControlFlowView vp) {
88 assertNotNull(vp);
89 }
90
91 private void testHV(IViewPart vp) {
92 SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID);
93 List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
94 for (SWTBotToolbarButton hvTool : hvTools) {
95 if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
96 hvTool.click();
97 }
98 }
99 HistogramView hv = (HistogramView) vp;
100 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp());
101 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp());
102 hv.updateTimeRange(100000);
103 SWTBotUtils.waitForJobs();
104 hv.selectionRangeUpdated(signal);
105 hv.broadcast(signal);
106 SWTBotUtils.waitForJobs();
107 SWTBotUtils.delay(1000);
108
109 hv.updateTimeRange(1000000000);
110 SWTBotUtils.waitForJobs();
111 hv.selectionRangeUpdated(signal2);
112 hv.broadcast(signal2);
113 SWTBotUtils.waitForJobs();
114 SWTBotUtils.delay(1000);
115 assertNotNull(hv);
116 }
117
118 private static void testRV(ResourcesView vp) {
119 assertNotNull(vp);
120 }
121
122 private static CtfTmfEvent getEvent(CtfTmfTrace trace, int rank) {
123 ITmfContext ctx = trace.seekEvent(0);
124 for (int i = 0; i < rank; i++) {
125 trace.getNext(ctx);
126 }
127 return trace.getNext(ctx);
128 }
129
130 private static IViewPart getViewPart(final String viewTile) {
131 final IViewPart[] vps = new IViewPart[1];
132 UIThreadRunnable.syncExec(new VoidResult() {
133 @Override
134 public void run() {
135 IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
136 for (IViewReference viewRef : viewRefs) {
137 IViewPart vp = viewRef.getView(true);
138 if (vp.getTitle().equals(viewTile)) {
139 vps[0] = vp;
140 return;
141 }
142 }
143 }
144 });
145
146 return vps[0];
147 }
148 }
This page took 0.034313 seconds and 4 git commands to generate.