1e7f7b6b490a12fe3190279cdd40f03dc78ee2e1
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.
40 * @throws CTFReaderException
43 public void setUp() throws CTFReaderException
{
44 fixture
= new CTFTraceReader(TestParams
.createTrace());
48 * Perform post-test clean-up.
51 public void tearDown() {
52 // Add additional tear down code here
56 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
58 * @throws CTFReaderException
61 public void testOpen_existing() throws CTFReaderException
{
62 CTFTrace trace
= TestParams
.createTrace();
64 CTFTraceReader result
= new CTFTraceReader(trace
);
65 assertNotNull(result
);
69 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
70 * trace, expect the exception.
72 * @throws CTFReaderException
74 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
75 public void testOpen_nonexisting() throws CTFReaderException
{
76 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
78 CTFTraceReader result
= new CTFTraceReader(trace
);
79 assertNotNull(result
);
83 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
84 * path, expect exception.
86 * @throws CTFReaderException
88 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
89 public void testOpen_invalid() throws CTFReaderException
{
90 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
92 CTFTraceReader result
= new CTFTraceReader(trace
);
93 assertNotNull(result
);
97 * Run the boolean advance() method test. Test advancing normally.
100 public void testAdvance_normal() {
101 boolean result
= fixture
.advance();
106 * Run the boolean advance() method test. Test advancing when we're at the
107 * end, so we expect that there is no more events.
109 * @throws CTFReaderException
112 public void testAdvance_end() throws CTFReaderException
{
113 fixture
.goToLastEvent();
114 while (fixture
.hasMoreEvents()) {
117 boolean result
= fixture
.advance();
122 * Run the CTFTraceReader copy constructor test.
125 public void testCopyFrom() {
126 CTFTraceReader result
= fixture
.copyFrom();
127 assertNotNull(result
);
131 * Test the hashCode method.
134 public void testHash() {
135 int result
= fixture
.hashCode();
136 assertTrue(0 != result
);
140 * Test the equals method. Uses the class-wide 'fixture' and another
141 * method-local 'fixture2', which both point to the same trace.
143 * Both trace reader are different objects, so they shouldn't "equals" each
145 * @throws CTFReaderException
148 public void testEquals() throws CTFReaderException
{
149 CTFTraceReader fixture2
= new CTFTraceReader(TestParams
.createTrace());
150 assertFalse(fixture
.equals(fixture2
));
154 * Run the getCurrentEventDef() method test. Get the first event's
158 public void testGetCurrentEventDef_first() {
159 EventDefinition result
= fixture
.getCurrentEventDef();
160 assertNotNull(result
);
164 * Run the getCurrentEventDef() method test. Get the last event's
167 * @throws CTFReaderException
170 public void testGetCurrentEventDef_last() throws CTFReaderException
{
171 fixture
.goToLastEvent();
172 EventDefinition result
= fixture
.getCurrentEventDef();
173 assertNotNull(result
);
177 * Run the long getEndTime() method test.
180 public void testGetEndTime() {
181 long result
= fixture
.getEndTime();
182 assertTrue(0L < result
);
186 * Run the long getStartTime() method test.
189 public void testGetStartTime() {
190 long result
= fixture
.getStartTime();
191 assertTrue(0L < result
);
195 * Run the void goToLastEvent() method test.
197 * @throws CTFReaderException
200 public void testGoToLastEvent() throws CTFReaderException
{
201 fixture
.goToLastEvent();
202 long ts1
= getTimestamp();
203 long ts2
= fixture
.getEndTime();
204 // the end time can be later than the last event.
205 assertTrue(ts1
<= ts2
);
209 * Run the boolean hasMoreEvents() method test.
211 * @throws CTFReaderException
214 public void testHasMoreEvents() {
215 boolean result
= fixture
.hasMoreEvents();
220 * Run the void printStats() method test with no 'width' parameter.
223 public void testPrintStats_noparam() {
225 fixture
.printStats();
229 * Run the void printStats(int) method test with width = 0.
232 public void testPrintStats_width0() {
234 fixture
.printStats(0);
238 * Run the void printStats(int) method test with width = 1.
241 public void testPrintStats_width1() {
243 fixture
.printStats(1);
247 * Run the void printStats(int) method test with width = 2.
250 public void testPrintStats_width2() {
252 fixture
.printStats(2);
256 * Run the void printStats(int) method test with width = 10.
259 public void testPrintStats_width10() {
261 fixture
.printStats(10);
265 * Run the void printStats(int) method test with width = 100.
268 public void testPrintStats_100() {
269 for (int i
= 0; i
< 1000; i
++) {
272 fixture
.printStats(100);
276 * Run the boolean seek(long) method test.
279 public void testSeek() {
281 boolean result
= fixture
.seek(timestamp
);
287 * Run the boolean seek(long) method test.
288 * @throws CTFReaderException
291 public void testSeekIndex() throws CTFReaderException
{
293 long first
, second
= 0, third
, fourth
;
295 * we need to read the trace before seeking
297 first
= getTimestamp();
298 for( int i
= 0 ; i
< 60000; i
++ )
301 second
= getTimestamp();
305 boolean result
= fixture
.seekIndex(0);
306 third
= getTimestamp();
307 boolean result2
= fixture
.seekIndex(rank
);
308 fourth
= getTimestamp();
311 assertEquals( first
, third
);
312 assertEquals( second
, fourth
);
318 private long getTimestamp() {
319 return fixture
.getCurrentEventDef().timestamp
;
This page took 0.0381 seconds and 5 git commands to generate.