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
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
13 import org
.junit
.After
;
14 import org
.junit
.Before
;
15 import org
.junit
.Test
;
18 * The class <code>CTFTraceReaderTest</code> contains tests for the class
19 * <code>{@link CTFTraceReader}</code>.
22 * @version $Revision: 1.0 $
24 @SuppressWarnings("javadoc")
25 public class CTFTraceReaderTest
{
27 CTFTraceReader fixture
;
33 * the command line arguments
35 public static void main(String
[] args
) {
36 new org
.junit
.runner
.JUnitCore().run(CTFTraceReaderTest
.class);
40 * Perform pre-test initialization.
42 * @throws CTFReaderException
45 public void setUp() throws CTFReaderException
{
46 fixture
= new CTFTraceReader(TestParams
.createTrace());
50 * Perform post-test clean-up.
53 public void tearDown() {
54 // Add additional tear down code here
58 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
61 * @throws CTFReaderException
64 public void testOpen_existing() throws CTFReaderException
{
65 CTFTrace trace
= TestParams
.createTrace();
67 CTFTraceReader result
= new CTFTraceReader(trace
);
68 assertNotNull(result
);
72 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
73 * trace, expect the exception.
75 * @throws CTFReaderException
77 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
78 public void testOpen_nonexisting() throws CTFReaderException
{
79 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
81 CTFTraceReader result
= new CTFTraceReader(trace
);
82 assertNotNull(result
);
86 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
87 * path, expect exception.
89 * @throws CTFReaderException
91 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
92 public void testOpen_invalid() throws CTFReaderException
{
93 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
95 CTFTraceReader result
= new CTFTraceReader(trace
);
96 assertNotNull(result
);
100 * Run the boolean advance() method test. Test advancing normally.
103 public void testAdvance_normal() {
104 boolean result
= fixture
.advance();
109 * Run the boolean advance() method test. Test advancing when we're at the
110 * end, so we expect that there is no more events.
113 public void testAdvance_end() {
115 boolean result
= fixture
.advance();
117 result
= fixture
.advance();
122 fixture
.goToLastEvent();
124 result
= fixture
.advance();
126 result
= fixture
.advance();
134 * Run the CTFTraceReader copy constructor test.
137 public void testCopyFrom() {
138 CTFTraceReader result
= fixture
.copyFrom();
139 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 CTFTraceReader fixture2
= new CTFTraceReader(TestParams
.createTrace());
163 assertEquals(fixture
, fixture2
);
167 * Run the getCurrentEventDef() method test. Get the first event's
171 public void testGetCurrentEventDef_first() {
172 EventDefinition result
= fixture
.getCurrentEventDef();
173 assertNotNull(result
);
177 * Run the getCurrentEventDef() method test. Get the last event's
181 public void testGetCurrentEventDef_last() {
182 fixture
.goToLastEvent();
183 EventDefinition result
= fixture
.getCurrentEventDef();
184 assertNotNull(result
);
188 * Run the long getEndTime() method test.
191 public void testGetEndTime() {
192 long result
= fixture
.getEndTime();
193 assertTrue(0L < result
);
197 * Run the long getStartTime() method test.
200 public void testGetStartTime() {
201 long result
= fixture
.getStartTime();
202 assertTrue(0L < result
);
206 * Run the void goToLastEvent() method test.
209 public void testGoToLastEvent() {
210 fixture
.goToLastEvent();
211 long ts1
= getTimestamp();
212 long ts2
= fixture
.getEndTime();
213 assertEquals(ts1
, ts2
);
217 * Run the boolean hasMoreEvents() method test.
219 * @throws CTFReaderException
222 public void testHasMoreEvents() {
223 boolean result
= fixture
.hasMoreEvents();
228 * Run the void printStats() method test with no 'width' parameter.
231 public void testPrintStats_noparam() {
233 fixture
.printStats();
237 * Run the void printStats(int) method test with width = 0.
240 public void testPrintStats_width0() {
242 fixture
.printStats(0);
246 * Run the void printStats(int) method test with width = 1.
249 public void testPrintStats_width1() {
251 fixture
.printStats(1);
255 * Run the void printStats(int) method test with width = 2.
258 public void testPrintStats_width2() {
260 fixture
.printStats(2);
264 * Run the void printStats(int) method test with width = 10.
267 public void testPrintStats_width10() {
269 fixture
.printStats(10);
273 * Run the void printStats(int) method test with width = 100.
276 public void testPrintStats_100() {
277 for (int i
= 0; i
< 1000; i
++) {
280 fixture
.printStats(100);
284 * Run the boolean seek(long) method test.
287 public void testSeek() {
289 boolean result
= fixture
.seek(timestamp
);
298 private long getTimestamp() {
299 if (fixture
.getCurrentEventDef() != null) {
300 return fixture
.getTrace().timestampCyclesToNanos(fixture
.getCurrentEventDef().getTimestamp());
This page took 0.039622 seconds and 5 git commands to generate.