tmf: Correctly export all packages in runtime plugins
[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 */
be6df2d8 30@SuppressWarnings("javadoc")
866e5b51
FC
31public class StreamInputReaderTest {
32
33 private StreamInputReader fixture;
34
35 /**
36 * Launch the test.
ce2388e0 37 *
866e5b51
FC
38 * @param args
39 * the command line arguments
40 */
41 public static void main(String[] args) {
42 new org.junit.runner.JUnitCore().run(StreamInputReaderTest.class);
43 }
44
45 /**
46 * Perform pre-test initialization.
ce2388e0
FC
47 *
48 * @throws CTFReaderException
866e5b51
FC
49 */
50 @Before
13be1a8f
AM
51 public void setUp() throws CTFReaderException {
52 fixture = getStreamInputReader();
866e5b51
FC
53 fixture.setName(1);
54 fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
13be1a8f 55 getStreamInputReader()));
866e5b51
FC
56 }
57
58 /**
59 * Perform post-test clean-up.
60 */
61 @After
62 public void tearDown() {
63 // Add additional tear down code here
64 }
65
13be1a8f 66 private static StreamInputReader getStreamInputReader() throws CTFReaderException {
866e5b51
FC
67 CTFTrace trace = TestParams.createTrace();
68 Stream s = trace.getStream((long) 0);
69 Set<StreamInput> streamInput = s.getStreamInputs();
70 StreamInputReader retVal = null;
71 for (StreamInput si : streamInput) {
72 /*
73 * For the tests, we'll use the stream input corresponding to the
74 * CPU 0
75 */
76 if (si.getFilename().endsWith("0_0")) { //$NON-NLS-1$
77 retVal = new StreamInputReader(si);
78 break;
79 }
80 }
81 return retVal;
82 }
83
84 /**
85 * Run the StreamInputReader(StreamInput) constructor test, with a valid
86 * trace.
87 */
88 @Test
89 public void testStreamInputReader_valid() {
90 assertNotNull(fixture);
91 }
92
93 /**
94 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
95 * trace.
ce2388e0 96 *
866e5b51
FC
97 * @throws CTFReaderException
98 */
99 @Test(expected = CTFReaderException.class)
100 public void testStreamInputReader_invalid() throws CTFReaderException {
101 StreamInput streamInput = new StreamInput(
102 new Stream(new CTFTrace("")), (FileChannel) null, TestParams.getEmptyFile()); //$NON-NLS-1$
103
104 StreamInputReader result = new StreamInputReader(streamInput);
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the int getCPU() method test.
110 */
111 @Test
112 public void testGetCPU() {
113 int result = fixture.getCPU();
114 assertEquals(0, result);
115 }
116
117 /**
118 * Run the EventDefinition getCurrentEvent() method test.
119 */
120 @Test
121 public void testGetCurrentEvent() {
122 EventDefinition result = fixture.getCurrentEvent();
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the StructDefinition getCurrentPacketContext() method test.
128 */
129 @Test
130 public void testGetCurrentPacketContext() {
131 StructDefinition result = fixture.getCurrentPacketContext();
132 assertNotNull(result);
133 }
134
135 /**
136 * Run the int getName() method test.
137 */
138 @Test
139 public void testGetName() {
140 int result = fixture.getName();
141 assertEquals(1, result);
142 }
143
866e5b51
FC
144 /**
145 * Run the void goToLastEvent() method test.
866e5b51
FC
146 */
147 @Test
be6df2d8 148 public void testGoToLastEvent1() {
ec6f5beb
MK
149 final long endTimestamp = goToEnd();
150 final long endTime = 4287422460315L;
151 assertEquals(endTime , endTimestamp );
152 }
153
154 /**
155 * Run the void goToLastEvent() method test.
ec6f5beb
MK
156 */
157 @Test
be6df2d8 158 public void testGoToLastEvent2() {
ec6f5beb
MK
159 long timestamp = -1;
160 while(fixture.readNextEvent()) {
161 timestamp = fixture.getCurrentEvent().getTimestamp();
162 }
163 long endTimestamp = goToEnd();
164 assertEquals(0 , timestamp- endTimestamp );
165 }
166
be6df2d8 167 private long goToEnd() {
866e5b51 168 fixture.goToLastEvent();
ec6f5beb 169 return fixture.getCurrentEvent().getTimestamp();
866e5b51
FC
170 }
171
172 /**
173 * Run the boolean readNextEvent() method test.
174 */
175 @Test
176 public void testReadNextEvent() {
177 boolean result = fixture.readNextEvent();
178 assertTrue(result);
179 }
180
181 /**
182 * Run the void seek(long) method test. Seek by direct timestamp
183 */
184 @Test
185 public void testSeek_timestamp() {
186 long timestamp = 1L;
187 fixture.seek(timestamp);
188 }
189
190 /**
191 * Run the seek test. Seek by passing an EventDefinition to which we've
192 * given the timestamp we want.
ce2388e0
FC
193 *
194 * @throws CTFReaderException
866e5b51
FC
195 */
196 @Test
13be1a8f 197 public void testSeek_eventDefinition() throws CTFReaderException {
866e5b51 198 EventDefinition eventDefinition = new EventDefinition(
13be1a8f 199 new EventDeclaration(), getStreamInputReader());
aa572e22 200 eventDefinition.setTimestamp(1L);
866e5b51
FC
201 fixture.setCurrentEvent(eventDefinition);
202 }
203}
This page took 0.038031 seconds and 5 git commands to generate.