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 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.lttng2.ui.tests.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import junit.framework.TestCase; | |
15 | ||
115b4a01 BH |
16 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo; |
17 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType; | |
18 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel; | |
19 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventInfo; | |
eb1bab5b BH |
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()); | |
ccc66d01 | 78 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
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()); | |
ccc66d01 | 128 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
129 | |
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()); |
eb1bab5b BH |
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()); | |
ccc66d01 BH |
144 | |
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()); | |
152 | ||
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); | |
170 | ||
171 | TraceEventType result = fixture.getEventType(); | |
172 | ||
173 | assertNotNull(result); | |
174 | assertEquals("tracepoint", result.getInName()); | |
175 | assertEquals("TRACEPOINT", result.name()); | |
176 | assertEquals("TRACEPOINT", result.toString()); | |
177 | assertEquals(0, result.ordinal()); | |
178 | ||
179 | fixture.setEventType(TraceEventType.UNKNOWN); | |
180 | result = fixture.getEventType(); | |
181 | ||
182 | assertNotNull(result); | |
183 | assertEquals("unknown", result.getInName()); | |
184 | assertEquals("UNKNOWN", result.name()); | |
185 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 BH |
186 | assertEquals(3, result.ordinal()); |
187 | ||
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()); | |
195 | ||
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 BH |
204 | } |
205 | ||
206 | /** | |
207 | * Run the void setLogLevel(TraceLogLevel) method test. | |
208 | * Run the TraceLogLevel getLogLevel() method test | |
209 | * | |
210 | */ | |
211 | public void testSetLogLevel1() { | |
212 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
213 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
214 | fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); | |
215 | ||
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); |
eb1bab5b BH |
225 | |
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 | } | |
233 | ||
234 | /** | |
235 | * Run the void setLogLevel(String) method test. | |
236 | * Run the TraceLogLevel getLogLevel() method test | |
237 | * | |
238 | */ | |
239 | public void testSetLogLevel2() { | |
240 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
241 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
4775bcbf | 242 | fixture.setLogLevel("TRACE_EMERG"); |
eb1bab5b BH |
243 | |
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"); |
eb1bab5b BH |
252 | |
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()); | |
258 | ||
259 | //------------------------ | |
4775bcbf | 260 | fixture.setLogLevel("TRACE_CRIT"); |
eb1bab5b BH |
261 | |
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"); |
eb1bab5b BH |
270 | |
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"); |
eb1bab5b BH |
279 | |
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"); |
eb1bab5b BH |
288 | |
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"); |
eb1bab5b BH |
297 | |
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"); |
eb1bab5b BH |
306 | |
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"); |
eb1bab5b BH |
315 | |
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"); |
eb1bab5b BH |
324 | |
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"); |
eb1bab5b BH |
333 | |
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"); |
eb1bab5b BH |
342 | |
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"); |
eb1bab5b BH |
351 | |
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"); |
eb1bab5b BH |
360 | |
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"); |
eb1bab5b BH |
369 | |
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"); | |
eb1bab5b BH |
378 | |
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()); |
4775bcbf BH |
384 | |
385 | fixture.setLogLevel("garbage"); | |
eb1bab5b BH |
386 | |
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 BH |
392 | } |
393 | ||
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 | } | |
422 | ||
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 | } | |
433 | ||
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 | } | |
443 | ||
444 | public void testEqualsNull() { | |
445 | assertTrue("equals", !fEventInfo1.equals(null)); | |
446 | assertTrue("equals", !fEventInfo2.equals(null)); | |
447 | } | |
448 | ||
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 | } |