1 /*******************************************************************************
2 * Copyright (c) 2013 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
.linuxtools
.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
.linuxtools
.ctf
.core
.event
.EventDefinition
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.shared
.CtfTestTrace
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
24 import org
.eclipse
.linuxtools
.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 CTFReaderException
48 public void setUp() throws CTFReaderException
{
49 assumeTrue(testTrace
.exists());
50 fixture
= new CTFTraceReader(testTrace
.getTrace());
54 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
57 * @throws CTFReaderException
60 public void testOpen_existing() throws CTFReaderException
{
61 try (CTFTrace trace
= testTrace
.getTrace();
62 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 CTFReaderException
73 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
74 public void testOpen_nonexisting() throws CTFReaderException
{
75 try (CTFTrace trace
= new CTFTrace("badfile.bad");
76 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 CTFReaderException
87 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
88 public void testOpen_invalid() throws CTFReaderException
{
89 try (CTFTrace trace
= new CTFTrace("");
90 CTFTraceReader result
= new CTFTraceReader(trace
);) {
91 assertNotNull(result
);
96 * Run the boolean advance() method test. Test advancing normally.
97 * @throws CTFReaderException error
100 public void testAdvance_normal() throws CTFReaderException
{
101 boolean result
= fixture
.advance();
106 * Run the boolean advance() method test. Test advancing when we're at the
107 * end, so we expect that there is no more events.
108 * @throws CTFReaderException error
111 public void testAdvance_end() throws CTFReaderException
{
113 boolean result
= fixture
.advance();
115 result
= fixture
.advance();
120 fixture
.goToLastEvent();
122 result
= fixture
.advance();
124 result
= fixture
.advance();
132 * Run the CTFTraceReader copy constructor test.
133 * @throws CTFReaderException error
136 public void testCopyFrom() throws CTFReaderException
{
137 try (CTFTraceReader result
= fixture
.copyFrom();) {
138 assertNotNull(result
);
143 * Test the hashCode method.
146 public void testHash() {
147 int result
= fixture
.hashCode();
148 assertTrue(0 != result
);
152 * Test the equals method. Uses the class-wide 'fixture' and another
153 * method-local 'fixture2', which both point to the same trace.
155 * Both trace reader are different objects, so they shouldn't "equals" each
158 * @throws CTFReaderException
161 public void testEquals() throws CTFReaderException
{
162 try (CTFTraceReader fixture2
= new CTFTraceReader(testTrace
.getTrace());) {
163 assertEquals(fixture
, fixture2
);
168 * Run the getCurrentEventDef() method test. Get the first event's
172 public void testGetCurrentEventDef_first() {
173 EventDefinition result
= fixture
.getCurrentEventDef();
174 assertNotNull(result
);
178 * Run the getCurrentEventDef() method test. Get the last event's
180 * @throws CTFReaderException error
183 public void testGetCurrentEventDef_last() throws CTFReaderException
{
184 fixture
.goToLastEvent();
185 EventDefinition result
= fixture
.getCurrentEventDef();
186 assertNotNull(result
);
190 * Run the long getEndTime() method test.
193 public void testGetEndTime() {
194 long result
= fixture
.getEndTime();
195 assertTrue(0L < result
);
199 * Run the long getStartTime() method test.
202 public void testGetStartTime() {
203 long result
= fixture
.getStartTime();
204 assertTrue(0L < result
);
208 * Run the void goToLastEvent() method test.
209 * @throws CTFReaderException error
212 public void testGoToLastEvent() throws CTFReaderException
{
213 fixture
.goToLastEvent();
214 long ts1
= getTimestamp();
215 long ts2
= fixture
.getEndTime();
216 assertEquals(ts1
, ts2
);
220 * Run the boolean hasMoreEvents() method test.
222 * @throws CTFReaderException
225 public void testHasMoreEvents() {
226 boolean result
= fixture
.hasMoreEvents();
231 * Run the void printStats() method test with no 'width' parameter.
232 * @throws CTFReaderException error
235 public void testPrintStats_noparam() throws CTFReaderException
{
237 fixture
.printStats();
241 * Run the void printStats(int) method test with width = 0.
242 * @throws CTFReaderException error
245 public void testPrintStats_width0() throws CTFReaderException
{
247 fixture
.printStats(0);
251 * Run the void printStats(int) method test with width = 1.
252 * @throws CTFReaderException error
255 public void testPrintStats_width1() throws CTFReaderException
{
257 fixture
.printStats(1);
261 * Run the void printStats(int) method test with width = 2.
262 * @throws CTFReaderException error
265 public void testPrintStats_width2() throws CTFReaderException
{
267 fixture
.printStats(2);
271 * Run the void printStats(int) method test with width = 10.
272 * @throws CTFReaderException error
275 public void testPrintStats_width10() throws CTFReaderException
{
277 fixture
.printStats(10);
281 * Run the void printStats(int) method test with width = 100.
282 * @throws CTFReaderException error
285 public void testPrintStats_100() throws CTFReaderException
{
286 for (int i
= 0; i
< 1000; i
++) {
289 fixture
.printStats(100);
293 * Run the boolean seek(long) method test.
294 * @throws CTFReaderException error
297 public void testSeek() throws CTFReaderException
{
299 boolean result
= fixture
.seek(timestamp
);
308 private long getTimestamp() {
309 if (fixture
.getCurrentEventDef() != null) {
310 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.046971 seconds and 5 git commands to generate.