From: Jean-Christian Kouame Date: Wed, 11 May 2016 17:57:48 +0000 (-0400) Subject: tmf: Add SWTBot test for the pattern latency scatter chart X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=6b3aadab9503e145234ecb3ba38cf3ca54a483c2;p=deliverable%2Ftracecompass.git tmf: Add SWTBot test for the pattern latency scatter chart Change-Id: I5e73bc68a5ddf5e3cd30c0feb580338b27df4439 Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/72551 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternScatterChartViewTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternScatterChartViewTest.java new file mode 100644 index 0000000000..fa0cdec077 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternScatterChartViewTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests.latency; + +import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; +import org.eclipse.swtbot.swt.finder.results.Result; +import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl; +import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView; +import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.swtchart.Chart; +import org.swtchart.ISeries; +import org.swtchart.ISeriesSet; +import org.swtchart.Range; + +/** + * Tests of the pattern scatter chart view + * + * @author Jean-Christian Kouame + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class PatternScatterChartViewTest extends PatternLatencyViewTestBase { + + private static final String VIEW_ID = PatternScatterGraphView.ID; + private static final String VIEW_TITLE = "Latency vs Time"; + private Chart fScatterChart; + + private void setChart() { + SWTBotView viewBot = fBot.viewById(VIEW_ID); + final IViewReference viewReference = viewBot.getViewReference(); + IViewPart viewPart = UIThreadRunnable.syncExec(new Result() { + @Override + public IViewPart run() { + return viewReference.getView(true); + } + }); + assertNotNull(viewPart); + if (!(viewPart instanceof PatternScatterGraphView)) { + fail("Could not instanciate view"); + } + fScatterChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class)); + assertNotNull(fScatterChart); + } + + /** + * Test the pattern latency scatter graph. This method test if the chart has + * one series and the series has data + */ + @Test + public void testWithTrace() { + setChart(); + SWTBotUtils.waitForJobs(); + final Chart scatterChart = fScatterChart; + assertNotNull(scatterChart); + + SWTBotChart chartBot = new SWTBotChart(scatterChart); + assertVisible(chartBot); + final Range range = scatterChart.getAxisSet().getXAxes()[0].getRange(); + assertEquals(100000000, range.upper - range.lower, 0); + ISeriesSet seriesSet = fScatterChart.getSeriesSet(); + assertNotNull(seriesSet); + ISeries[] series = seriesSet.getSeries(); + assertNotNull(series); + + // Verify that the chart has 1 series + assertEquals(1, series.length); + // Verify that the series has data + assertTrue(series[0].getXSeries().length > 0); + } + + private static class SWTBotChart extends AbstractSWTBotControl { + public SWTBotChart(Chart w) throws WidgetNotFoundException { + super(w); + } + } + + @Override + protected String getViewId() { + return VIEW_ID; + } + + @Override + protected String getViewTitle() { + return VIEW_TITLE; + } +}