2010-01-19 Francois Chouinard <fchouinard@gmail.com>
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngEventFieldTest.java
CommitLineData
03c71d1e
ASL
1package org.eclipse.linuxtools.lttng.tests.event;
2
3
4
03c71d1e
ASL
5import junit.framework.TestCase;
6
03c71d1e
ASL
7import org.eclipse.linuxtools.lttng.event.LttngEventContent;
8import org.eclipse.linuxtools.lttng.event.LttngEventField;
86de1b08 9import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
03c71d1e 10import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
86de1b08 11import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
03c71d1e
ASL
12
13/*
14 Functions tested here :
15 public LttngEventField(String name, Object newContent)
16 public LttngEventField(LttngEventField oldField)
17 public String getName()
18 public String toString()
19
20 */
21
22public class LttngEventFieldTest extends TestCase {
23 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
24 private final static boolean skipIndexing=true;
25
86de1b08 26 private final static String firstEventName = "alignment";
03c71d1e
ASL
27 private final static String firstEventValue = "0";
28
03c71d1e 29 private LTTngTextTrace initializeEventStream() {
5fbe0b84
FC
30 LTTngTextTrace tmpStream = null;
31 try {
32 tmpStream = new LTTngTextTrace(tracepath1, skipIndexing);
33 }
34 catch (Exception e) {
35 fail("ERROR : Could not open " + tracepath1 + ". Test failed!" );
03c71d1e
ASL
36 }
37
5fbe0b84
FC
38 return tmpStream;
39 }
40
03c71d1e
ASL
41
42 private LttngEventField prepareToTest() {
43 LttngEventField tmpField = null;
44
45 // This trace should be valid
46 try {
47 LTTngTextTrace tmpStream = initializeEventStream();
86de1b08 48 tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0, new LttngTimestamp(0L), 0) ).getContent().getField(0);
03c71d1e
ASL
49 }
50 catch (Exception e) {
51 fail("ERROR : Failed to get field!");
52 }
53
54 return tmpField;
55 }
56
57 public void testConstructors() {
58 LttngEventContent testContent = null;
59 LttngEventField testField = null;
60 @SuppressWarnings("unused")
61 LttngEventField testField2 = null;
62
63 // Default construction with good argument
64 try {
65 testField = new LttngEventField(testContent, "test", "test");
66 }
67 catch( Exception e) {
68 fail("Default construction failed!");
69 }
70
71 // Copy constructor with correct parameters
72 try {
73 testField = new LttngEventField(testContent, "test", "test");
74 testField2 = new LttngEventField(testField);
75 }
76 catch( Exception e) {
77 fail("Copy constructor failed!");
78 }
79
80 }
81
82 public void testGetter() {
83
84 // *** To "really" test the field, we will get a real field from LTTngTrace
85 LTTngTextTrace tmpStream = initializeEventStream();
86
86de1b08 87 LttngEventField testField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0, new LttngTimestamp(0L), 0) ).getContent().getField(0);
03c71d1e
ASL
88 assertNotSame("getField is null!",null,testField);
89
5fbe0b84 90 assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
03c71d1e
ASL
91 assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString()));
92
93
94 }
95
96 public void testToString() {
97 LttngEventField tmpField = prepareToTest();
98
99 // Just make sure toString() does not return null or the java reference
100 assertNotSame("toString returned null",null, tmpField.toString() );
101 assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() );
102 }
103
104}
This page took 0.027402 seconds and 5 git commands to generate.