1 package org
.eclipse
.linuxtools
.lttng
.core
.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
.internal
.lttng
.core
.event
.LttngTimestamp
;
11 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTextTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
13 import org
.osgi
.framework
.FrameworkUtil
;
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 @SuppressWarnings("nls")
31 public class LttngTimestampTest
extends TestCase
{
32 private final static String tracepath1
= "traceset/trace-15316events_nolost_newformat.txt";
33 private final static boolean skipIndexing
= true;
35 private final static String firstEventTimeSecond
= "13589";
36 private final static String firstEventTimeNano
= "759412128";
37 private final static long firstEventTimeFull
= 13589759412128L;
39 private static LTTngTextTrace testStream
= null;
41 private LTTngTextTrace
initializeEventStream() {
42 if (testStream
== null)
44 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(tracepath1
), null);
45 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
46 final LTTngTextTrace tmpStream
= new LTTngTextTrace(null, testfile
.getPath(), skipIndexing
);
47 testStream
= tmpStream
;
48 } catch (final Exception e
) {
49 System
.out
.println("ERROR : Could not open " + tracepath1
);
55 private LttngTimestamp
prepareToTest() {
56 LttngTimestamp tmpTime
= null;
58 // This trace should be valid
60 final LTTngTextTrace tmpStream
= initializeEventStream();
61 tmpTime
= (LttngTimestamp
) tmpStream
.getNext(new TmfContext(null, 0)).getTimestamp();
62 } catch (final Exception e
) {
63 fail("ERROR : Failed to get reference!");
69 public void testConstructors() {
70 LttngTimestamp tmpTime
= null;
72 // Default construction with no argument
74 tmpTime
= new LttngTimestamp();
75 } catch (final Exception e
) {
76 fail("Construction failed!");
79 // Default construction with good argument
81 tmpTime
= new LttngTimestamp(1);
82 } catch (final Exception e
) {
83 fail("Construction failed!");
88 tmpTime
= new LttngTimestamp(1);
89 new LttngTimestamp(tmpTime
);
90 } catch (final Exception e
) {
91 fail("Construction failed!");
95 public void testGetter() {
96 final LttngTimestamp tmpTime
= prepareToTest();
98 assertEquals("Time in second is wrong", firstEventTimeSecond
, tmpTime
.getSeconds());
99 assertEquals("Time in nano second is wrong", firstEventTimeNano
, tmpTime
.getNanoSeconds());
101 assertEquals("Full time is wrong", firstEventTimeFull
, tmpTime
.getValue());
104 public void testSetter() {
105 final LttngTimestamp tmpTime
= prepareToTest();
107 // We will set a time and we will make sure the set is working then
109 assertEquals("Full time is wrong after set", 1, tmpTime
.getValue());
112 public void testToString() {
113 final LttngTimestamp tmpTime
= prepareToTest();
115 // Just make sure toString() does not return null or the java reference
116 assertNotSame("toString returned null", null, tmpTime
.toString());
117 assertNotSame("toString is not overridded!", tmpTime
.getClass().getName() + '@' + Integer
.toHexString(tmpTime
.hashCode()), tmpTime
.toString());
121 public void testToString2() {
122 final LttngTimestamp ts1
= new LttngTimestamp(2064357056377L);
123 final String expectedTS1
= "2064.357056377";
125 final LttngTimestamp ts2
= new LttngTimestamp(1L);
126 final String expectedTS2
= "0.000000001";
128 final LttngTimestamp ts3
= new LttngTimestamp(123456789L);
129 final String expectedTS3
= "0.123456789";
131 final LttngTimestamp ts4
= new LttngTimestamp(1234567890L);
132 final String expectedTS4
= "1.234567890";
134 assertEquals("toString()", expectedTS1
, ts1
.toString());
135 assertEquals("toString()", expectedTS2
, ts2
.toString());
136 assertEquals("toString()", expectedTS3
, ts3
.toString());
137 assertEquals("toString()", expectedTS4
, ts4
.toString());
139 final LttngTimestamp ts5
= new LttngTimestamp(2234567890L);
140 final LttngTimestamp delta
= ts4
.getDelta(ts5
);
141 final String expectedDelta
= "-1.000000000";
142 assertEquals("toString()", expectedDelta
, delta
.toString());