1 package org
.eclipse
.linuxtools
.lttng
.core
.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
.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
;
19 Functions tested here :
20 public LttngEventField(String name, Object newContent)
21 public LttngEventField(LttngEventField oldField)
22 public String getName()
23 public String toString()
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;
31 // private final static String firstEventName = "alignment";
32 private final static String firstEventValue
= "0";
34 private static LTTngTextTrace testStream
= null;
35 private LTTngTextTrace
initializeEventStream() {
36 if (testStream
== null)
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
;
43 catch (final Exception e
) {
44 System
.out
.println("ERROR : Could not open " + tracepath1
);
48 testStream
.seekEvent(0);
53 private LttngEventField
prepareToTest() {
54 LttngEventField tmpField
= null;
56 // This trace should be valid
58 final LTTngTextTrace tmpStream
= initializeEventStream();
59 tmpField
= (LttngEventField
)tmpStream
.getNext( new TmfContext(new TmfLocation
<Long
>(0L), 0) ).getContent().getField(0);
61 catch (final Exception e
) {
62 fail("ERROR : Failed to get field!");
68 public void testConstructors() {
69 LttngEventField testField
= null;
71 // Default construction with good argument
73 testField
= new LttngEventField("test", "test");
75 catch( final Exception e
) {
76 fail("Default construction failed!");
79 // Copy constructor with correct parameters
81 testField
= new LttngEventField("test", "test");
82 new LttngEventField(testField
);
84 catch( final Exception e
) {
85 fail("Copy constructor failed!");
90 public void testGetter() {
92 // *** To "really" test the field, we will get a real field from LTTngTrace
93 final LTTngTextTrace tmpStream
= initializeEventStream();
95 LttngEventField testField
= null;
97 testField
= (LttngEventField
) tmpStream
.getNext( new TmfContext(new TmfLocation
<Long
>(0L), 0) ).getContent().getField(0);
98 // } catch (TmfNoSuchFieldException e) {
99 // e.printStackTrace();
101 assertNotSame("getField is null!", null, testField
);
104 // Depending from the Java version because of the "hashcode()" on String.
105 // We can't really test that safetly
107 //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString()));
108 assertNotSame("getName() returned unexpected result!",null, testField
.getName());
110 assertTrue("getValue() returned unexpected result!",firstEventValue
.equals(testField
.getValue().toString()));
115 public void testToString() {
116 final LttngEventField tmpField
= prepareToTest();
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() );