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