tmf: formatting of tmf.ui.statistics
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / statistics / TmfBaseColumnDataTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Contributors:
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.tests.statistics;
14
15 import junit.framework.TestCase;
16
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.core.util.TmfFixedArray;
21 import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseColumnData;
22 import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider;
23 import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseStatisticsTree;
24 import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeNode;
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;
29
30 /**
31 * TmfBaseColumnData Test Case.
32 */
33 @SuppressWarnings("nls")
34 public class TmfBaseColumnDataTest extends TestCase {
35
36 // ------------------------------------------------------------------------
37 // Fields
38 // ------------------------------------------------------------------------
39
40 private int fAlignment;
41 private int fWidth;
42 private String fHeader;
43 private String fToolTip;
44 private ColumnLabelProvider fLabelProvider;
45 private ViewerComparator fComparator;
46 private ITmfColumnPercentageProvider fPercentageProvider;
47 private TmfStatisticsTreeNode fTreeNode;
48 private String fTraceName;
49 private TmfBaseColumnData fBaseColumnData;
50
51 // ------------------------------------------------------------------------
52 // Housekeeping
53 // ------------------------------------------------------------------------
54
55 private void init() {
56 fHeader = "test Column1";
57 fWidth = 300;
58 fAlignment = SWT.LEFT;
59 fToolTip = "Tooltip " + fHeader;
60 fLabelProvider = new ColumnLabelProvider() {
61 @Override
62 public String getText(Object element) {
63 return ((TmfStatisticsTreeNode) element).getKey();
64 }
65
66 @Override
67 public Image getImage(Object element) {
68 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
69 }
70 };
71 fComparator = new ViewerComparator() {
72 @Override
73 public int compare(Viewer viewer, Object e1, Object e2) {
74 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
75 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
76
77 return n1.getKey().compareTo(n2.getKey());
78 }
79 };
80 fPercentageProvider = new ITmfColumnPercentageProvider() {
81 @Override
82 public double getPercentage(TmfStatisticsTreeNode node) {
83 TmfStatisticsTreeNode parent = node;
84 do {
85 parent = parent.getParent();
86 } while (parent != null && parent.getValue().nbEvents == 0);
87
88 if (parent == null) {
89 return 0;
90 }
91 return (double) node.getValue().nbEvents / parent.getValue().nbEvents;
92 }
93 };
94
95 TmfBaseStatisticsTree baseData = new TmfBaseStatisticsTree();
96 fTraceName = "trace1";
97 fTreeNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>(fTraceName), baseData);
98
99 fBaseColumnData = new TmfBaseColumnData(fHeader, fWidth, fAlignment, fToolTip, fLabelProvider, fComparator, fPercentageProvider);
100 }
101
102 @Override
103 public void setUp() throws Exception {
104 super.setUp();
105 init();
106 }
107
108 @Override
109 public void tearDown() throws Exception {
110 super.tearDown();
111 }
112
113 // ------------------------------------------------------------------------
114 // getHeader
115 // ------------------------------------------------------------------------
116
117 /**
118 * Test get header
119 */
120 public void testGetHeader() {
121 assertEquals("getHeader", 0, fBaseColumnData.getHeader().compareTo(fHeader));
122 }
123
124 // ------------------------------------------------------------------------
125 // getWidth
126 // ------------------------------------------------------------------------
127
128 /**
129 * Test getting of column width.
130 */
131 public void testGetWidth() {
132 assertEquals("getWidth", fWidth, fBaseColumnData.getWidth());
133 }
134
135 // ------------------------------------------------------------------------
136 // getAlignment
137 // ------------------------------------------------------------------------
138
139 /**
140 * Test getting of alignment value
141 */
142 public void testGetAlignment() {
143 assertEquals("getAlignment", fAlignment, fBaseColumnData.getAlignment());
144 }
145
146 // ------------------------------------------------------------------------
147 // getToolTip
148 // ------------------------------------------------------------------------
149
150 /**
151 * Test getting of tooltip.
152 */
153 public void testGetTooltip() {
154 assertEquals("getTooltip", fToolTip, fBaseColumnData.getTooltip());
155 }
156
157 // ------------------------------------------------------------------------
158 // getLabelProvider
159 // ------------------------------------------------------------------------
160
161 /**
162 * Test getting of label provider
163 */
164 public void testGetLabelProvider() {
165 assertEquals("getLabelProvider", 0, fBaseColumnData.getLabelProvider().getText(fTreeNode).compareTo(fLabelProvider.getText(fTreeNode)));
166 assertTrue("getLabelProvider", fBaseColumnData.getLabelProvider().getImage(fTreeNode).equals(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT)));
167 assertTrue("getLabelProvider", fBaseColumnData.getLabelProvider().equals(fLabelProvider));
168 }
169
170 // ------------------------------------------------------------------------
171 // getComparator
172 // ------------------------------------------------------------------------
173
174 /**
175 * Test getting of comparator.
176 */
177 public void testGetComparator() {
178 assertTrue("getComparator", fBaseColumnData.getComparator().equals(fComparator));
179 }
180
181 // ------------------------------------------------------------------------
182 // getPercentageProvider
183 // ------------------------------------------------------------------------
184
185 /**
186 * Test getting of percentage provider.
187 */
188 public void testGetPercentageProvider() {
189 assertTrue("getPercentageProvider", fBaseColumnData.getPercentageProvider().equals(fPercentageProvider));
190 }
191 }
This page took 0.034072 seconds and 5 git commands to generate.