ctf: Introduce LostEventDeclaration singleton
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / EventDeclarationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.tracecompass.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assume.assumeTrue;
20
21 import org.eclipse.tracecompass.ctf.core.CTFException;
22 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
23 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
24 import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
25 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
26 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
27 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
28 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
29 import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
30 import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 /**
35 * The class <code>EventDeclarationTest</code> contains tests for the class
36 * <code>{@link EventDeclaration}</code>.
37 *
38 * @author ematkho
39 * @version $Revision: 1.0 $
40 */
41 @SuppressWarnings("javadoc")
42 public class EventDeclarationTest {
43
44 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
45
46 private EventDeclaration fixture;
47
48 /**
49 * Perform pre-test initialization.
50 *
51 * @throws CTFException
52 */
53 @Before
54 public void setUp() throws CTFException {
55 assumeTrue(testTrace.exists());
56 fixture = new EventDeclaration();
57 fixture.setContext(new StructDeclaration(1L));
58 fixture.setId(1L);
59 fixture.setFields(new StructDeclaration(1L));
60 fixture.setStream(new CTFStream(testTrace.getTrace()));
61 fixture.setName("");
62 }
63
64 /**
65 * Run the EventDeclaration() constructor test.
66 */
67 @Test
68 public void testEventDeclaration() {
69 EventDeclaration result = new EventDeclaration();
70 assertNotNull(result);
71 }
72
73 /**
74 * Run the boolean contextIsSet() method test.
75 */
76 @Test
77 public void testContextIsSet() {
78 boolean result = fixture.contextIsSet();
79 assertTrue(result);
80 }
81
82 /**
83 * Run the boolean contextIsSet() method test.
84 */
85 @Test
86 public void testContextIsSet_null() {
87 fixture.setContext((StructDeclaration) null);
88
89 boolean result = fixture.contextIsSet();
90 assertFalse(result);
91 }
92
93 /**
94 * Run the boolean equals(Object) method test.
95 *
96 * @throws CTFException
97 */
98 @Test
99 public void testEquals() throws CTFException {
100 EventDeclaration obj = new EventDeclaration();
101 obj.setContext(new StructDeclaration(1L));
102 obj.setId(1L);
103 obj.setFields(new StructDeclaration(1L));
104 obj.setStream(new CTFStream(testTrace.getTrace()));
105 obj.setName("");
106
107 assertTrue(fixture.equals(fixture));
108 boolean result = fixture.equals(obj);
109 assertFalse(result);
110 }
111
112 /**
113 * Run the boolean equals(Object) method test.
114 */
115 @Test
116 public void testEquals_null() {
117 Object obj = null;
118
119 boolean result = fixture.equals(obj);
120 assertFalse(result);
121 }
122
123 /**
124 * Run the boolean equals(Object) method test.
125 */
126 @Test
127 public void testEquals_emptyObject() {
128 Object obj = new Object();
129
130 boolean result = fixture.equals(obj);
131 assertFalse(result);
132 }
133
134 /**
135 * Run the boolean equals(Object) method test.
136 */
137 @Test
138 public void testEquals_other1() {
139 EventDeclaration obj = new EventDeclaration();
140 obj.setContext(fixture.getContext());
141
142 boolean result = fixture.equals(obj);
143 assertFalse(result);
144 }
145
146 /**
147 * Run the boolean equals(Object) method test.
148 */
149 @Test
150 public void testEquals_other2() {
151 EventDeclaration obj = new EventDeclaration();
152 obj.setContext(new StructDeclaration(1L));
153 obj.setFields(new StructDeclaration(1L));
154
155 boolean result = fixture.equals(obj);
156 assertFalse(result);
157 }
158
159 /**
160 * Run the boolean equals(Object) method test.
161 */
162 @Test
163 public void testEquals_other3() {
164 EventDeclaration obj = new EventDeclaration();
165 obj.setContext(new StructDeclaration(1L));
166 obj.setId(1L);
167 obj.setFields(new StructDeclaration(1L));
168
169 boolean result = fixture.equals(obj);
170 assertFalse(result);
171 }
172
173 /**
174 * Run the boolean equals(Object) method test.
175 */
176 @Test
177 public void testEquals_other4() {
178 EventDeclaration obj = new EventDeclaration();
179 obj.setContext(new StructDeclaration(1L));
180 obj.setId(1L);
181 obj.setFields(new StructDeclaration(1L));
182 obj.setName("");
183
184 boolean result = fixture.equals(obj);
185 assertFalse(result);
186 }
187
188 /**
189 * Run the boolean fieldsIsSet() method test.
190 */
191 @Test
192 public void testFieldsIsSet() {
193 boolean result = fixture.fieldsIsSet();
194 assertTrue(result);
195 }
196
197 /**
198 * Run the boolean fieldsIsSet() method test.
199 */
200 @Test
201 public void testFieldsIsSet_null() {
202 fixture.setFields((StructDeclaration) null);
203
204 boolean result = fixture.fieldsIsSet();
205 assertFalse(result);
206 }
207
208 /**
209 * Run the StructDeclaration getFields() method test.
210 */
211 @Test
212 public void testGetFields() {
213 StructDeclaration result = fixture.getFields();
214 assertNotNull(result);
215 }
216
217 /**
218 * Run the Long getId() method test.
219 */
220 @Test
221 public void testGetId() {
222 assertEquals(1, fixture.id());
223 }
224
225 /**
226 * Run the String getName() method test.
227 */
228 @Test
229 public void testGetName() {
230 String result = fixture.getName();
231 assertNotNull(result);
232 }
233
234 /**
235 * Run the Stream getStream() method test.
236 */
237 @Test
238 public void testGetStream() {
239 CTFStream result = fixture.getStream();
240 assertNotNull(result);
241 }
242
243 /**
244 * Run the int hashCode() method test.
245 */
246 @Test
247 public void testHashCode() {
248 int result = fixture.hashCode();
249 assertTrue(0 != result);
250 }
251
252 /**
253 * Run the int hashCode() method test.
254 */
255 @Test
256 public void testHashCode_null() {
257 fixture.setStream((CTFStream) null);
258 fixture.setName((String) null);
259
260 int result = fixture.hashCode();
261 assertTrue(0 != result);
262 }
263
264 /**
265 * Run the boolean idIsSet() method test.
266 */
267 @Test
268 public void testIdIsSet() {
269 boolean result = fixture.idIsSet();
270 assertTrue(result);
271 }
272
273 /**
274 * Run the boolean nameIsSet() method test.
275 */
276 @Test
277 public void testNameIsSet() {
278 boolean result = fixture.nameIsSet();
279 assertTrue(result);
280 }
281
282 /**
283 * Run the boolean nameIsSet() method test.
284 */
285 @Test
286 public void testNameIsSet_null() {
287 fixture.setName((String) null);
288
289 boolean result = fixture.nameIsSet();
290 assertFalse(result);
291 }
292
293 /**
294 * Run the boolean streamIsSet() method test.
295 */
296 @Test
297 public void testStreamIsSet() {
298 boolean result = fixture.streamIsSet();
299 assertTrue(result);
300 }
301
302 /**
303 * Run the boolean streamIsSet() method test.
304 */
305 @Test
306 public void testStreamIsSet_null() {
307 fixture.setStream((CTFStream) null);
308
309 boolean result = fixture.streamIsSet();
310 assertEquals(false, result);
311 }
312
313 /**
314 * Test for the EventDefinition class
315 *
316 * @throws CTFException
317 */
318 @Test
319 public void testEventDefinition() throws CTFException {
320 CTFTrace trace = testTrace.getTrace();
321 EventDefinition ed = null;
322 try (CTFTraceReader tr = new CTFTraceReader(trace);) {
323 tr.advance();
324 ed = tr.getCurrentEventDef();
325 }
326
327 assertNotNull(ed);
328 assertNotNull(ed.getScopePath());
329 assertNotNull(ed.getDeclaration());
330 assertNotNull(ed.getFields());
331 assertNull(ed.getContext());
332 assertNotNull(ed.getPacketContext());
333 assertNotNull(ed.getCPU());
334 assertNotNull(ed.getStreamInputReader());
335 assertNull(ed.lookupDefinition("context"));
336 assertNotNull(ed.lookupDefinition("fields"));
337 assertNull(ed.lookupDefinition("other"));
338 assertNotNull(ed.toString());
339 }
340
341 IEventDeclaration e1;
342 IEventDeclaration e2;
343
344 @Test
345 public void testEquals1() {
346 e1 = new EventDeclaration();
347 assertFalse(e1.equals(null));
348 }
349
350 @Test
351 public void testEquals2() {
352 e1 = LostEventDeclaration.INSTANCE;
353 assertFalse(e1.equals(new Long(23L)));
354 }
355
356 @Test
357 public void testEquals3() {
358 e1 = LostEventDeclaration.INSTANCE;
359 assertEquals(e1, e1);
360 }
361
362 @Test
363 public void testEquals4() {
364 e1 = LostEventDeclaration.INSTANCE;
365 e2 = LostEventDeclaration.INSTANCE;
366 assertEquals(e1, e2);
367 }
368
369 @Test
370 public void testEquals5() {
371 e1 = LostEventDeclaration.INSTANCE;
372 e2 = new EventDeclaration();
373 assertFalse(e1.equals(e2));
374 }
375 }
This page took 0.041786 seconds and 6 git commands to generate.