Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 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 | 10 | * Bernd Hufmann - Initial API and implementation |
2ba3d0a1 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
eb1bab5b | 12 | **********************************************************************/ |
2ba3d0a1 | 13 | |
9315aeee | 14 | package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl; |
eb1bab5b | 15 | |
2ba3d0a1 AM |
16 | import static org.junit.Assert.*; |
17 | ||
d4514365 BH |
18 | import java.util.LinkedList; |
19 | import java.util.List; | |
20 | ||
9315aeee | 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo; |
d4514365 | 22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo; |
9315aeee BH |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; |
24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo; | |
d4514365 | 26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo; |
2ba3d0a1 AM |
27 | import org.junit.Before; |
28 | import org.junit.Test; | |
eb1bab5b BH |
29 | |
30 | /** | |
2ba3d0a1 AM |
31 | * The class <code>BaseEventInfoTest</code> contains test for the class |
32 | * <code>{@link BaseEventInfo}</code>. | |
eb1bab5b | 33 | */ |
2ba3d0a1 | 34 | public class BaseEventInfoTest { |
eb1bab5b BH |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // Test data | |
38 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 39 | |
eb1bab5b BH |
40 | private IBaseEventInfo fEventInfo1 = null; |
41 | private IBaseEventInfo fEventInfo2 = null; | |
b0318660 | 42 | |
eb1bab5b BH |
43 | // ------------------------------------------------------------------------ |
44 | // Housekeeping | |
45 | // ------------------------------------------------------------------------ | |
46 | /** | |
47 | * Perform pre-test initialization. | |
eb1bab5b | 48 | */ |
2ba3d0a1 AM |
49 | @Before |
50 | public void setUp() { | |
b0318660 | 51 | ModelImplFactory factory = new ModelImplFactory(); |
eb1bab5b BH |
52 | fEventInfo1 = factory.getBaseEventInfo1(); |
53 | fEventInfo2 = factory.getBaseEventInfo2(); | |
54 | } | |
55 | ||
eb1bab5b BH |
56 | // ------------------------------------------------------------------------ |
57 | // Tests | |
58 | // ------------------------------------------------------------------------ | |
59 | ||
60 | /** | |
61 | * Run the BaseEventInfo() constructor test. | |
eb1bab5b | 62 | */ |
2ba3d0a1 | 63 | @Test |
eb1bab5b BH |
64 | public void testBaseEventInfo() { |
65 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
66 | assertNotNull(fixture); | |
b0318660 | 67 | |
eb1bab5b | 68 | TraceEventType result = fixture.getEventType(); |
b0318660 | 69 | |
eb1bab5b BH |
70 | assertEquals("event", fixture.getName()); |
71 | assertEquals("unknown", result.getInName()); | |
72 | assertEquals("UNKNOWN", result.name()); | |
73 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 74 | assertEquals(4, result.ordinal()); |
b0318660 | 75 | |
eb1bab5b | 76 | TraceLogLevel level = fixture.getLogLevel(); |
4775bcbf BH |
77 | assertEquals("TRACE_DEBUG", level.getInName()); |
78 | assertEquals("TRACE_DEBUG", level.name()); | |
79 | assertEquals("TRACE_DEBUG", level.toString()); | |
80 | assertEquals(14, level.ordinal()); | |
eb1bab5b BH |
81 | } |
82 | ||
83 | /** | |
84 | * Test Copy Constructor | |
85 | */ | |
2ba3d0a1 | 86 | @Test |
eb1bab5b BH |
87 | public void testEventInfoCopy() { |
88 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
b0318660 | 89 | |
eb1bab5b BH |
90 | assertEquals(fEventInfo1.getName(), info.getName()); |
91 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
92 | assertEquals(fEventInfo1.getLogLevel(), info.getLogLevel()); | |
d4514365 BH |
93 | assertEquals(fEventInfo1.getFilterExpression(), info.getFilterExpression()); |
94 | ||
95 | IFieldInfo[] orignalFields = fEventInfo1.getFields(); | |
96 | IFieldInfo[] copiedFields = info.getFields(); | |
97 | assertEquals(orignalFields.length, copiedFields.length); | |
98 | ||
99 | for (int i = 0; i < copiedFields.length; i++) { | |
100 | assertEquals(orignalFields[i], copiedFields[i]); | |
101 | } | |
eb1bab5b BH |
102 | } |
103 | ||
104 | /** | |
105 | * Test Copy Constructor | |
106 | */ | |
2ba3d0a1 | 107 | @Test |
eb1bab5b BH |
108 | public void testEventCopy2() { |
109 | try { | |
110 | BaseEventInfo info = null; | |
111 | new BaseEventInfo(info); | |
112 | fail("null copy"); | |
113 | } | |
114 | catch (IllegalArgumentException e) { | |
115 | // Success | |
116 | } | |
117 | } | |
b0318660 | 118 | |
eb1bab5b BH |
119 | /** |
120 | * Run the TraceEventType getEventType() method test. | |
eb1bab5b | 121 | */ |
2ba3d0a1 | 122 | @Test |
eb1bab5b BH |
123 | public void testGetEventType_1() { |
124 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
125 | fixture.setEventType("unknown"); | |
126 | ||
127 | TraceEventType result = fixture.getEventType(); | |
128 | ||
129 | assertNotNull(result); | |
130 | assertEquals("unknown", result.getInName()); | |
131 | assertEquals("UNKNOWN", result.name()); | |
132 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 133 | assertEquals(4, result.ordinal()); |
b0318660 | 134 | |
eb1bab5b BH |
135 | fixture.setEventType(""); |
136 | result = fixture.getEventType(); | |
137 | assertEquals("unknown", result.getInName()); | |
138 | assertEquals("UNKNOWN", result.name()); | |
139 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 140 | assertEquals(4, result.ordinal()); |
b0318660 | 141 | |
eb1bab5b BH |
142 | fixture.setEventType("tracepoint"); |
143 | result = fixture.getEventType(); | |
144 | assertNotNull(result); | |
145 | assertEquals("tracepoint", result.getInName()); | |
146 | assertEquals("TRACEPOINT", result.name()); | |
147 | assertEquals("TRACEPOINT", result.toString()); | |
148 | assertEquals(0, result.ordinal()); | |
b0318660 | 149 | |
ccc66d01 BH |
150 | fixture.setEventType("syscall"); |
151 | result = fixture.getEventType(); | |
152 | assertNotNull(result); | |
153 | assertEquals("syscall", result.getInName()); | |
154 | assertEquals("SYSCALL", result.name()); | |
155 | assertEquals("SYSCALL", result.toString()); | |
156 | assertEquals(1, result.ordinal()); | |
b0318660 | 157 | |
ccc66d01 BH |
158 | fixture.setEventType("probe"); |
159 | result = fixture.getEventType(); | |
160 | assertNotNull(result); | |
161 | assertEquals("probe", result.getInName()); | |
162 | assertEquals("PROBE", result.name()); | |
163 | assertEquals("PROBE", result.toString()); | |
164 | assertEquals(2, result.ordinal()); | |
165 | ||
1f07c96c BH |
166 | fixture.setEventType("function"); |
167 | result = fixture.getEventType(); | |
168 | assertNotNull(result); | |
169 | assertEquals("function", result.getInName()); | |
170 | assertEquals("FUNCTION", result.name()); | |
171 | assertEquals("FUNCTION", result.toString()); | |
172 | assertEquals(3, result.ordinal()); | |
173 | ||
174 | ||
eb1bab5b BH |
175 | } |
176 | ||
177 | /** | |
178 | * Run the void setEventType(TraceEventType) method test. | |
eb1bab5b | 179 | */ |
2ba3d0a1 | 180 | @Test |
eb1bab5b BH |
181 | public void testSetEventType_2() { |
182 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
183 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
b0318660 | 184 | |
eb1bab5b | 185 | TraceEventType result = fixture.getEventType(); |
b0318660 | 186 | |
eb1bab5b BH |
187 | assertNotNull(result); |
188 | assertEquals("tracepoint", result.getInName()); | |
189 | assertEquals("TRACEPOINT", result.name()); | |
190 | assertEquals("TRACEPOINT", result.toString()); | |
191 | assertEquals(0, result.ordinal()); | |
b0318660 | 192 | |
eb1bab5b BH |
193 | fixture.setEventType(TraceEventType.UNKNOWN); |
194 | result = fixture.getEventType(); | |
b0318660 | 195 | |
eb1bab5b BH |
196 | assertNotNull(result); |
197 | assertEquals("unknown", result.getInName()); | |
198 | assertEquals("UNKNOWN", result.name()); | |
199 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 200 | assertEquals(4, result.ordinal()); |
b0318660 | 201 | |
ccc66d01 BH |
202 | fixture.setEventType(TraceEventType.SYSCALL); |
203 | result = fixture.getEventType(); | |
204 | assertNotNull(result); | |
205 | assertEquals("syscall", result.getInName()); | |
206 | assertEquals("SYSCALL", result.name()); | |
207 | assertEquals("SYSCALL", result.toString()); | |
208 | assertEquals(1, result.ordinal()); | |
b0318660 | 209 | |
ccc66d01 BH |
210 | fixture.setEventType(TraceEventType.PROBE); |
211 | result = fixture.getEventType(); | |
212 | assertNotNull(result); | |
213 | assertEquals("probe", result.getInName()); | |
214 | assertEquals("PROBE", result.name()); | |
215 | assertEquals("PROBE", result.toString()); | |
9d8a90ad | 216 | assertEquals(2, result.ordinal()); |
ccc66d01 | 217 | |
1f07c96c BH |
218 | fixture.setEventType(TraceEventType.FUNCTION); |
219 | result = fixture.getEventType(); | |
220 | assertNotNull(result); | |
221 | assertEquals("function", result.getInName()); | |
222 | assertEquals("FUNCTION", result.name()); | |
223 | assertEquals("FUNCTION", result.toString()); | |
224 | assertEquals(3, result.ordinal()); | |
225 | ||
226 | ||
eb1bab5b | 227 | } |
b0318660 | 228 | |
eb1bab5b BH |
229 | /** |
230 | * Run the void setLogLevel(TraceLogLevel) method test. | |
231 | * Run the TraceLogLevel getLogLevel() method test | |
eb1bab5b | 232 | */ |
2ba3d0a1 | 233 | @Test |
eb1bab5b BH |
234 | public void testSetLogLevel1() { |
235 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
236 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
237 | fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); | |
b0318660 | 238 | |
eb1bab5b BH |
239 | // 2 set/get-operations are enough to test the method |
240 | TraceLogLevel result = fixture.getLogLevel(); | |
241 | assertNotNull(result); | |
4775bcbf | 242 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
243 | assertEquals("TRACE_CRIT", result.name()); |
244 | assertEquals("TRACE_CRIT", result.toString()); | |
245 | assertEquals(2, result.ordinal()); | |
246 | ||
4775bcbf | 247 | fixture.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION); |
b0318660 | 248 | |
eb1bab5b BH |
249 | result = fixture.getLogLevel(); |
250 | assertNotNull(result); | |
4775bcbf BH |
251 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
252 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
253 | assertEquals("TRACE_DEBUG_FUNCTION", result.toString()); | |
eb1bab5b BH |
254 | assertEquals(12, result.ordinal()); |
255 | } | |
b0318660 | 256 | |
eb1bab5b BH |
257 | /** |
258 | * Run the void setLogLevel(String) method test. | |
259 | * Run the TraceLogLevel getLogLevel() method test | |
eb1bab5b | 260 | */ |
2ba3d0a1 | 261 | @Test |
eb1bab5b BH |
262 | public void testSetLogLevel2() { |
263 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
264 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
4775bcbf | 265 | fixture.setLogLevel("TRACE_EMERG"); |
b0318660 | 266 | |
eb1bab5b BH |
267 | TraceLogLevel result = fixture.getLogLevel(); |
268 | assertNotNull(result); | |
4775bcbf | 269 | assertEquals("TRACE_EMERG", result.getInName()); |
eb1bab5b BH |
270 | assertEquals("TRACE_EMERG", result.name()); |
271 | assertEquals(0, result.ordinal()); | |
272 | ||
273 | //------------------------ | |
4775bcbf | 274 | fixture.setLogLevel("TRACE_ALERT"); |
b0318660 | 275 | |
eb1bab5b BH |
276 | result = fixture.getLogLevel(); |
277 | assertNotNull(result); | |
4775bcbf | 278 | assertEquals("TRACE_ALERT", result.getInName()); |
eb1bab5b BH |
279 | assertEquals("TRACE_ALERT", result.name()); |
280 | assertEquals(1, result.ordinal()); | |
b0318660 | 281 | |
eb1bab5b | 282 | //------------------------ |
4775bcbf | 283 | fixture.setLogLevel("TRACE_CRIT"); |
b0318660 | 284 | |
eb1bab5b BH |
285 | result = fixture.getLogLevel(); |
286 | assertNotNull(result); | |
4775bcbf | 287 | assertEquals("TRACE_CRIT", result.getInName()); |
eb1bab5b BH |
288 | assertEquals("TRACE_CRIT", result.name()); |
289 | assertEquals(2, result.ordinal()); | |
290 | ||
291 | //------------------------ | |
4775bcbf | 292 | fixture.setLogLevel("TRACE_ERR"); |
b0318660 | 293 | |
eb1bab5b BH |
294 | result = fixture.getLogLevel(); |
295 | assertNotNull(result); | |
4775bcbf | 296 | assertEquals("TRACE_ERR", result.getInName()); |
eb1bab5b BH |
297 | assertEquals("TRACE_ERR", result.name()); |
298 | assertEquals(3, result.ordinal()); | |
299 | ||
300 | //------------------------ | |
4775bcbf | 301 | fixture.setLogLevel("TRACE_WARNING"); |
b0318660 | 302 | |
eb1bab5b BH |
303 | result = fixture.getLogLevel(); |
304 | assertNotNull(result); | |
4775bcbf | 305 | assertEquals("TRACE_WARNING", result.getInName()); |
eb1bab5b BH |
306 | assertEquals("TRACE_WARNING", result.name()); |
307 | assertEquals(4, result.ordinal()); | |
308 | ||
309 | //------------------------ | |
4775bcbf | 310 | fixture.setLogLevel("TRACE_NOTICE"); |
b0318660 | 311 | |
eb1bab5b BH |
312 | result = fixture.getLogLevel(); |
313 | assertNotNull(result); | |
4775bcbf | 314 | assertEquals("TRACE_NOTICE", result.getInName()); |
eb1bab5b BH |
315 | assertEquals("TRACE_NOTICE", result.name()); |
316 | assertEquals(5, result.ordinal()); | |
317 | ||
318 | //------------------------ | |
4775bcbf | 319 | fixture.setLogLevel("TRACE_INFO"); |
b0318660 | 320 | |
eb1bab5b BH |
321 | result = fixture.getLogLevel(); |
322 | assertNotNull(result); | |
4775bcbf | 323 | assertEquals("TRACE_INFO", result.getInName()); |
eb1bab5b BH |
324 | assertEquals("TRACE_INFO", result.name()); |
325 | assertEquals(6, result.ordinal()); | |
326 | ||
327 | //------------------------ | |
4775bcbf | 328 | fixture.setLogLevel("TRACE_DEBUG_SYSTEM"); |
b0318660 | 329 | |
eb1bab5b BH |
330 | result = fixture.getLogLevel(); |
331 | assertNotNull(result); | |
4775bcbf BH |
332 | assertEquals("TRACE_DEBUG_SYSTEM", result.getInName()); |
333 | assertEquals("TRACE_DEBUG_SYSTEM", result.name()); | |
eb1bab5b BH |
334 | assertEquals(7, result.ordinal()); |
335 | ||
336 | //------------------------ | |
4775bcbf | 337 | fixture.setLogLevel("TRACE_DEBUG_PROGRAM"); |
b0318660 | 338 | |
eb1bab5b BH |
339 | result = fixture.getLogLevel(); |
340 | assertNotNull(result); | |
4775bcbf BH |
341 | assertEquals("TRACE_DEBUG_PROGRAM", result.getInName()); |
342 | assertEquals("TRACE_DEBUG_PROGRAM", result.name()); | |
eb1bab5b BH |
343 | assertEquals(8, result.ordinal()); |
344 | ||
345 | //------------------------ | |
4775bcbf | 346 | fixture.setLogLevel("TRACE_DEBUG_PROCESS"); |
b0318660 | 347 | |
eb1bab5b BH |
348 | result = fixture.getLogLevel(); |
349 | assertNotNull(result); | |
4775bcbf BH |
350 | assertEquals("TRACE_DEBUG_PROCESS", result.getInName()); |
351 | assertEquals("TRACE_DEBUG_PROCESS", result.name()); | |
eb1bab5b BH |
352 | assertEquals(9, result.ordinal()); |
353 | ||
354 | //------------------------ | |
4775bcbf | 355 | fixture.setLogLevel("TRACE_DEBUG_MODULE"); |
b0318660 | 356 | |
eb1bab5b BH |
357 | result = fixture.getLogLevel(); |
358 | assertNotNull(result); | |
4775bcbf BH |
359 | assertEquals("TRACE_DEBUG_MODULE", result.getInName()); |
360 | assertEquals("TRACE_DEBUG_MODULE", result.name()); | |
eb1bab5b BH |
361 | assertEquals(10, result.ordinal()); |
362 | ||
363 | //------------------------ | |
4775bcbf | 364 | fixture.setLogLevel("TRACE_DEBUG_UNIT"); |
b0318660 | 365 | |
eb1bab5b BH |
366 | result = fixture.getLogLevel(); |
367 | assertNotNull(result); | |
4775bcbf BH |
368 | assertEquals("TRACE_DEBUG_UNIT", result.getInName()); |
369 | assertEquals("TRACE_DEBUG_UNIT", result.name()); | |
eb1bab5b BH |
370 | assertEquals(11, result.ordinal()); |
371 | ||
372 | //------------------------ | |
4775bcbf | 373 | fixture.setLogLevel("TRACE_DEBUG_FUNCTION"); |
b0318660 | 374 | |
eb1bab5b BH |
375 | result = fixture.getLogLevel(); |
376 | assertNotNull(result); | |
4775bcbf BH |
377 | assertEquals("TRACE_DEBUG_FUNCTION", result.getInName()); |
378 | assertEquals("TRACE_DEBUG_FUNCTION", result.name()); | |
eb1bab5b BH |
379 | assertEquals(12, result.ordinal()); |
380 | ||
381 | //------------------------ | |
4775bcbf | 382 | fixture.setLogLevel("TRACE_DEBUG_LINE"); |
b0318660 | 383 | |
eb1bab5b BH |
384 | result = fixture.getLogLevel(); |
385 | assertNotNull(result); | |
4775bcbf BH |
386 | assertEquals("TRACE_DEBUG_LINE", result.getInName()); |
387 | assertEquals("TRACE_DEBUG_LINE", result.name()); | |
eb1bab5b BH |
388 | assertEquals(13, result.ordinal()); |
389 | ||
390 | //------------------------ | |
4775bcbf | 391 | fixture.setLogLevel("TRACE_DEBUG"); |
b0318660 | 392 | |
eb1bab5b BH |
393 | result = fixture.getLogLevel(); |
394 | assertNotNull(result); | |
4775bcbf BH |
395 | assertEquals("TRACE_DEBUG", result.getInName()); |
396 | assertEquals("TRACE_DEBUG", result.name()); | |
eb1bab5b BH |
397 | assertEquals(14, result.ordinal()); |
398 | ||
4775bcbf BH |
399 | //------------------------- |
400 | fixture.setLogLevel("LEVEL_UNKNOWN"); | |
b0318660 | 401 | |
eb1bab5b BH |
402 | result = fixture.getLogLevel(); |
403 | assertNotNull(result); | |
4775bcbf BH |
404 | assertEquals("LEVEL_UNKNOWN", result.getInName()); |
405 | assertEquals("LEVEL_UNKNOWN", result.name()); | |
eb1bab5b | 406 | assertEquals(15, result.ordinal()); |
b0318660 | 407 | |
4775bcbf | 408 | fixture.setLogLevel("garbage"); |
b0318660 | 409 | |
eb1bab5b BH |
410 | result = fixture.getLogLevel(); |
411 | assertNotNull(result); | |
4775bcbf BH |
412 | assertEquals("TRACE_DEBUG", result.getInName()); |
413 | assertEquals("TRACE_DEBUG", result.name()); | |
414 | assertEquals(14, result.ordinal()); | |
eb1bab5b | 415 | } |
b0318660 | 416 | |
d4514365 BH |
417 | /** |
418 | * test filter expression | |
419 | */ | |
2ba3d0a1 | 420 | @Test |
d4514365 BH |
421 | public void testSetFields() { |
422 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
423 | info.setFilterExpression("stringfield==test"); | |
424 | assertEquals("stringfield==test", info.getFilterExpression()); | |
425 | } | |
426 | ||
427 | ||
428 | /** | |
429 | * test add field | |
430 | */ | |
2ba3d0a1 | 431 | @Test |
d4514365 BH |
432 | public void testAddField() { |
433 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
434 | ||
435 | IFieldInfo field = new FieldInfo("intfield"); | |
436 | field.setFieldType("int"); | |
437 | ||
438 | info.addField(field); | |
439 | ||
440 | // Verify the stored events | |
441 | IFieldInfo[] result = info.getFields(); | |
442 | ||
443 | assertNotNull(result); | |
444 | assertEquals(1, result.length); | |
445 | assertNotNull(result[0]); | |
446 | assertTrue(field.equals(result[0])); | |
447 | } | |
448 | ||
449 | /** | |
450 | * test set fields | |
451 | */ | |
2ba3d0a1 | 452 | @Test |
d4514365 BH |
453 | public void testFields() { |
454 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
455 | ||
456 | IFieldInfo field1 = new FieldInfo("intfield"); | |
457 | field1.setFieldType("int"); | |
458 | ||
459 | IFieldInfo field2 = new FieldInfo("stringfield"); | |
460 | field2.setFieldType("string"); | |
461 | ||
e0838ca1 | 462 | List<IFieldInfo> fields = new LinkedList<>(); |
d4514365 BH |
463 | fields.add(field1); |
464 | fields.add(field2); | |
465 | info.setFields(fields); | |
466 | ||
467 | // Verify the stored events | |
468 | IFieldInfo[] result = info.getFields(); | |
469 | ||
470 | assertNotNull(result); | |
471 | assertEquals(2, result.length); | |
472 | ||
473 | for (int i = 0; i < result.length; i++) { | |
474 | assertNotNull(result[i]); | |
475 | assertTrue(fields.get(i).equals(result[i])); | |
476 | } | |
477 | } | |
eb1bab5b BH |
478 | |
479 | /** | |
480 | * Run the String toString() method test. | |
eb1bab5b | 481 | */ |
2ba3d0a1 | 482 | @Test |
eb1bab5b BH |
483 | public void testToString_1() { |
484 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
485 | fixture.setName("testName"); | |
486 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
487 | fixture.setLogLevel(TraceLogLevel.TRACE_ERR); | |
488 | ||
489 | String result = fixture.toString(); | |
490 | ||
491 | // add additional test code here | |
492 | assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result); | |
493 | } | |
494 | ||
495 | // ------------------------------------------------------------------------ | |
496 | // equals | |
497 | // ------------------------------------------------------------------------ | |
498 | ||
2ba3d0a1 AM |
499 | /** |
500 | * Test the .equals() method. | |
501 | */ | |
502 | @Test | |
eb1bab5b BH |
503 | public void testEqualsReflexivity() { |
504 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
505 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
506 | ||
507 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
508 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
509 | } | |
b0318660 | 510 | |
2ba3d0a1 AM |
511 | /** |
512 | * Test the .equals() method. | |
513 | */ | |
514 | @Test | |
eb1bab5b BH |
515 | public void testEqualsSymmetry() { |
516 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
517 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
518 | ||
519 | assertTrue("equals", info1.equals(fEventInfo1)); | |
520 | assertTrue("equals", fEventInfo1.equals(info1)); | |
521 | ||
522 | assertTrue("equals", info2.equals(fEventInfo2)); | |
523 | assertTrue("equals", fEventInfo2.equals(info2)); | |
524 | } | |
b0318660 | 525 | |
2ba3d0a1 AM |
526 | /** |
527 | * Test the .equals() method. | |
528 | */ | |
529 | @Test | |
eb1bab5b BH |
530 | public void testEqualsTransivity() { |
531 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
532 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
533 | BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
534 | ||
535 | assertTrue("equals", info1.equals(info2)); | |
536 | assertTrue("equals", info2.equals(info3)); | |
537 | assertTrue("equals", info1.equals(info3)); | |
538 | } | |
b0318660 | 539 | |
2ba3d0a1 AM |
540 | /** |
541 | * Test the .equals() method. | |
542 | */ | |
543 | @Test | |
eb1bab5b BH |
544 | public void testEqualsNull() { |
545 | assertTrue("equals", !fEventInfo1.equals(null)); | |
546 | assertTrue("equals", !fEventInfo2.equals(null)); | |
547 | } | |
b0318660 | 548 | |
eb1bab5b BH |
549 | // ------------------------------------------------------------------------ |
550 | // hashCode | |
551 | // ------------------------------------------------------------------------ | |
552 | ||
2ba3d0a1 AM |
553 | /** |
554 | * Test the hashCode() method. | |
555 | */ | |
556 | @Test | |
eb1bab5b BH |
557 | public void testHashCode() { |
558 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
559 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
560 | ||
561 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
562 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
563 | ||
564 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
565 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
566 | } | |
567 | } |