[TMF] Don't enable OK button in delete supp files dialog unless something is selected
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / BaseEventInfoTest.java
CommitLineData
eb1bab5b 1/**********************************************************************
2ba3d0a1 2 * Copyright (c) 2012, 2013 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 14package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
eb1bab5b 15
2ba3d0a1
AM
16import static org.junit.Assert.*;
17
d4514365
BH
18import java.util.LinkedList;
19import java.util.List;
20
9315aeee 21import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo;
d4514365 22import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
9315aeee
BH
23import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
24import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
25import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo;
d4514365 26import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo;
2ba3d0a1
AM
27import org.junit.Before;
28import 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 34public 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());
ccc66d01 74 assertEquals(3, 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());
ccc66d01 133 assertEquals(3, 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());
ccc66d01 140 assertEquals(3, 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
eb1bab5b
BH
166 }
167
168 /**
169 * Run the void setEventType(TraceEventType) method test.
eb1bab5b 170 */
2ba3d0a1 171 @Test
eb1bab5b
BH
172 public void testSetEventType_2() {
173 BaseEventInfo fixture = new BaseEventInfo("event");
174 fixture.setEventType(TraceEventType.TRACEPOINT);
b0318660 175
eb1bab5b 176 TraceEventType result = fixture.getEventType();
b0318660 177
eb1bab5b
BH
178 assertNotNull(result);
179 assertEquals("tracepoint", result.getInName());
180 assertEquals("TRACEPOINT", result.name());
181 assertEquals("TRACEPOINT", result.toString());
182 assertEquals(0, result.ordinal());
b0318660 183
eb1bab5b
BH
184 fixture.setEventType(TraceEventType.UNKNOWN);
185 result = fixture.getEventType();
b0318660 186
eb1bab5b
BH
187 assertNotNull(result);
188 assertEquals("unknown", result.getInName());
189 assertEquals("UNKNOWN", result.name());
190 assertEquals("UNKNOWN", result.toString());
ccc66d01 191 assertEquals(3, result.ordinal());
b0318660 192
ccc66d01
BH
193 fixture.setEventType(TraceEventType.SYSCALL);
194 result = fixture.getEventType();
195 assertNotNull(result);
196 assertEquals("syscall", result.getInName());
197 assertEquals("SYSCALL", result.name());
198 assertEquals("SYSCALL", result.toString());
199 assertEquals(1, result.ordinal());
b0318660 200
ccc66d01
BH
201 fixture.setEventType(TraceEventType.PROBE);
202 result = fixture.getEventType();
203 assertNotNull(result);
204 assertEquals("probe", result.getInName());
205 assertEquals("PROBE", result.name());
206 assertEquals("PROBE", result.toString());
9d8a90ad 207 assertEquals(2, result.ordinal());
ccc66d01 208
eb1bab5b 209 }
b0318660 210
eb1bab5b
BH
211 /**
212 * Run the void setLogLevel(TraceLogLevel) method test.
213 * Run the TraceLogLevel getLogLevel() method test
eb1bab5b 214 */
2ba3d0a1 215 @Test
eb1bab5b
BH
216 public void testSetLogLevel1() {
217 BaseEventInfo fixture = new BaseEventInfo("event");
218 fixture.setEventType(TraceEventType.TRACEPOINT);
219 fixture.setLogLevel(TraceLogLevel.TRACE_CRIT);
b0318660 220
eb1bab5b
BH
221 // 2 set/get-operations are enough to test the method
222 TraceLogLevel result = fixture.getLogLevel();
223 assertNotNull(result);
4775bcbf 224 assertEquals("TRACE_CRIT", result.getInName());
eb1bab5b
BH
225 assertEquals("TRACE_CRIT", result.name());
226 assertEquals("TRACE_CRIT", result.toString());
227 assertEquals(2, result.ordinal());
228
4775bcbf 229 fixture.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION);
b0318660 230
eb1bab5b
BH
231 result = fixture.getLogLevel();
232 assertNotNull(result);
4775bcbf
BH
233 assertEquals("TRACE_DEBUG_FUNCTION", result.getInName());
234 assertEquals("TRACE_DEBUG_FUNCTION", result.name());
235 assertEquals("TRACE_DEBUG_FUNCTION", result.toString());
eb1bab5b
BH
236 assertEquals(12, result.ordinal());
237 }
b0318660 238
eb1bab5b
BH
239 /**
240 * Run the void setLogLevel(String) method test.
241 * Run the TraceLogLevel getLogLevel() method test
eb1bab5b 242 */
2ba3d0a1 243 @Test
eb1bab5b
BH
244 public void testSetLogLevel2() {
245 BaseEventInfo fixture = new BaseEventInfo("event");
246 fixture.setEventType(TraceEventType.TRACEPOINT);
4775bcbf 247 fixture.setLogLevel("TRACE_EMERG");
b0318660 248
eb1bab5b
BH
249 TraceLogLevel result = fixture.getLogLevel();
250 assertNotNull(result);
4775bcbf 251 assertEquals("TRACE_EMERG", result.getInName());
eb1bab5b
BH
252 assertEquals("TRACE_EMERG", result.name());
253 assertEquals(0, result.ordinal());
254
255 //------------------------
4775bcbf 256 fixture.setLogLevel("TRACE_ALERT");
b0318660 257
eb1bab5b
BH
258 result = fixture.getLogLevel();
259 assertNotNull(result);
4775bcbf 260 assertEquals("TRACE_ALERT", result.getInName());
eb1bab5b
BH
261 assertEquals("TRACE_ALERT", result.name());
262 assertEquals(1, result.ordinal());
b0318660 263
eb1bab5b 264 //------------------------
4775bcbf 265 fixture.setLogLevel("TRACE_CRIT");
b0318660 266
eb1bab5b
BH
267 result = fixture.getLogLevel();
268 assertNotNull(result);
4775bcbf 269 assertEquals("TRACE_CRIT", result.getInName());
eb1bab5b
BH
270 assertEquals("TRACE_CRIT", result.name());
271 assertEquals(2, result.ordinal());
272
273 //------------------------
4775bcbf 274 fixture.setLogLevel("TRACE_ERR");
b0318660 275
eb1bab5b
BH
276 result = fixture.getLogLevel();
277 assertNotNull(result);
4775bcbf 278 assertEquals("TRACE_ERR", result.getInName());
eb1bab5b
BH
279 assertEquals("TRACE_ERR", result.name());
280 assertEquals(3, result.ordinal());
281
282 //------------------------
4775bcbf 283 fixture.setLogLevel("TRACE_WARNING");
b0318660 284
eb1bab5b
BH
285 result = fixture.getLogLevel();
286 assertNotNull(result);
4775bcbf 287 assertEquals("TRACE_WARNING", result.getInName());
eb1bab5b
BH
288 assertEquals("TRACE_WARNING", result.name());
289 assertEquals(4, result.ordinal());
290
291 //------------------------
4775bcbf 292 fixture.setLogLevel("TRACE_NOTICE");
b0318660 293
eb1bab5b
BH
294 result = fixture.getLogLevel();
295 assertNotNull(result);
4775bcbf 296 assertEquals("TRACE_NOTICE", result.getInName());
eb1bab5b
BH
297 assertEquals("TRACE_NOTICE", result.name());
298 assertEquals(5, result.ordinal());
299
300 //------------------------
4775bcbf 301 fixture.setLogLevel("TRACE_INFO");
b0318660 302
eb1bab5b
BH
303 result = fixture.getLogLevel();
304 assertNotNull(result);
4775bcbf 305 assertEquals("TRACE_INFO", result.getInName());
eb1bab5b
BH
306 assertEquals("TRACE_INFO", result.name());
307 assertEquals(6, result.ordinal());
308
309 //------------------------
4775bcbf 310 fixture.setLogLevel("TRACE_DEBUG_SYSTEM");
b0318660 311
eb1bab5b
BH
312 result = fixture.getLogLevel();
313 assertNotNull(result);
4775bcbf
BH
314 assertEquals("TRACE_DEBUG_SYSTEM", result.getInName());
315 assertEquals("TRACE_DEBUG_SYSTEM", result.name());
eb1bab5b
BH
316 assertEquals(7, result.ordinal());
317
318 //------------------------
4775bcbf 319 fixture.setLogLevel("TRACE_DEBUG_PROGRAM");
b0318660 320
eb1bab5b
BH
321 result = fixture.getLogLevel();
322 assertNotNull(result);
4775bcbf
BH
323 assertEquals("TRACE_DEBUG_PROGRAM", result.getInName());
324 assertEquals("TRACE_DEBUG_PROGRAM", result.name());
eb1bab5b
BH
325 assertEquals(8, result.ordinal());
326
327 //------------------------
4775bcbf 328 fixture.setLogLevel("TRACE_DEBUG_PROCESS");
b0318660 329
eb1bab5b
BH
330 result = fixture.getLogLevel();
331 assertNotNull(result);
4775bcbf
BH
332 assertEquals("TRACE_DEBUG_PROCESS", result.getInName());
333 assertEquals("TRACE_DEBUG_PROCESS", result.name());
eb1bab5b
BH
334 assertEquals(9, result.ordinal());
335
336 //------------------------
4775bcbf 337 fixture.setLogLevel("TRACE_DEBUG_MODULE");
b0318660 338
eb1bab5b
BH
339 result = fixture.getLogLevel();
340 assertNotNull(result);
4775bcbf
BH
341 assertEquals("TRACE_DEBUG_MODULE", result.getInName());
342 assertEquals("TRACE_DEBUG_MODULE", result.name());
eb1bab5b
BH
343 assertEquals(10, result.ordinal());
344
345 //------------------------
4775bcbf 346 fixture.setLogLevel("TRACE_DEBUG_UNIT");
b0318660 347
eb1bab5b
BH
348 result = fixture.getLogLevel();
349 assertNotNull(result);
4775bcbf
BH
350 assertEquals("TRACE_DEBUG_UNIT", result.getInName());
351 assertEquals("TRACE_DEBUG_UNIT", result.name());
eb1bab5b
BH
352 assertEquals(11, result.ordinal());
353
354 //------------------------
4775bcbf 355 fixture.setLogLevel("TRACE_DEBUG_FUNCTION");
b0318660 356
eb1bab5b
BH
357 result = fixture.getLogLevel();
358 assertNotNull(result);
4775bcbf
BH
359 assertEquals("TRACE_DEBUG_FUNCTION", result.getInName());
360 assertEquals("TRACE_DEBUG_FUNCTION", result.name());
eb1bab5b
BH
361 assertEquals(12, result.ordinal());
362
363 //------------------------
4775bcbf 364 fixture.setLogLevel("TRACE_DEBUG_LINE");
b0318660 365
eb1bab5b
BH
366 result = fixture.getLogLevel();
367 assertNotNull(result);
4775bcbf
BH
368 assertEquals("TRACE_DEBUG_LINE", result.getInName());
369 assertEquals("TRACE_DEBUG_LINE", result.name());
eb1bab5b
BH
370 assertEquals(13, result.ordinal());
371
372 //------------------------
4775bcbf 373 fixture.setLogLevel("TRACE_DEBUG");
b0318660 374
eb1bab5b
BH
375 result = fixture.getLogLevel();
376 assertNotNull(result);
4775bcbf
BH
377 assertEquals("TRACE_DEBUG", result.getInName());
378 assertEquals("TRACE_DEBUG", result.name());
eb1bab5b
BH
379 assertEquals(14, result.ordinal());
380
4775bcbf
BH
381 //-------------------------
382 fixture.setLogLevel("LEVEL_UNKNOWN");
b0318660 383
eb1bab5b
BH
384 result = fixture.getLogLevel();
385 assertNotNull(result);
4775bcbf
BH
386 assertEquals("LEVEL_UNKNOWN", result.getInName());
387 assertEquals("LEVEL_UNKNOWN", result.name());
eb1bab5b 388 assertEquals(15, result.ordinal());
b0318660 389
4775bcbf 390 fixture.setLogLevel("garbage");
b0318660 391
eb1bab5b
BH
392 result = fixture.getLogLevel();
393 assertNotNull(result);
4775bcbf
BH
394 assertEquals("TRACE_DEBUG", result.getInName());
395 assertEquals("TRACE_DEBUG", result.name());
396 assertEquals(14, result.ordinal());
eb1bab5b 397 }
b0318660 398
d4514365
BH
399 /**
400 * test filter expression
401 */
2ba3d0a1 402 @Test
d4514365
BH
403 public void testSetFields() {
404 BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
405 info.setFilterExpression("stringfield==test");
406 assertEquals("stringfield==test", info.getFilterExpression());
407 }
408
409
410 /**
411 * test add field
412 */
2ba3d0a1 413 @Test
d4514365
BH
414 public void testAddField() {
415 BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
416
417 IFieldInfo field = new FieldInfo("intfield");
418 field.setFieldType("int");
419
420 info.addField(field);
421
422 // Verify the stored events
423 IFieldInfo[] result = info.getFields();
424
425 assertNotNull(result);
426 assertEquals(1, result.length);
427 assertNotNull(result[0]);
428 assertTrue(field.equals(result[0]));
429 }
430
431 /**
432 * test set fields
433 */
2ba3d0a1 434 @Test
d4514365
BH
435 public void testFields() {
436 BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
437
438 IFieldInfo field1 = new FieldInfo("intfield");
439 field1.setFieldType("int");
440
441 IFieldInfo field2 = new FieldInfo("stringfield");
442 field2.setFieldType("string");
443
444 List<IFieldInfo> fields = new LinkedList<IFieldInfo>();
445 fields.add(field1);
446 fields.add(field2);
447 info.setFields(fields);
448
449 // Verify the stored events
450 IFieldInfo[] result = info.getFields();
451
452 assertNotNull(result);
453 assertEquals(2, result.length);
454
455 for (int i = 0; i < result.length; i++) {
456 assertNotNull(result[i]);
457 assertTrue(fields.get(i).equals(result[i]));
458 }
459 }
eb1bab5b
BH
460
461 /**
462 * Run the String toString() method test.
eb1bab5b 463 */
2ba3d0a1 464 @Test
eb1bab5b
BH
465 public void testToString_1() {
466 BaseEventInfo fixture = new BaseEventInfo("event");
467 fixture.setName("testName");
468 fixture.setEventType(TraceEventType.TRACEPOINT);
469 fixture.setLogLevel(TraceLogLevel.TRACE_ERR);
470
471 String result = fixture.toString();
472
473 // add additional test code here
474 assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result);
475 }
476
477 // ------------------------------------------------------------------------
478 // equals
479 // ------------------------------------------------------------------------
480
2ba3d0a1
AM
481 /**
482 * Test the .equals() method.
483 */
484 @Test
eb1bab5b
BH
485 public void testEqualsReflexivity() {
486 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
487 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
488
489 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
490 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
491 }
b0318660 492
2ba3d0a1
AM
493 /**
494 * Test the .equals() method.
495 */
496 @Test
eb1bab5b
BH
497 public void testEqualsSymmetry() {
498 BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
499 BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2);
500
501 assertTrue("equals", info1.equals(fEventInfo1));
502 assertTrue("equals", fEventInfo1.equals(info1));
503
504 assertTrue("equals", info2.equals(fEventInfo2));
505 assertTrue("equals", fEventInfo2.equals(info2));
506 }
b0318660 507
2ba3d0a1
AM
508 /**
509 * Test the .equals() method.
510 */
511 @Test
eb1bab5b
BH
512 public void testEqualsTransivity() {
513 BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
514 BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
515 BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
516
517 assertTrue("equals", info1.equals(info2));
518 assertTrue("equals", info2.equals(info3));
519 assertTrue("equals", info1.equals(info3));
520 }
b0318660 521
2ba3d0a1
AM
522 /**
523 * Test the .equals() method.
524 */
525 @Test
eb1bab5b
BH
526 public void testEqualsNull() {
527 assertTrue("equals", !fEventInfo1.equals(null));
528 assertTrue("equals", !fEventInfo2.equals(null));
529 }
b0318660 530
eb1bab5b
BH
531 // ------------------------------------------------------------------------
532 // hashCode
533 // ------------------------------------------------------------------------
534
2ba3d0a1
AM
535 /**
536 * Test the hashCode() method.
537 */
538 @Test
eb1bab5b
BH
539 public void testHashCode() {
540 BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
541 BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2);
542
543 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
544 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
545
546 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
547 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
548 }
549}
This page took 0.085481 seconds and 5 git commands to generate.