Commit | Line | Data |
---|---|---|
79e08fd0 BH |
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; | |
6c13869b | 20 | import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray; |
79e08fd0 BH |
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; | |
79e08fd0 BH |
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 | @SuppressWarnings("nls") | |
31 | public class TmfBaseColumnDataTest extends TestCase { | |
32 | ||
33 | // ------------------------------------------------------------------------ | |
34 | // Fields | |
35 | // ------------------------------------------------------------------------ | |
36 | ||
37 | private int fAlignment; | |
38 | private int fWidth; | |
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; | |
47 | ||
48 | // ------------------------------------------------------------------------ | |
49 | // Housekeeping | |
50 | // ------------------------------------------------------------------------ | |
51 | ||
52 | private void init() { | |
53 | fHeader = "test Column1"; | |
54 | fWidth = 300; | |
55 | fAlignment = SWT.LEFT; | |
56 | fToolTip = "Tooltip " + fHeader; | |
57 | fLabelProvider = new ColumnLabelProvider() { | |
58 | @Override | |
59 | public String getText(Object element) { | |
60 | return ((TmfStatisticsTreeNode) element).getKey(); | |
61 | } | |
62 | ||
63 | @Override | |
64 | public Image getImage(Object element) { | |
65 | return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); | |
66 | } | |
67 | }; | |
68 | fComparator = new ViewerComparator() { | |
69 | @Override | |
70 | public int compare(Viewer viewer, Object e1, Object e2) { | |
71 | TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1; | |
72 | TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2; | |
73 | ||
74 | return n1.getKey().compareTo(n2.getKey()); | |
75 | } | |
76 | }; | |
77 | fPercentageProvider = new ITmfColumnPercentageProvider() { | |
78 | @Override | |
79 | public double getPercentage(TmfStatisticsTreeNode node) { | |
80 | TmfStatisticsTreeNode parent = node; | |
81 | do { | |
82 | parent = parent.getParent(); | |
83 | } while (parent != null && parent.getValue().nbEvents == 0); | |
84 | ||
85 | if (parent == null) { | |
86 | return 0; | |
87 | } else { | |
88 | return (double) node.getValue().nbEvents / parent.getValue().nbEvents; | |
89 | } | |
90 | } | |
91 | }; | |
92 | ||
93 | TmfBaseStatisticsTree baseData = new TmfBaseStatisticsTree(); | |
94 | fTraceName = "trace1"; | |
95 | fTreeNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>(fTraceName), baseData); | |
96 | ||
97 | fBaseColumnData = new TmfBaseColumnData(fHeader, fWidth, fAlignment, fToolTip, fLabelProvider, fComparator, fPercentageProvider); | |
98 | } | |
99 | ||
100 | @Override | |
101 | public void setUp() throws Exception { | |
102 | super.setUp(); | |
103 | init(); | |
104 | } | |
105 | ||
106 | @Override | |
107 | public void tearDown() throws Exception { | |
108 | super.tearDown(); | |
109 | } | |
110 | ||
111 | // ------------------------------------------------------------------------ | |
112 | // getHeader | |
113 | // ------------------------------------------------------------------------ | |
114 | ||
115 | public void testGetHeader() { | |
116 | assertEquals("getHeader", 0, fBaseColumnData.getHeader().compareTo(fHeader)); | |
117 | } | |
118 | ||
119 | // ------------------------------------------------------------------------ | |
120 | // getWidth | |
121 | // ------------------------------------------------------------------------ | |
122 | ||
123 | public void testGetWidth() { | |
124 | assertEquals("getWidth", fWidth, fBaseColumnData.getWidth()); | |
125 | } | |
126 | ||
127 | // ------------------------------------------------------------------------ | |
128 | // getAlignment | |
129 | // ------------------------------------------------------------------------ | |
130 | ||
131 | public void testGetAlignment() { | |
132 | assertEquals("getAlignment", fAlignment, fBaseColumnData.getAlignment()); | |
133 | } | |
134 | ||
135 | // ------------------------------------------------------------------------ | |
136 | // getToolTip | |
137 | // ------------------------------------------------------------------------ | |
138 | ||
139 | public void testGetTooltip() { | |
140 | assertEquals("getTooltip", fToolTip, fBaseColumnData.getTooltip()); | |
141 | } | |
142 | ||
143 | // ------------------------------------------------------------------------ | |
144 | // getLabelProvider | |
145 | // ------------------------------------------------------------------------ | |
146 | ||
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)); | |
151 | } | |
152 | ||
153 | // ------------------------------------------------------------------------ | |
154 | // getComparator | |
155 | // ------------------------------------------------------------------------ | |
156 | ||
157 | public void testGetComparator() { | |
158 | assertTrue("getComparator", fBaseColumnData.getComparator().equals(fComparator)); | |
159 | } | |
160 | ||
161 | // ------------------------------------------------------------------------ | |
162 | // getPercentageProvider | |
163 | // ------------------------------------------------------------------------ | |
164 | ||
165 | public void testGetPercentageProvider() { | |
166 | assertTrue("getPercentageProvider", fBaseColumnData.getPercentageProvider().equals(fPercentageProvider)); | |
167 | } | |
168 | } |