Commit | Line | Data |
---|---|---|
ffa8146c | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
ffa8146c MK |
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 | |
2fe6a9ea | 12 | * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest |
ffa8146c MK |
13 | *******************************************************************************/ |
14 | ||
9bc60be7 | 15 | package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; |
ffa8146c | 16 | |
ffa8146c | 17 | import static org.junit.Assert.assertNotNull; |
ffa8146c | 18 | |
ffa8146c MK |
19 | import java.util.List; |
20 | ||
ffa8146c MK |
21 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
22 | import org.eclipse.jface.viewers.StructuredSelection; | |
ffa8146c | 23 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
bf0f892f | 24 | import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; |
ffa8146c MK |
25 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
26 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
cbbd323f | 27 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
ffa8146c | 28 | import org.eclipse.swtbot.swt.finder.results.VoidResult; |
ffa8146c | 29 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; |
e363eae1 AM |
30 | import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView; |
31 | import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView; | |
2bdf0193 | 32 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
97c71024 | 33 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
2bdf0193 | 34 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
9722e5d7 | 35 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
2bdf0193 | 36 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 37 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
2bdf0193 | 38 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
fa24d78b | 39 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
2bdf0193 | 40 | import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
ffa8146c MK |
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; | |
bf0f892f | 46 | import org.hamcrest.Matcher; |
ffa8146c | 47 | import org.junit.Test; |
cbbd323f | 48 | import org.junit.runner.RunWith; |
ffa8146c MK |
49 | |
50 | /** | |
51 | * SWTBot Smoke test for LTTng Kernel UI. | |
52 | * | |
53 | * @author Matthew Khouzam | |
54 | */ | |
cbbd323f | 55 | @RunWith(SWTBotJunit4ClassRunner.class) |
2fe6a9ea | 56 | public class ImportAndReadKernelSmokeTest extends KernelTest { |
ffa8146c | 57 | |
553bccd6 | 58 | private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE; |
ffa8146c | 59 | |
ffa8146c MK |
60 | private ITmfEvent fDesired1; |
61 | private ITmfEvent fDesired2; | |
62 | ||
ffa8146c MK |
63 | /** |
64 | * Main test case | |
65 | */ | |
66 | @Test | |
67 | public void test() { | |
553bccd6 | 68 | Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(CTT.getTrace().getName()); |
bf0f892f | 69 | IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true); |
2fe6a9ea | 70 | final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; |
7211c4e6 AM |
71 | try (CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace();) { |
72 | fDesired1 = getEvent(trace, 100); | |
73 | fDesired2 = getEvent(trace, 10000); | |
74 | } | |
ffa8146c MK |
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 | }); | |
2fe6a9ea PT |
82 | testHV(getViewPart("Histogram")); |
83 | testCFV((ControlFlowView) getViewPart("Control Flow")); | |
84 | testRV((ResourcesView) getViewPart("Resources")); | |
ffa8146c MK |
85 | } |
86 | ||
ffa8146c MK |
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; | |
97c71024 AM |
100 | final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp()); |
101 | final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp()); | |
ffa8146c | 102 | hv.updateTimeRange(100000); |
fa24d78b | 103 | SWTBotUtils.waitForJobs(); |
97c71024 | 104 | hv.selectionRangeUpdated(signal); |
ffa8146c | 105 | hv.broadcast(signal); |
fa24d78b AM |
106 | SWTBotUtils.waitForJobs(); |
107 | SWTBotUtils.delay(1000); | |
ffa8146c MK |
108 | |
109 | hv.updateTimeRange(1000000000); | |
fa24d78b | 110 | SWTBotUtils.waitForJobs(); |
97c71024 | 111 | hv.selectionRangeUpdated(signal2); |
ffa8146c | 112 | hv.broadcast(signal2); |
fa24d78b AM |
113 | SWTBotUtils.waitForJobs(); |
114 | SWTBotUtils.delay(1000); | |
ffa8146c MK |
115 | assertNotNull(hv); |
116 | } | |
117 | ||
118 | private static void testRV(ResourcesView vp) { | |
119 | assertNotNull(vp); | |
120 | } | |
121 | ||
7211c4e6 AM |
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); | |
ffa8146c | 126 | } |
7211c4e6 | 127 | return trace.getNext(ctx); |
ffa8146c MK |
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 | } |