1 package org
.eclipse
.linuxtools
.lttng
.event
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotSame
;
5 import static org
.junit
.Assert
.fail
;
7 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTrace
;
8 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
12 Functions tested here :
13 public LttngEventFormat()
14 public String[] getLabels(LttngEvent thisEvent)
15 public LttngEventField[] parse(LttngEvent thisEvent)
16 public LttngEventField[] parse(HashMap<String, Object> parsedEvents)
17 public LttngEventField[] parse(String uselessContent)
21 public class LttngEventFormatTest
{
22 private final static boolean skipIndexing
=true;
23 private final static boolean waitForCompletion
=true;
24 private final static String tracepath1
="traceset/trace-618339events-1293lost-1cpu";
26 private final static long timestampAfterMetadata
= 952090116049L;
28 private final static String secondEventFirstField
= "loglevel";
29 private final static String secondEventSecondField
= "string";
30 //private final static String secondEventThirdField = "ip";
32 private final static String secondEventThirdFieldParsedValue
= "ip:0xc04f402c";
35 private LTTngTrace
initializeEventStream() {
36 LTTngTrace tmpStream
= null;
38 tmpStream
= new LTTngTrace(tracepath1
, waitForCompletion
, skipIndexing
);
41 fail("ERROR : Could not open " + tracepath1
+ ". Test failed!" );
48 private LttngEventFormat
prepareToTest() {
49 LttngEventFormat tmpEventFormat
= null;
51 // This trace should be valid
53 LTTngTrace tmpStream
= initializeEventStream();
54 tmpEventFormat
= (LttngEventFormat
)tmpStream
.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getFormat();
57 fail("ERROR : Failed to get format!");
60 return tmpEventFormat
;
64 public void testConstructors() {
65 LttngEventFormat testFormat
= null;
66 @SuppressWarnings("unused")
67 LttngEventFormat testFormat2
= null;
70 // Default construction with good argument
72 testFormat
= new LttngEventFormat(new String
[1]);
75 fail("Construction failed!");
80 testFormat
= new LttngEventFormat(new String
[1]);
81 testFormat2
= new LttngEventFormat(testFormat
);
84 fail("Copy construction failed!");
91 public void testGetter() {
92 LttngEventFormat testFormat
= null;
93 LTTngTrace tmpStream
= null;
94 LttngEvent tmpEvent
= null;
95 TmfTraceContext tmpContext
= new TmfTraceContext(null, null, 0);
97 //*** Position ourself to the second event to have something interesting to test with ***
99 tmpStream
= initializeEventStream();
100 // Skip first events and seek to events past metadata
101 tmpContext
= tmpStream
.seekLocation(new LttngTimestamp(timestampAfterMetadata
) );
103 tmpEvent
= (LttngEvent
)tmpStream
.parseEvent(tmpContext
);
104 // Second event should have more fields
105 tmpEvent
= (LttngEvent
)tmpStream
.parseEvent(tmpContext
);
106 // Get a real format from the event
107 testFormat
= (LttngEventFormat
)tmpEvent
.getContent().getFormat();
110 assertEquals("Label not as expected!",secondEventFirstField
,testFormat
.getLabels()[0].toString());
111 assertEquals("Label not as expected!",secondEventSecondField
,testFormat
.getLabels()[1].toString());
114 // Test different parse()
116 assertNotSame("parse() returned null!",null, testFormat
.parse(tmpEvent
));
117 assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue
,testFormat
.parse(tmpEvent
)[2].toString());
120 assertNotSame("parse() returned null!",null, testFormat
.parse(tmpEvent
.convertEventTmfToJni().parseAllFields()));
121 assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue
,testFormat
.parse(tmpEvent
.convertEventTmfToJni().parseAllFields())[2].toString());
125 System
.out
.println(tmpEvent
.getContent().getContent().toString());
126 assertNotSame("parse() returned null!",null, testFormat
.parse(tmpEvent
.getContent().getContent().toString()));
127 assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue
,testFormat
.parse(tmpEvent
.getContent().getContent())[2].toString());
131 public void testToString() {
132 LttngEventFormat tmpFormat
= prepareToTest();
134 // Just make sure toString() does not return null or the java reference
135 assertNotSame("toString returned null",null, tmpFormat
.toString() );
136 assertNotSame("toString is not overridded!", tmpFormat
.getClass().getName() + '@' + Integer
.toHexString(tmpFormat
.hashCode()), tmpFormat
.toString() );