ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFTraceReaderTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
b562a24f 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51 13
ce2388e0 14import static org.junit.Assert.assertEquals;
866e5b51
FC
15import static org.junit.Assert.assertFalse;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
18
680f9173 19import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4 20import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
c4d57ac1 21import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils;
f357bcd4
AM
22import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
23import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
c4d57ac1 24import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
866e5b51
FC
25import org.junit.Before;
26import org.junit.Test;
27
28/**
29 * The class <code>CTFTraceReaderTest</code> contains tests for the class
30 * <code>{@link CTFTraceReader}</code>.
31 *
32 * @author ematkho
33 * @version $Revision: 1.0 $
34 */
be6df2d8 35@SuppressWarnings("javadoc")
866e5b51
FC
36public class CTFTraceReaderTest {
37
9ac63b5b 38 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
32bf80d2
AM
39
40 private CTFTraceReader fixture;
866e5b51 41
866e5b51
FC
42 /**
43 * Perform pre-test initialization.
bfe038ff 44 *
680f9173 45 * @throws CTFException
866e5b51
FC
46 */
47 @Before
680f9173 48 public void setUp() throws CTFException {
c4d57ac1 49 fixture = new CTFTraceReader(CtfTestTraceUtils.getTrace(testTrace));
866e5b51
FC
50 }
51
866e5b51
FC
52 /**
53 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
54 * trace.
bfe038ff 55 *
680f9173 56 * @throws CTFException
866e5b51
FC
57 */
58 @Test
680f9173 59 public void testOpen_existing() throws CTFException {
c4d57ac1 60 CTFTrace trace = CtfTestTraceUtils.getTrace(testTrace);
b562a24f 61 try (CTFTraceReader result = new CTFTraceReader(trace);) {
05ce5fef
AM
62 assertNotNull(result);
63 }
866e5b51
FC
64 }
65
66 /**
67 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
68 * trace, expect the exception.
69 *
680f9173 70 * @throws CTFException
866e5b51 71 */
680f9173
MK
72 @Test(expected = org.eclipse.tracecompass.ctf.core.CTFException.class)
73 public void testOpen_nonexisting() throws CTFException {
b562a24f
MK
74 CTFTrace trace = new CTFTrace("badfile.bad");
75 try (CTFTraceReader result = new CTFTraceReader(trace);) {
05ce5fef
AM
76 assertNotNull(result);
77 }
866e5b51
FC
78 }
79
80 /**
81 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
82 * path, expect exception.
83 *
680f9173 84 * @throws CTFException
866e5b51 85 */
680f9173
MK
86 @Test(expected = org.eclipse.tracecompass.ctf.core.CTFException.class)
87 public void testOpen_invalid() throws CTFException {
b562a24f
MK
88 CTFTrace trace = new CTFTrace("");
89 try (CTFTraceReader result = new CTFTraceReader(trace);) {
05ce5fef
AM
90 assertNotNull(result);
91 }
866e5b51
FC
92 }
93
94 /**
95 * Run the boolean advance() method test. Test advancing normally.
b562a24f 96 *
680f9173 97 * @throws CTFException
b562a24f 98 * error
866e5b51
FC
99 */
100 @Test
680f9173 101 public void testAdvance_normal() throws CTFException {
866e5b51
FC
102 boolean result = fixture.advance();
103 assertTrue(result);
104 }
105
106 /**
107 * Run the boolean advance() method test. Test advancing when we're at the
108 * end, so we expect that there is no more events.
b562a24f 109 *
680f9173 110 * @throws CTFException
b562a24f 111 * error
866e5b51
FC
112 */
113 @Test
680f9173 114 public void testAdvance_end() throws CTFException {
bfe038ff
MK
115 int i = 0;
116 boolean result = fixture.advance();
117 while (result) {
118 result = fixture.advance();
119 i++;
120 }
121 fixture.seek(0);
122 fixture.advance();
866e5b51 123 fixture.goToLastEvent();
bfe038ff
MK
124 i = 1;
125 result = fixture.advance();
126 while (result) {
127 result = fixture.advance();
128 i++;
866e5b51 129 }
866e5b51 130 assertFalse(result);
bfe038ff 131 assertEquals(i, 1);
866e5b51
FC
132 }
133
134 /**
135 * Run the CTFTraceReader copy constructor test.
b562a24f 136 *
680f9173 137 * @throws CTFException
b562a24f 138 * error
866e5b51
FC
139 */
140 @Test
680f9173 141 public void testCopyFrom() throws CTFException {
05ce5fef
AM
142 try (CTFTraceReader result = fixture.copyFrom();) {
143 assertNotNull(result);
144 }
866e5b51
FC
145 }
146
866e5b51
FC
147 /**
148 * Run the getCurrentEventDef() method test. Get the first event's
149 * definition.
150 */
151 @Test
152 public void testGetCurrentEventDef_first() {
153 EventDefinition result = fixture.getCurrentEventDef();
154 assertNotNull(result);
155 }
156
157 /**
158 * Run the getCurrentEventDef() method test. Get the last event's
159 * definition.
b562a24f 160 *
680f9173 161 * @throws CTFException
b562a24f 162 * error
866e5b51
FC
163 */
164 @Test
680f9173 165 public void testGetCurrentEventDef_last() throws CTFException {
866e5b51
FC
166 fixture.goToLastEvent();
167 EventDefinition result = fixture.getCurrentEventDef();
168 assertNotNull(result);
169 }
170
171 /**
172 * Run the long getEndTime() method test.
173 */
174 @Test
175 public void testGetEndTime() {
176 long result = fixture.getEndTime();
177 assertTrue(0L < result);
178 }
179
180 /**
181 * Run the long getStartTime() method test.
182 */
183 @Test
184 public void testGetStartTime() {
185 long result = fixture.getStartTime();
186 assertTrue(0L < result);
187 }
188
189 /**
190 * Run the void goToLastEvent() method test.
b562a24f 191 *
680f9173 192 * @throws CTFException
b562a24f 193 * error
866e5b51
FC
194 */
195 @Test
680f9173 196 public void testGoToLastEvent() throws CTFException {
866e5b51 197 fixture.goToLastEvent();
ce2388e0 198 long ts1 = getTimestamp();
866e5b51 199 long ts2 = fixture.getEndTime();
bfe038ff 200 assertEquals(ts1, ts2);
866e5b51
FC
201 }
202
203 /**
204 * Run the boolean hasMoreEvents() method test.
205 *
680f9173 206 * @throws CTFException
866e5b51
FC
207 */
208 @Test
209 public void testHasMoreEvents() {
210 boolean result = fixture.hasMoreEvents();
211 assertTrue(result);
212 }
213
214 /**
215 * Run the void printStats() method test with no 'width' parameter.
b562a24f 216 *
680f9173 217 * @throws CTFException
b562a24f 218 * error
866e5b51
FC
219 */
220 @Test
680f9173 221 public void testPrintStats_noparam() throws CTFException {
866e5b51
FC
222 fixture.advance();
223 fixture.printStats();
224 }
225
226 /**
227 * Run the void printStats(int) method test with width = 0.
b562a24f 228 *
680f9173 229 * @throws CTFException
b562a24f 230 * error
866e5b51
FC
231 */
232 @Test
680f9173 233 public void testPrintStats_width0() throws CTFException {
866e5b51
FC
234 fixture.advance();
235 fixture.printStats(0);
236 }
237
238 /**
239 * Run the void printStats(int) method test with width = 1.
b562a24f 240 *
680f9173 241 * @throws CTFException
b562a24f 242 * error
866e5b51
FC
243 */
244 @Test
680f9173 245 public void testPrintStats_width1() throws CTFException {
866e5b51
FC
246 fixture.advance();
247 fixture.printStats(1);
248 }
249
250 /**
251 * Run the void printStats(int) method test with width = 2.
b562a24f 252 *
680f9173 253 * @throws CTFException
b562a24f 254 * error
866e5b51
FC
255 */
256 @Test
680f9173 257 public void testPrintStats_width2() throws CTFException {
866e5b51
FC
258 fixture.advance();
259 fixture.printStats(2);
260 }
261
262 /**
263 * Run the void printStats(int) method test with width = 10.
b562a24f 264 *
680f9173 265 * @throws CTFException
b562a24f 266 * error
866e5b51
FC
267 */
268 @Test
680f9173 269 public void testPrintStats_width10() throws CTFException {
866e5b51
FC
270 fixture.advance();
271 fixture.printStats(10);
272 }
273
274 /**
275 * Run the void printStats(int) method test with width = 100.
b562a24f 276 *
680f9173 277 * @throws CTFException
b562a24f 278 * error
866e5b51
FC
279 */
280 @Test
680f9173 281 public void testPrintStats_100() throws CTFException {
866e5b51
FC
282 for (int i = 0; i < 1000; i++) {
283 fixture.advance();
284 }
285 fixture.printStats(100);
286 }
287
288 /**
289 * Run the boolean seek(long) method test.
b562a24f 290 *
680f9173 291 * @throws CTFException
b562a24f 292 * error
866e5b51
FC
293 */
294 @Test
680f9173 295 public void testSeek() throws CTFException {
866e5b51
FC
296 long timestamp = 1L;
297 boolean result = fixture.seek(timestamp);
298 assertTrue(result);
299 }
ce2388e0 300
ce2388e0
FC
301 /**
302 * @return
303 */
304 private long getTimestamp() {
bfe038ff 305 if (fixture.getCurrentEventDef() != null) {
1d7277f3 306 return fixture.getTrace().timestampCyclesToNanos(fixture.getCurrentEventDef().getTimestamp());
bfe038ff
MK
307 }
308 return -1;
ce2388e0 309 }
866e5b51 310}
This page took 0.116988 seconds and 5 git commands to generate.