Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / event / LttngEventContentTest.java
CommitLineData
07d9e2ee
FC
1package org.eclipse.linuxtools.lttng.event;
2
07d9e2ee
FC
3import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
4import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
28b94d61 5import junit.framework.TestCase;
07d9e2ee
FC
6
7/*
8 Functions tested here :
9 public LttngEventContent(LttngEventFormat thisFormat)
10 public LttngEventContent(LttngEventFormat thisFormat, String thisParsedContent, LttngEventField[] thisFields)
11 public LttngEventContent(LttngEventContent oldContent)
12 public TmfEventField[] getFields()
13 public LttngEventField getField(int id)
14 public TmfEventField[] getFields(LttngEvent thisEvent)
15 public LttngEventField getField(int id, LttngEvent thisEvent)
16 public String toString()
17 */
18
28b94d61 19public class LttngEventContentTest extends TestCase {
07d9e2ee
FC
20 private final static boolean skipIndexing=true;
21 private final static boolean waitForCompletion=true;
eddd9002 22 private final static String tracepath1="traceset/trace-618339events-1293lost-1cpu";
07d9e2ee
FC
23
24 private final static String firstEventContentFirstField = "alignment:0";
25 private final static String secondEventContentSecondField = "string:LTT state dump begin";
26
27 private final static long timestampAfterMetadata = 952090116049L;
28
29 private LTTngTrace initializeEventStream() {
30 LTTngTrace tmpStream = null;
31 try {
32 tmpStream = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing);
33 }
34 catch (Exception e) {
35 fail("ERROR : Could not open " + tracepath1 + ". Test failed!" );
36 }
37
38 return tmpStream;
39 }
40
41
42 private LttngEventContent prepareToTest() {
43 LttngEventContent tmpEventContent = null;
44
45 // This trace should be valid
46 try {
47 LTTngTrace tmpStream = initializeEventStream();
48 tmpEventContent = (LttngEventContent)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent();
49 }
50 catch (Exception e) {
51 fail("ERROR : Failed to get content!");
52 }
53
54 return tmpEventContent;
55 }
56
07d9e2ee 57 public void testConstructors() {
28b94d61 58 LttngEvent testEvent = null;
07d9e2ee
FC
59 LttngEventContent testContent = null;
60 @SuppressWarnings("unused")
61 LttngEventContent testContent2 = null;
07d9e2ee 62 LttngEventField[] testFields = new LttngEventField[1];
28b94d61 63 testFields[0] = new LttngEventField(testContent2, "test");
07d9e2ee
FC
64
65 // Default construction with good argument
66 try {
28b94d61 67 testContent = new LttngEventContent();
07d9e2ee
FC
68 }
69 catch( Exception e) {
70 fail("Construction with format failed!");
71 }
72
73 // Construction with good parameters
74 try {
28b94d61 75 testContent = new LttngEventContent(testEvent);
07d9e2ee
FC
76 }
77 catch( Exception e) {
78 fail("Construction with format, content and fields failed!");
79 }
80
81 // Copy constructor with correct parameters
82 try {
28b94d61 83 testContent = new LttngEventContent(testEvent);
07d9e2ee
FC
84 testContent2 = new LttngEventContent(testContent);
85 }
86 catch( Exception e) {
87 fail("Copy constructor failed!");
88 }
89
90 }
91
92
07d9e2ee
FC
93 public void testGetter() {
94 LttngEventContent testContent = null;
95 LTTngTrace tmpStream = null;
96 LttngEvent tmpEvent = null;
97 TmfTraceContext tmpContext = null;
98
07d9e2ee
FC
99 // Require an event
100 tmpStream = initializeEventStream();
101 tmpContext = new TmfTraceContext(null, null, 0);
102 tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext);
103
104 testContent = prepareToTest();
105 // getFieldS()
28b94d61 106 assertNotSame("getFields() returned null!",null,testContent.getFields() );
07d9e2ee 107 // getField(int)
28b94d61 108 assertEquals("getField(int) returned unexpected result!",firstEventContentFirstField, testContent.getField(0).toString());
07d9e2ee
FC
109
110
111
112 //*** To test getFiels with a fields number >0, we need to move to an event that have some more
113 tmpStream = initializeEventStream();
114 tmpContext = new TmfTraceContext(null, null, 0);
115 // Skip first events and seek to event pass metadata
116 tmpContext= tmpStream.seekLocation(new LttngTimestamp(timestampAfterMetadata) );
117 // Skip first one
118 tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext);
119 // Second event past metadata should have more fields
120 tmpEvent = (LttngEvent)tmpStream.parseEvent(tmpContext);
121
07d9e2ee 122 // getFieldS()
28b94d61 123 assertNotSame("getFields() returned null!",null,testContent.getFields() );
07d9e2ee
FC
124 // getField(int)
125 assertEquals("getField(int) returned unexpected result!",secondEventContentSecondField, testContent.getField(1).toString());
126
07d9e2ee
FC
127 }
128
07d9e2ee
FC
129 public void testToString() {
130 LttngEventContent tmpContent = prepareToTest();
131
132 // Just make sure toString() does not return null or the java reference
133 assertNotSame("toString returned null",null, tmpContent.toString() );
134 assertNotSame("toString is not overridded!", tmpContent.getClass().getName() + '@' + Integer.toHexString(tmpContent.hashCode()), tmpContent.toString() );
135 }
136
137}
This page took 0.029144 seconds and 5 git commands to generate.