Refactor TmfTrace and dependencies - remove getTrace()
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / event / LttngEventFieldTest.java
CommitLineData
6c13869b 1package org.eclipse.linuxtools.lttng.core.tests.event;
03c71d1e
ASL
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;
5945cec9
FC
12import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventField;
13import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace;
6c13869b
FC
14import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
15import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
9269df72 16import org.osgi.framework.FrameworkUtil;
03c71d1e
ASL
17
18/*
19 Functions tested here :
25e48683
FC
20 public LttngEventField(String name, Object newContent)
21 public LttngEventField(LttngEventField oldField)
22 public String getName()
23 public String toString()
03c71d1e
ASL
24
25 */
3b38ea61 26@SuppressWarnings("nls")
03c71d1e
ASL
27public class LttngEventFieldTest extends TestCase {
28 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
29 private final static boolean skipIndexing=true;
25e48683
FC
30
31 // private final static String firstEventName = "alignment";
03c71d1e 32 private final static String firstEventValue = "0";
25e48683 33
e1ab8984 34 private static LTTngTextTrace testStream = null;
03c71d1e 35 private LTTngTextTrace initializeEventStream() {
25e48683
FC
36 if (testStream == null)
37 try {
38 final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null);
39 final File testfile = new File(FileLocator.toFileURL(location).toURI());
40 final LTTngTextTrace tmpStream = new LTTngTextTrace(null, testfile.getPath(), skipIndexing);
41 testStream = tmpStream;
42 }
43 catch (final Exception e) {
44 System.out.println("ERROR : Could not open " + tracepath1);
45 testStream = null;
46 }
47 else
48 testStream.seekEvent(0);
49
50 return testStream;
51 }
52
53 private LttngEventField prepareToTest() {
54 LttngEventField tmpField = null;
55
56 // This trace should be valid
57 try {
58 final LTTngTextTrace tmpStream = initializeEventStream();
59 tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
60 }
61 catch (final Exception e) {
62 fail("ERROR : Failed to get field!");
63 }
64
65 return tmpField;
66 }
67
68 public void testConstructors() {
69 LttngEventField testField = null;
70
71 // Default construction with good argument
03c71d1e 72 try {
25e48683 73 testField = new LttngEventField("test", "test");
03c71d1e 74 }
25e48683
FC
75 catch( final Exception e) {
76 fail("Default construction failed!");
03c71d1e 77 }
25e48683 78
03c71d1e
ASL
79 // Copy constructor with correct parameters
80 try {
25e48683
FC
81 testField = new LttngEventField("test", "test");
82 new LttngEventField(testField);
03c71d1e 83 }
25e48683
FC
84 catch( final Exception e) {
85 fail("Copy constructor failed!");
03c71d1e 86 }
25e48683 87
cb866e08 88 }
25e48683
FC
89
90 public void testGetter() {
91
92 // *** To "really" test the field, we will get a real field from LTTngTrace
93 final LTTngTextTrace tmpStream = initializeEventStream();
94
95 LttngEventField testField = null;
96 // try {
97 testField = (LttngEventField) tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
98 // } catch (TmfNoSuchFieldException e) {
99 // e.printStackTrace();
100 // }
101 assertNotSame("getField is null!", null, testField);
102
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.getName());
109
110 assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString()));
111
112
113 }
114
115 public void testToString() {
116 final 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() );
cb866e08 121 }
25e48683 122
03c71d1e 123}
This page took 0.035405 seconds and 5 git commands to generate.