1 /*******************************************************************************
2 * Copyright (c) 2011 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
10 * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial design and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.statistics
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
18 import org
.eclipse
.jface
.viewers
.Viewer
;
19 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfBaseColumnData
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfBaseColumnData
.ITmfColumnPercentageProvider
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfBaseStatisticsTree
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfStatisticsTreeNode
;
24 import org
.eclipse
.linuxtools
.tmf
.util
.TmfFixedArray
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.ui
.ISharedImages
;
28 import org
.eclipse
.ui
.PlatformUI
;
30 @SuppressWarnings("nls")
31 public class TmfBaseColumnDataTest
extends TestCase
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 private int fAlignment
;
39 private String fHeader
;
40 private String fToolTip
;
41 private ColumnLabelProvider fLabelProvider
;
42 private ViewerComparator fComparator
;
43 private ITmfColumnPercentageProvider fPercentageProvider
;
44 private TmfStatisticsTreeNode fTreeNode
;
45 private String fTraceName
;
46 private TmfBaseColumnData fBaseColumnData
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 fHeader
= "test Column1";
55 fAlignment
= SWT
.LEFT
;
56 fToolTip
= "Tooltip " + fHeader
;
57 fLabelProvider
= new ColumnLabelProvider() {
59 public String
getText(Object element
) {
60 return ((TmfStatisticsTreeNode
) element
).getKey();
64 public Image
getImage(Object element
) {
65 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_ELEMENT
);
68 fComparator
= new ViewerComparator() {
70 public int compare(Viewer viewer
, Object e1
, Object e2
) {
71 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
72 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
74 return n1
.getKey().compareTo(n2
.getKey());
77 fPercentageProvider
= new ITmfColumnPercentageProvider() {
79 public double getPercentage(TmfStatisticsTreeNode node
) {
80 TmfStatisticsTreeNode parent
= node
;
82 parent
= parent
.getParent();
83 } while (parent
!= null && parent
.getValue().nbEvents
== 0);
88 return (double) node
.getValue().nbEvents
/ parent
.getValue().nbEvents
;
93 TmfBaseStatisticsTree baseData
= new TmfBaseStatisticsTree();
94 fTraceName
= "trace1";
95 fTreeNode
= new TmfStatisticsTreeNode(new TmfFixedArray
<String
>(fTraceName
), baseData
);
97 fBaseColumnData
= new TmfBaseColumnData(fHeader
, fWidth
, fAlignment
, fToolTip
, fLabelProvider
, fComparator
, fPercentageProvider
);
101 public void setUp() throws Exception
{
107 public void tearDown() throws Exception
{
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
115 public void testGetHeader() {
116 assertEquals("getHeader", 0, fBaseColumnData
.getHeader().compareTo(fHeader
));
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
123 public void testGetWidth() {
124 assertEquals("getWidth", fWidth
, fBaseColumnData
.getWidth());
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
131 public void testGetAlignment() {
132 assertEquals("getAlignment", fAlignment
, fBaseColumnData
.getAlignment());
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
139 public void testGetTooltip() {
140 assertEquals("getTooltip", fToolTip
, fBaseColumnData
.getTooltip());
143 // ------------------------------------------------------------------------
145 // ------------------------------------------------------------------------
147 public void testGetLabelProvider() {
148 assertEquals("getLabelProvider", 0, fBaseColumnData
.getLabelProvider().getText(fTreeNode
).compareTo(fLabelProvider
.getText(fTreeNode
)));
149 assertTrue("getLabelProvider", fBaseColumnData
.getLabelProvider().getImage(fTreeNode
).equals(PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_ELEMENT
)));
150 assertTrue("getLabelProvider", fBaseColumnData
.getLabelProvider().equals(fLabelProvider
));
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
157 public void testGetComparator() {
158 assertTrue("getComparator", fBaseColumnData
.getComparator().equals(fComparator
));
161 // ------------------------------------------------------------------------
162 // getPercentageProvider
163 // ------------------------------------------------------------------------
165 public void testGetPercentageProvider() {
166 assertTrue("getPercentageProvider", fBaseColumnData
.getPercentageProvider().equals(fPercentageProvider
));