Contribute native CTF Parser (bug370499)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7
8 import java.io.File;
9 import java.nio.ByteOrder;
10 import java.util.Map;
11 import java.util.UUID;
12
13 import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
14 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
15 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
16 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
17 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
18 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
19 import org.eclipse.linuxtools.ctf.core.trace.Stream;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 /**
25 * The class <code>CTFTraceTest</code> contains tests for the class
26 * <code>{@link CTFTrace}</code>.
27 *
28 * @author ematkho
29 * @version $Revision: 1.0 $
30 */
31 public class CTFTraceTest {
32
33 private CTFTrace fixture;
34
35 /**
36 * Launch the test.
37 *
38 * @param args
39 * the command line arguments
40 */
41 public static void main(String[] args) {
42 new org.junit.runner.JUnitCore().run(CTFTraceTest.class);
43 }
44
45 /**
46 * Perform pre-test initialization.
47 */
48 @Before
49 public void setUp() {
50 fixture = TestParams.createTraceFromFile();
51 fixture.setMinor(1L);
52 fixture.setUUID(UUID.randomUUID());
53 fixture.setPacketHeader(new StructDeclaration(1L));
54 fixture.setMajor(1L);
55 fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
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
66 /**
67 * Run the CTFTrace(File) constructor test with a known existing trace.
68 */
69 @Test
70 public void testOpen_existing() {
71 CTFTrace result = TestParams.createTraceFromFile();
72 assertNotNull(result.getUUID());
73 }
74
75 /**
76 * Run the CTFTrace(File) constructor test with an invalid path.
77 *
78 * @throws CTFReaderException
79 */
80 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
81 public void testOpen_invalid() throws CTFReaderException {
82 File path = new File(""); //$NON-NLS-1$
83 CTFTrace result = new CTFTrace(path);
84 assertNotNull(result);
85 }
86
87 /**
88 * Run the boolean UUIDIsSet() method test.
89 */
90 @Test
91 public void testUUIDIsSet() {
92 boolean result = fixture.UUIDIsSet();
93 assertTrue(result);
94 }
95
96 /**
97 * Run the void addStream(Stream) method test.
98 *
99 * @throws ParseException
100 */
101 @Test
102 public void testAddStream() throws ParseException {
103 Stream stream = new Stream(TestParams.createTrace());
104 stream.setId(1L);
105 fixture.addStream(stream);
106 }
107
108 /**
109 * Run the boolean byteOrderIsSet() method test.
110 */
111 @Test
112 public void testByteOrderIsSet() {
113 boolean result = fixture.byteOrderIsSet();
114 assertTrue(result);
115 }
116
117 /**
118 * Run the ByteOrder getByteOrder() method test.
119 */
120 @Test
121 public void testGetByteOrder_1() {
122 ByteOrder result = fixture.getByteOrder();
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the long getMajor() method test.
128 */
129 @Test
130 public void testGetMajor() {
131 long result = fixture.getMajor();
132 assertEquals(1L, result);
133 }
134
135 /**
136 * Run the long getMinor() method test.
137 */
138 @Test
139 public void testGetMinor() {
140 long result = fixture.getMinor();
141 assertEquals(1L, result);
142 }
143
144 /**
145 * Run the StructDeclaration getPacketHeader() method test.
146 */
147 @Test
148 public void testGetPacketHeader() {
149 StructDeclaration result = fixture.getPacketHeader();
150 assertNotNull(result);
151 }
152
153 /**
154 * Run the String getPath() method test.
155 */
156 @Test
157 public void testGetPath() {
158 String result = fixture.getPath();
159 assertNotNull(result);
160 }
161
162 /**
163 * Run the Stream getStream(Long) method test.
164 */
165 @Test
166 public void testGetStream() {
167 Long id = new Long(0L);
168 Stream result = fixture.getStream(id);
169 assertNotNull(result);
170 }
171
172 /**
173 * Run the Map<Long, Stream> getStreams() method test.
174 */
175 @Test
176 public void testGetStreams() {
177 Map<Long, Stream> result = fixture.getStreams();
178 assertNotNull(result);
179 }
180
181 /**
182 * Run the File getTraceDirectory() method test.
183 */
184 @Test
185 public void testGetTraceDirectory() {
186 File result = fixture.getTraceDirectory();
187 assertNotNull(result);
188 }
189
190 /**
191 * Run the UUID getUUID() method test.
192 */
193 @Test
194 public void testGetUUID() {
195 UUID result = fixture.getUUID();
196 assertNotNull(result);
197 }
198
199 /**
200 * Run the Definition lookupDefinition(String) method test.
201 */
202 @Test
203 public void testLookupDefinition() {
204 String lookupPath = "trace.packet.header"; //$NON-NLS-1$
205 Definition result = fixture.lookupDefinition(lookupPath);
206 assertNotNull(result);
207 }
208
209 /**
210 * Run the boolean majortIsSet() method test.
211 */
212 @Test
213 public void testMajortIsSet() {
214 boolean result = fixture.majortIsSet();
215 assertTrue(result);
216 }
217
218 /**
219 * Run the boolean minorIsSet() method test.
220 */
221 @Test
222 public void testMinorIsSet() {
223 boolean result = fixture.minorIsSet();
224 assertTrue(result);
225 }
226
227 /**
228 * Run the int nbStreams() method test.
229 */
230 @Test
231 public void testNbStreams() {
232 int result = fixture.nbStreams();
233 assertEquals(2, result);
234 }
235
236 /**
237 * Run the boolean packetHeaderIsSet() method test with a valid header set.
238 */
239 @Test
240 public void testPacketHeaderIsSet_valid() {
241 boolean result = fixture.packetHeaderIsSet();
242 assertTrue(result);
243 }
244
245 /**
246 * Run the boolean packetHeaderIsSet() method test, without having a valid
247 * header set.
248 */
249 @Test
250 public void testPacketHeaderIsSet_invalid() {
251 CTFTrace fixture2 = TestParams.createTraceFromFile();
252 fixture2.setMinor(1L);
253 fixture2.setUUID(UUID.randomUUID());
254 fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */
255 fixture2.setMajor(1L);
256 fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
257
258 boolean result = fixture2.packetHeaderIsSet();
259 assertFalse(result);
260 }
261
262 /**
263 * Run the void setByteOrder(ByteOrder) method test.
264 */
265 @Test
266 public void testSetByteOrder() {
267 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
268 fixture.setByteOrder(byteOrder);
269 }
270
271 /**
272 * Run the void setMajor(long) method test.
273 */
274 @Test
275 public void testSetMajor() {
276 long major = 1L;
277 fixture.setMajor(major);
278 }
279
280 /**
281 * Run the void setMinor(long) method test.
282 */
283 @Test
284 public void testSetMinor() {
285 long minor = 1L;
286 fixture.setMinor(minor);
287 }
288
289 /**
290 * Run the void setPacketHeader(StructDeclaration) method test.
291 */
292 @Test
293 public void testSetPacketHeader() {
294 StructDeclaration packetHeader = new StructDeclaration(1L);
295 fixture.setPacketHeader(packetHeader);
296 }
297
298 /**
299 * Run the void setUUID(UUID) method test.
300 */
301 @Test
302 public void testSetUUID() {
303 UUID uuid = UUID.randomUUID();
304 fixture.setUUID(uuid);
305 }
306 }
This page took 0.042415 seconds and 6 git commands to generate.