Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / event / LttngEventFieldTest.java
CommitLineData
07d9e2ee
FC
1package org.eclipse.linuxtools.lttng.event;
2
28b94d61 3
07d9e2ee
FC
4
5import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
6import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
28b94d61 7import junit.framework.TestCase;
07d9e2ee
FC
8
9/*
10 Functions tested here :
11 public LttngEventField(String name, Object newContent)
12 public LttngEventField(LttngEventField oldField)
13 public String getName()
14 public String toString()
15
16 */
17
28b94d61 18public class LttngEventFieldTest extends TestCase {
07d9e2ee
FC
19 private final static boolean skipIndexing=true;
20 private final static boolean waitForCompletion=true;
eddd9002 21 private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu";
07d9e2ee
FC
22
23 private final static String firstEventName = "alignment";
24 private final static String firstEventValue = "0";
25
26 private LTTngTrace initializeEventStream() {
27 LTTngTrace tmpStream = null;
28 try {
29 tmpStream = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing);
30 }
31 catch (Exception e) {
32 fail("ERROR : Could not open " + tracepath1 + ". Test failed!" );
33 }
34
35 return tmpStream;
36 }
37
38
39 private LttngEventField prepareToTest() {
40 LttngEventField tmpField = null;
41
42 // This trace should be valid
43 try {
44 LTTngTrace tmpStream = initializeEventStream();
45 tmpField = (LttngEventField)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getField(0);
46 }
47 catch (Exception e) {
48 fail("ERROR : Failed to get field!");
49 }
50
51 return tmpField;
52 }
53
07d9e2ee 54 public void testConstructors() {
28b94d61 55 LttngEventContent testContent = null;
07d9e2ee
FC
56 LttngEventField testField = null;
57 @SuppressWarnings("unused")
58 LttngEventField testField2 = null;
59
60 // Default construction with good argument
61 try {
28b94d61 62 testField = new LttngEventField(testContent, "test", "test");
07d9e2ee
FC
63 }
64 catch( Exception e) {
65 fail("Default construction failed!");
66 }
67
68 // Copy constructor with correct parameters
69 try {
28b94d61 70 testField = new LttngEventField(testContent, "test", "test");
07d9e2ee
FC
71 testField2 = new LttngEventField(testField);
72 }
73 catch( Exception e) {
74 fail("Copy constructor failed!");
75 }
76
77 }
78
07d9e2ee
FC
79 public void testGetter() {
80
81 // *** To "really" test the field, we will get a real field from LTTngTrace
82 LTTngTrace tmpStream = initializeEventStream();
83
84 LttngEventField testField = (LttngEventField)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getField(0);
85 assertNotSame("getField is null!",null,testField);
86
28b94d61
FC
87 assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
88 assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString()));
07d9e2ee
FC
89
90
91 }
92
07d9e2ee
FC
93 public void testToString() {
94 LttngEventField tmpField = prepareToTest();
95
96 // Just make sure toString() does not return null or the java reference
97 assertNotSame("toString returned null",null, tmpField.toString() );
98 assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() );
99 }
100
101}
This page took 0.028339 seconds and 5 git commands to generate.