Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
b0318660 | 3 | * |
eb1bab5b 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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9315aeee | 12 | package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import junit.framework.TestCase; | |
15 | ||
9315aeee BH |
16 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo; |
17 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo; | |
eb1bab5b BH |
20 | |
21 | /** | |
22 | * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>. | |
23 | */ | |
b0318660 | 24 | @SuppressWarnings({"nls", "javadoc"}) |
eb1bab5b BH |
25 | public class BaseEventInfoTest extends TestCase { |
26 | ||
27 | // ------------------------------------------------------------------------ | |
28 | // Test data | |
29 | // ------------------------------------------------------------------------ | |
30 | private IBaseEventInfo fEventInfo1 = null; | |
31 | private IBaseEventInfo fEventInfo2 = null; | |
b0318660 | 32 | |
eb1bab5b BH |
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(); | |
b0318660 | 45 | ModelImplFactory factory = new ModelImplFactory(); |
eb1bab5b BH |
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); | |
b0318660 | 71 | |
eb1bab5b | 72 | TraceEventType result = fixture.getEventType(); |
b0318660 | 73 | |
eb1bab5b BH |
74 | assertEquals("event", fixture.getName()); |
75 | assertEquals("unknown", result.getInName()); | |
76 | assertEquals("UNKNOWN", result.name()); | |
77 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 78 | assertEquals(3, result.ordinal()); |
b0318660 | 79 | |
eb1bab5b | 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); | |
b0318660 | 92 | |
eb1bab5b BH |
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 | } | |
b0318660 | 111 | |
eb1bab5b BH |
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()); | |
ccc66d01 | 128 | assertEquals(3, result.ordinal()); |
b0318660 | 129 | |
eb1bab5b BH |
130 | fixture.setEventType(""); |
131 | result = fixture.getEventType(); | |
132 | assertEquals("unknown", result.getInName()); | |
133 | assertEquals("UNKNOWN", result.name()); | |
134 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 135 | assertEquals(3, result.ordinal()); |
b0318660 | 136 | |
eb1bab5b BH |
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()); | |
b0318660 | 144 | |
ccc66d01 BH |
145 | fixture.setEventType("syscall"); |
146 | result = fixture.getEventType(); | |
147 | assertNotNull(result); | |
148 | assertEquals("syscall", result.getInName()); | |
149 | assertEquals("SYSCALL", result.name()); | |
150 | assertEquals("SYSCALL", result.toString()); | |
151 | assertEquals(1, result.ordinal()); | |
b0318660 | 152 | |
ccc66d01 BH |
153 | fixture.setEventType("probe"); |
154 | result = fixture.getEventType(); | |
155 | assertNotNull(result); | |
156 | assertEquals("probe", result.getInName()); | |
157 | assertEquals("PROBE", result.name()); | |
158 | assertEquals("PROBE", result.toString()); | |
159 | assertEquals(2, result.ordinal()); | |
160 | ||
eb1bab5b BH |
161 | } |
162 | ||
163 | /** | |
164 | * Run the void setEventType(TraceEventType) method test. | |
165 | * | |
166 | */ | |
167 | public void testSetEventType_2() { | |
168 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
169 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
b0318660 | 170 | |
eb1bab5b | 171 | TraceEventType result = fixture.getEventType(); |
b0318660 | 172 | |
eb1bab5b BH |
173 | assertNotNull(result); |
174 | assertEquals("tracepoint", result.getInName()); | |
175 | assertEquals("TRACEPOINT", result.name()); | |
176 | assertEquals("TRACEPOINT", result.toString()); | |
177 | assertEquals(0, result.ordinal()); | |
b0318660 | 178 | |
eb1bab5b BH |
179 | fixture.setEventType(TraceEventType.UNKNOWN); |
180 | result = fixture.getEventType(); | |
b0318660 | 181 | |
eb1bab5b BH |
182 | assertNotNull(result); |
183 | assertEquals("unknown", result.getInName()); | |
184 | assertEquals("UNKNOWN", result.name()); | |
185 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 186 | assertEquals(3, result.ordinal()); |
b0318660 | 187 | |
ccc66d01 BH |
188 | fixture.setEventType(TraceEventType.SYSCALL); |
189 | result = fixture.getEventType(); | |
190 | assertNotNull(result); | |
191 | assertEquals("syscall", result.getInName()); | |
192 | assertEquals("SYSCALL", result.name()); | |
193 | assertEquals("SYSCALL", result.toString()); | |
194 | assertEquals(1, result.ordinal()); | |
b0318660 | 195 | |
ccc66d01 BH |
196 | fixture.setEventType(TraceEventType.PROBE); |
197 | result = fixture.getEventType(); | |
198 | assertNotNull(result); | |
199 | assertEquals("probe", result.getInName()); | |
200 | assertEquals("PROBE", result.name()); | |
201 | assertEquals("PROBE", result.toString()); | |
9d8a90ad | 202 | assertEquals(2, result.ordinal()); |
ccc66d01 | 203 | |
eb1bab5b | 204 | } |
b0318660 | 205 | |
eb1bab5b BH |
206 | /** |
207 | * Run the void setLogLevel(TraceLogLevel) method test. | |
208 | * Run the TraceLogLevel getLogLevel() method test | |
b0318660 | 209 | * |
eb1bab5b BH |
210 | */ |
211 | public void testSetLogLevel1() { | |
212 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
213 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
214 | fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); | |
b0318660 | 215 | |
eb1bab5b BH |
216 | // 2 set/get-operations are enough to test the method |
217 | TraceLogLevel result = fixture.getLogLevel(); | |
218 | assertNotNull(result); | |
4775bcbf | 219 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
220 | assertEquals("TRACE_CRIT", result.name()); |
221 | assertEquals("TRACE_CRIT", result.toString()); | |
222 | assertEquals(2, result.ordinal()); | |
223 | ||
4775bcbf | 224 | fixture.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION); |
b0318660 | 225 | |
eb1bab5b BH |
226 | result = fixture.getLogLevel(); |
227 | assertNotNull(result); | |
4775bcbf BH |
228 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
229 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
230 | assertEquals("TRACE_DEBUG_FUNCTION", result.toString()); | |
eb1bab5b BH |
231 | assertEquals(12, result.ordinal()); |
232 | } | |
b0318660 | 233 | |
eb1bab5b BH |
234 | /** |
235 | * Run the void setLogLevel(String) method test. | |
236 | * Run the TraceLogLevel getLogLevel() method test | |
b0318660 | 237 | * |
eb1bab5b BH |
238 | */ |
239 | public void testSetLogLevel2() { | |
240 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
241 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
4775bcbf | 242 | fixture.setLogLevel("TRACE_EMERG"); |
b0318660 | 243 | |
eb1bab5b BH |
244 | TraceLogLevel result = fixture.getLogLevel(); |
245 | assertNotNull(result); | |
4775bcbf | 246 | assertEquals("TRACE_EMERG", result.getInName()); |
eb1bab5b BH |
247 | assertEquals("TRACE_EMERG", result.name()); |
248 | assertEquals(0, result.ordinal()); | |
249 | ||
250 | //------------------------ | |
4775bcbf | 251 | fixture.setLogLevel("TRACE_ALERT"); |
b0318660 | 252 | |
eb1bab5b BH |
253 | result = fixture.getLogLevel(); |
254 | assertNotNull(result); | |
4775bcbf | 255 | assertEquals("TRACE_ALERT", result.getInName()); |
eb1bab5b BH |
256 | assertEquals("TRACE_ALERT", result.name()); |
257 | assertEquals(1, result.ordinal()); | |
b0318660 | 258 | |
eb1bab5b | 259 | //------------------------ |
4775bcbf | 260 | fixture.setLogLevel("TRACE_CRIT"); |
b0318660 | 261 | |
eb1bab5b BH |
262 | result = fixture.getLogLevel(); |
263 | assertNotNull(result); | |
4775bcbf | 264 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
265 | assertEquals("TRACE_CRIT", result.name()); |
266 | assertEquals(2, result.ordinal()); | |
267 | ||
268 | //------------------------ | |
4775bcbf | 269 | fixture.setLogLevel("TRACE_ERR"); |
b0318660 | 270 | |
eb1bab5b BH |
271 | result = fixture.getLogLevel(); |
272 | assertNotNull(result); | |
4775bcbf | 273 | assertEquals("TRACE_ERR", result.getInName()); |
eb1bab5b BH |
274 | assertEquals("TRACE_ERR", result.name()); |
275 | assertEquals(3, result.ordinal()); | |
276 | ||
277 | //------------------------ | |
4775bcbf | 278 | fixture.setLogLevel("TRACE_WARNING"); |
b0318660 | 279 | |
eb1bab5b BH |
280 | result = fixture.getLogLevel(); |
281 | assertNotNull(result); | |
4775bcbf | 282 | assertEquals("TRACE_WARNING", result.getInName()); |
eb1bab5b BH |
283 | assertEquals("TRACE_WARNING", result.name()); |
284 | assertEquals(4, result.ordinal()); | |
285 | ||
286 | //------------------------ | |
4775bcbf | 287 | fixture.setLogLevel("TRACE_NOTICE"); |
b0318660 | 288 | |
eb1bab5b BH |
289 | result = fixture.getLogLevel(); |
290 | assertNotNull(result); | |
4775bcbf | 291 | assertEquals("TRACE_NOTICE", result.getInName()); |
eb1bab5b BH |
292 | assertEquals("TRACE_NOTICE", result.name()); |
293 | assertEquals(5, result.ordinal()); | |
294 | ||
295 | //------------------------ | |
4775bcbf | 296 | fixture.setLogLevel("TRACE_INFO"); |
b0318660 | 297 | |
eb1bab5b BH |
298 | result = fixture.getLogLevel(); |
299 | assertNotNull(result); | |
4775bcbf | 300 | assertEquals("TRACE_INFO", result.getInName()); |
eb1bab5b BH |
301 | assertEquals("TRACE_INFO", result.name()); |
302 | assertEquals(6, result.ordinal()); | |
303 | ||
304 | //------------------------ | |
4775bcbf | 305 | fixture.setLogLevel("TRACE_DEBUG_SYSTEM"); |
b0318660 | 306 | |
eb1bab5b BH |
307 | result = fixture.getLogLevel(); |
308 | assertNotNull(result); | |
4775bcbf BH |
309 | assertEquals("TRACE_DEBUG_SYSTEM", result.getInName()); |
310 | assertEquals("TRACE_DEBUG_SYSTEM", result.name()); | |
eb1bab5b BH |
311 | assertEquals(7, result.ordinal()); |
312 | ||
313 | //------------------------ | |
4775bcbf | 314 | fixture.setLogLevel("TRACE_DEBUG_PROGRAM"); |
b0318660 | 315 | |
eb1bab5b BH |
316 | result = fixture.getLogLevel(); |
317 | assertNotNull(result); | |
4775bcbf BH |
318 | assertEquals("TRACE_DEBUG_PROGRAM", result.getInName()); |
319 | assertEquals("TRACE_DEBUG_PROGRAM", result.name()); | |
eb1bab5b BH |
320 | assertEquals(8, result.ordinal()); |
321 | ||
322 | //------------------------ | |
4775bcbf | 323 | fixture.setLogLevel("TRACE_DEBUG_PROCESS"); |
b0318660 | 324 | |
eb1bab5b BH |
325 | result = fixture.getLogLevel(); |
326 | assertNotNull(result); | |
4775bcbf BH |
327 | assertEquals("TRACE_DEBUG_PROCESS", result.getInName()); |
328 | assertEquals("TRACE_DEBUG_PROCESS", result.name()); | |
eb1bab5b BH |
329 | assertEquals(9, result.ordinal()); |
330 | ||
331 | //------------------------ | |
4775bcbf | 332 | fixture.setLogLevel("TRACE_DEBUG_MODULE"); |
b0318660 | 333 | |
eb1bab5b BH |
334 | result = fixture.getLogLevel(); |
335 | assertNotNull(result); | |
4775bcbf BH |
336 | assertEquals("TRACE_DEBUG_MODULE", result.getInName()); |
337 | assertEquals("TRACE_DEBUG_MODULE", result.name()); | |
eb1bab5b BH |
338 | assertEquals(10, result.ordinal()); |
339 | ||
340 | //------------------------ | |
4775bcbf | 341 | fixture.setLogLevel("TRACE_DEBUG_UNIT"); |
b0318660 | 342 | |
eb1bab5b BH |
343 | result = fixture.getLogLevel(); |
344 | assertNotNull(result); | |
4775bcbf BH |
345 | assertEquals("TRACE_DEBUG_UNIT", result.getInName()); |
346 | assertEquals("TRACE_DEBUG_UNIT", result.name()); | |
eb1bab5b BH |
347 | assertEquals(11, result.ordinal()); |
348 | ||
349 | //------------------------ | |
4775bcbf | 350 | fixture.setLogLevel("TRACE_DEBUG_FUNCTION"); |
b0318660 | 351 | |
eb1bab5b BH |
352 | result = fixture.getLogLevel(); |
353 | assertNotNull(result); | |
4775bcbf BH |
354 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
355 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
eb1bab5b BH |
356 | assertEquals(12, result.ordinal()); |
357 | ||
358 | //------------------------ | |
4775bcbf | 359 | fixture.setLogLevel("TRACE_DEBUG_LINE"); |
b0318660 | 360 | |
eb1bab5b BH |
361 | result = fixture.getLogLevel(); |
362 | assertNotNull(result); | |
4775bcbf BH |
363 | assertEquals("TRACE_DEBUG_LINE", result.getInName()); |
364 | assertEquals("TRACE_DEBUG_LINE", result.name()); | |
eb1bab5b BH |
365 | assertEquals(13, result.ordinal()); |
366 | ||
367 | //------------------------ | |
4775bcbf | 368 | fixture.setLogLevel("TRACE_DEBUG"); |
b0318660 | 369 | |
eb1bab5b BH |
370 | result = fixture.getLogLevel(); |
371 | assertNotNull(result); | |
4775bcbf BH |
372 | assertEquals("TRACE_DEBUG", result.getInName()); |
373 | assertEquals("TRACE_DEBUG", result.name()); | |
eb1bab5b BH |
374 | assertEquals(14, result.ordinal()); |
375 | ||
4775bcbf BH |
376 | //------------------------- |
377 | fixture.setLogLevel("LEVEL_UNKNOWN"); | |
b0318660 | 378 | |
eb1bab5b BH |
379 | result = fixture.getLogLevel(); |
380 | assertNotNull(result); | |
4775bcbf BH |
381 | assertEquals("LEVEL_UNKNOWN", result.getInName()); |
382 | assertEquals("LEVEL_UNKNOWN", result.name()); | |
eb1bab5b | 383 | assertEquals(15, result.ordinal()); |
b0318660 | 384 | |
4775bcbf | 385 | fixture.setLogLevel("garbage"); |
b0318660 | 386 | |
eb1bab5b BH |
387 | result = fixture.getLogLevel(); |
388 | assertNotNull(result); | |
4775bcbf BH |
389 | assertEquals("TRACE_DEBUG", result.getInName()); |
390 | assertEquals("TRACE_DEBUG", result.name()); | |
391 | assertEquals(14, result.ordinal()); | |
eb1bab5b | 392 | } |
b0318660 | 393 | |
eb1bab5b BH |
394 | |
395 | /** | |
396 | * Run the String toString() method test. | |
397 | * | |
398 | */ | |
399 | public void testToString_1() { | |
400 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
401 | fixture.setName("testName"); | |
402 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
403 | fixture.setLogLevel(TraceLogLevel.TRACE_ERR); | |
404 | ||
405 | String result = fixture.toString(); | |
406 | ||
407 | // add additional test code here | |
408 | assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result); | |
409 | } | |
410 | ||
411 | // ------------------------------------------------------------------------ | |
412 | // equals | |
413 | // ------------------------------------------------------------------------ | |
414 | ||
415 | public void testEqualsReflexivity() { | |
416 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
417 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
418 | ||
419 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
420 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
421 | } | |
b0318660 | 422 | |
eb1bab5b BH |
423 | public void testEqualsSymmetry() { |
424 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
425 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
426 | ||
427 | assertTrue("equals", info1.equals(fEventInfo1)); | |
428 | assertTrue("equals", fEventInfo1.equals(info1)); | |
429 | ||
430 | assertTrue("equals", info2.equals(fEventInfo2)); | |
431 | assertTrue("equals", fEventInfo2.equals(info2)); | |
432 | } | |
b0318660 | 433 | |
eb1bab5b BH |
434 | public void testEqualsTransivity() { |
435 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
436 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
437 | BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
438 | ||
439 | assertTrue("equals", info1.equals(info2)); | |
440 | assertTrue("equals", info2.equals(info3)); | |
441 | assertTrue("equals", info1.equals(info3)); | |
442 | } | |
b0318660 | 443 | |
eb1bab5b BH |
444 | public void testEqualsNull() { |
445 | assertTrue("equals", !fEventInfo1.equals(null)); | |
446 | assertTrue("equals", !fEventInfo2.equals(null)); | |
447 | } | |
b0318660 | 448 | |
eb1bab5b BH |
449 | // ------------------------------------------------------------------------ |
450 | // hashCode | |
451 | // ------------------------------------------------------------------------ | |
452 | ||
453 | public void testHashCode() { | |
454 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
455 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
456 | ||
457 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
458 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
459 | ||
460 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
461 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
462 | } | |
463 | } |