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