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