Implement the new TMF Event Model
[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.lttng.core.event.LttngEventContent;
13 import org.eclipse.linuxtools.lttng.core.event.LttngEventField;
14 import org.eclipse.linuxtools.lttng.core.tests.LTTngCoreTestPlugin;
15 import org.eclipse.linuxtools.lttng.core.trace.LTTngTextTrace;
16 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
17 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
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 */
27 @SuppressWarnings("nls")
28 public class LttngEventFieldTest extends TestCase {
29 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
30 private final static boolean skipIndexing=true;
31
32 // private final static String firstEventName = "alignment";
33 private final static String firstEventValue = "0";
34
35 private static LTTngTextTrace testStream = null;
36 private LTTngTextTrace initializeEventStream() {
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 }
48 }
49 else {
50 testStream.seekEvent(0);
51 }
52
53 return testStream;
54 }
55
56 private LttngEventField prepareToTest() {
57 LttngEventField tmpField = null;
58
59 // This trace should be valid
60 try {
61 LTTngTextTrace tmpStream = initializeEventStream();
62 tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
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("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("test", "test");
88 testField2 = new LttngEventField(testField);
89 }
90 catch( Exception e) {
91 fail("Copy constructor failed!");
92 }
93
94 }
95
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 = null;
102 // try {
103 testField = (LttngEventField) tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0);
104 // } catch (TmfNoSuchFieldException e) {
105 // e.printStackTrace();
106 // }
107 assertNotSame("getField is null!", null, testField);
108
109 // *** FIXME ***
110 // Depending from the Java version because of the "hashcode()" on String.
111 // We can't really test that safetly
112 //
113 //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
114 assertNotSame("getName() returned unexpected result!",null, testField.getName());
115
116 assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString()));
117
118
119 }
120
121 public void testToString() {
122 LttngEventField tmpField = prepareToTest();
123
124 // Just make sure toString() does not return null or the java reference
125 assertNotSame("toString returned null",null, tmpField.toString() );
126 assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() );
127 }
128
129 }
This page took 0.033707 seconds and 5 git commands to generate.