2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[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;
cbd4ad82 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;
9f584e4c 13import org.eclipse.linuxtools.tmf.trace.TmfContext;
03c71d1e
ASL
14
15/*
16 Functions tested here :
a5ec08e5
WB
17 public LttngTimestamp()
18 public LttngTimestamp(long newEventTime)
19 public LttngTimestamp(TmfTimestamp oldEventTime)
20
21 public long getValue()
22 public String getSeconds()
23 public String getNanoSeconds()
24
25 public void setValue(long newValue)
26
27 public String toString()
03c71d1e
ASL
28 */
29
3b38ea61 30@SuppressWarnings("nls")
03c71d1e
ASL
31public class LttngTimestampTest extends TestCase {
32 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
33 private final static boolean skipIndexing=true;
34
35 private final static String firstEventTimeSecond = "13589";
9f861850
WB
36 private final static String firstEventTimeNano = "759412128";
37 private final static long firstEventTimeFull = 13589759412128L;
03c71d1e 38
e1ab8984 39 private static LTTngTextTrace testStream = null;
03c71d1e 40 private LTTngTextTrace initializeEventStream() {
e1ab8984
FC
41 if (testStream == null) {
42 try {
43 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
44 File testfile = new File(FileLocator.toFileURL(location).toURI());
45 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
46 testStream = tmpStream;
47 }
48 catch (Exception e) {
49 System.out.println("ERROR : Could not open " + tracepath1);
50 testStream = null;
51 }
52 }
53 return testStream;
54 }
55
03c71d1e
ASL
56 private LttngTimestamp prepareToTest() {
57 LttngTimestamp tmpTime = null;
58
59 // This trace should be valid
60 try {
61 LTTngTextTrace tmpStream = initializeEventStream();
9f584e4c 62 tmpTime = (LttngTimestamp)tmpStream.getNextEvent( new TmfContext(null, 0) ).getTimestamp();
03c71d1e
ASL
63 }
64 catch (Exception e) {
65 fail("ERROR : Failed to get reference!");
66 }
67
68 return tmpTime;
69 }
70
71 public void testConstructors() {
72 LttngTimestamp tmpTime = null;
73 @SuppressWarnings("unused")
74 LttngTimestamp tmpTime2 = null;
75
a5ec08e5
WB
76 // Default construction with no argument
77 try {
78 tmpTime = new LttngTimestamp();
79 }
80 catch( Exception e) {
81 fail("Construction failed!");
82 }
83
03c71d1e
ASL
84 // Default construction with good argument
85 try {
86 tmpTime = new LttngTimestamp(1);
87 }
88 catch( Exception e) {
89 fail("Construction failed!");
90 }
91
92 // Copy constructor
93 try {
94 tmpTime = new LttngTimestamp(1);
95 tmpTime2 = new LttngTimestamp(tmpTime);
96 }
97 catch( Exception e) {
98 fail("Construction failed!");
99 }
100 }
101
102
cb866e08
FC
103 public void testGetter() {
104 LttngTimestamp tmpTime = prepareToTest();
105
106 assertEquals("Time in second is wrong", firstEventTimeSecond, tmpTime.getSeconds() );
107 assertEquals("Time in nano second is wrong", firstEventTimeNano, tmpTime.getNanoSeconds() );
108
109 assertEquals("Full time is wrong", firstEventTimeFull, tmpTime.getValue() );
110 }
111
112 public void testSetter() {
113 LttngTimestamp tmpTime = prepareToTest();
114
115 // We will set a time and we will make sure the set is working then
116 tmpTime.setValue(1);
117 assertEquals("Full time is wrong after set", 1, tmpTime.getValue() );
118 }
119
120
121 public void testToString() {
122 LttngTimestamp tmpTime = prepareToTest();
123
124 // Just make sure toString() does not return null or the java reference
125 assertNotSame("toString returned null",null, tmpTime.toString() );
126 assertNotSame("toString is not overridded!", tmpTime.getClass().getName() + '@' + Integer.toHexString(tmpTime.hashCode()), tmpTime.toString() );
127 }
03c71d1e
ASL
128
129}
This page took 0.048045 seconds and 5 git commands to generate.