[Bug293101] Context menu fix: removed the unimplemented menu choices and enabled...
[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
e1ab8984
FC
5import java.io.File;
6import java.net.URL;
7
03c71d1e
ASL
8import junit.framework.TestCase;
9
e1ab8984
FC
10import org.eclipse.core.runtime.FileLocator;
11import org.eclipse.core.runtime.Path;
03c71d1e
ASL
12import org.eclipse.linuxtools.lttng.event.LttngEventContent;
13import org.eclipse.linuxtools.lttng.event.LttngEventField;
e1ab8984 14import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
03c71d1e 15import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
86de1b08 16import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
03c71d1e
ASL
17
18/*
19 Functions tested here :
20 public LttngEventField(String name, Object newContent)
21 public LttngEventField(LttngEventField oldField)
22 public String getName()
23 public String toString()
24
25 */
26
27public class LttngEventFieldTest extends TestCase {
28 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
29 private final static boolean skipIndexing=true;
30
e31e01e8 31// private final static String firstEventName = "alignment";
03c71d1e
ASL
32 private final static String firstEventValue = "0";
33
e1ab8984 34 private static LTTngTextTrace testStream = null;
03c71d1e 35 private LTTngTextTrace initializeEventStream() {
e1ab8984
FC
36 if (testStream == null) {
37 try {
38 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
39 File testfile = new File(FileLocator.toFileURL(location).toURI());
40 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
41 testStream = tmpStream;
42 }
43 catch (Exception e) {
44 System.out.println("ERROR : Could not open " + tracepath1);
45 testStream = null;
46 }
03c71d1e 47 }
ccc4dc5b
WB
48 else {
49 testStream.seekEvent(0);
50 }
51
e1ab8984
FC
52 return testStream;
53 }
03c71d1e
ASL
54
55 private LttngEventField prepareToTest() {
56 LttngEventField tmpField = null;
57
58 // This trace should be valid
59 try {
60 LTTngTextTrace tmpStream = initializeEventStream();
e31e01e8 61 tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0L, 0) ).getContent().getField(0);
03c71d1e
ASL
62 }
63 catch (Exception e) {
64 fail("ERROR : Failed to get field!");
65 }
66
67 return tmpField;
68 }
69
70 public void testConstructors() {
71 LttngEventContent testContent = null;
72 LttngEventField testField = null;
73 @SuppressWarnings("unused")
74 LttngEventField testField2 = null;
75
76 // Default construction with good argument
77 try {
78 testField = new LttngEventField(testContent, "test", "test");
79 }
80 catch( Exception e) {
81 fail("Default construction failed!");
82 }
83
84 // Copy constructor with correct parameters
85 try {
86 testField = new LttngEventField(testContent, "test", "test");
87 testField2 = new LttngEventField(testField);
88 }
89 catch( Exception e) {
90 fail("Copy constructor failed!");
91 }
92
93 }
94
95 public void testGetter() {
96
97 // *** To "really" test the field, we will get a real field from LTTngTrace
98 LTTngTextTrace tmpStream = initializeEventStream();
99
e31e01e8 100 LttngEventField testField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0L, 0) ).getContent().getField(0);
03c71d1e
ASL
101 assertNotSame("getField is null!",null,testField);
102
0a9422df
WB
103 // *** FIXME ***
104 // Depending from the Java version because of the "hashcode()" on String.
105 // We can't really test that safetly
106 //
107 //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
108 assertNotSame("getName() returned unexpected result!",null, testField.getId());
109
03c71d1e
ASL
110 assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString()));
111
112
113 }
114
115 public void testToString() {
116 LttngEventField tmpField = prepareToTest();
117
118 // Just make sure toString() does not return null or the java reference
119 assertNotSame("toString returned null",null, tmpField.toString() );
120 assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() );
121 }
122
123}
This page took 0.028605 seconds and 5 git commands to generate.