Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.event; |
2 | ||
e1ab8984 FC |
3 | import java.io.File; |
4 | import java.net.URL; | |
5 | ||
03c71d1e | 6 | import junit.framework.TestCase; |
e1ab8984 FC |
7 | import org.eclipse.core.runtime.FileLocator; |
8 | import org.eclipse.core.runtime.Path; | |
03c71d1e | 9 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; |
e1ab8984 | 10 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
03c71d1e | 11 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
86de1b08 | 12 | import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; |
03c71d1e ASL |
13 | |
14 | /* | |
15 | Functions tested here : | |
a5ec08e5 WB |
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() | |
03c71d1e ASL |
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"; | |
ac9e91f4 WB |
34 | private final static String firstEventTimeNano = "759412127"; |
35 | private final static long firstEventTimeFull = 13589759412127L; | |
03c71d1e | 36 | |
e1ab8984 | 37 | private static LTTngTextTrace testStream = null; |
03c71d1e | 38 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
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 | ||
03c71d1e ASL |
54 | private LttngTimestamp prepareToTest() { |
55 | LttngTimestamp tmpTime = null; | |
56 | ||
57 | // This trace should be valid | |
58 | try { | |
59 | LTTngTextTrace tmpStream = initializeEventStream(); | |
e31e01e8 | 60 | tmpTime = (LttngTimestamp)tmpStream.getNextEvent( new TmfTraceContext(null, 0) ).getTimestamp(); |
03c71d1e ASL |
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 | ||
a5ec08e5 WB |
74 | // Default construction with no argument |
75 | try { | |
76 | tmpTime = new LttngTimestamp(); | |
77 | } | |
78 | catch( Exception e) { | |
79 | fail("Construction failed!"); | |
80 | } | |
81 | ||
03c71d1e ASL |
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 | ||
a5ec08e5 WB |
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 | ||
03c71d1e ASL |
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 | } |