1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertFalse
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assume
.assumeTrue
;
20 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
21 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
22 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTrace
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTraceReader
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * The class <code>CTFTraceReaderTest</code> contains tests for the class
30 * <code>{@link CTFTraceReader}</code>.
33 * @version $Revision: 1.0 $
35 @SuppressWarnings("javadoc")
36 public class CTFTraceReaderTest
{
38 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
40 private CTFTraceReader fixture
;
43 * Perform pre-test initialization.
45 * @throws CTFException
48 public void setUp() throws CTFException
{
49 assumeTrue(testTrace
.exists());
50 fixture
= new CTFTraceReader(testTrace
.getTrace());
54 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
57 * @throws CTFException
60 public void testOpen_existing() throws CTFException
{
61 CTFTrace trace
= testTrace
.getTrace();
62 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
63 assertNotNull(result
);
68 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
69 * trace, expect the exception.
71 * @throws CTFException
73 @Test(expected
= org
.eclipse
.tracecompass
.ctf
.core
.CTFException
.class)
74 public void testOpen_nonexisting() throws CTFException
{
75 CTFTrace trace
= new CTFTrace("badfile.bad");
76 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
77 assertNotNull(result
);
82 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
83 * path, expect exception.
85 * @throws CTFException
87 @Test(expected
= org
.eclipse
.tracecompass
.ctf
.core
.CTFException
.class)
88 public void testOpen_invalid() throws CTFException
{
89 CTFTrace trace
= new CTFTrace("");
90 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
91 assertNotNull(result
);
96 * Run the boolean advance() method test. Test advancing normally.
98 * @throws CTFException
102 public void testAdvance_normal() throws CTFException
{
103 boolean result
= fixture
.advance();
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.
111 * @throws CTFException
115 public void testAdvance_end() throws CTFException
{
117 boolean result
= fixture
.advance();
119 result
= fixture
.advance();
124 fixture
.goToLastEvent();
126 result
= fixture
.advance();
128 result
= fixture
.advance();
136 * Run the CTFTraceReader copy constructor test.
138 * @throws CTFException
142 public void testCopyFrom() throws CTFException
{
143 try (CTFTraceReader result
= fixture
.copyFrom();) {
144 assertNotNull(result
);
149 * Test the hashCode method.
152 public void testHash() {
153 int result
= fixture
.hashCode();
154 assertTrue(0 != result
);
158 * Test the equals method. Uses the class-wide 'fixture' and another
159 * method-local 'fixture2', which both point to the same trace.
161 * Both trace reader are different objects, so they shouldn't "equals" each
164 * @throws CTFException
167 public void testEquals() throws CTFException
{
168 try (CTFTraceReader fixture2
= new CTFTraceReader(testTrace
.getTrace());) {
169 assertEquals(fixture
, fixture2
);
174 * Run the getCurrentEventDef() method test. Get the first event's
178 public void testGetCurrentEventDef_first() {
179 EventDefinition result
= fixture
.getCurrentEventDef();
180 assertNotNull(result
);
184 * Run the getCurrentEventDef() method test. Get the last event's
187 * @throws CTFException
191 public void testGetCurrentEventDef_last() throws CTFException
{
192 fixture
.goToLastEvent();
193 EventDefinition result
= fixture
.getCurrentEventDef();
194 assertNotNull(result
);
198 * Run the long getEndTime() method test.
201 public void testGetEndTime() {
202 long result
= fixture
.getEndTime();
203 assertTrue(0L < result
);
207 * Run the long getStartTime() method test.
210 public void testGetStartTime() {
211 long result
= fixture
.getStartTime();
212 assertTrue(0L < result
);
216 * Run the void goToLastEvent() method test.
218 * @throws CTFException
222 public void testGoToLastEvent() throws CTFException
{
223 fixture
.goToLastEvent();
224 long ts1
= getTimestamp();
225 long ts2
= fixture
.getEndTime();
226 assertEquals(ts1
, ts2
);
230 * Run the boolean hasMoreEvents() method test.
232 * @throws CTFException
235 public void testHasMoreEvents() {
236 boolean result
= fixture
.hasMoreEvents();
241 * Run the void printStats() method test with no 'width' parameter.
243 * @throws CTFException
247 public void testPrintStats_noparam() throws CTFException
{
249 fixture
.printStats();
253 * Run the void printStats(int) method test with width = 0.
255 * @throws CTFException
259 public void testPrintStats_width0() throws CTFException
{
261 fixture
.printStats(0);
265 * Run the void printStats(int) method test with width = 1.
267 * @throws CTFException
271 public void testPrintStats_width1() throws CTFException
{
273 fixture
.printStats(1);
277 * Run the void printStats(int) method test with width = 2.
279 * @throws CTFException
283 public void testPrintStats_width2() throws CTFException
{
285 fixture
.printStats(2);
289 * Run the void printStats(int) method test with width = 10.
291 * @throws CTFException
295 public void testPrintStats_width10() throws CTFException
{
297 fixture
.printStats(10);
301 * Run the void printStats(int) method test with width = 100.
303 * @throws CTFException
307 public void testPrintStats_100() throws CTFException
{
308 for (int i
= 0; i
< 1000; i
++) {
311 fixture
.printStats(100);
315 * Run the boolean seek(long) method test.
317 * @throws CTFException
321 public void testSeek() throws CTFException
{
323 boolean result
= fixture
.seek(timestamp
);
330 private long getTimestamp() {
331 if (fixture
.getCurrentEventDef() != null) {
332 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.039885 seconds and 6 git commands to generate.