Improve javadoc for ctfAdapter in Tmf.Core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceReaderTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7
8 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
9 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
10 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
11 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
12 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
13 import org.junit.After;
14 import org.junit.Before;
15 import org.junit.Test;
16
17 /**
18 * The class <code>CTFTraceReaderTest</code> contains tests for the class
19 * <code>{@link CTFTraceReader}</code>.
20 *
21 * @author ematkho
22 * @version $Revision: 1.0 $
23 */
24 public class CTFTraceReaderTest {
25
26 CTFTraceReader fixture;
27
28 /**
29 * Launch the test.
30 *
31 * @param args
32 * the command line arguments
33 */
34 public static void main(String[] args) {
35 new org.junit.runner.JUnitCore().run(CTFTraceReaderTest.class);
36 }
37
38 /**
39 * Perform pre-test initialization.
40 *
41 * @throws CTFReaderException
42 */
43 @Before
44 public void setUp() throws CTFReaderException {
45 fixture = new CTFTraceReader(TestParams.createTrace());
46 }
47
48 /**
49 * Perform post-test clean-up.
50 */
51 @After
52 public void tearDown() {
53 // Add additional tear down code here
54 }
55
56 /**
57 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
58 * trace.
59 *
60 * @throws CTFReaderException
61 */
62 @Test
63 public void testOpen_existing() throws CTFReaderException {
64 CTFTrace trace = TestParams.createTrace();
65
66 CTFTraceReader result = new CTFTraceReader(trace);
67 assertNotNull(result);
68 }
69
70 /**
71 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
72 * trace, expect the exception.
73 *
74 * @throws CTFReaderException
75 */
76 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
77 public void testOpen_nonexisting() throws CTFReaderException {
78 CTFTrace trace = new CTFTrace("badfile.bad"); //$NON-NLS-1$
79
80 CTFTraceReader result = new CTFTraceReader(trace);
81 assertNotNull(result);
82 }
83
84 /**
85 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
86 * path, expect exception.
87 *
88 * @throws CTFReaderException
89 */
90 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
91 public void testOpen_invalid() throws CTFReaderException {
92 CTFTrace trace = new CTFTrace(""); //$NON-NLS-1$
93
94 CTFTraceReader result = new CTFTraceReader(trace);
95 assertNotNull(result);
96 }
97
98 /**
99 * Run the boolean advance() method test. Test advancing normally.
100 */
101 @Test
102 public void testAdvance_normal() {
103 boolean result = fixture.advance();
104 assertTrue(result);
105 }
106
107 /**
108 * Run the boolean advance() method test. Test advancing when we're at the
109 * end, so we expect that there is no more events.
110 */
111 @Test
112 public void testAdvance_end() {
113 int i = 0;
114 boolean result = fixture.advance();
115 while (result) {
116 result = fixture.advance();
117 i++;
118 }
119 fixture.seek(0);
120 fixture.advance();
121 fixture.goToLastEvent();
122 i = 1;
123 result = fixture.advance();
124 while (result) {
125 result = fixture.advance();
126 i++;
127 }
128 assertFalse(result);
129 assertEquals(i, 1);
130 }
131
132 /**
133 * Run the CTFTraceReader copy constructor test.
134 */
135 @Test
136 public void testCopyFrom() {
137 CTFTraceReader result = fixture.copyFrom();
138 assertNotNull(result);
139 }
140
141 /**
142 * Test the hashCode method.
143 */
144 @Test
145 public void testHash() {
146 int result = fixture.hashCode();
147 assertTrue(0 != result);
148 }
149
150 /**
151 * Test the equals method. Uses the class-wide 'fixture' and another
152 * method-local 'fixture2', which both point to the same trace.
153 *
154 * Both trace reader are different objects, so they shouldn't "equals" each
155 * other.
156 *
157 * @throws CTFReaderException
158 */
159 @Test
160 public void testEquals() throws CTFReaderException {
161 CTFTraceReader fixture2 = new CTFTraceReader(TestParams.createTrace());
162 assertEquals(fixture, fixture2);
163 }
164
165 /**
166 * Run the getCurrentEventDef() method test. Get the first event's
167 * definition.
168 */
169 @Test
170 public void testGetCurrentEventDef_first() {
171 EventDefinition result = fixture.getCurrentEventDef();
172 assertNotNull(result);
173 }
174
175 /**
176 * Run the getCurrentEventDef() method test. Get the last event's
177 * definition.
178 */
179 @Test
180 public void testGetCurrentEventDef_last() {
181 fixture.goToLastEvent();
182 EventDefinition result = fixture.getCurrentEventDef();
183 assertNotNull(result);
184 }
185
186 /**
187 * Run the long getEndTime() method test.
188 */
189 @Test
190 public void testGetEndTime() {
191 long result = fixture.getEndTime();
192 assertTrue(0L < result);
193 }
194
195 /**
196 * Run the long getStartTime() method test.
197 */
198 @Test
199 public void testGetStartTime() {
200 long result = fixture.getStartTime();
201 assertTrue(0L < result);
202 }
203
204 /**
205 * Run the void goToLastEvent() method test.
206 *
207 * @throws CTFReaderException
208 */
209 @Test
210 public void testGoToLastEvent() throws CTFReaderException {
211 fixture.goToLastEvent();
212 long ts1 = getTimestamp();
213 long ts2 = fixture.getEndTime();
214 assertEquals(ts1, ts2);
215 }
216
217 /**
218 * Run the boolean hasMoreEvents() method test.
219 *
220 * @throws CTFReaderException
221 */
222 @Test
223 public void testHasMoreEvents() {
224 boolean result = fixture.hasMoreEvents();
225 assertTrue(result);
226 }
227
228 /**
229 * Run the void printStats() method test with no 'width' parameter.
230 */
231 @Test
232 public void testPrintStats_noparam() {
233 fixture.advance();
234 fixture.printStats();
235 }
236
237 /**
238 * Run the void printStats(int) method test with width = 0.
239 */
240 @Test
241 public void testPrintStats_width0() {
242 fixture.advance();
243 fixture.printStats(0);
244 }
245
246 /**
247 * Run the void printStats(int) method test with width = 1.
248 */
249 @Test
250 public void testPrintStats_width1() {
251 fixture.advance();
252 fixture.printStats(1);
253 }
254
255 /**
256 * Run the void printStats(int) method test with width = 2.
257 */
258 @Test
259 public void testPrintStats_width2() {
260 fixture.advance();
261 fixture.printStats(2);
262 }
263
264 /**
265 * Run the void printStats(int) method test with width = 10.
266 */
267 @Test
268 public void testPrintStats_width10() {
269 fixture.advance();
270 fixture.printStats(10);
271 }
272
273 /**
274 * Run the void printStats(int) method test with width = 100.
275 */
276 @Test
277 public void testPrintStats_100() {
278 for (int i = 0; i < 1000; i++) {
279 fixture.advance();
280 }
281 fixture.printStats(100);
282 }
283
284 /**
285 * Run the boolean seek(long) method test.
286 */
287 @Test
288 public void testSeek() {
289 long timestamp = 1L;
290 boolean result = fixture.seek(timestamp);
291 assertTrue(result);
292 }
293
294
295
296 /**
297 * @return
298 */
299 private long getTimestamp() {
300 if (fixture.getCurrentEventDef() != null) {
301 return fixture.getCurrentEventDef().getTimestamp()+ this.fixture.getTrace().getOffset();
302 }
303 return -1;
304 }
305 }
This page took 0.036673 seconds and 5 git commands to generate.