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.
49 fixture
= createStreamInputReader();
51 fixture
.setCurrentEvent(new EventDefinition(new EventDeclaration(),
52 createStreamInputReader()));
56 * Perform post-test clean-up.
59 public void tearDown() {
60 // Add additional tear down code here
63 private static StreamInputReader
createStreamInputReader() {
64 CTFTrace trace
= TestParams
.createTrace();
65 Stream s
= trace
.getStream((long) 0);
66 Set
<StreamInput
> streamInput
= s
.getStreamInputs();
67 StreamInputReader retVal
= null;
68 for (StreamInput si
: streamInput
) {
70 * For the tests, we'll use the stream input corresponding to the
73 if (si
.getFilename().endsWith("0_0")) { //$NON-NLS-1$
74 retVal
= new StreamInputReader(si
);
82 * Run the StreamInputReader(StreamInput) constructor test, with a valid
86 public void testStreamInputReader_valid() {
87 assertNotNull(fixture
);
91 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
94 * @throws CTFReaderException
96 @Test(expected
= CTFReaderException
.class)
97 public void testStreamInputReader_invalid() throws CTFReaderException
{
98 StreamInput streamInput
= new StreamInput(
99 new Stream(new CTFTrace("")), (FileChannel
) null, TestParams
.getEmptyFile()); //$NON-NLS-1$
101 StreamInputReader result
= new StreamInputReader(streamInput
);
102 assertNotNull(result
);
106 * Run the int getCPU() method test.
109 public void testGetCPU() {
110 int result
= fixture
.getCPU();
111 assertEquals(0, result
);
115 * Run the EventDefinition getCurrentEvent() method test.
118 public void testGetCurrentEvent() {
119 EventDefinition result
= fixture
.getCurrentEvent();
120 assertNotNull(result
);
124 * Run the StructDefinition getCurrentPacketContext() method test.
127 public void testGetCurrentPacketContext() {
128 StructDefinition result
= fixture
.getCurrentPacketContext();
129 assertNotNull(result
);
133 * Run the int getName() method test.
136 public void testGetName() {
137 int result
= fixture
.getName();
138 assertEquals(1, result
);
142 * Run the StreamInput getStreamInput() method test.
145 public void testGetStreamInput() {
146 StreamInput result
= fixture
.getStreamInput();
147 assertNotNull(result
);
151 * Run the void goToLastEvent() method test.
153 * @throws CTFReaderException
156 public void testGoToLastEvent() throws CTFReaderException
{
157 fixture
.goToLastEvent();
161 * Run the boolean readNextEvent() method test.
164 public void testReadNextEvent() {
165 boolean result
= fixture
.readNextEvent();
170 * Run the void seek(long) method test. Seek by direct timestamp
173 public void testSeek_timestamp() {
175 fixture
.seek(timestamp
);
179 * Run the seek test. Seek by passing an EventDefinition to which we've
180 * given the timestamp we want.
183 public void testSeek_eventDefinition() {
184 EventDefinition eventDefinition
= new EventDefinition(
185 new EventDeclaration(), createStreamInputReader());
186 eventDefinition
.timestamp
= 1L;
187 fixture
.setCurrentEvent(eventDefinition
);