ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / EventDeclarationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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.linuxtools.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.linuxtools.ctf.core.event.EventDefinition;
22 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
23 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
24 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
25 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
26 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
27 import org.eclipse.linuxtools.ctf.core.trace.Stream;
28 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 /**
33 * The class <code>EventDeclarationTest</code> contains tests for the class
34 * <code>{@link EventDeclaration}</code>.
35 *
36 * @author ematkho
37 * @version $Revision: 1.0 $
38 */
39 @SuppressWarnings("javadoc")
40 public class EventDeclarationTest {
41
42 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
43
44 private EventDeclaration fixture;
45
46 /**
47 * Perform pre-test initialization.
48 *
49 * @throws CTFReaderException
50 */
51 @Before
52 public void setUp() throws CTFReaderException {
53 assumeTrue(testTrace.exists());
54 fixture = new EventDeclaration();
55 fixture.setContext(new StructDeclaration(1L));
56 fixture.setId(1L);
57 fixture.setFields(new StructDeclaration(1L));
58 fixture.setStream(new Stream(testTrace.getTrace()));
59 fixture.setName("");
60 }
61
62 /**
63 * Run the EventDeclaration() constructor test.
64 */
65 @Test
66 public void testEventDeclaration() {
67 EventDeclaration result = new EventDeclaration();
68 assertNotNull(result);
69 }
70
71 /**
72 * Run the boolean contextIsSet() method test.
73 */
74 @Test
75 public void testContextIsSet() {
76 boolean result = fixture.contextIsSet();
77 assertTrue(result);
78 }
79
80 /**
81 * Run the boolean contextIsSet() method test.
82 */
83 @Test
84 public void testContextIsSet_null() {
85 fixture.setContext((StructDeclaration) null);
86
87 boolean result = fixture.contextIsSet();
88 assertFalse(result);
89 }
90
91 /**
92 * Run the boolean equals(Object) method test.
93 *
94 * @throws CTFReaderException
95 */
96 @Test
97 public void testEquals() throws CTFReaderException {
98 EventDeclaration obj = new EventDeclaration();
99 obj.setContext(new StructDeclaration(1L));
100 obj.setId(1L);
101 obj.setFields(new StructDeclaration(1L));
102 obj.setStream(new Stream(testTrace.getTrace()));
103 obj.setName("");
104
105 assertTrue(fixture.equals(fixture));
106 boolean result = fixture.equals(obj);
107 assertFalse(result);
108 }
109
110 /**
111 * Run the boolean equals(Object) method test.
112 */
113 @Test
114 public void testEquals_null() {
115 Object obj = null;
116
117 boolean result = fixture.equals(obj);
118 assertFalse(result);
119 }
120
121 /**
122 * Run the boolean equals(Object) method test.
123 */
124 @Test
125 public void testEquals_emptyObject() {
126 Object obj = new Object();
127
128 boolean result = fixture.equals(obj);
129 assertFalse(result);
130 }
131
132 /**
133 * Run the boolean equals(Object) method test.
134 */
135 @Test
136 public void testEquals_other1() {
137 EventDeclaration obj = new EventDeclaration();
138 obj.setContext(fixture.getContext());
139
140 boolean result = fixture.equals(obj);
141 assertFalse(result);
142 }
143
144 /**
145 * Run the boolean equals(Object) method test.
146 */
147 @Test
148 public void testEquals_other2() {
149 EventDeclaration obj = new EventDeclaration();
150 obj.setContext(new StructDeclaration(1L));
151 obj.setFields(new StructDeclaration(1L));
152
153 boolean result = fixture.equals(obj);
154 assertFalse(result);
155 }
156
157 /**
158 * Run the boolean equals(Object) method test.
159 */
160 @Test
161 public void testEquals_other3() {
162 EventDeclaration obj = new EventDeclaration();
163 obj.setContext(new StructDeclaration(1L));
164 obj.setId(1L);
165 obj.setFields(new StructDeclaration(1L));
166
167 boolean result = fixture.equals(obj);
168 assertFalse(result);
169 }
170
171 /**
172 * Run the boolean equals(Object) method test.
173 */
174 @Test
175 public void testEquals_other4() {
176 EventDeclaration obj = new EventDeclaration();
177 obj.setContext(new StructDeclaration(1L));
178 obj.setId(1L);
179 obj.setFields(new StructDeclaration(1L));
180 obj.setName("");
181
182 boolean result = fixture.equals(obj);
183 assertFalse(result);
184 }
185
186 /**
187 * Run the boolean fieldsIsSet() method test.
188 */
189 @Test
190 public void testFieldsIsSet() {
191 boolean result = fixture.fieldsIsSet();
192 assertTrue(result);
193 }
194
195 /**
196 * Run the boolean fieldsIsSet() method test.
197 */
198 @Test
199 public void testFieldsIsSet_null() {
200 fixture.setFields((StructDeclaration) null);
201
202 boolean result = fixture.fieldsIsSet();
203 assertFalse(result);
204 }
205
206 /**
207 * Run the StructDeclaration getFields() method test.
208 */
209 @Test
210 public void testGetFields() {
211 StructDeclaration result = fixture.getFields();
212 assertNotNull(result);
213 }
214
215 /**
216 * Run the Long getId() method test.
217 */
218 @Test
219 public void testGetId() {
220 Long result = fixture.getId();
221 assertNotNull(result);
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 Stream 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((Stream) 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((Stream) null);
307
308 boolean result = fixture.streamIsSet();
309 assertEquals(false, result);
310 }
311
312 /**
313 * Test for the EventDefinition class
314 *
315 * @throws CTFReaderException
316 */
317 @Test
318 public void testEventDefinition() throws CTFReaderException {
319 CTFTrace trace = testTrace.getTrace();
320 EventDefinition ed = null;
321 try (CTFTraceReader tr = new CTFTraceReader(trace);) {
322 tr.advance();
323 ed = tr.getCurrentEventDef();
324 }
325 assertNotNull(ed);
326 assertNotNull(ed.getScopePath());
327 assertNotNull(ed.getDeclaration());
328 assertNotNull(ed.getFields());
329 assertNull(ed.getContext());
330 assertNotNull(ed.getPacketContext());
331 assertNotNull(ed.getCPU());
332 assertNotNull(ed.getStreamInputReader());
333 assertNull(ed.lookupDefinition("context"));
334 assertNotNull(ed.lookupDefinition("fields"));
335 assertNull(ed.lookupDefinition("other"));
336 assertNotNull(ed.toString());
337 }
338
339 EventDeclaration e1;
340 EventDeclaration e2;
341
342
343 @Test
344 public void testEquals1(){
345 e1 = new EventDeclaration();
346 assertFalse(e1.equals(null));
347 }
348
349 @Test
350 public void testEquals2(){
351 e1 = EventDeclaration.getLostEventDeclaration();
352 assertFalse(e1.equals(new Long(23L)));
353 }
354
355 @Test
356 public void testEquals3(){
357 e1 = EventDeclaration.getLostEventDeclaration();
358 assertEquals(e1,e1);
359 }
360
361 @Test
362 public void testEquals4(){
363 e1 = EventDeclaration.getLostEventDeclaration();
364 e2 = EventDeclaration.getLostEventDeclaration();
365 assertEquals(e1,e2);
366 }
367
368 @Test
369 public void testEquals5(){
370 e1 = EventDeclaration.getLostEventDeclaration();
371 e2 = new EventDeclaration();
372 assertFalse(e1.equals(e2));
373 }
374 }
This page took 0.040619 seconds and 5 git commands to generate.