ctf: Fix remaining warnings the CTF plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / statistics / TmfBaseStatisticsDataTest.java
CommitLineData
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 * Bernd Hufmann - Fixed warnings
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.ui.tests.statistics;
15
16import java.util.Collection;
17import java.util.Iterator;
18import java.util.Vector;
19
20import junit.framework.TestCase;
21
4c564a2d 22import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
6c13869b 23import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
4c564a2d 24import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
6c13869b
FC
25import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
26import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
27import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
79e08fd0 28import org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfExtraEventInfo;
99005796 29import org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree;
79e08fd0
BH
30import org.eclipse.linuxtools.tmf.ui.views.statistics.model.Messages;
31import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseStatisticsTree;
79e08fd0 32import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeNode;
79e08fd0
BH
33
34@SuppressWarnings("nls")
35public class TmfBaseStatisticsDataTest extends TestCase {
36
37 // ------------------------------------------------------------------------
38 // Fields
39 // ------------------------------------------------------------------------
40 private String fTestName = null;
41
cbbcc354 42 private final String fContext = "UnitTest";
43 private final String fTypeId1 = "Some type1";
44 private final String fTypeId2 = "Some type2";
79e08fd0
BH
45
46 private final String fLabel0 = "label1";
47 private final String fLabel1 = "label2";
48 private final String fLabel2 = "label3";
49 private final String[] fLabels = new String[] { fLabel0, fLabel1, fLabel2 };
50
4641c2f7
FC
51 private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5);
52 private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5);
53 private final TmfTimestamp fTimestamp3 = new TmfTimestamp(12355, (byte) 2, 5);
79e08fd0 54
4641c2f7 55 private final String fSource = "Source";
79e08fd0 56
4c564a2d
FC
57 private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
58 private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
59 private final TmfEventType fType3 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
79e08fd0 60
4641c2f7 61 private final String fReference = "Some reference";
79e08fd0
BH
62
63 private final TmfEvent fEvent1;
64 private final TmfEvent fEvent2;
65 private final TmfEvent fEvent3;
66
4c564a2d
FC
67 private final TmfEventField fContent1;
68 private final TmfEventField fContent2;
69 private final TmfEventField fContent3;
79e08fd0
BH
70
71 private final TmfBaseStatisticsTree fStatsData;
72
73 private final ITmfExtraEventInfo fExtraInfo;
74
75 // ------------------------------------------------------------------------
76 // Housekeeping
77 // ------------------------------------------------------------------------
78
79 /**
80 * @param name of the test
81 */
82 public TmfBaseStatisticsDataTest(final String name) {
83 super(name);
84
85 fTestName = name;
86
a4115405 87 fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content");
7b477cc3 88 fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType1, fContent1, fReference);
79e08fd0 89
a4115405 90 fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content");
7b477cc3 91 fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType2, fContent2, fReference);
79e08fd0 92
a4115405 93 fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
7b477cc3 94 fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType3, fContent3, fReference);
79e08fd0
BH
95
96 fStatsData = new TmfBaseStatisticsTree();
97 fExtraInfo = new ITmfExtraEventInfo() {
98 @Override
99 public String getTraceName() {
100 return name;
101 }
102 };
103 fStatsData.registerEvent(fEvent1, fExtraInfo);
104 fStatsData.registerEvent(fEvent2, fExtraInfo);
105 fStatsData.registerEvent(fEvent3, fExtraInfo);
106 }
107
108 // ------------------------------------------------------------------------
109 // GetChildren
110 // ------------------------------------------------------------------------
111
112 public void testGetChildren() {
113 // Getting children of the ROOT
114 Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(AbsTmfStatisticsTree.ROOT);
115 assertEquals("getChildren", 1, childrenTreeNode.size());
116 TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
117 assertEquals("getChildren", fTestName, treeNode.getKey());
118
119 // Getting children of the trace
120 childrenTreeNode = fStatsData.getChildren(new TmfFixedArray<String>(fTestName));
121 assertEquals("getChildren", 1, childrenTreeNode.size());
122 treeNode = childrenTreeNode.iterator().next();
123 assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
124
125 Vector<String> keyExpected = new Vector<String>();
126 keyExpected.add(fEvent1.getType().toString());
127 keyExpected.add(fEvent3.getType().toString());
128 // Getting children of a category
129 childrenTreeNode = fStatsData.getChildren(treeNode.getPath());
130 assertEquals("getChildren", 2, childrenTreeNode.size());
131
132 Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
133 TmfStatisticsTreeNode temp;
134 while (iterChild.hasNext()) {
135 temp = iterChild.next();
136 if (keyExpected.contains(temp.getKey())) {
137 keyExpected.removeElement(temp.getKey());
138 }
139 else {
140 fail();
141 }
142 }
143
144 // Get children of a specific event type
145 childrenTreeNode = fStatsData.getChildren(childrenTreeNode.iterator().next().getPath());
146 assertEquals("getChildren", 0, childrenTreeNode.size());
147 }
148
149 // ------------------------------------------------------------------------
150 // GetAllChildren
151 // ------------------------------------------------------------------------
152
153 public void testGetAllChildren() {
154 // Getting children of the ROOT
155 Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getAllChildren(AbsTmfStatisticsTree.ROOT);
156 assertEquals("getChildren", 1, childrenTreeNode.size());
157 TmfStatisticsTreeNode treeNode = childrenTreeNode.iterator().next();
158 assertEquals("getChildren", fTestName, treeNode.getKey());
159
160 // Getting children of the trace
161 childrenTreeNode = fStatsData.getAllChildren(new TmfFixedArray<String>(fTestName));
162 assertEquals("getChildren", 1, childrenTreeNode.size());
163 treeNode = childrenTreeNode.iterator().next();
164 assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
165
166 Vector<String> keyExpected = new Vector<String>();
167 keyExpected.add(fEvent1.getType().toString());
168 keyExpected.add(fEvent3.getType().toString());
169 // It should return the eventType even though the number of events equals 0
170 fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString())).reset();
171 // Getting children of a category
172 childrenTreeNode = fStatsData.get(treeNode.getPath()).getAllChildren();
173 assertEquals("getChildren", 2, childrenTreeNode.size());
174
175 Iterator<TmfStatisticsTreeNode> iterChild = childrenTreeNode.iterator();
176 TmfStatisticsTreeNode temp;
177 while (iterChild.hasNext()) {
178 temp = iterChild.next();
179 if (keyExpected.contains(temp.getKey())) {
180 keyExpected.removeElement(temp.getKey());
181 }
182 else {
183 fail();
184 }
185 }
186
187 // Get children of a specific event type
188 childrenTreeNode = fStatsData.getAllChildren(childrenTreeNode.iterator().next().getPath());
189 assertEquals("getChildren", 0, childrenTreeNode.size());
190 }
191
192 // ------------------------------------------------------------------------
193 // RegisterEvent
194 // ------------------------------------------------------------------------
195
196 public void testRegisterEvent() {
197 TmfStatisticsTreeNode trace = fStatsData.get(new TmfFixedArray<String>(fTestName));
198 assertEquals("registerEvent", 3, trace.getValue().nbEvents);
199
200 Collection<TmfStatisticsTreeNode> childrenTreeNode = fStatsData.getChildren(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
201 for (TmfStatisticsTreeNode child : childrenTreeNode) {
202 if (child.getKey().compareTo(fEvent1.getType().toString()) == 0) {
203 assertEquals("registerEvent", 2, child.getValue().nbEvents);
204 }
205 else if (child.getKey().compareTo(fEvent3.getType().toString()) == 0) {
206 assertEquals("registerEvent", 1, child.getValue().nbEvents);
207 }
208 }
209 }
210
211 // ------------------------------------------------------------------------
212 // Get a node
213 // ------------------------------------------------------------------------
214
215 public void testGet() {
216 TmfStatisticsTreeNode traceRoot = fStatsData.get(new TmfFixedArray<String>(fTestName));
217 assertNotNull("get", traceRoot);
218 assertEquals("get", 0, traceRoot.getPath().toString().compareTo("[" + fTestName + "]"));
219 assertEquals("get", 3, traceRoot.getValue().nbEvents);
220 assertEquals("get", 1, traceRoot.getNbChildren());
221 }
222
223 // ------------------------------------------------------------------------
224 // GetOrCreate
225 // ------------------------------------------------------------------------
226
227 public void testGetOrCreate() {
228 TmfFixedArray<String> newEventType = new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, "Fancy Type");
229 TmfStatisticsTreeNode newEventTypeNode;
230
231 // newEventType is not in the tree
232 newEventTypeNode = fStatsData.get(newEventType);
233 assertNull("getOrCreate", newEventTypeNode);
234
235 newEventTypeNode = fStatsData.getOrCreate(newEventType);
236 assertNotNull("getOrCreate", newEventTypeNode);
237 assertTrue("getOrCreate", newEventTypeNode.getPath().equals(newEventType));
238
239 // newEventType is in the tree
240 newEventTypeNode.reset();
241 newEventTypeNode = fStatsData.get(newEventType);
242 assertNotNull("getOrCreate", newEventTypeNode);
243
244 newEventTypeNode = fStatsData.getOrCreate(newEventType);
245 assertNotNull("getOrCreate", newEventTypeNode);
246 assertTrue("getOrCreate", newEventTypeNode.getPath().equals(newEventType));
247 }
248
249 // ------------------------------------------------------------------------
250 // GetParent
251 // ------------------------------------------------------------------------
252
253 public void testGetParent() {
254 TmfStatisticsTreeNode parentNode = fStatsData.getParent(AbsTmfStatisticsTree.ROOT);
255 assertNull("getParent", parentNode);
256
257 parentNode = fStatsData.getParent(new TmfFixedArray<String>("TreeRootNode that should not exist"));
258 assertNotNull("getParent", parentNode);
259 assertEquals("getParent", 0, parentNode.getKey().compareTo(fStatsData.get(AbsTmfStatisticsTree.ROOT).getKey().toString()));
260
261 parentNode = fStatsData.getParent(new TmfFixedArray<String>("TreeNode", Messages.TmfStatisticsData_EventTypes, "TreeNode that should not exist"));
262 assertNull("getParent", parentNode);
263 parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
264 assertNull("getParent", parentNode);
265
266 parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName));
267 assertNotNull("getParent", parentNode);
268 assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(AbsTmfStatisticsTree.ROOT.toString()));
269
270 parentNode = fStatsData.getParent(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
271 assertNotNull("getParent", parentNode);
272 assertEquals("getParent", 0, parentNode.getPath().toString().compareTo(fStatsData.get(new TmfFixedArray<String>(fTestName)).getPath().toString()));
273 }
274
275 // ------------------------------------------------------------------------
276 // Reset
277 // ------------------------------------------------------------------------
278
279 public void testReset() {
280 fStatsData.reset(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes));
281
282 assertEquals("reset", 0, fStatsData.getChildren(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)).size());
4c564a2d
FC
283 assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.getName())));
284 assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType3.getName())));
79e08fd0
BH
285
286 fStatsData.reset(new TmfFixedArray<String>(fTestName));
287
288 // A rootz should always have at least one child that is eventType
289 assertEquals("reset", 1, fStatsData.getChildren(new TmfFixedArray<String>(fTestName)).size());
290 }
291}
This page took 0.042323 seconds and 5 git commands to generate.