| /******************************************************************************* |
| * Copyright (c) 2013, 2015 Ericsson |
| * |
| * All rights reserved. This program and the accompanying materials are |
| * made available under the terms of the Eclipse Public License v1.0 which |
| * accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Matthew Khouzam - Initial API and implementation |
| * Marc-Andre Laperle |
| * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest |
| *******************************************************************************/ |
| |
| package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; |
| |
| import static org.junit.Assert.assertNotNull; |
| |
| import java.util.List; |
| |
| import org.eclipse.jface.viewers.SelectionChangedEvent; |
| import org.eclipse.jface.viewers.StructuredSelection; |
| import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
| import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; |
| import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
| import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
| import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; |
| import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView; |
| import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView; |
| import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
| import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
| import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
| import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
| import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
| import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
| import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
| import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
| import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IEditorReference; |
| import org.eclipse.ui.IViewPart; |
| import org.eclipse.ui.IViewReference; |
| import org.eclipse.ui.PlatformUI; |
| import org.hamcrest.Matcher; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| |
| /** |
| * SWTBot Smoke test for LTTng Kernel UI. |
| * |
| * @author Matthew Khouzam |
| */ |
| @RunWith(SWTBotJunit4ClassRunner.class) |
| public class ImportAndReadKernelSmokeTest extends KernelTest { |
| |
| private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE; |
| |
| private ITmfEvent fDesired1; |
| private ITmfEvent fDesired2; |
| |
| /** |
| * Main test case |
| */ |
| @Test |
| public void test() { |
| Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(CTT.getTrace().getName()); |
| IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true); |
| final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; |
| fDesired1 = getEvent(100); |
| fDesired2 = getEvent(10000); |
| UIThreadRunnable.syncExec(new VoidResult() { |
| @Override |
| public void run() { |
| tmfEd.setFocus(); |
| tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1))); |
| } |
| }); |
| testHV(getViewPart("Histogram")); |
| testCFV((ControlFlowView) getViewPart("Control Flow")); |
| testRV((ResourcesView) getViewPart("Resources")); |
| } |
| |
| private static void testCFV(ControlFlowView vp) { |
| assertNotNull(vp); |
| } |
| |
| private void testHV(IViewPart vp) { |
| SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID); |
| List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons(); |
| for (SWTBotToolbarButton hvTool : hvTools) { |
| if (hvTool.getToolTipText().toLowerCase().contains("lost")) { |
| hvTool.click(); |
| } |
| } |
| HistogramView hv = (HistogramView) vp; |
| final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp()); |
| final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp()); |
| hv.updateTimeRange(100000); |
| SWTBotUtils.waitForJobs(); |
| hv.selectionRangeUpdated(signal); |
| hv.broadcast(signal); |
| SWTBotUtils.waitForJobs(); |
| SWTBotUtils.delay(1000); |
| |
| hv.updateTimeRange(1000000000); |
| SWTBotUtils.waitForJobs(); |
| hv.selectionRangeUpdated(signal2); |
| hv.broadcast(signal2); |
| SWTBotUtils.waitForJobs(); |
| SWTBotUtils.delay(1000); |
| assertNotNull(hv); |
| } |
| |
| private static void testRV(ResourcesView vp) { |
| assertNotNull(vp); |
| } |
| |
| private static CtfTmfEvent getEvent(int rank) { |
| try (CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace()) { |
| ITmfContext ctx = trace.seekEvent(0); |
| for (int i = 0; i < rank; i++) { |
| trace.getNext(ctx); |
| } |
| return trace.getNext(ctx); |
| } |
| |
| } |
| |
| private static IViewPart getViewPart(final String viewTile) { |
| final IViewPart[] vps = new IViewPart[1]; |
| UIThreadRunnable.syncExec(new VoidResult() { |
| @Override |
| public void run() { |
| IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences(); |
| for (IViewReference viewRef : viewRefs) { |
| IViewPart vp = viewRef.getView(true); |
| if (vp.getTitle().equals(viewTile)) { |
| vps[0] = vp; |
| return; |
| } |
| } |
| } |
| }); |
| |
| return vps[0]; |
| } |
| } |