[292393] Revisited header search function
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / event / LttngEventFormatTest.java
1 package org.eclipse.linuxtools.lttng.event;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotSame;
5 import static org.junit.Assert.fail;
6
7 import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
8 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
9 import org.junit.Test;
10
11 /*
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)
18
19 */
20
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";
25
26 private final static long timestampAfterMetadata = 952090116049L;
27
28 private final static String secondEventFirstField = "loglevel";
29 private final static String secondEventSecondField = "string";
30 //private final static String secondEventThirdField = "ip";
31
32 private final static String secondEventThirdFieldParsedValue = "ip:0xc04f402c";
33
34
35 private LTTngTrace initializeEventStream() {
36 LTTngTrace tmpStream = null;
37 try {
38 tmpStream = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing);
39 }
40 catch (Exception e) {
41 fail("ERROR : Could not open " + tracepath1 + ". Test failed!" );
42 }
43
44 return tmpStream;
45 }
46
47
48 private LttngEventFormat prepareToTest() {
49 LttngEventFormat tmpEventFormat = null;
50
51 // This trace should be valid
52 try {
53 LTTngTrace tmpStream = initializeEventStream();
54 tmpEventFormat = (LttngEventFormat)tmpStream.parseEvent( new TmfTraceContext(null, null, 0) ).getContent().getFormat();
55 }
56 catch (Exception e) {
57 fail("ERROR : Failed to get format!");
58 }
59
60 return tmpEventFormat;
61 }
62
63 @Test
64 public void testConstructors() {
65 LttngEventFormat testFormat = null;
66 @SuppressWarnings("unused")
67 LttngEventFormat testFormat2 = null;
68
69
70 // Default construction with good argument
71 try {
72 testFormat = new LttngEventFormat(new String[1]);
73 }
74 catch( Exception e) {
75 fail("Construction failed!");
76 }
77
78 // Copy constructor
79 try {
80 testFormat = new LttngEventFormat(new String[1]);
81 testFormat2 = new LttngEventFormat(testFormat);
82 }
83 catch( Exception e) {
84 fail("Copy construction failed!");
85 }
86
87 }
88
89
90 @Test
91 public void testGetter() {
92 LttngEventFormat testFormat = null;
93 LTTngTrace tmpStream = null;
94 LttngEvent tmpEvent = null;
95 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
96
97 //*** Position ourself to the second event to have something interesting to test with ***
98
99 tmpStream = initializeEventStream();
100 // Skip first events and seek to events past metadata
101 tmpContext= tmpStream.seekLocation(new LttngTimestamp(timestampAfterMetadata) );
102 // Skip first one
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();
108
109 // Test getLabels()
110 assertEquals("Label not as expected!",secondEventFirstField,testFormat.getLabels()[0].toString());
111 assertEquals("Label not as expected!",secondEventSecondField,testFormat.getLabels()[1].toString());
112
113
114 // Test different parse()
115 // parse(event)
116 assertNotSame("parse() returned null!",null, testFormat.parse(tmpEvent));
117 assertEquals("Parsed field not as expected!",secondEventThirdFieldParsedValue,testFormat.parse(tmpEvent)[2].toString());
118
119 // parse(hashmap)
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());
122
123
124 // parse(string)
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());
128 }
129
130 @Test
131 public void testToString() {
132 LttngEventFormat tmpFormat = prepareToTest();
133
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() );
137 }
138
139 }
This page took 0.032728 seconds and 5 git commands to generate.