1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assert
.assertTrue
;
7 import java
.nio
.channels
.FileChannel
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDeclaration
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.Stream
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInput
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
19 import org
.junit
.After
;
20 import org
.junit
.Before
;
21 import org
.junit
.Test
;
24 * The class <code>StreamInputReaderTest</code> contains tests for the class
25 * <code>{@link StreamInputReader}</code>.
28 * @version $Revision: 1.0 $
30 @SuppressWarnings("javadoc")
31 public class StreamInputReaderTest
{
33 private StreamInputReader fixture
;
39 * the command line arguments
41 public static void main(String
[] args
) {
42 new org
.junit
.runner
.JUnitCore().run(StreamInputReaderTest
.class);
46 * Perform pre-test initialization.
48 * @throws CTFReaderException
51 public void setUp() throws CTFReaderException
{
52 fixture
= getStreamInputReader();
54 fixture
.setCurrentEvent(new EventDefinition(new EventDeclaration(),
55 getStreamInputReader()));
59 * Perform post-test clean-up.
62 public void tearDown() {
63 // Add additional tear down code here
66 private static StreamInputReader
getStreamInputReader() throws CTFReaderException
{
67 CTFTrace trace
= TestParams
.createTrace();
68 Stream s
= trace
.getStream((long) 0);
69 Set
<StreamInput
> streamInput
= s
.getStreamInputs();
70 StreamInputReader retVal
= null;
71 for (StreamInput si
: streamInput
) {
73 * For the tests, we'll use the stream input corresponding to the
76 if (si
.getFilename().endsWith("0_0")) { //$NON-NLS-1$
77 retVal
= new StreamInputReader(si
);
85 * Run the StreamInputReader(StreamInput) constructor test, with a valid
89 public void testStreamInputReader_valid() {
90 assertNotNull(fixture
);
94 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
97 * @throws CTFReaderException
99 @Test(expected
= CTFReaderException
.class)
100 public void testStreamInputReader_invalid() throws CTFReaderException
{
101 StreamInput streamInput
= new StreamInput(
102 new Stream(new CTFTrace("")), (FileChannel
) null, TestParams
.getEmptyFile()); //$NON-NLS-1$
104 StreamInputReader result
= new StreamInputReader(streamInput
);
105 assertNotNull(result
);
109 * Run the int getCPU() method test.
112 public void testGetCPU() {
113 int result
= fixture
.getCPU();
114 assertEquals(0, result
);
118 * Run the EventDefinition getCurrentEvent() method test.
121 public void testGetCurrentEvent() {
122 EventDefinition result
= fixture
.getCurrentEvent();
123 assertNotNull(result
);
127 * Run the StructDefinition getCurrentPacketContext() method test.
130 public void testGetCurrentPacketContext() {
131 StructDefinition result
= fixture
.getCurrentPacketContext();
132 assertNotNull(result
);
136 * Run the int getName() method test.
139 public void testGetName() {
140 int result
= fixture
.getName();
141 assertEquals(1, result
);
145 * Run the void goToLastEvent() method test.
148 public void testGoToLastEvent1() {
149 final long endTimestamp
= goToEnd();
150 final long endTime
= 4287422460315L;
151 assertEquals(endTime
, endTimestamp
);
155 * Run the void goToLastEvent() method test.
158 public void testGoToLastEvent2() {
160 while(fixture
.readNextEvent()) {
161 timestamp
= fixture
.getCurrentEvent().getTimestamp();
163 long endTimestamp
= goToEnd();
164 assertEquals(0 , timestamp
- endTimestamp
);
167 private long goToEnd() {
168 fixture
.goToLastEvent();
169 return fixture
.getCurrentEvent().getTimestamp();
173 * Run the boolean readNextEvent() method test.
176 public void testReadNextEvent() {
177 boolean result
= fixture
.readNextEvent();
182 * Run the void seek(long) method test. Seek by direct timestamp
185 public void testSeek_timestamp() {
187 fixture
.seek(timestamp
);
191 * Run the seek test. Seek by passing an EventDefinition to which we've
192 * given the timestamp we want.
194 * @throws CTFReaderException
197 public void testSeek_eventDefinition() throws CTFReaderException
{
198 EventDefinition eventDefinition
= new EventDefinition(
199 new EventDeclaration(), getStreamInputReader());
200 eventDefinition
.setTimestamp(1L);
201 fixture
.setCurrentEvent(eventDefinition
);