| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2016 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 | |
| 10 | package org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests.latency; |
| 11 | |
| 12 | import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible; |
| 13 | import static org.junit.Assert.assertEquals; |
| 14 | import static org.junit.Assert.assertNotNull; |
| 15 | import static org.junit.Assert.assertTrue; |
| 16 | import static org.junit.Assert.fail; |
| 17 | |
| 18 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
| 19 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 20 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
| 21 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| 22 | import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; |
| 23 | import org.eclipse.swtbot.swt.finder.results.Result; |
| 24 | import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl; |
| 25 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView; |
| 26 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
| 27 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
| 28 | import org.eclipse.ui.IViewPart; |
| 29 | import org.eclipse.ui.IViewReference; |
| 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
| 32 | import org.swtchart.Chart; |
| 33 | import org.swtchart.ISeries; |
| 34 | import org.swtchart.ISeriesSet; |
| 35 | import org.swtchart.Range; |
| 36 | |
| 37 | /** |
| 38 | * Tests of the pattern scatter chart view |
| 39 | * |
| 40 | * @author Jean-Christian Kouame |
| 41 | */ |
| 42 | @RunWith(SWTBotJunit4ClassRunner.class) |
| 43 | public class PatternScatterChartViewTest extends PatternLatencyViewTestBase { |
| 44 | |
| 45 | private static final String VIEW_ID = PatternScatterGraphView.ID; |
| 46 | private static final String VIEW_TITLE = "Latency vs Time"; |
| 47 | private Chart fScatterChart; |
| 48 | |
| 49 | private void setChart() { |
| 50 | SWTBotView viewBot = fBot.viewById(VIEW_ID); |
| 51 | final IViewReference viewReference = viewBot.getViewReference(); |
| 52 | IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() { |
| 53 | @Override |
| 54 | public IViewPart run() { |
| 55 | return viewReference.getView(true); |
| 56 | } |
| 57 | }); |
| 58 | assertNotNull(viewPart); |
| 59 | if (!(viewPart instanceof PatternScatterGraphView)) { |
| 60 | fail("Could not instanciate view"); |
| 61 | } |
| 62 | fScatterChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class)); |
| 63 | assertNotNull(fScatterChart); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Test the pattern latency scatter graph. This method test if the chart has |
| 68 | * one series and the series has data |
| 69 | */ |
| 70 | @Test |
| 71 | public void testWithTrace() { |
| 72 | setChart(); |
| 73 | SWTBotUtils.waitForJobs(); |
| 74 | final Chart scatterChart = fScatterChart; |
| 75 | assertNotNull(scatterChart); |
| 76 | fBot.waitUntil(ConditionHelpers.numberOfSeries(scatterChart, 1)); |
| 77 | |
| 78 | SWTBotChart chartBot = new SWTBotChart(scatterChart); |
| 79 | assertVisible(chartBot); |
| 80 | final Range range = scatterChart.getAxisSet().getXAxes()[0].getRange(); |
| 81 | assertEquals(100000000, range.upper - range.lower, 0); |
| 82 | ISeriesSet seriesSet = fScatterChart.getSeriesSet(); |
| 83 | assertNotNull(seriesSet); |
| 84 | ISeries[] series = seriesSet.getSeries(); |
| 85 | assertNotNull(series); |
| 86 | |
| 87 | // Verify that the chart has 1 series |
| 88 | assertEquals(1, series.length); |
| 89 | // Verify that the series has data |
| 90 | assertTrue(series[0].getXSeries().length > 0); |
| 91 | } |
| 92 | |
| 93 | private static class SWTBotChart extends AbstractSWTBotControl<Chart> { |
| 94 | public SWTBotChart(Chart w) throws WidgetNotFoundException { |
| 95 | super(w); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | protected String getViewId() { |
| 101 | return VIEW_ID; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | protected String getViewTitle() { |
| 106 | return VIEW_TITLE; |
| 107 | } |
| 108 | } |