1 package org
.eclipse
.linuxtools
.lttng
.tests
.event
;
6 import junit
.framework
.TestCase
;
7 import org
.eclipse
.core
.runtime
.FileLocator
;
8 import org
.eclipse
.core
.runtime
.Path
;
9 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
10 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
11 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
15 Functions tested here :
16 public LttngTimestamp()
17 public LttngTimestamp(long newEventTime)
18 public LttngTimestamp(TmfTimestamp oldEventTime)
20 public long getValue()
21 public String getSeconds()
22 public String getNanoSeconds()
24 public void setValue(long newValue)
26 public String toString()
29 public class LttngTimestampTest
extends TestCase
{
30 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
31 private final static boolean skipIndexing
=true;
33 private final static String firstEventTimeSecond
= "13589";
34 private final static String firstEventTimeNano
= "759412127";
35 private final static long firstEventTimeFull
= 13589759412127L;
37 private static LTTngTextTrace testStream
= null;
38 private LTTngTextTrace
initializeEventStream() {
39 if (testStream
== null) {
41 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
42 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
43 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
44 testStream
= tmpStream
;
47 System
.out
.println("ERROR : Could not open " + tracepath1
);
54 private LttngTimestamp
prepareToTest() {
55 LttngTimestamp tmpTime
= null;
57 // This trace should be valid
59 LTTngTextTrace tmpStream
= initializeEventStream();
60 tmpTime
= (LttngTimestamp
)tmpStream
.getNextEvent( new TmfTraceContext(null, 0) ).getTimestamp();
63 fail("ERROR : Failed to get reference!");
69 public void testConstructors() {
70 LttngTimestamp tmpTime
= null;
71 @SuppressWarnings("unused")
72 LttngTimestamp tmpTime2
= null;
74 // Default construction with no argument
76 tmpTime
= new LttngTimestamp();
79 fail("Construction failed!");
82 // Default construction with good argument
84 tmpTime
= new LttngTimestamp(1);
87 fail("Construction failed!");
92 tmpTime
= new LttngTimestamp(1);
93 tmpTime2
= new LttngTimestamp(tmpTime
);
96 fail("Construction failed!");
101 public void testGetter() {
102 LttngTimestamp tmpTime
= prepareToTest();
104 assertEquals("Time in second is wrong", firstEventTimeSecond
, tmpTime
.getSeconds() );
105 assertEquals("Time in nano second is wrong", firstEventTimeNano
, tmpTime
.getNanoSeconds() );
107 assertEquals("Full time is wrong", firstEventTimeFull
, tmpTime
.getValue() );
110 public void testSetter() {
111 LttngTimestamp tmpTime
= prepareToTest();
113 // We will set a time and we will make sure the set is working then
115 assertEquals("Full time is wrong after set", 1, tmpTime
.getValue() );
119 public void testToString() {
120 LttngTimestamp tmpTime
= prepareToTest();
122 // Just make sure toString() does not return null or the java reference
123 assertNotSame("toString returned null",null, tmpTime
.toString() );
124 assertNotSame("toString is not overridded!", tmpTime
.getClass().getName() + '@' + Integer
.toHexString(tmpTime
.hashCode()), tmpTime
.toString() );