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 public class StreamInputReaderTest
{
32 private StreamInputReader fixture
;
38 * the command line arguments
40 public static void main(String
[] args
) {
41 new org
.junit
.runner
.JUnitCore().run(StreamInputReaderTest
.class);
45 * Perform pre-test initialization.
47 * @throws CTFReaderException
50 public void setUp() throws CTFReaderException
{
51 fixture
= getStreamInputReader();
53 fixture
.setCurrentEvent(new EventDefinition(new EventDeclaration(),
54 getStreamInputReader()));
58 * Perform post-test clean-up.
61 public void tearDown() {
62 // Add additional tear down code here
65 private static StreamInputReader
getStreamInputReader() throws CTFReaderException
{
66 CTFTrace trace
= TestParams
.createTrace();
67 Stream s
= trace
.getStream((long) 0);
68 Set
<StreamInput
> streamInput
= s
.getStreamInputs();
69 StreamInputReader retVal
= null;
70 for (StreamInput si
: streamInput
) {
72 * For the tests, we'll use the stream input corresponding to the
75 if (si
.getFilename().endsWith("0_0")) { //$NON-NLS-1$
76 retVal
= new StreamInputReader(si
);
84 * Run the StreamInputReader(StreamInput) constructor test, with a valid
88 public void testStreamInputReader_valid() {
89 assertNotNull(fixture
);
93 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
96 * @throws CTFReaderException
98 @Test(expected
= CTFReaderException
.class)
99 public void testStreamInputReader_invalid() throws CTFReaderException
{
100 StreamInput streamInput
= new StreamInput(
101 new Stream(new CTFTrace("")), (FileChannel
) null, TestParams
.getEmptyFile()); //$NON-NLS-1$
103 StreamInputReader result
= new StreamInputReader(streamInput
);
104 assertNotNull(result
);
108 * Run the int getCPU() method test.
111 public void testGetCPU() {
112 int result
= fixture
.getCPU();
113 assertEquals(0, result
);
117 * Run the EventDefinition getCurrentEvent() method test.
120 public void testGetCurrentEvent() {
121 EventDefinition result
= fixture
.getCurrentEvent();
122 assertNotNull(result
);
126 * Run the StructDefinition getCurrentPacketContext() method test.
129 public void testGetCurrentPacketContext() {
130 StructDefinition result
= fixture
.getCurrentPacketContext();
131 assertNotNull(result
);
135 * Run the int getName() method test.
138 public void testGetName() {
139 int result
= fixture
.getName();
140 assertEquals(1, result
);
144 * Run the StreamInput getStreamInput() method test.
147 public void testGetStreamInput() {
148 StreamInput result
= fixture
.getStreamInput();
149 assertNotNull(result
);
153 * Run the void goToLastEvent() method test.
155 * @throws CTFReaderException
158 public void testGoToLastEvent() throws CTFReaderException
{
159 fixture
.goToLastEvent();
163 * Run the boolean readNextEvent() method test.
166 public void testReadNextEvent() {
167 boolean result
= fixture
.readNextEvent();
172 * Run the void seek(long) method test. Seek by direct timestamp
175 public void testSeek_timestamp() {
177 fixture
.seek(timestamp
);
181 * Run the seek test. Seek by passing an EventDefinition to which we've
182 * given the timestamp we want.
184 * @throws CTFReaderException
187 public void testSeek_eventDefinition() throws CTFReaderException
{
188 EventDefinition eventDefinition
= new EventDefinition(
189 new EventDeclaration(), getStreamInputReader());
190 eventDefinition
.timestamp
= 1L;
191 fixture
.setCurrentEvent(eventDefinition
);