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; |
ace7140d | 30 | import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowView; |
eeff806b | 31 | import org.eclipse.tracecompass.internal.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; |
c4d57ac1 | 36 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
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; |
f0beeb4a | 40 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
2bdf0193 | 41 | import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
ffa8146c MK |
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; | |
bf0f892f | 47 | import org.hamcrest.Matcher; |
ffa8146c | 48 | import org.junit.Test; |
cbbd323f | 49 | import org.junit.runner.RunWith; |
ffa8146c MK |
50 | |
51 | /** | |
52 | * SWTBot Smoke test for LTTng Kernel UI. | |
53 | * | |
54 | * @author Matthew Khouzam | |
55 | */ | |
cbbd323f | 56 | @RunWith(SWTBotJunit4ClassRunner.class) |
b0d2c558 | 57 | public class ImportAndReadKernelSmokeTest extends KernelTestBase { |
ffa8146c | 58 | |
ffa8146c MK |
59 | private ITmfEvent fDesired1; |
60 | private ITmfEvent fDesired2; | |
61 | ||
ffa8146c MK |
62 | /** |
63 | * Main test case | |
64 | */ | |
65 | @Test | |
66 | public void test() { | |
c4d57ac1 AM |
67 | CtfTmfTrace trace = CtfTmfTestTraceUtils.getSyntheticTrace(); |
68 | Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(trace.getName()); | |
bf0f892f | 69 | IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true); |
2fe6a9ea | 70 | final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; |
c4d57ac1 | 71 | |
0ff9e595 AM |
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")); | |
0ff9e595 | 85 | trace.dispose(); |
ffa8146c MK |
86 | } |
87 | ||
ffa8146c MK |
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; | |
97c71024 AM |
101 | final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp()); |
102 | final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp()); | |
ffa8146c | 103 | hv.updateTimeRange(100000); |
f0beeb4a | 104 | WaitUtils.waitForJobs(); |
97c71024 | 105 | hv.selectionRangeUpdated(signal); |
ffa8146c | 106 | hv.broadcast(signal); |
f0beeb4a | 107 | WaitUtils.waitForJobs(); |
fa24d78b | 108 | SWTBotUtils.delay(1000); |
ffa8146c MK |
109 | |
110 | hv.updateTimeRange(1000000000); | |
f0beeb4a | 111 | WaitUtils.waitForJobs(); |
97c71024 | 112 | hv.selectionRangeUpdated(signal2); |
ffa8146c | 113 | hv.broadcast(signal2); |
f0beeb4a | 114 | WaitUtils.waitForJobs(); |
fa24d78b | 115 | SWTBotUtils.delay(1000); |
ffa8146c MK |
116 | assertNotNull(hv); |
117 | } | |
118 | ||
119 | private static void testRV(ResourcesView vp) { | |
120 | assertNotNull(vp); | |
121 | } | |
122 | ||
7211c4e6 AM |
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); | |
ffa8146c | 127 | } |
7211c4e6 | 128 | return trace.getNext(ctx); |
ffa8146c MK |
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 | } |