1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertFalse
;
5 import static org
.junit
.Assert
.assertNotNull
;
6 import static org
.junit
.Assert
.assertTrue
;
7 import static org
.junit
.Assume
.assumeTrue
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.shared
.CtfTestTraces
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
14 import org
.junit
.After
;
15 import org
.junit
.Before
;
16 import org
.junit
.Test
;
19 * The class <code>CTFTraceReaderTest</code> contains tests for the class
20 * <code>{@link CTFTraceReader}</code>.
23 * @version $Revision: 1.0 $
25 @SuppressWarnings("javadoc")
26 public class CTFTraceReaderTest
{
28 private static final int TRACE_INDEX
= 0;
30 private CTFTraceReader fixture
;
36 * the command line arguments
38 public static void main(String
[] args
) {
39 new org
.junit
.runner
.JUnitCore().run(CTFTraceReaderTest
.class);
43 * Perform pre-test initialization.
45 * @throws CTFReaderException
48 public void setUp() throws CTFReaderException
{
49 assumeTrue(CtfTestTraces
.tracesExist());
50 fixture
= new CTFTraceReader(CtfTestTraces
.getTestTrace(TRACE_INDEX
));
54 * Perform post-test clean-up.
57 public void tearDown() {
58 // Add additional tear down code here
62 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
65 * @throws CTFReaderException
68 public void testOpen_existing() throws CTFReaderException
{
69 CTFTrace trace
= CtfTestTraces
.getTestTrace(TRACE_INDEX
);
71 CTFTraceReader result
= new CTFTraceReader(trace
);
72 assertNotNull(result
);
76 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
77 * trace, expect the exception.
79 * @throws CTFReaderException
81 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
82 public void testOpen_nonexisting() throws CTFReaderException
{
83 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
85 CTFTraceReader result
= new CTFTraceReader(trace
);
86 assertNotNull(result
);
90 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
91 * path, expect exception.
93 * @throws CTFReaderException
95 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
96 public void testOpen_invalid() throws CTFReaderException
{
97 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
99 CTFTraceReader result
= new CTFTraceReader(trace
);
100 assertNotNull(result
);
104 * Run the boolean advance() method test. Test advancing normally.
107 public void testAdvance_normal() {
108 boolean result
= fixture
.advance();
113 * Run the boolean advance() method test. Test advancing when we're at the
114 * end, so we expect that there is no more events.
117 public void testAdvance_end() {
119 boolean result
= fixture
.advance();
121 result
= fixture
.advance();
126 fixture
.goToLastEvent();
128 result
= fixture
.advance();
130 result
= fixture
.advance();
138 * Run the CTFTraceReader copy constructor test.
141 public void testCopyFrom() {
142 CTFTraceReader result
= fixture
.copyFrom();
143 assertNotNull(result
);
147 * Test the hashCode method.
150 public void testHash() {
151 int result
= fixture
.hashCode();
152 assertTrue(0 != result
);
156 * Test the equals method. Uses the class-wide 'fixture' and another
157 * method-local 'fixture2', which both point to the same trace.
159 * Both trace reader are different objects, so they shouldn't "equals" each
162 * @throws CTFReaderException
165 public void testEquals() throws CTFReaderException
{
166 CTFTraceReader fixture2
= new CTFTraceReader(CtfTestTraces
.getTestTrace(TRACE_INDEX
));
167 assertEquals(fixture
, fixture2
);
171 * Run the getCurrentEventDef() method test. Get the first event's
175 public void testGetCurrentEventDef_first() {
176 EventDefinition result
= fixture
.getCurrentEventDef();
177 assertNotNull(result
);
181 * Run the getCurrentEventDef() method test. Get the last event's
185 public void testGetCurrentEventDef_last() {
186 fixture
.goToLastEvent();
187 EventDefinition result
= fixture
.getCurrentEventDef();
188 assertNotNull(result
);
192 * Run the long getEndTime() method test.
195 public void testGetEndTime() {
196 long result
= fixture
.getEndTime();
197 assertTrue(0L < result
);
201 * Run the long getStartTime() method test.
204 public void testGetStartTime() {
205 long result
= fixture
.getStartTime();
206 assertTrue(0L < result
);
210 * Run the void goToLastEvent() method test.
213 public void testGoToLastEvent() {
214 fixture
.goToLastEvent();
215 long ts1
= getTimestamp();
216 long ts2
= fixture
.getEndTime();
217 assertEquals(ts1
, ts2
);
221 * Run the boolean hasMoreEvents() method test.
223 * @throws CTFReaderException
226 public void testHasMoreEvents() {
227 boolean result
= fixture
.hasMoreEvents();
232 * Run the void printStats() method test with no 'width' parameter.
235 public void testPrintStats_noparam() {
237 fixture
.printStats();
241 * Run the void printStats(int) method test with width = 0.
244 public void testPrintStats_width0() {
246 fixture
.printStats(0);
250 * Run the void printStats(int) method test with width = 1.
253 public void testPrintStats_width1() {
255 fixture
.printStats(1);
259 * Run the void printStats(int) method test with width = 2.
262 public void testPrintStats_width2() {
264 fixture
.printStats(2);
268 * Run the void printStats(int) method test with width = 10.
271 public void testPrintStats_width10() {
273 fixture
.printStats(10);
277 * Run the void printStats(int) method test with width = 100.
280 public void testPrintStats_100() {
281 for (int i
= 0; i
< 1000; i
++) {
284 fixture
.printStats(100);
288 * Run the boolean seek(long) method test.
291 public void testSeek() {
293 boolean result
= fixture
.seek(timestamp
);
302 private long getTimestamp() {
303 if (fixture
.getCurrentEventDef() != null) {
304 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.037946 seconds and 5 git commands to generate.