1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.swtbot
.tests
.latency
;
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
;
18 import java
.lang
.reflect
.Field
;
20 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
21 import org
.eclipse
.swtbot
.swt
.finder
.exceptions
.WidgetNotFoundException
;
22 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
23 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
24 import org
.eclipse
.swtbot
.swt
.finder
.matchers
.WidgetOfType
;
25 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
26 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.AbstractSWTBotControl
;
27 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
28 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.density
.AbstractSegmentStoreDensityView
;
29 import org
.eclipse
.tracecompass
.analysis
.timing
.ui
.views
.segmentstore
.table
.AbstractSegmentStoreTableViewer
;
30 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternDensityView
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
33 import org
.eclipse
.ui
.IViewPart
;
34 import org
.eclipse
.ui
.IViewReference
;
35 import org
.junit
.Test
;
36 import org
.junit
.runner
.RunWith
;
37 import org
.swtchart
.Chart
;
38 import org
.swtchart
.ISeries
;
39 import org
.swtchart
.ISeriesSet
;
42 * Test of the pattern density view
44 * @author Jean-Christian Kouame
46 @RunWith(SWTBotJunit4ClassRunner
.class)
47 public class PatternDensityViewTest
extends PatternLatencyViewTestBase
{
49 private static final String COLUMN_HEADER
= "Name";
50 private static final String SYSTEM_CALL_PREFIX
= "sys_";
51 private static final String VIEW_ID
= PatternDensityView
.ID
;
52 private static final String VIEW_TITLE
= "Latency vs Count";
54 private AbstractSegmentStoreDensityView fDensityView
;
55 private AbstractSegmentStoreTableViewer fDensityViewer
;
56 private Chart fDensityChart
;
59 * Set the density viewer
61 * @throws SecurityException
62 * If a security manager is present and any the wrong class is
63 * loaded or the class loader is not the same as its ancestor's
66 * @throws NoSuchFieldException
68 * @throws IllegalAccessException
69 * Field is inaccessible
70 * @throws IllegalArgumentException
71 * the object is not the correct class type
73 public void setDensityViewer() throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
74 SWTBotView viewBot
= fBot
.viewById(VIEW_ID
);
75 final IViewReference viewReference
= viewBot
.getViewReference();
76 IViewPart viewPart
= UIThreadRunnable
.syncExec(new Result
<IViewPart
>() {
78 public IViewPart
run() {
79 return viewReference
.getView(true);
82 assertNotNull(viewPart
);
83 if (!(viewPart
instanceof PatternDensityView
)) {
84 fail("Could not instanciate view");
86 fDensityView
= (PatternDensityView
) viewPart
;
89 * Use reflection to access the table viewer
91 final Field field
= AbstractSegmentStoreDensityView
.class.getDeclaredField("fTableViewer");
92 field
.setAccessible(true);
93 fDensityViewer
= (AbstractSegmentStoreTableViewer
) field
.get(fDensityView
);
94 fDensityChart
= viewBot
.bot().widget(WidgetOfType
.widgetOfType(Chart
.class));
95 assertNotNull(fDensityViewer
);
99 * Test the pattern density view and its viewers data
101 * @throws SecurityException
102 * If a security manager is present and any the wrong class is
103 * loaded or the class loader is not the same as its ancestor's
106 * @throws NoSuchFieldException
107 * Field not available
108 * @throws IllegalAccessException
109 * Field is inaccessible
110 * @throws IllegalArgumentException
111 * the object is not the correct class type
115 public void testWithTrace() throws NoSuchFieldException
, SecurityException
, IllegalArgumentException
, IllegalAccessException
{
117 SWTBotUtils
.waitForJobs();
119 //Test the table content
120 SWTBotTable tableBot
= new SWTBotTable(fDensityViewer
.getTableViewer().getTable());
121 fBot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, SYSTEM_CALL_PREFIX
, 0, 3));
122 tableBot
.header(COLUMN_HEADER
).click();
123 fBot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, SYSTEM_CALL_PREFIX
, 0, 3));
124 tableBot
.header(COLUMN_HEADER
).click();
125 fBot
.waitUntil(ConditionHelpers
.isTableCellFilled(tableBot
, SYSTEM_CALL_PREFIX
, 0, 3));
127 //Test the chart content
128 final Chart densityChart
= fDensityChart
;
129 assertNotNull(densityChart
);
130 SWTBotChart chartBot
= new SWTBotChart(densityChart
);
131 assertVisible(chartBot
);
133 ISeriesSet seriesSet
= fDensityChart
.getSeriesSet();
134 assertNotNull(seriesSet
);
135 ISeries
[] series
= seriesSet
.getSeries();
136 assertNotNull(series
);
138 // Verify that the chart has 1 series
139 assertEquals(1, series
.length
);
140 // Verify that the series has data
141 assertTrue(series
[0].getXSeries().length
> 0);
144 private static class SWTBotChart
extends AbstractSWTBotControl
<Chart
> {
145 public SWTBotChart(Chart w
) throws WidgetNotFoundException
{
151 protected String
getViewId() {
156 protected String
getViewTitle() {