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
;
19 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
20 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
21 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTraceUtils
;
22 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTraceReader
;
24 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
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 fixture
= new CTFTraceReader(CtfTestTraceUtils
.getTrace(testTrace
));
53 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
56 * @throws CTFException
59 public void testOpen_existing() throws CTFException
{
60 CTFTrace trace
= CtfTestTraceUtils
.getTrace(testTrace
);
61 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
62 assertNotNull(result
);
67 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
68 * trace, expect the exception.
70 * @throws CTFException
72 @Test(expected
= org
.eclipse
.tracecompass
.ctf
.core
.CTFException
.class)
73 public void testOpen_nonexisting() throws CTFException
{
74 CTFTrace trace
= new CTFTrace("badfile.bad");
75 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
76 assertNotNull(result
);
81 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
82 * path, expect exception.
84 * @throws CTFException
86 @Test(expected
= org
.eclipse
.tracecompass
.ctf
.core
.CTFException
.class)
87 public void testOpen_invalid() throws CTFException
{
88 CTFTrace trace
= new CTFTrace("");
89 try (CTFTraceReader result
= new CTFTraceReader(trace
);) {
90 assertNotNull(result
);
95 * Run the boolean advance() method test. Test advancing normally.
97 * @throws CTFException
101 public void testAdvance_normal() throws CTFException
{
102 boolean result
= fixture
.advance();
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.
110 * @throws CTFException
114 public void testAdvance_end() throws CTFException
{
116 boolean result
= fixture
.advance();
118 result
= fixture
.advance();
123 fixture
.goToLastEvent();
125 result
= fixture
.advance();
127 result
= fixture
.advance();
135 * Run the CTFTraceReader copy constructor test.
137 * @throws CTFException
141 public void testCopyFrom() throws CTFException
{
142 try (CTFTraceReader result
= fixture
.copyFrom();) {
143 assertNotNull(result
);
148 * Run the getCurrentEventDef() method test. Get the first event's
152 public void testGetCurrentEventDef_first() {
153 EventDefinition result
= fixture
.getCurrentEventDef();
154 assertNotNull(result
);
158 * Run the getCurrentEventDef() method test. Get the last event's
161 * @throws CTFException
165 public void testGetCurrentEventDef_last() throws CTFException
{
166 fixture
.goToLastEvent();
167 EventDefinition result
= fixture
.getCurrentEventDef();
168 assertNotNull(result
);
172 * Run the long getEndTime() method test.
175 public void testGetEndTime() {
176 long result
= fixture
.getEndTime();
177 assertTrue(0L < result
);
181 * Run the long getStartTime() method test.
184 public void testGetStartTime() {
185 long result
= fixture
.getStartTime();
186 assertTrue(0L < result
);
190 * Run the void goToLastEvent() method test.
192 * @throws CTFException
196 public void testGoToLastEvent() throws CTFException
{
197 fixture
.goToLastEvent();
198 long ts1
= getTimestamp();
199 long ts2
= fixture
.getEndTime();
200 assertEquals(ts1
, ts2
);
204 * Run the boolean hasMoreEvents() method test.
206 * @throws CTFException
209 public void testHasMoreEvents() {
210 boolean result
= fixture
.hasMoreEvents();
215 * Run the void printStats() method test with no 'width' parameter.
217 * @throws CTFException
221 public void testPrintStats_noparam() throws CTFException
{
223 fixture
.printStats();
227 * Run the void printStats(int) method test with width = 0.
229 * @throws CTFException
233 public void testPrintStats_width0() throws CTFException
{
235 fixture
.printStats(0);
239 * Run the void printStats(int) method test with width = 1.
241 * @throws CTFException
245 public void testPrintStats_width1() throws CTFException
{
247 fixture
.printStats(1);
251 * Run the void printStats(int) method test with width = 2.
253 * @throws CTFException
257 public void testPrintStats_width2() throws CTFException
{
259 fixture
.printStats(2);
263 * Run the void printStats(int) method test with width = 10.
265 * @throws CTFException
269 public void testPrintStats_width10() throws CTFException
{
271 fixture
.printStats(10);
275 * Run the void printStats(int) method test with width = 100.
277 * @throws CTFException
281 public void testPrintStats_100() throws CTFException
{
282 for (int i
= 0; i
< 1000; i
++) {
285 fixture
.printStats(100);
289 * Run the boolean seek(long) method test.
291 * @throws CTFException
295 public void testSeek() throws CTFException
{
297 boolean result
= fixture
.seek(timestamp
);
304 private long getTimestamp() {
305 if (fixture
.getCurrentEventDef() != null) {
306 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.037658 seconds and 5 git commands to generate.