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