1 package org
.eclipse
.linuxtools
.lttng
.tests
.event
;
8 import junit
.framework
.TestCase
;
10 import org
.eclipse
.core
.runtime
.FileLocator
;
11 import org
.eclipse
.core
.runtime
.Path
;
12 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventContent
;
13 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventField
;
14 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
15 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
16 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
17 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
20 Functions tested here :
21 public LttngEventField(String name, Object newContent)
22 public LttngEventField(LttngEventField oldField)
23 public String getName()
24 public String toString()
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;
32 // private final static String firstEventName = "alignment";
33 private final static String firstEventValue
= "0";
35 private static LTTngTextTrace testStream
= null;
36 private LTTngTextTrace
initializeEventStream() {
37 if (testStream
== null) {
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
;
45 System
.out
.println("ERROR : Could not open " + tracepath1
);
50 testStream
.seekEvent(0);
56 private LttngEventField
prepareToTest() {
57 LttngEventField tmpField
= null;
59 // This trace should be valid
61 LTTngTextTrace tmpStream
= initializeEventStream();
62 tmpField
= (LttngEventField
)tmpStream
.getNextEvent( new TmfContext(new TmfLocation
<Long
>(0L), 0) ).getContent().getField(0);
65 fail("ERROR : Failed to get field!");
71 public void testConstructors() {
72 LttngEventContent testContent
= null;
73 LttngEventField testField
= null;
74 @SuppressWarnings("unused")
75 LttngEventField testField2
= null;
77 // Default construction with good argument
79 testField
= new LttngEventField(testContent
, "test", "test");
82 fail("Default construction failed!");
85 // Copy constructor with correct parameters
87 testField
= new LttngEventField(testContent
, "test", "test");
88 testField2
= new LttngEventField(testField
);
91 fail("Copy constructor failed!");
96 public void testGetter() {
98 // *** To "really" test the field, we will get a real field from LTTngTrace
99 LTTngTextTrace tmpStream
= initializeEventStream();
101 LttngEventField testField
= (LttngEventField
)tmpStream
.getNextEvent( new TmfContext(new TmfLocation
<Long
>(0L), 0) ).getContent().getField(0);
102 assertNotSame("getField is null!",null,testField
);
105 // Depending from the Java version because of the "hashcode()" on String.
106 // We can't really test that safetly
108 //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
109 assertNotSame("getName() returned unexpected result!",null, testField
.getId());
111 assertTrue("getValue() returned unexpected result!",firstEventValue
.equals(testField
.getValue().toString()));
116 public void testToString() {
117 LttngEventField tmpField
= prepareToTest();
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() );