5c8b9282c162224ce5069bf3e10ee19667e7261d
1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
3 import static org
.junit
.Assert
.assertFalse
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
7 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
12 import org
.junit
.After
;
13 import org
.junit
.Before
;
14 import org
.junit
.Test
;
17 * The class <code>CTFTraceReaderTest</code> contains tests for the class
18 * <code>{@link CTFTraceReader}</code>.
21 * @version $Revision: 1.0 $
23 public class CTFTraceReaderTest
{
25 CTFTraceReader fixture
;
31 * the command line arguments
33 public static void main(String
[] args
) {
34 new org
.junit
.runner
.JUnitCore().run(CTFTraceReaderTest
.class);
38 * Perform pre-test initialization.
39 * @throws CTFReaderException
42 public void setUp() throws CTFReaderException
{
43 fixture
= new CTFTraceReader(TestParams
.createTrace());
47 * Perform post-test clean-up.
50 public void tearDown() {
51 // Add additional tear down code here
55 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
57 * @throws CTFReaderException
60 public void testOpen_existing() throws CTFReaderException
{
61 CTFTrace trace
= TestParams
.createTrace();
63 CTFTraceReader result
= new CTFTraceReader(trace
);
64 assertNotNull(result
);
68 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
69 * trace, expect the exception.
71 * @throws CTFReaderException
73 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
74 public void testOpen_nonexisting() throws CTFReaderException
{
75 CTFTrace trace
= new CTFTrace("badfile.bad"); //$NON-NLS-1$
77 CTFTraceReader result
= new CTFTraceReader(trace
);
78 assertNotNull(result
);
82 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
83 * path, expect exception.
85 * @throws CTFReaderException
87 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
88 public void testOpen_invalid() throws CTFReaderException
{
89 CTFTrace trace
= new CTFTrace(""); //$NON-NLS-1$
91 CTFTraceReader result
= new CTFTraceReader(trace
);
92 assertNotNull(result
);
96 * Run the boolean advance() method test. Test advancing normally.
99 public void testAdvance_normal() {
100 boolean result
= fixture
.advance();
105 * Run the boolean advance() method test. Test advancing when we're at the
106 * end, so we expect that there is no more events.
108 * @throws CTFReaderException
111 public void testAdvance_end() throws CTFReaderException
{
112 fixture
.goToLastEvent();
113 while (fixture
.hasMoreEvents()) {
116 boolean result
= fixture
.advance();
121 * Run the CTFTraceReader copy constructor test.
124 public void testCopyFrom() {
125 CTFTraceReader result
= fixture
.copyFrom();
126 assertNotNull(result
);
130 * Test the hashCode method.
133 public void testHash() {
134 int result
= fixture
.hashCode();
135 assertTrue(0 != result
);
139 * Test the equals method. Uses the class-wide 'fixture' and another
140 * method-local 'fixture2', which both point to the same trace.
142 * Both trace reader are different objects, so they shouldn't "equals" each
144 * @throws CTFReaderException
147 public void testEquals() throws CTFReaderException
{
148 CTFTraceReader fixture2
= new CTFTraceReader(TestParams
.createTrace());
149 assertFalse(fixture
.equals(fixture2
));
153 * Run the getCurrentEventDef() method test. Get the first event's
157 public void testGetCurrentEventDef_first() {
158 EventDefinition result
= fixture
.getCurrentEventDef();
159 assertNotNull(result
);
163 * Run the getCurrentEventDef() method test. Get the last event's
166 * @throws CTFReaderException
169 public void testGetCurrentEventDef_last() throws CTFReaderException
{
170 fixture
.goToLastEvent();
171 EventDefinition result
= fixture
.getCurrentEventDef();
172 assertNotNull(result
);
176 * Run the long getEndTime() method test.
179 public void testGetEndTime() {
180 long result
= fixture
.getEndTime();
181 assertTrue(0L < result
);
185 * Run the long getStartTime() method test.
188 public void testGetStartTime() {
189 long result
= fixture
.getStartTime();
190 assertTrue(0L < result
);
194 * Run the void goToLastEvent() method test.
196 * @throws CTFReaderException
199 public void testGoToLastEvent() throws CTFReaderException
{
200 fixture
.goToLastEvent();
201 long ts1
= fixture
.getCurrentEventDef().timestamp
;
202 long ts2
= fixture
.getEndTime();
203 assertTrue(ts1
== ts2
);
207 * Run the boolean hasMoreEvents() method test.
209 * @throws CTFReaderException
212 public void testHasMoreEvents() {
213 boolean result
= fixture
.hasMoreEvents();
218 * Run the void printStats() method test with no 'width' parameter.
221 public void testPrintStats_noparam() {
223 fixture
.printStats();
227 * Run the void printStats(int) method test with width = 0.
230 public void testPrintStats_width0() {
232 fixture
.printStats(0);
236 * Run the void printStats(int) method test with width = 1.
239 public void testPrintStats_width1() {
241 fixture
.printStats(1);
245 * Run the void printStats(int) method test with width = 2.
248 public void testPrintStats_width2() {
250 fixture
.printStats(2);
254 * Run the void printStats(int) method test with width = 10.
257 public void testPrintStats_width10() {
259 fixture
.printStats(10);
263 * Run the void printStats(int) method test with width = 100.
266 public void testPrintStats_100() {
267 for (int i
= 0; i
< 1000; i
++) {
270 fixture
.printStats(100);
274 * Run the boolean seek(long) method test.
277 public void testSeek() {
279 boolean result
= fixture
.seek(timestamp
);
This page took 0.039569 seconds and 5 git commands to generate.