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