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