Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
64636df8 | 3 | * |
79e08fd0 BH |
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 | |
64636df8 | 8 | * |
79e08fd0 | 9 | * Contributors: |
09667aa4 | 10 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation |
79e08fd0 BH |
11 | * Bernd Hufmann - Fixed warnings |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ui.tests.statistics; | |
15 | ||
16 | import java.util.Collection; | |
17 | import java.util.Iterator; | |
18 | import java.util.Vector; | |
19 | ||
20 | import junit.framework.TestCase; | |
21 | ||
4c564a2d | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
6c13869b | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
4c564a2d | 24 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
6c13869b FC |
25 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; |
26 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
27 | import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray; | |
cfd22ad0 MD |
28 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo; |
29 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree; | |
30 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.Messages; | |
31 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseStatisticsTree; | |
32 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode; | |
79e08fd0 | 33 | |
64636df8 BH |
34 | /** |
35 | * TmfStatisticsTreeNode Test Cases. | |
36 | */ | |
79e08fd0 BH |
37 | @SuppressWarnings("nls") |
38 | public class TmfStatisticsTreeNodeTest extends TestCase { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Fields | |
42 | // ------------------------------------------------------------------------ | |
43 | private String fTestName = null; | |
64636df8 BH |
44 | |
45 | ||
cbbcc354 | 46 | private final String fContext = "UnitTest"; |
47 | private final String fTypeId1 = "Some type1"; | |
48 | private final String fTypeId2 = "Some type2"; | |
64636df8 | 49 | |
79e08fd0 BH |
50 | private final String fLabel0 = "label1"; |
51 | private final String fLabel1 = "label2"; | |
52 | private final String fLabel2 = "label3"; | |
53 | private final String[] fLabels = new String[] { fLabel0, fLabel1, fLabel2 }; | |
54 | ||
4641c2f7 FC |
55 | private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5); |
56 | private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5); | |
57 | private final TmfTimestamp fTimestamp3 = new TmfTimestamp(12355, (byte) 2, 5); | |
64636df8 | 58 | |
4641c2f7 | 59 | private final String fSource = "Source"; |
64636df8 | 60 | |
4c564a2d | 61 | private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels)); |
255224d9 | 62 | private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels)); |
64636df8 | 63 | |
4641c2f7 | 64 | private final String fReference = "Some reference"; |
79e08fd0 BH |
65 | |
66 | private final TmfEvent fEvent1; | |
67 | private final TmfEvent fEvent2; | |
68 | private final TmfEvent fEvent3; | |
69 | ||
4c564a2d FC |
70 | private final TmfEventField fContent1; |
71 | private final TmfEventField fContent2; | |
72 | private final TmfEventField fContent3; | |
64636df8 | 73 | |
79e08fd0 | 74 | private final TmfBaseStatisticsTree fStatsData; |
64636df8 | 75 | |
79e08fd0 | 76 | private final ITmfExtraEventInfo fExtraInfo; |
64636df8 | 77 | |
79e08fd0 BH |
78 | // ------------------------------------------------------------------------ |
79 | // Housekeeping | |
80 | // ------------------------------------------------------------------------ | |
64636df8 | 81 | |
79e08fd0 | 82 | /** |
09667aa4 MD |
83 | * @param name |
84 | * Test name | |
79e08fd0 BH |
85 | */ |
86 | public TmfStatisticsTreeNodeTest(final String name) { | |
87 | super(name); | |
64636df8 | 88 | |
79e08fd0 | 89 | fTestName = name; |
64636df8 | 90 | |
a4115405 | 91 | fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content"); |
7b477cc3 | 92 | fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType1, fContent1, fReference); |
79e08fd0 | 93 | |
a4115405 | 94 | fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content"); |
255224d9 | 95 | fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType1, fContent2, fReference); |
64636df8 | 96 | |
a4115405 | 97 | fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content"); |
255224d9 | 98 | fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType2, fContent3, fReference); |
7b477cc3 | 99 | |
79e08fd0 BH |
100 | fStatsData = new TmfBaseStatisticsTree(); |
101 | fExtraInfo = new ITmfExtraEventInfo() { | |
102 | @Override | |
103 | public String getTraceName() { | |
255224d9 | 104 | return fTestName; |
79e08fd0 BH |
105 | } |
106 | }; | |
107 | fStatsData.registerEvent(fEvent1, fExtraInfo); | |
59b50985 | 108 | fStatsData.registerEvent(fEvent1, fExtraInfo, 2); |
79e08fd0 | 109 | fStatsData.registerEvent(fEvent2, fExtraInfo); |
59b50985 | 110 | fStatsData.registerEvent(fEvent2, fExtraInfo, 3); |
79e08fd0 | 111 | fStatsData.registerEvent(fEvent3, fExtraInfo); |
59b50985 | 112 | fStatsData.registerEvent(fEvent3, fExtraInfo, 4); |
255224d9 MD |
113 | |
114 | // Registers some events in time range | |
115 | fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo); | |
59b50985 | 116 | fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo, 3); |
255224d9 | 117 | fStatsData.registerEventInTimeRange(fEvent2, fExtraInfo); |
59b50985 | 118 | fStatsData.registerEventInTimeRange(fEvent2, fExtraInfo, 4); |
255224d9 | 119 | fStatsData.registerEventInTimeRange(fEvent3, fExtraInfo); |
59b50985 | 120 | fStatsData.registerEventInTimeRange(fEvent3, fExtraInfo, 5); |
79e08fd0 | 121 | } |
64636df8 | 122 | |
79e08fd0 BH |
123 | // ------------------------------------------------------------------------ |
124 | // ContainsChild | |
125 | // ------------------------------------------------------------------------ | |
126 | ||
64636df8 BH |
127 | /** |
128 | * Test checking for child. | |
129 | */ | |
79e08fd0 BH |
130 | public void testContainsChild() { |
131 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
132 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
133 | // Creates a category from the key already created | |
134 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
64636df8 | 135 | |
09667aa4 | 136 | assertTrue("containsChild", rootNode.containsChild(fTestName)); |
79e08fd0 BH |
137 | assertFalse("containsChild", rootNode.containsChild(catNode.getKey())); |
138 | assertFalse("containsChild", rootNode.containsChild(null)); | |
64636df8 | 139 | |
09667aa4 | 140 | assertTrue("containsChild", traceNode.containsChild(catNode.getKey())); |
59b50985 | 141 | assertFalse("containsChild", traceNode.containsChild(fType1.getName())); |
79e08fd0 | 142 | assertFalse("containsChild", traceNode.containsChild(null)); |
64636df8 | 143 | |
59b50985 MD |
144 | assertTrue("containsChild", catNode.containsChild(fType1.getName())); |
145 | assertTrue("containsChild", catNode.containsChild(fType2.getName())); | |
79e08fd0 BH |
146 | assertFalse("containsChild", catNode.containsChild(null)); |
147 | } | |
64636df8 | 148 | |
79e08fd0 BH |
149 | // ------------------------------------------------------------------------ |
150 | // GetChildren | |
151 | // ------------------------------------------------------------------------ | |
152 | ||
64636df8 BH |
153 | /** |
154 | * Test getting of children. | |
155 | */ | |
79e08fd0 BH |
156 | public void testGetChildren() { |
157 | // Getting children of the ROOT | |
158 | Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(AbsTmfStatisticsTree.ROOT).getChildren(); | |
159 | assertEquals("getChildren", 1, childrenTreeNode.size()); | |
160 | TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next(); | |
161 | assertEquals("getChildren", fTestName, treeNode.getKey()); | |
64636df8 | 162 | |
79e08fd0 BH |
163 | // Getting children of the trace |
164 | childrenTreeNode = fStatsData.get(new TmfFixedArray<String>(fTestName)).getChildren(); | |
165 | assertEquals("getChildren", 1, childrenTreeNode.size()); | |
166 | treeNode = childrenTreeNode.iterator().next(); | |
167 | assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey()); | |
64636df8 BH |
168 | |
169 | Vector<String> keyExpected = new Vector<String>(); | |
59b50985 MD |
170 | keyExpected.add(fType1.getName()); |
171 | keyExpected.add(fType2.getName()); | |
79e08fd0 BH |
172 | // Getting children of a category |
173 | childrenTreeNode = treeNode.getChildren(); | |
174 | assertEquals("getChildren", 2, childrenTreeNode.size()); | |
64636df8 | 175 | |
79e08fd0 BH |
176 | Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator(); |
177 | TmfStatisticsTreeNode temp; | |
178 | while (iterChild.hasNext()) { | |
179 | temp = iterChild.next(); | |
180 | if (keyExpected.contains(temp.getKey())) { | |
181 | keyExpected.removeElement(temp.getKey()); | |
09667aa4 | 182 | } else { |
79e08fd0 BH |
183 | fail(); |
184 | } | |
185 | } | |
64636df8 | 186 | |
79e08fd0 BH |
187 | // Get children of a specific event type |
188 | childrenTreeNode = fStatsData.get(childrenTreeNode.iterator().next().getPath()).getChildren(); | |
189 | assertEquals("getChildren", 0, childrenTreeNode.size()); | |
190 | } | |
64636df8 | 191 | |
79e08fd0 BH |
192 | // ------------------------------------------------------------------------ |
193 | // GetAllChildren | |
194 | // ------------------------------------------------------------------------ | |
195 | ||
64636df8 BH |
196 | /** |
197 | * Test getting of all children. | |
198 | */ | |
79e08fd0 BH |
199 | public void testGetAllChildren() { |
200 | // Getting children of the ROOT | |
201 | Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.get(AbsTmfStatisticsTree.ROOT).getAllChildren(); | |
202 | assertEquals("getChildren", 1, childrenTreeNode.size()); | |
203 | TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next(); | |
204 | assertEquals("getChildren", fTestName, treeNode.getKey()); | |
64636df8 | 205 | |
79e08fd0 BH |
206 | // Getting children of the trace |
207 | childrenTreeNode = fStatsData.get(new TmfFixedArray<String>(fTestName)).getAllChildren(); | |
208 | assertEquals("getChildren", 1, childrenTreeNode.size()); | |
209 | treeNode = childrenTreeNode.iterator().next(); | |
210 | assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey()); | |
64636df8 BH |
211 | |
212 | Vector<String> keyExpected = new Vector<String>(); | |
59b50985 MD |
213 | keyExpected.add(fType1.getName()); |
214 | keyExpected.add(fType2.getName()); | |
09667aa4 MD |
215 | /* |
216 | * It should return the eventType even though the number of events | |
217 | * equals 0 | |
218 | */ | |
59b50985 | 219 | fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())).reset(); |
79e08fd0 BH |
220 | // Getting children of a category |
221 | childrenTreeNode = treeNode.getAllChildren(); | |
222 | assertEquals("getChildren", 2, childrenTreeNode.size()); | |
64636df8 | 223 | |
79e08fd0 BH |
224 | Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator(); |
225 | TmfStatisticsTreeNode temp; | |
226 | while (iterChild.hasNext()) { | |
227 | temp = iterChild.next(); | |
228 | if (keyExpected.contains(temp.getKey())) { | |
229 | keyExpected.removeElement(temp.getKey()); | |
09667aa4 | 230 | } else { |
79e08fd0 BH |
231 | fail(); |
232 | } | |
233 | } | |
64636df8 | 234 | |
79e08fd0 BH |
235 | // Get children of a specific event type |
236 | childrenTreeNode = fStatsData.get(childrenTreeNode.iterator().next().getPath()).getAllChildren(); | |
237 | assertEquals("getChildren", 0, childrenTreeNode.size()); | |
238 | } | |
64636df8 | 239 | |
79e08fd0 BH |
240 | // ------------------------------------------------------------------------ |
241 | // GetNbChildren | |
242 | // ------------------------------------------------------------------------ | |
09667aa4 | 243 | |
64636df8 BH |
244 | /** |
245 | * Test getting of number of children. | |
246 | */ | |
79e08fd0 BH |
247 | public void testGetNbChildren() { |
248 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
249 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
250 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 | 251 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
64636df8 | 252 | |
09667aa4 MD |
253 | assertEquals("getNbChildren", 1, rootNode.getNbChildren()); |
254 | assertEquals("getNbChildren", 1, traceNode.getNbChildren()); | |
255 | assertEquals("getNbChildren", 2, catNode.getNbChildren()); | |
79e08fd0 BH |
256 | assertEquals("getNbChildren", 0, elementNode.getNbChildren()); |
257 | } | |
64636df8 | 258 | |
79e08fd0 BH |
259 | // ------------------------------------------------------------------------ |
260 | // HasChildren | |
261 | // ------------------------------------------------------------------------ | |
64636df8 BH |
262 | |
263 | /** | |
264 | * Test checking for children. | |
265 | */ | |
79e08fd0 BH |
266 | public void testHasChildren() { |
267 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
268 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
269 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 | 270 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
64636df8 | 271 | |
09667aa4 MD |
272 | assertTrue("hasChildren", rootNode.hasChildren()); |
273 | assertTrue("hasChildren", traceNode.hasChildren()); | |
274 | assertTrue("hasChildren", catNode.hasChildren()); | |
79e08fd0 BH |
275 | assertFalse("hasChildren", elementNode.hasChildren()); |
276 | } | |
64636df8 | 277 | |
79e08fd0 BH |
278 | // ------------------------------------------------------------------------ |
279 | // GetParent | |
280 | // ------------------------------------------------------------------------ | |
64636df8 BH |
281 | |
282 | /** | |
255224d9 | 283 | * Test getting of parent. |
64636df8 | 284 | */ |
79e08fd0 BH |
285 | public void testGetParent() { |
286 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
287 | TmfStatisticsTreeNode parentNode = rootNode.getParent(); | |
288 | assertNull("getParent", parentNode); | |
64636df8 | 289 | |
79e08fd0 BH |
290 | TmfStatisticsTreeNode newTraceNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>("newly created trace node"), fStatsData); |
291 | parentNode = newTraceNode.getParent(); | |
292 | assertNotNull("getParent", parentNode); | |
293 | assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(AbsTmfStatisticsTree.ROOT).getKey().toString())); | |
64636df8 | 294 | |
79e08fd0 BH |
295 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); |
296 | parentNode = traceNode.getParent(); | |
297 | assertNotNull("getParent", parentNode); | |
298 | assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString())); | |
64636df8 | 299 | |
79e08fd0 BH |
300 | TmfStatisticsTreeNode newNode = new TmfStatisticsTreeNode(new TmfFixedArray<String>("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist"), fStatsData); |
301 | parentNode = newNode.getParent(); | |
302 | assertNull("getParent", parentNode); | |
64636df8 | 303 | |
59b50985 | 304 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
79e08fd0 BH |
305 | parentNode = elementNode.getParent(); |
306 | assertNull("getParent", parentNode); | |
64636df8 | 307 | |
79e08fd0 BH |
308 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); |
309 | parentNode = catNode.getParent(); | |
310 | assertNotNull("getParent", parentNode); | |
311 | assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(new TmfFixedArray<String>(fTestName)).getPath().toString())); | |
64636df8 | 312 | |
79e08fd0 BH |
313 | parentNode = elementNode.getParent(); |
314 | assertNotNull("getParent", parentNode); | |
315 | assertTrue("getParent", parentNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes))); | |
316 | } | |
64636df8 | 317 | |
79e08fd0 BH |
318 | // ------------------------------------------------------------------------ |
319 | // GetKey | |
320 | // ------------------------------------------------------------------------ | |
09667aa4 | 321 | |
64636df8 BH |
322 | /** |
323 | * Test getting of key. | |
324 | */ | |
79e08fd0 BH |
325 | public void testGetKey() { |
326 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
327 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
328 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 | 329 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
64636df8 | 330 | |
09667aa4 MD |
331 | assertEquals("getKey", 0, rootNode.getKey().compareTo(AbsTmfStatisticsTree.ROOT.get(0))); |
332 | assertEquals("getKey", 0, traceNode.getKey().compareTo(fTestName)); | |
333 | assertEquals("getKey", 0, catNode.getKey().compareTo(Messages.TmfStatisticsData_EventTypes)); | |
59b50985 | 334 | assertEquals("getKey", 0, elementNode.getKey().compareTo(fType1.getName())); |
79e08fd0 | 335 | } |
64636df8 | 336 | |
79e08fd0 BH |
337 | // ------------------------------------------------------------------------ |
338 | // GetPath | |
339 | // ------------------------------------------------------------------------ | |
64636df8 BH |
340 | |
341 | /** | |
342 | * Test getting of path to node. | |
343 | */ | |
79e08fd0 BH |
344 | public void testGetPath() { |
345 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
346 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
347 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 | 348 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
64636df8 | 349 | |
09667aa4 MD |
350 | assertTrue("getPath", rootNode.getPath().equals(AbsTmfStatisticsTree.ROOT)); |
351 | assertTrue("getPath", traceNode.getPath().equals(new TmfFixedArray<String>(fTestName))); | |
352 | assertTrue("getPath", catNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes))); | |
59b50985 | 353 | assertTrue("getPath", elementNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()))); |
79e08fd0 | 354 | } |
64636df8 | 355 | |
79e08fd0 BH |
356 | // ------------------------------------------------------------------------ |
357 | // GetValue | |
358 | // ------------------------------------------------------------------------ | |
64636df8 BH |
359 | |
360 | /** | |
255224d9 | 361 | * Test getting statistic value. |
64636df8 | 362 | */ |
79e08fd0 BH |
363 | public void testGetValue() { |
364 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
365 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
366 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 MD |
367 | TmfStatisticsTreeNode elementNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
368 | TmfStatisticsTreeNode elementNode3 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName())); | |
64636df8 | 369 | |
25a042b3 | 370 | assertEquals("getValue", 0, rootNode.getValue().getTotal()); |
59b50985 | 371 | assertEquals("getValue", 12, traceNode.getValue().getTotal()); |
25a042b3 | 372 | assertEquals("getValue", 0, catNode.getValue().getTotal()); |
59b50985 MD |
373 | assertEquals("getValue", 7, elementNode1.getValue().getTotal()); |
374 | assertEquals("getValue", 5, elementNode3.getValue().getTotal()); | |
375 | ||
376 | assertEquals("getValue", 0, rootNode.getValue().getPartial()); | |
377 | assertEquals("getValue", 15, traceNode.getValue().getPartial()); | |
378 | assertEquals("getValue", 0, catNode.getValue().getPartial()); | |
379 | assertEquals("getValue", 9, elementNode1.getValue().getPartial()); | |
380 | assertEquals("getValue", 6, elementNode3.getValue().getPartial()); | |
79e08fd0 | 381 | } |
64636df8 | 382 | |
79e08fd0 BH |
383 | // ------------------------------------------------------------------------ |
384 | // Reset | |
385 | // ------------------------------------------------------------------------ | |
64636df8 BH |
386 | |
387 | /** | |
388 | * Test reset of tree. | |
389 | */ | |
79e08fd0 BH |
390 | public void testReset() { |
391 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
392 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
393 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 | 394 | TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
64636df8 | 395 | |
79e08fd0 | 396 | elementNode.reset(); |
25a042b3 | 397 | assertEquals("reset", 0, elementNode.getValue().getTotal()); |
59b50985 | 398 | assertEquals("reset", 0, elementNode.getValue().getPartial()); |
64636df8 | 399 | |
79e08fd0 | 400 | catNode.reset(); |
25a042b3 | 401 | assertEquals("reset", 0, catNode.getValue().getTotal()); |
59b50985 | 402 | assertEquals("reset", 0, catNode.getValue().getPartial()); |
79e08fd0 | 403 | assertEquals("reset", 0, catNode.getNbChildren()); |
59b50985 | 404 | assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName()))); |
64636df8 | 405 | |
79e08fd0 | 406 | traceNode.reset(); |
25a042b3 | 407 | assertEquals("reset", 0, traceNode.getValue().getTotal()); |
59b50985 | 408 | assertEquals("reset", 0, traceNode.getValue().getPartial()); |
79e08fd0 BH |
409 | // A trace always have at least one child that is eventType |
410 | assertEquals("reset", 1, traceNode.getNbChildren()); | |
411 | ||
412 | rootNode.reset(); | |
25a042b3 | 413 | assertEquals("reset", 0, rootNode.getValue().getTotal()); |
59b50985 | 414 | assertEquals("reset", 0, rootNode.getValue().getPartial()); |
79e08fd0 BH |
415 | assertEquals("reset", 1, rootNode.getNbChildren()); |
416 | } | |
255224d9 | 417 | |
59b50985 MD |
418 | /** |
419 | * Test reset global value of the node in the tree. It should only clear | |
420 | * the global value without removing any node from the tree. | |
421 | */ | |
422 | public void testResetGlobalValue() { | |
423 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
424 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
425 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
426 | TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); | |
427 | TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName())); | |
428 | ||
429 | rootNode.resetGlobalValue(); | |
430 | ||
431 | assertEquals(0, rootNode.getValue().getTotal()); | |
432 | assertEquals(0, traceNode.getValue().getTotal()); | |
433 | assertEquals(0, catNode.getValue().getTotal()); | |
434 | assertEquals(0, eventTypeNode1.getValue().getTotal()); | |
435 | assertEquals(0, eventTypeNode2.getValue().getTotal()); | |
436 | ||
437 | // Checks the state of the statistics tree | |
438 | Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getAllChildren(); | |
439 | assertEquals(1, rootChildren.size()); | |
440 | assertTrue(rootChildren.contains(traceNode)); | |
441 | ||
442 | Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getAllChildren(); | |
443 | assertEquals(1, traceChildren.size()); | |
444 | assertTrue(traceChildren.contains(catNode)); | |
445 | ||
446 | Collection<TmfStatisticsTreeNode> catChildren = catNode.getAllChildren(); | |
447 | assertEquals(2, catChildren.size()); | |
448 | assertTrue(catChildren.contains(eventTypeNode1)); | |
449 | assertTrue(catChildren.contains(eventTypeNode2)); | |
450 | } | |
451 | ||
255224d9 MD |
452 | /** |
453 | * Test reset time range value of the node in the tree. It should only clear | |
454 | * the time range value without removing any node from the tree. | |
455 | */ | |
456 | public void testResetTimeRangeValue() { | |
457 | TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT); | |
458 | TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName)); | |
459 | TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next(); | |
59b50985 MD |
460 | TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())); |
461 | TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.getName())); | |
255224d9 MD |
462 | |
463 | rootNode.resetTimeRangeValue(); | |
464 | ||
465 | assertEquals(0, rootNode.getValue().getPartial()); | |
466 | assertEquals(0, traceNode.getValue().getPartial()); | |
467 | assertEquals(0, catNode.getValue().getPartial()); | |
468 | assertEquals(0, eventTypeNode1.getValue().getPartial()); | |
469 | assertEquals(0, eventTypeNode2.getValue().getPartial()); | |
470 | ||
471 | // Checks the state of the statistics tree | |
472 | Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getAllChildren(); | |
473 | assertEquals(1, rootChildren.size()); | |
474 | assertTrue(rootChildren.contains(traceNode)); | |
475 | ||
476 | Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getAllChildren(); | |
477 | assertEquals(1, traceChildren.size()); | |
478 | assertTrue(traceChildren.contains(catNode)); | |
479 | ||
480 | Collection<TmfStatisticsTreeNode> catChildren = catNode.getAllChildren(); | |
481 | assertEquals(2, catChildren.size()); | |
482 | assertTrue(catChildren.contains(eventTypeNode1)); | |
483 | assertTrue(catChildren.contains(eventTypeNode2)); | |
484 | } | |
79e08fd0 | 485 | } |