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
1 package org.eclipse.linuxtools.lttng.core.tests.event;
2
3
4
5 import java.io.File;
6 import java.net.URL;
7
8 import junit.framework.TestCase;
9
10 import org.eclipse.core.runtime.FileLocator;
11 import org.eclipse.core.runtime.Path;
12 import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventField;
13 import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace;
14 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
15 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
16 import org.osgi.framework.FrameworkUtil;
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 @SuppressWarnings("nls")
27 public class LttngEventFieldTest extends TestCase {
28 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
29 private final static boolean skipIndexing=true;
30
31 // private final static String firstEventName = "alignment";
32 private final static String firstEventValue = "0";
33
34 private static LTTngTextTrace testStream = null;
35 private LTTngTextTrace initializeEventStream() {
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
72 try {
73 testField = new LttngEventField("test", "test");
74 }
75 catch( final Exception e) {
76 fail("Default construction failed!");
77 }
78
79 // Copy constructor with correct parameters
80 try {
81 testField = new LttngEventField("test", "test");
82 new LttngEventField(testField);
83 }
84 catch( final Exception e) {
85 fail("Copy constructor failed!");
86 }
87
88 }
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() );
121 }
122
123 }
This page took 0.033314 seconds and 5 git commands to generate.