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 public class CTFTraceReaderTest
{
26 CTFTraceReader fixture
;
32 * the command line arguments
34 public static void main(String
[] args
) {
35 new org
.junit
.runner
.JUnitCore().run(CTFTraceReaderTest
.class);
39 * Perform pre-test initialization.
41 * @throws CTFReaderException
44 public void setUp() throws CTFReaderException
{
45 fixture
= new CTFTraceReader(TestParams
.createTrace());
49 * Perform post-test clean-up.
52 public void tearDown() {
53 // Add additional tear down code here
57 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
60 * @throws CTFReaderException
63 public void testOpen_existing() throws CTFReaderException
{
64 CTFTrace trace
= TestParams
.createTrace();
66 CTFTraceReader result
= new CTFTraceReader(trace
);
67 assertNotNull(result
);
71 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
72 * trace, expect the exception.
74 * @throws CTFReaderException
76 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
77 public void testOpen_nonexisting() throws CTFReaderException
{
78 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
80 CTFTraceReader result
= new CTFTraceReader(trace
);
81 assertNotNull(result
);
85 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
86 * path, expect exception.
88 * @throws CTFReaderException
90 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
91 public void testOpen_invalid() throws CTFReaderException
{
92 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
94 CTFTraceReader result
= new CTFTraceReader(trace
);
95 assertNotNull(result
);
99 * Run the boolean advance() method test. Test advancing normally.
102 public void testAdvance_normal() {
103 boolean result
= fixture
.advance();
108 * Run the boolean advance() method test. Test advancing when we're at the
109 * end, so we expect that there is no more events.
112 public void testAdvance_end() {
114 boolean result
= fixture
.advance();
116 result
= fixture
.advance();
121 fixture
.goToLastEvent();
123 result
= fixture
.advance();
125 result
= fixture
.advance();
133 * Run the CTFTraceReader copy constructor test.
136 public void testCopyFrom() {
137 CTFTraceReader result
= fixture
.copyFrom();
138 assertNotNull(result
);
142 * Test the hashCode method.
145 public void testHash() {
146 int result
= fixture
.hashCode();
147 assertTrue(0 != result
);
151 * Test the equals method. Uses the class-wide 'fixture' and another
152 * method-local 'fixture2', which both point to the same trace.
154 * Both trace reader are different objects, so they shouldn't "equals" each
157 * @throws CTFReaderException
160 public void testEquals() throws CTFReaderException
{
161 CTFTraceReader fixture2
= new CTFTraceReader(TestParams
.createTrace());
162 assertEquals(fixture
, fixture2
);
166 * Run the getCurrentEventDef() method test. Get the first event's
170 public void testGetCurrentEventDef_first() {
171 EventDefinition result
= fixture
.getCurrentEventDef();
172 assertNotNull(result
);
176 * Run the getCurrentEventDef() method test. Get the last event's
180 public void testGetCurrentEventDef_last() {
181 fixture
.goToLastEvent();
182 EventDefinition result
= fixture
.getCurrentEventDef();
183 assertNotNull(result
);
187 * Run the long getEndTime() method test.
190 public void testGetEndTime() {
191 long result
= fixture
.getEndTime();
192 assertTrue(0L < result
);
196 * Run the long getStartTime() method test.
199 public void testGetStartTime() {
200 long result
= fixture
.getStartTime();
201 assertTrue(0L < result
);
205 * Run the void goToLastEvent() method test.
207 * @throws CTFReaderException
210 public void testGoToLastEvent() throws CTFReaderException
{
211 fixture
.goToLastEvent();
212 long ts1
= getTimestamp();
213 long ts2
= fixture
.getEndTime();
214 assertEquals(ts1
, ts2
);
218 * Run the boolean hasMoreEvents() method test.
220 * @throws CTFReaderException
223 public void testHasMoreEvents() {
224 boolean result
= fixture
.hasMoreEvents();
229 * Run the void printStats() method test with no 'width' parameter.
232 public void testPrintStats_noparam() {
234 fixture
.printStats();
238 * Run the void printStats(int) method test with width = 0.
241 public void testPrintStats_width0() {
243 fixture
.printStats(0);
247 * Run the void printStats(int) method test with width = 1.
250 public void testPrintStats_width1() {
252 fixture
.printStats(1);
256 * Run the void printStats(int) method test with width = 2.
259 public void testPrintStats_width2() {
261 fixture
.printStats(2);
265 * Run the void printStats(int) method test with width = 10.
268 public void testPrintStats_width10() {
270 fixture
.printStats(10);
274 * Run the void printStats(int) method test with width = 100.
277 public void testPrintStats_100() {
278 for (int i
= 0; i
< 1000; i
++) {
281 fixture
.printStats(100);
285 * Run the boolean seek(long) method test.
288 public void testSeek() {
290 boolean result
= fixture
.seek(timestamp
);
299 private long getTimestamp() {
300 if (fixture
.getCurrentEventDef() != null) {
301 return fixture
.getCurrentEventDef().getTimestamp()+ this.fixture
.getTrace().getOffset();
This page took 0.036673 seconds and 5 git commands to generate.