Updated some javadoc in org.eclipse.linuxtools.tmf.core plug-in
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputReaderTest.java
CommitLineData
866e5b51
FC
1package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertTrue;
6
7import java.nio.channels.FileChannel;
8import java.util.Set;
9
10import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
11import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
12import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
13import org.eclipse.linuxtools.ctf.core.tests.TestParams;
14import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
15import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
866e5b51 16import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
ce2388e0
FC
17import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
18import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
866e5b51
FC
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22
23/**
24 * The class <code>StreamInputReaderTest</code> contains tests for the class
25 * <code>{@link StreamInputReader}</code>.
ce2388e0 26 *
866e5b51
FC
27 * @author ematkho
28 * @version $Revision: 1.0 $
29 */
30public class StreamInputReaderTest {
31
32 private StreamInputReader fixture;
33
34 /**
35 * Launch the test.
ce2388e0 36 *
866e5b51
FC
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.
ce2388e0
FC
46 *
47 * @throws CTFReaderException
866e5b51
FC
48 */
49 @Before
13be1a8f
AM
50 public void setUp() throws CTFReaderException {
51 fixture = getStreamInputReader();
866e5b51
FC
52 fixture.setName(1);
53 fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
13be1a8f 54 getStreamInputReader()));
866e5b51
FC
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
13be1a8f 65 private static StreamInputReader getStreamInputReader() throws CTFReaderException {
866e5b51
FC
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.
ce2388e0 95 *
866e5b51
FC
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
866e5b51
FC
143 /**
144 * Run the void goToLastEvent() method test.
ce2388e0 145 *
866e5b51
FC
146 * @throws CTFReaderException
147 */
148 @Test
ec6f5beb
MK
149 public void testGoToLastEvent1() throws CTFReaderException {
150 final long endTimestamp = goToEnd();
151 final long endTime = 4287422460315L;
152 assertEquals(endTime , endTimestamp );
153 }
154
155 /**
156 * Run the void goToLastEvent() method test.
157 *
158 * @throws CTFReaderException
159 */
160 @Test
161 public void testGoToLastEvent2() throws CTFReaderException {
162 long timestamp = -1;
163 while(fixture.readNextEvent()) {
164 timestamp = fixture.getCurrentEvent().getTimestamp();
165 }
166 long endTimestamp = goToEnd();
167 assertEquals(0 , timestamp- endTimestamp );
168 }
169
170 /**
171 * @throws CTFReaderException
172 */
173 private long goToEnd() throws CTFReaderException {
866e5b51 174 fixture.goToLastEvent();
ec6f5beb 175 return fixture.getCurrentEvent().getTimestamp();
866e5b51
FC
176 }
177
178 /**
179 * Run the boolean readNextEvent() method test.
180 */
181 @Test
182 public void testReadNextEvent() {
183 boolean result = fixture.readNextEvent();
184 assertTrue(result);
185 }
186
187 /**
188 * Run the void seek(long) method test. Seek by direct timestamp
189 */
190 @Test
191 public void testSeek_timestamp() {
192 long timestamp = 1L;
193 fixture.seek(timestamp);
194 }
195
196 /**
197 * Run the seek test. Seek by passing an EventDefinition to which we've
198 * given the timestamp we want.
ce2388e0
FC
199 *
200 * @throws CTFReaderException
866e5b51
FC
201 */
202 @Test
13be1a8f 203 public void testSeek_eventDefinition() throws CTFReaderException {
866e5b51 204 EventDefinition eventDefinition = new EventDefinition(
13be1a8f 205 new EventDeclaration(), getStreamInputReader());
aa572e22 206 eventDefinition.setTimestamp(1L);
866e5b51
FC
207 fixture.setCurrentEvent(eventDefinition);
208 }
209}
This page took 0.035167 seconds and 5 git commands to generate.