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