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