Contribute native CTF Parser (bug370499)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputReaderTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6
7 import java.nio.channels.FileChannel;
8 import java.util.Set;
9
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;
22
23 /**
24 * The class <code>StreamInputReaderTest</code> contains tests for the class
25 * <code>{@link StreamInputReader}</code>.
26 *
27 * @author ematkho
28 * @version $Revision: 1.0 $
29 */
30 public class StreamInputReaderTest {
31
32 private StreamInputReader fixture;
33
34 /**
35 * Launch the test.
36 *
37 * @param args
38 * the command line arguments
39 */
40 public static void main(String[] args) {
41 new org.junit.runner.JUnitCore().run(StreamInputReaderTest.class);
42 }
43
44 /**
45 * Perform pre-test initialization.
46 */
47 @Before
48 public void setUp() {
49 fixture = createStreamInputReader();
50 fixture.setName(1);
51 fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
52 createStreamInputReader()));
53 }
54
55 /**
56 * Perform post-test clean-up.
57 */
58 @After
59 public void tearDown() {
60 // Add additional tear down code here
61 }
62
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) {
69 /*
70 * For the tests, we'll use the stream input corresponding to the
71 * CPU 0
72 */
73 if (si.getFilename().endsWith("0_0")) { //$NON-NLS-1$
74 retVal = new StreamInputReader(si);
75 break;
76 }
77 }
78 return retVal;
79 }
80
81 /**
82 * Run the StreamInputReader(StreamInput) constructor test, with a valid
83 * trace.
84 */
85 @Test
86 public void testStreamInputReader_valid() {
87 assertNotNull(fixture);
88 }
89
90 /**
91 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
92 * trace.
93 *
94 * @throws CTFReaderException
95 */
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$
100
101 StreamInputReader result = new StreamInputReader(streamInput);
102 assertNotNull(result);
103 }
104
105 /**
106 * Run the int getCPU() method test.
107 */
108 @Test
109 public void testGetCPU() {
110 int result = fixture.getCPU();
111 assertEquals(0, result);
112 }
113
114 /**
115 * Run the EventDefinition getCurrentEvent() method test.
116 */
117 @Test
118 public void testGetCurrentEvent() {
119 EventDefinition result = fixture.getCurrentEvent();
120 assertNotNull(result);
121 }
122
123 /**
124 * Run the StructDefinition getCurrentPacketContext() method test.
125 */
126 @Test
127 public void testGetCurrentPacketContext() {
128 StructDefinition result = fixture.getCurrentPacketContext();
129 assertNotNull(result);
130 }
131
132 /**
133 * Run the int getName() method test.
134 */
135 @Test
136 public void testGetName() {
137 int result = fixture.getName();
138 assertEquals(1, result);
139 }
140
141 /**
142 * Run the StreamInput getStreamInput() method test.
143 */
144 @Test
145 public void testGetStreamInput() {
146 StreamInput result = fixture.getStreamInput();
147 assertNotNull(result);
148 }
149
150 /**
151 * Run the void goToLastEvent() method test.
152 *
153 * @throws CTFReaderException
154 */
155 @Test
156 public void testGoToLastEvent() throws CTFReaderException {
157 fixture.goToLastEvent();
158 }
159
160 /**
161 * Run the boolean readNextEvent() method test.
162 */
163 @Test
164 public void testReadNextEvent() {
165 boolean result = fixture.readNextEvent();
166 assertTrue(result);
167 }
168
169 /**
170 * Run the void seek(long) method test. Seek by direct timestamp
171 */
172 @Test
173 public void testSeek_timestamp() {
174 long timestamp = 1L;
175 fixture.seek(timestamp);
176 }
177
178 /**
179 * Run the seek test. Seek by passing an EventDefinition to which we've
180 * given the timestamp we want.
181 */
182 @Test
183 public void testSeek_eventDefinition() {
184 EventDefinition eventDefinition = new EventDefinition(
185 new EventDeclaration(), createStreamInputReader());
186 eventDefinition.timestamp = 1L;
187 fixture.setCurrentEvent(eventDefinition);
188 }
189 }
This page took 0.03546 seconds and 6 git commands to generate.