1 package org
.eclipse
.linuxtools
.lttng
.tests
.event
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
11 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
12 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
13 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
16 Functions tested here :
17 public LttngTimestamp()
18 public LttngTimestamp(long newEventTime)
19 public LttngTimestamp(TmfTimestamp oldEventTime)
21 public long getValue()
22 public String getSeconds()
23 public String getNanoSeconds()
25 public void setValue(long newValue)
27 public String toString()
30 public class LttngTimestampTest
extends TestCase
{
31 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
32 private final static boolean skipIndexing
=true;
34 private final static String firstEventTimeSecond
= "13589";
35 private final static String firstEventTimeNano
= "759412128";
36 private final static long firstEventTimeFull
= 13589759412128L;
38 private static LTTngTextTrace testStream
= null;
39 private LTTngTextTrace
initializeEventStream() {
40 if (testStream
== null) {
42 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
43 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
44 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
45 testStream
= tmpStream
;
48 System
.out
.println("ERROR : Could not open " + tracepath1
);
55 private LttngTimestamp
prepareToTest() {
56 LttngTimestamp tmpTime
= null;
58 // This trace should be valid
60 LTTngTextTrace tmpStream
= initializeEventStream();
61 tmpTime
= (LttngTimestamp
)tmpStream
.getNextEvent( new TmfContext(null, 0) ).getTimestamp();
64 fail("ERROR : Failed to get reference!");
70 public void testConstructors() {
71 LttngTimestamp tmpTime
= null;
72 @SuppressWarnings("unused")
73 LttngTimestamp tmpTime2
= null;
75 // Default construction with no argument
77 tmpTime
= new LttngTimestamp();
80 fail("Construction failed!");
83 // Default construction with good argument
85 tmpTime
= new LttngTimestamp(1);
88 fail("Construction failed!");
93 tmpTime
= new LttngTimestamp(1);
94 tmpTime2
= new LttngTimestamp(tmpTime
);
97 fail("Construction failed!");
102 public void testGetter() {
103 LttngTimestamp tmpTime
= prepareToTest();
105 assertEquals("Time in second is wrong", firstEventTimeSecond
, tmpTime
.getSeconds() );
106 assertEquals("Time in nano second is wrong", firstEventTimeNano
, tmpTime
.getNanoSeconds() );
108 assertEquals("Full time is wrong", firstEventTimeFull
, tmpTime
.getValue() );
111 public void testSetter() {
112 LttngTimestamp tmpTime
= prepareToTest();
114 // We will set a time and we will make sure the set is working then
116 assertEquals("Full time is wrong after set", 1, tmpTime
.getValue() );
120 public void testToString() {
121 LttngTimestamp tmpTime
= prepareToTest();
123 // Just make sure toString() does not return null or the java reference
124 assertNotSame("toString returned null",null, tmpTime
.toString() );
125 assertNotSame("toString is not overridded!", tmpTime
.getClass().getName() + '@' + Integer
.toHexString(tmpTime
.hashCode()), tmpTime
.toString() );