9b3c96c915fc533903b713fc0db6e02a258319cd
[deliverable/tracecompass.git] / ctf / 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
20 import org.eclipse.tracecompass.ctf.core.CTFException;
21 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
22 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
23 import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
24 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
25 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils;
26 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
27 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
28 import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
29 import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
30 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
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 fixture = new EventDeclaration();
56 fixture.setContext(new StructDeclaration(1L));
57 fixture.setId(1L);
58 fixture.setFields(new StructDeclaration(1L));
59 fixture.setStream(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)));
60 fixture.setName("");
61 }
62
63 /**
64 * Run the EventDeclaration() constructor test.
65 */
66 @Test
67 public void testEventDeclaration() {
68 EventDeclaration result = new EventDeclaration();
69 assertNotNull(result);
70 }
71
72 /**
73 * Run the boolean contextIsSet() method test.
74 */
75 @Test
76 public void testContextIsSet() {
77 boolean result = fixture.contextIsSet();
78 assertTrue(result);
79 }
80
81 /**
82 * Run the boolean contextIsSet() method test.
83 */
84 @Test
85 public void testContextIsSet_null() {
86 fixture.setContext((StructDeclaration) null);
87
88 boolean result = fixture.contextIsSet();
89 assertFalse(result);
90 }
91
92 /**
93 * Run the boolean equals(Object) method test.
94 *
95 * @throws CTFException
96 */
97 @Test
98 public void testEquals() throws CTFException {
99 EventDeclaration obj = new EventDeclaration();
100 obj.setContext(new StructDeclaration(1L));
101 obj.setId(1L);
102 obj.setFields(new StructDeclaration(1L));
103 obj.setStream(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)));
104 obj.setName("");
105
106 assertTrue(fixture.equals(fixture));
107 boolean result = fixture.equals(obj);
108 assertFalse(result);
109 }
110
111 /**
112 * Run the boolean equals(Object) method test.
113 */
114 @Test
115 public void testEquals_null() {
116 Object obj = null;
117
118 boolean result = fixture.equals(obj);
119 assertFalse(result);
120 }
121
122 /**
123 * Run the boolean equals(Object) method test.
124 */
125 @Test
126 public void testEquals_emptyObject() {
127 Object obj = new Object();
128
129 boolean result = fixture.equals(obj);
130 assertFalse(result);
131 }
132
133 /**
134 * Run the boolean equals(Object) method test.
135 */
136 @Test
137 public void testEquals_other1() {
138 EventDeclaration obj = new EventDeclaration();
139 obj.setContext(fixture.getContext());
140
141 boolean result = fixture.equals(obj);
142 assertFalse(result);
143 }
144
145 /**
146 * Run the boolean equals(Object) method test.
147 */
148 @Test
149 public void testEquals_other2() {
150 EventDeclaration obj = new EventDeclaration();
151 obj.setContext(new StructDeclaration(1L));
152 obj.setFields(new StructDeclaration(1L));
153
154 boolean result = fixture.equals(obj);
155 assertFalse(result);
156 }
157
158 /**
159 * Run the boolean equals(Object) method test.
160 */
161 @Test
162 public void testEquals_other3() {
163 EventDeclaration obj = new EventDeclaration();
164 obj.setContext(new StructDeclaration(1L));
165 obj.setId(1L);
166 obj.setFields(new StructDeclaration(1L));
167
168 boolean result = fixture.equals(obj);
169 assertFalse(result);
170 }
171
172 /**
173 * Run the boolean equals(Object) method test.
174 */
175 @Test
176 public void testEquals_other4() {
177 EventDeclaration obj = new EventDeclaration();
178 obj.setContext(new StructDeclaration(1L));
179 obj.setId(1L);
180 obj.setFields(new StructDeclaration(1L));
181 obj.setName("");
182
183 boolean result = fixture.equals(obj);
184 assertFalse(result);
185 }
186
187 /**
188 * Run the boolean fieldsIsSet() method test.
189 */
190 @Test
191 public void testFieldsIsSet() {
192 boolean result = fixture.fieldsIsSet();
193 assertTrue(result);
194 }
195
196 /**
197 * Run the boolean fieldsIsSet() method test.
198 */
199 @Test
200 public void testFieldsIsSet_null() {
201 fixture.setFields((StructDeclaration) null);
202
203 boolean result = fixture.fieldsIsSet();
204 assertFalse(result);
205 }
206
207 /**
208 * Run the StructDeclaration getFields() method test.
209 */
210 @Test
211 public void testGetFields() {
212 StructDeclaration result = fixture.getFields();
213 assertNotNull(result);
214 }
215
216 /**
217 * Run the Long getId() method test.
218 */
219 @Test
220 public void testGetId() {
221 assertEquals(1, fixture.id());
222 }
223
224 /**
225 * Run the String getName() method test.
226 */
227 @Test
228 public void testGetName() {
229 String result = fixture.getName();
230 assertNotNull(result);
231 }
232
233 /**
234 * Run the Stream getStream() method test.
235 */
236 @Test
237 public void testGetStream() {
238 CTFStream result = fixture.getStream();
239 assertNotNull(result);
240 }
241
242 /**
243 * Run the int hashCode() method test.
244 */
245 @Test
246 public void testHashCode() {
247 int result = fixture.hashCode();
248 assertTrue(0 != result);
249 }
250
251 /**
252 * Run the int hashCode() method test.
253 */
254 @Test
255 public void testHashCode_null() {
256 fixture.setStream((CTFStream) null);
257 fixture.setName((String) null);
258
259 int result = fixture.hashCode();
260 assertTrue(0 != result);
261 }
262
263 /**
264 * Run the boolean idIsSet() method test.
265 */
266 @Test
267 public void testIdIsSet() {
268 boolean result = fixture.idIsSet();
269 assertTrue(result);
270 }
271
272 /**
273 * Run the boolean nameIsSet() method test.
274 */
275 @Test
276 public void testNameIsSet() {
277 boolean result = fixture.nameIsSet();
278 assertTrue(result);
279 }
280
281 /**
282 * Run the boolean nameIsSet() method test.
283 */
284 @Test
285 public void testNameIsSet_null() {
286 fixture.setName((String) null);
287
288 boolean result = fixture.nameIsSet();
289 assertFalse(result);
290 }
291
292 /**
293 * Run the boolean streamIsSet() method test.
294 */
295 @Test
296 public void testStreamIsSet() {
297 boolean result = fixture.streamIsSet();
298 assertTrue(result);
299 }
300
301 /**
302 * Run the boolean streamIsSet() method test.
303 */
304 @Test
305 public void testStreamIsSet_null() {
306 fixture.setStream((CTFStream) null);
307
308 boolean result = fixture.streamIsSet();
309 assertEquals(false, result);
310 }
311
312 /**
313 * Test for the EventDefinition class
314 *
315 * @throws CTFException
316 */
317 @Test
318 public void testEventDefinition() throws CTFException {
319 CTFTrace trace = CtfTestTraceUtils.getTrace(testTrace);
320 EventDefinition ed = null;
321 try (CTFTraceReader tr = new CTFTraceReader(trace);) {
322 tr.advance();
323 ed = tr.getCurrentEventDef();
324 }
325
326 assertNotNull(ed);
327 assertNotNull(ed.getScopePath());
328 assertNotNull(ed.getDeclaration());
329 assertNotNull(ed.getFields());
330 assertNull(ed.getContext());
331 assertNotNull(ed.getPacketContext());
332 assertNotNull(ed.getCPU());
333 assertNull(ed.lookupDefinition("context"));
334 assertNotNull(ed.lookupDefinition("fields"));
335 assertNull(ed.lookupDefinition("other"));
336 assertNotNull(ed.toString());
337 }
338
339 IEventDeclaration e1;
340 IEventDeclaration e2;
341
342 @Test
343 public void testEquals1() {
344 e1 = new EventDeclaration();
345 assertFalse(e1.equals(null));
346 }
347
348 @Test
349 public void testEquals2() {
350 e1 = LostEventDeclaration.INSTANCE;
351 assertFalse(e1.equals(new Long(23L)));
352 }
353
354 @Test
355 public void testEquals3() {
356 e1 = LostEventDeclaration.INSTANCE;
357 assertEquals(e1, e1);
358 }
359
360 @Test
361 public void testEquals4() {
362 e1 = LostEventDeclaration.INSTANCE;
363 e2 = LostEventDeclaration.INSTANCE;
364 assertEquals(e1, e2);
365 }
366
367 @Test
368 public void testEquals5() {
369 e1 = LostEventDeclaration.INSTANCE;
370 e2 = new EventDeclaration();
371 assertFalse(e1.equals(e2));
372 }
373 }
This page took 0.042247 seconds and 4 git commands to generate.