c9ceb3fef96b64712a7d03f8603a6f4145ef898d
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
.CtfTestTraces
;
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
.After
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * The class <code>CTFTraceReaderTest</code> contains tests for the class
31 * <code>{@link CTFTraceReader}</code>.
34 * @version $Revision: 1.0 $
36 @SuppressWarnings("javadoc")
37 public class CTFTraceReaderTest
{
39 private static final int TRACE_INDEX
= 0;
41 private CTFTraceReader fixture
;
47 * the command line arguments
49 public static void main(String
[] args
) {
50 new org
.junit
.runner
.JUnitCore().run(CTFTraceReaderTest
.class);
54 * Perform pre-test initialization.
56 * @throws CTFReaderException
59 public void setUp() throws CTFReaderException
{
60 assumeTrue(CtfTestTraces
.tracesExist());
61 fixture
= new CTFTraceReader(CtfTestTraces
.getTestTrace(TRACE_INDEX
));
65 * Perform post-test clean-up.
68 public void tearDown() {
69 // Add additional tear down code here
73 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
76 * @throws CTFReaderException
79 public void testOpen_existing() throws CTFReaderException
{
80 CTFTrace trace
= CtfTestTraces
.getTestTrace(TRACE_INDEX
);
82 CTFTraceReader result
= new CTFTraceReader(trace
);
83 assertNotNull(result
);
87 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
88 * trace, expect the exception.
90 * @throws CTFReaderException
92 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
93 public void testOpen_nonexisting() throws CTFReaderException
{
94 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
96 CTFTraceReader result
= new CTFTraceReader(trace
);
97 assertNotNull(result
);
101 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
102 * path, expect exception.
104 * @throws CTFReaderException
106 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
107 public void testOpen_invalid() throws CTFReaderException
{
108 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
110 CTFTraceReader result
= new CTFTraceReader(trace
);
111 assertNotNull(result
);
115 * Run the boolean advance() method test. Test advancing normally.
118 public void testAdvance_normal() {
119 boolean result
= fixture
.advance();
124 * Run the boolean advance() method test. Test advancing when we're at the
125 * end, so we expect that there is no more events.
128 public void testAdvance_end() {
130 boolean result
= fixture
.advance();
132 result
= fixture
.advance();
137 fixture
.goToLastEvent();
139 result
= fixture
.advance();
141 result
= fixture
.advance();
149 * Run the CTFTraceReader copy constructor test.
152 public void testCopyFrom() {
153 CTFTraceReader result
= fixture
.copyFrom();
154 assertNotNull(result
);
158 * Test the hashCode method.
161 public void testHash() {
162 int result
= fixture
.hashCode();
163 assertTrue(0 != result
);
167 * Test the equals method. Uses the class-wide 'fixture' and another
168 * method-local 'fixture2', which both point to the same trace.
170 * Both trace reader are different objects, so they shouldn't "equals" each
173 * @throws CTFReaderException
176 public void testEquals() throws CTFReaderException
{
177 CTFTraceReader fixture2
= new CTFTraceReader(CtfTestTraces
.getTestTrace(TRACE_INDEX
));
178 assertEquals(fixture
, fixture2
);
182 * Run the getCurrentEventDef() method test. Get the first event's
186 public void testGetCurrentEventDef_first() {
187 EventDefinition result
= fixture
.getCurrentEventDef();
188 assertNotNull(result
);
192 * Run the getCurrentEventDef() method test. Get the last event's
196 public void testGetCurrentEventDef_last() {
197 fixture
.goToLastEvent();
198 EventDefinition result
= fixture
.getCurrentEventDef();
199 assertNotNull(result
);
203 * Run the long getEndTime() method test.
206 public void testGetEndTime() {
207 long result
= fixture
.getEndTime();
208 assertTrue(0L < result
);
212 * Run the long getStartTime() method test.
215 public void testGetStartTime() {
216 long result
= fixture
.getStartTime();
217 assertTrue(0L < result
);
221 * Run the void goToLastEvent() method test.
224 public void testGoToLastEvent() {
225 fixture
.goToLastEvent();
226 long ts1
= getTimestamp();
227 long ts2
= fixture
.getEndTime();
228 assertEquals(ts1
, ts2
);
232 * Run the boolean hasMoreEvents() method test.
234 * @throws CTFReaderException
237 public void testHasMoreEvents() {
238 boolean result
= fixture
.hasMoreEvents();
243 * Run the void printStats() method test with no 'width' parameter.
246 public void testPrintStats_noparam() {
248 fixture
.printStats();
252 * Run the void printStats(int) method test with width = 0.
255 public void testPrintStats_width0() {
257 fixture
.printStats(0);
261 * Run the void printStats(int) method test with width = 1.
264 public void testPrintStats_width1() {
266 fixture
.printStats(1);
270 * Run the void printStats(int) method test with width = 2.
273 public void testPrintStats_width2() {
275 fixture
.printStats(2);
279 * Run the void printStats(int) method test with width = 10.
282 public void testPrintStats_width10() {
284 fixture
.printStats(10);
288 * Run the void printStats(int) method test with width = 100.
291 public void testPrintStats_100() {
292 for (int i
= 0; i
< 1000; i
++) {
295 fixture
.printStats(100);
299 * Run the boolean seek(long) method test.
302 public void testSeek() {
304 boolean result
= fixture
.seek(timestamp
);
313 private long getTimestamp() {
314 if (fixture
.getCurrentEventDef() != null) {
315 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.037095 seconds and 5 git commands to generate.