[156247] Preparation work for LTTng/TMF automated testing in Linux Tools build system.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngTimestampTest.java
1 package org.eclipse.linuxtools.lttng.tests.event;
2
3 import junit.framework.TestCase;
4
5 import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
6 import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
7 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
8
9 /*
10 Functions tested here :
11 public LttngTimestamp(TmfTimestamp newEventTime)
12 public LttngTimestamp(long newEventTime)
13 public String getSeconds()
14 public String getNanoSeconds()
15 public String toString()
16 */
17
18 public class LttngTimestampTest extends TestCase {
19 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
20 private final static boolean skipIndexing=true;
21
22 private final static String firstEventTimeSecond = "13589";
23 private final static String firstEventTimeNano = "759412127";
24 private final static long firstEventTimeFull = 13589759412127L;
25
26 private LTTngTextTrace initializeEventStream() {
27 LTTngTextTrace tmpStream = null;
28 try {
29 tmpStream = new LTTngTextTrace(tracepath1, skipIndexing);
30 }
31 catch (Exception e) {
32 fail("ERROR : Could not open " + tracepath1 + ". Test failed!" );
33 }
34
35 return tmpStream;
36 }
37
38
39 private LttngTimestamp prepareToTest() {
40 LttngTimestamp tmpTime = null;
41
42 // This trace should be valid
43 try {
44 LTTngTextTrace tmpStream = initializeEventStream();
45 tmpTime = (LttngTimestamp)tmpStream.getNextEvent( new TmfTraceContext(null, null, 0) ).getTimestamp();
46 }
47 catch (Exception e) {
48 fail("ERROR : Failed to get reference!");
49 }
50
51 return tmpTime;
52 }
53
54 public void testConstructors() {
55 LttngTimestamp tmpTime = null;
56 @SuppressWarnings("unused")
57 LttngTimestamp tmpTime2 = null;
58
59 // Default construction with good argument
60 try {
61 tmpTime = new LttngTimestamp(1);
62 }
63 catch( Exception e) {
64 fail("Construction failed!");
65 }
66
67 // Copy constructor
68 try {
69 tmpTime = new LttngTimestamp(1);
70 tmpTime2 = new LttngTimestamp(tmpTime);
71 }
72 catch( Exception e) {
73 fail("Construction failed!");
74 }
75 }
76
77
78 public void testGetter() {
79 LttngTimestamp tmpTime = prepareToTest();
80
81 assertEquals("Time in second is wrong", firstEventTimeSecond, tmpTime.getSeconds() );
82 assertEquals("Time in nano second is wrong", firstEventTimeNano, tmpTime.getNanoSeconds() );
83
84 assertEquals("Full time is wrong", firstEventTimeFull, tmpTime.getValue() );
85 }
86
87
88 public void testToString() {
89 LttngTimestamp tmpTime = prepareToTest();
90
91 // Just make sure toString() does not return null or the java reference
92 assertNotSame("toString returned null",null, tmpTime.toString() );
93 assertNotSame("toString is not overridded!", tmpTime.getClass().getName() + '@' + Integer.toHexString(tmpTime.hashCode()), tmpTime.toString() );
94 }
95
96 }
This page took 0.033322 seconds and 6 git commands to generate.