Merge branch 'master' into lttng_2_0_control_dev
[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 * @throws CTFReaderException
48 */
49 @Before
50 public void setUp() throws CTFReaderException {
51 fixture = getStreamInputReader();
52 fixture.setName(1);
53 fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
54 getStreamInputReader()));
55 }
56
57 /**
58 * Perform post-test clean-up.
59 */
60 @After
61 public void tearDown() {
62 // Add additional tear down code here
63 }
64
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) {
71 /*
72 * For the tests, we'll use the stream input corresponding to the
73 * CPU 0
74 */
75 if (si.getFilename().endsWith("0_0")) { //$NON-NLS-1$
76 retVal = new StreamInputReader(si);
77 break;
78 }
79 }
80 return retVal;
81 }
82
83 /**
84 * Run the StreamInputReader(StreamInput) constructor test, with a valid
85 * trace.
86 */
87 @Test
88 public void testStreamInputReader_valid() {
89 assertNotNull(fixture);
90 }
91
92 /**
93 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
94 * trace.
95 *
96 * @throws CTFReaderException
97 */
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$
102
103 StreamInputReader result = new StreamInputReader(streamInput);
104 assertNotNull(result);
105 }
106
107 /**
108 * Run the int getCPU() method test.
109 */
110 @Test
111 public void testGetCPU() {
112 int result = fixture.getCPU();
113 assertEquals(0, result);
114 }
115
116 /**
117 * Run the EventDefinition getCurrentEvent() method test.
118 */
119 @Test
120 public void testGetCurrentEvent() {
121 EventDefinition result = fixture.getCurrentEvent();
122 assertNotNull(result);
123 }
124
125 /**
126 * Run the StructDefinition getCurrentPacketContext() method test.
127 */
128 @Test
129 public void testGetCurrentPacketContext() {
130 StructDefinition result = fixture.getCurrentPacketContext();
131 assertNotNull(result);
132 }
133
134 /**
135 * Run the int getName() method test.
136 */
137 @Test
138 public void testGetName() {
139 int result = fixture.getName();
140 assertEquals(1, result);
141 }
142
143 /**
144 * Run the StreamInput getStreamInput() method test.
145 */
146 @Test
147 public void testGetStreamInput() {
148 StreamInput result = fixture.getStreamInput();
149 assertNotNull(result);
150 }
151
152 /**
153 * Run the void goToLastEvent() method test.
154 *
155 * @throws CTFReaderException
156 */
157 @Test
158 public void testGoToLastEvent() throws CTFReaderException {
159 fixture.goToLastEvent();
160 }
161
162 /**
163 * Run the boolean readNextEvent() method test.
164 */
165 @Test
166 public void testReadNextEvent() {
167 boolean result = fixture.readNextEvent();
168 assertTrue(result);
169 }
170
171 /**
172 * Run the void seek(long) method test. Seek by direct timestamp
173 */
174 @Test
175 public void testSeek_timestamp() {
176 long timestamp = 1L;
177 fixture.seek(timestamp);
178 }
179
180 /**
181 * Run the seek test. Seek by passing an EventDefinition to which we've
182 * given the timestamp we want.
183 *
184 * @throws CTFReaderException
185 */
186 @Test
187 public void testSeek_eventDefinition() throws CTFReaderException {
188 EventDefinition eventDefinition = new EventDefinition(
189 new EventDeclaration(), getStreamInputReader());
190 eventDefinition.timestamp = 1L;
191 fixture.setCurrentEvent(eventDefinition);
192 }
193 }
This page took 0.037896 seconds and 6 git commands to generate.