Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 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 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.tests.control.model.impl; | |
13 | ||
14 | import junit.framework.TestCase; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; | |
17 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; | |
18 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; | |
20 | ||
21 | /** | |
22 | * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>. | |
23 | */ | |
24 | @SuppressWarnings("nls") | |
25 | public class BaseEventInfoTest extends TestCase { | |
26 | ||
27 | // ------------------------------------------------------------------------ | |
28 | // Test data | |
29 | // ------------------------------------------------------------------------ | |
30 | private IBaseEventInfo fEventInfo1 = null; | |
31 | private IBaseEventInfo fEventInfo2 = null; | |
32 | ||
33 | // ------------------------------------------------------------------------ | |
34 | // Housekeeping | |
35 | // ------------------------------------------------------------------------ | |
36 | /** | |
37 | * Perform pre-test initialization. | |
38 | * | |
39 | * @throws Exception if the initialization fails for some reason | |
40 | * | |
41 | */ | |
42 | @Override | |
43 | public void setUp() throws Exception { | |
44 | super.setUp(); | |
45 | ModelImplFactory factory = new ModelImplFactory(); | |
46 | fEventInfo1 = factory.getBaseEventInfo1(); | |
47 | fEventInfo2 = factory.getBaseEventInfo2(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Perform post-test clean-up. | |
52 | * | |
53 | * @throws Exception if the clean-up fails for some reason | |
54 | * | |
55 | */ | |
56 | @Override | |
57 | public void tearDown() throws Exception { | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Tests | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | /** | |
65 | * Run the BaseEventInfo() constructor test. | |
66 | * | |
67 | */ | |
68 | public void testBaseEventInfo() { | |
69 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
70 | assertNotNull(fixture); | |
71 | ||
72 | TraceEventType result = fixture.getEventType(); | |
73 | ||
74 | assertEquals("event", fixture.getName()); | |
75 | assertEquals("unknown", result.getInName()); | |
76 | assertEquals("UNKNOWN", result.name()); | |
77 | assertEquals("UNKNOWN", result.toString()); | |
78 | assertEquals(1, result.ordinal()); | |
79 | ||
80 | TraceLogLevel level = fixture.getLogLevel(); | |
4775bcbf BH |
81 | assertEquals("TRACE_DEBUG", level.getInName()); |
82 | assertEquals("TRACE_DEBUG", level.name()); | |
83 | assertEquals("TRACE_DEBUG", level.toString()); | |
84 | assertEquals(14, level.ordinal()); | |
eb1bab5b BH |
85 | } |
86 | ||
87 | /** | |
88 | * Test Copy Constructor | |
89 | */ | |
90 | public void testEventInfoCopy() { | |
91 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
92 | ||
93 | assertEquals(fEventInfo1.getName(), info.getName()); | |
94 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
95 | assertEquals(fEventInfo1.getLogLevel(), info.getLogLevel()); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test Copy Constructor | |
100 | */ | |
101 | public void testEventCopy2() { | |
102 | try { | |
103 | BaseEventInfo info = null; | |
104 | new BaseEventInfo(info); | |
105 | fail("null copy"); | |
106 | } | |
107 | catch (IllegalArgumentException e) { | |
108 | // Success | |
109 | } | |
110 | } | |
111 | ||
112 | /** | |
113 | * Run the TraceEventType getEventType() method test. | |
114 | * | |
115 | * @throws Exception | |
116 | * | |
117 | */ | |
118 | public void testGetEventType_1() { | |
119 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
120 | fixture.setEventType("unknown"); | |
121 | ||
122 | TraceEventType result = fixture.getEventType(); | |
123 | ||
124 | assertNotNull(result); | |
125 | assertEquals("unknown", result.getInName()); | |
126 | assertEquals("UNKNOWN", result.name()); | |
127 | assertEquals("UNKNOWN", result.toString()); | |
128 | assertEquals(1, result.ordinal()); | |
129 | ||
130 | fixture.setEventType(""); | |
131 | result = fixture.getEventType(); | |
132 | assertEquals("unknown", result.getInName()); | |
133 | assertEquals("UNKNOWN", result.name()); | |
134 | assertEquals("UNKNOWN", result.toString()); | |
135 | assertEquals(1, result.ordinal()); | |
136 | ||
137 | fixture.setEventType("tracepoint"); | |
138 | result = fixture.getEventType(); | |
139 | assertNotNull(result); | |
140 | assertEquals("tracepoint", result.getInName()); | |
141 | assertEquals("TRACEPOINT", result.name()); | |
142 | assertEquals("TRACEPOINT", result.toString()); | |
143 | assertEquals(0, result.ordinal()); | |
144 | } | |
145 | ||
146 | /** | |
147 | * Run the void setEventType(TraceEventType) method test. | |
148 | * | |
149 | */ | |
150 | public void testSetEventType_2() { | |
151 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
152 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
153 | ||
154 | TraceEventType result = fixture.getEventType(); | |
155 | ||
156 | assertNotNull(result); | |
157 | assertEquals("tracepoint", result.getInName()); | |
158 | assertEquals("TRACEPOINT", result.name()); | |
159 | assertEquals("TRACEPOINT", result.toString()); | |
160 | assertEquals(0, result.ordinal()); | |
161 | ||
162 | fixture.setEventType(TraceEventType.UNKNOWN); | |
163 | result = fixture.getEventType(); | |
164 | ||
165 | assertNotNull(result); | |
166 | assertEquals("unknown", result.getInName()); | |
167 | assertEquals("UNKNOWN", result.name()); | |
168 | assertEquals("UNKNOWN", result.toString()); | |
169 | assertEquals(1, result.ordinal()); | |
170 | } | |
171 | ||
172 | /** | |
173 | * Run the void setLogLevel(TraceLogLevel) method test. | |
174 | * Run the TraceLogLevel getLogLevel() method test | |
175 | * | |
176 | */ | |
177 | public void testSetLogLevel1() { | |
178 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
179 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
180 | fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); | |
181 | ||
182 | // 2 set/get-operations are enough to test the method | |
183 | TraceLogLevel result = fixture.getLogLevel(); | |
184 | assertNotNull(result); | |
4775bcbf | 185 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
186 | assertEquals("TRACE_CRIT", result.name()); |
187 | assertEquals("TRACE_CRIT", result.toString()); | |
188 | assertEquals(2, result.ordinal()); | |
189 | ||
4775bcbf | 190 | fixture.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION); |
eb1bab5b BH |
191 | |
192 | result = fixture.getLogLevel(); | |
193 | assertNotNull(result); | |
4775bcbf BH |
194 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
195 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
196 | assertEquals("TRACE_DEBUG_FUNCTION", result.toString()); | |
eb1bab5b BH |
197 | assertEquals(12, result.ordinal()); |
198 | } | |
199 | ||
200 | /** | |
201 | * Run the void setLogLevel(String) method test. | |
202 | * Run the TraceLogLevel getLogLevel() method test | |
203 | * | |
204 | */ | |
205 | public void testSetLogLevel2() { | |
206 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
207 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
4775bcbf | 208 | fixture.setLogLevel("TRACE_EMERG"); |
eb1bab5b BH |
209 | |
210 | TraceLogLevel result = fixture.getLogLevel(); | |
211 | assertNotNull(result); | |
4775bcbf | 212 | assertEquals("TRACE_EMERG", result.getInName()); |
eb1bab5b BH |
213 | assertEquals("TRACE_EMERG", result.name()); |
214 | assertEquals(0, result.ordinal()); | |
215 | ||
216 | //------------------------ | |
4775bcbf | 217 | fixture.setLogLevel("TRACE_ALERT"); |
eb1bab5b BH |
218 | |
219 | result = fixture.getLogLevel(); | |
220 | assertNotNull(result); | |
4775bcbf | 221 | assertEquals("TRACE_ALERT", result.getInName()); |
eb1bab5b BH |
222 | assertEquals("TRACE_ALERT", result.name()); |
223 | assertEquals(1, result.ordinal()); | |
224 | ||
225 | //------------------------ | |
4775bcbf | 226 | fixture.setLogLevel("TRACE_CRIT"); |
eb1bab5b BH |
227 | |
228 | result = fixture.getLogLevel(); | |
229 | assertNotNull(result); | |
4775bcbf | 230 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
231 | assertEquals("TRACE_CRIT", result.name()); |
232 | assertEquals(2, result.ordinal()); | |
233 | ||
234 | //------------------------ | |
4775bcbf | 235 | fixture.setLogLevel("TRACE_ERR"); |
eb1bab5b BH |
236 | |
237 | result = fixture.getLogLevel(); | |
238 | assertNotNull(result); | |
4775bcbf | 239 | assertEquals("TRACE_ERR", result.getInName()); |
eb1bab5b BH |
240 | assertEquals("TRACE_ERR", result.name()); |
241 | assertEquals(3, result.ordinal()); | |
242 | ||
243 | //------------------------ | |
4775bcbf | 244 | fixture.setLogLevel("TRACE_WARNING"); |
eb1bab5b BH |
245 | |
246 | result = fixture.getLogLevel(); | |
247 | assertNotNull(result); | |
4775bcbf | 248 | assertEquals("TRACE_WARNING", result.getInName()); |
eb1bab5b BH |
249 | assertEquals("TRACE_WARNING", result.name()); |
250 | assertEquals(4, result.ordinal()); | |
251 | ||
252 | //------------------------ | |
4775bcbf | 253 | fixture.setLogLevel("TRACE_NOTICE"); |
eb1bab5b BH |
254 | |
255 | result = fixture.getLogLevel(); | |
256 | assertNotNull(result); | |
4775bcbf | 257 | assertEquals("TRACE_NOTICE", result.getInName()); |
eb1bab5b BH |
258 | assertEquals("TRACE_NOTICE", result.name()); |
259 | assertEquals(5, result.ordinal()); | |
260 | ||
261 | //------------------------ | |
4775bcbf | 262 | fixture.setLogLevel("TRACE_INFO"); |
eb1bab5b BH |
263 | |
264 | result = fixture.getLogLevel(); | |
265 | assertNotNull(result); | |
4775bcbf | 266 | assertEquals("TRACE_INFO", result.getInName()); |
eb1bab5b BH |
267 | assertEquals("TRACE_INFO", result.name()); |
268 | assertEquals(6, result.ordinal()); | |
269 | ||
270 | //------------------------ | |
4775bcbf | 271 | fixture.setLogLevel("TRACE_DEBUG_SYSTEM"); |
eb1bab5b BH |
272 | |
273 | result = fixture.getLogLevel(); | |
274 | assertNotNull(result); | |
4775bcbf BH |
275 | assertEquals("TRACE_DEBUG_SYSTEM", result.getInName()); |
276 | assertEquals("TRACE_DEBUG_SYSTEM", result.name()); | |
eb1bab5b BH |
277 | assertEquals(7, result.ordinal()); |
278 | ||
279 | //------------------------ | |
4775bcbf | 280 | fixture.setLogLevel("TRACE_DEBUG_PROGRAM"); |
eb1bab5b BH |
281 | |
282 | result = fixture.getLogLevel(); | |
283 | assertNotNull(result); | |
4775bcbf BH |
284 | assertEquals("TRACE_DEBUG_PROGRAM", result.getInName()); |
285 | assertEquals("TRACE_DEBUG_PROGRAM", result.name()); | |
eb1bab5b BH |
286 | assertEquals(8, result.ordinal()); |
287 | ||
288 | //------------------------ | |
4775bcbf | 289 | fixture.setLogLevel("TRACE_DEBUG_PROCESS"); |
eb1bab5b BH |
290 | |
291 | result = fixture.getLogLevel(); | |
292 | assertNotNull(result); | |
4775bcbf BH |
293 | assertEquals("TRACE_DEBUG_PROCESS", result.getInName()); |
294 | assertEquals("TRACE_DEBUG_PROCESS", result.name()); | |
eb1bab5b BH |
295 | assertEquals(9, result.ordinal()); |
296 | ||
297 | //------------------------ | |
4775bcbf | 298 | fixture.setLogLevel("TRACE_DEBUG_MODULE"); |
eb1bab5b BH |
299 | |
300 | result = fixture.getLogLevel(); | |
301 | assertNotNull(result); | |
4775bcbf BH |
302 | assertEquals("TRACE_DEBUG_MODULE", result.getInName()); |
303 | assertEquals("TRACE_DEBUG_MODULE", result.name()); | |
eb1bab5b BH |
304 | assertEquals(10, result.ordinal()); |
305 | ||
306 | //------------------------ | |
4775bcbf | 307 | fixture.setLogLevel("TRACE_DEBUG_UNIT"); |
eb1bab5b BH |
308 | |
309 | result = fixture.getLogLevel(); | |
310 | assertNotNull(result); | |
4775bcbf BH |
311 | assertEquals("TRACE_DEBUG_UNIT", result.getInName()); |
312 | assertEquals("TRACE_DEBUG_UNIT", result.name()); | |
eb1bab5b BH |
313 | assertEquals(11, result.ordinal()); |
314 | ||
315 | //------------------------ | |
4775bcbf | 316 | fixture.setLogLevel("TRACE_DEBUG_FUNCTION"); |
eb1bab5b BH |
317 | |
318 | result = fixture.getLogLevel(); | |
319 | assertNotNull(result); | |
4775bcbf BH |
320 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
321 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
eb1bab5b BH |
322 | assertEquals(12, result.ordinal()); |
323 | ||
324 | //------------------------ | |
4775bcbf | 325 | fixture.setLogLevel("TRACE_DEBUG_LINE"); |
eb1bab5b BH |
326 | |
327 | result = fixture.getLogLevel(); | |
328 | assertNotNull(result); | |
4775bcbf BH |
329 | assertEquals("TRACE_DEBUG_LINE", result.getInName()); |
330 | assertEquals("TRACE_DEBUG_LINE", result.name()); | |
eb1bab5b BH |
331 | assertEquals(13, result.ordinal()); |
332 | ||
333 | //------------------------ | |
4775bcbf | 334 | fixture.setLogLevel("TRACE_DEBUG"); |
eb1bab5b BH |
335 | |
336 | result = fixture.getLogLevel(); | |
337 | assertNotNull(result); | |
4775bcbf BH |
338 | assertEquals("TRACE_DEBUG", result.getInName()); |
339 | assertEquals("TRACE_DEBUG", result.name()); | |
eb1bab5b BH |
340 | assertEquals(14, result.ordinal()); |
341 | ||
4775bcbf BH |
342 | //------------------------- |
343 | fixture.setLogLevel("LEVEL_UNKNOWN"); | |
eb1bab5b BH |
344 | |
345 | result = fixture.getLogLevel(); | |
346 | assertNotNull(result); | |
4775bcbf BH |
347 | assertEquals("LEVEL_UNKNOWN", result.getInName()); |
348 | assertEquals("LEVEL_UNKNOWN", result.name()); | |
eb1bab5b | 349 | assertEquals(15, result.ordinal()); |
4775bcbf BH |
350 | |
351 | fixture.setLogLevel("garbage"); | |
eb1bab5b BH |
352 | |
353 | result = fixture.getLogLevel(); | |
354 | assertNotNull(result); | |
4775bcbf BH |
355 | assertEquals("TRACE_DEBUG", result.getInName()); |
356 | assertEquals("TRACE_DEBUG", result.name()); | |
357 | assertEquals(14, result.ordinal()); | |
eb1bab5b BH |
358 | } |
359 | ||
360 | ||
361 | /** | |
362 | * Run the String toString() method test. | |
363 | * | |
364 | */ | |
365 | public void testToString_1() { | |
366 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
367 | fixture.setName("testName"); | |
368 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
369 | fixture.setLogLevel(TraceLogLevel.TRACE_ERR); | |
370 | ||
371 | String result = fixture.toString(); | |
372 | ||
373 | // add additional test code here | |
374 | assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result); | |
375 | } | |
376 | ||
377 | // ------------------------------------------------------------------------ | |
378 | // equals | |
379 | // ------------------------------------------------------------------------ | |
380 | ||
381 | public void testEqualsReflexivity() { | |
382 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
383 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
384 | ||
385 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
386 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
387 | } | |
388 | ||
389 | public void testEqualsSymmetry() { | |
390 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
391 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
392 | ||
393 | assertTrue("equals", info1.equals(fEventInfo1)); | |
394 | assertTrue("equals", fEventInfo1.equals(info1)); | |
395 | ||
396 | assertTrue("equals", info2.equals(fEventInfo2)); | |
397 | assertTrue("equals", fEventInfo2.equals(info2)); | |
398 | } | |
399 | ||
400 | public void testEqualsTransivity() { | |
401 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
402 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
403 | BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
404 | ||
405 | assertTrue("equals", info1.equals(info2)); | |
406 | assertTrue("equals", info2.equals(info3)); | |
407 | assertTrue("equals", info1.equals(info3)); | |
408 | } | |
409 | ||
410 | public void testEqualsNull() { | |
411 | assertTrue("equals", !fEventInfo1.equals(null)); | |
412 | assertTrue("equals", !fEventInfo2.equals(null)); | |
413 | } | |
414 | ||
415 | // ------------------------------------------------------------------------ | |
416 | // hashCode | |
417 | // ------------------------------------------------------------------------ | |
418 | ||
419 | public void testHashCode() { | |
420 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
421 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
422 | ||
423 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
424 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
425 | ||
426 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
427 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
428 | } | |
429 | } |