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