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; |
cbd4ad82 | 7 | |
e1ab8984 FC |
8 | import org.eclipse.core.runtime.FileLocator; |
9 | import org.eclipse.core.runtime.Path; | |
03c71d1e | 10 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; |
e1ab8984 | 11 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
03c71d1e | 12 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
9f584e4c | 13 | import 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 | ||
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"; | |
9f861850 WB |
35 | private final static String firstEventTimeNano = "759412128"; |
36 | private final static long firstEventTimeFull = 13589759412128L; | |
03c71d1e | 37 | |
e1ab8984 | 38 | private static LTTngTextTrace testStream = null; |
03c71d1e | 39 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
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 | ||
03c71d1e ASL |
55 | private LttngTimestamp prepareToTest() { |
56 | LttngTimestamp tmpTime = null; | |
57 | ||
58 | // This trace should be valid | |
59 | try { | |
60 | LTTngTextTrace tmpStream = initializeEventStream(); | |
9f584e4c | 61 | tmpTime = (LttngTimestamp)tmpStream.getNextEvent( new TmfContext(null, 0) ).getTimestamp(); |
03c71d1e ASL |
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 | ||
a5ec08e5 WB |
75 | // Default construction with no argument |
76 | try { | |
77 | tmpTime = new LttngTimestamp(); | |
78 | } | |
79 | catch( Exception e) { | |
80 | fail("Construction failed!"); | |
81 | } | |
82 | ||
03c71d1e ASL |
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 | ||
cb866e08 FC |
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 | } | |
03c71d1e ASL |
127 | |
128 | } |