ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.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.CTFStream;
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 CTFStream(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 CTFStream(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 assertEquals(1,fixture.id());
221 }
222
223 /**
224 * Run the String getName() method test.
225 */
226 @Test
227 public void testGetName() {
228 String result = fixture.getName();
229 assertNotNull(result);
230 }
231
232 /**
233 * Run the Stream getStream() method test.
234 */
235 @Test
236 public void testGetStream() {
237 CTFStream result = fixture.getStream();
238 assertNotNull(result);
239 }
240
241 /**
242 * Run the int hashCode() method test.
243 */
244 @Test
245 public void testHashCode() {
246 int result = fixture.hashCode();
247 assertTrue(0 != result);
248 }
249
250 /**
251 * Run the int hashCode() method test.
252 */
253 @Test
254 public void testHashCode_null() {
255 fixture.setStream((CTFStream) null);
256 fixture.setName((String) null);
257
258 int result = fixture.hashCode();
259 assertTrue(0 != result);
260 }
261
262 /**
263 * Run the boolean idIsSet() method test.
264 */
265 @Test
266 public void testIdIsSet() {
267 boolean result = fixture.idIsSet();
268 assertTrue(result);
269 }
270
271 /**
272 * Run the boolean nameIsSet() method test.
273 */
274 @Test
275 public void testNameIsSet() {
276 boolean result = fixture.nameIsSet();
277 assertTrue(result);
278 }
279
280 /**
281 * Run the boolean nameIsSet() method test.
282 */
283 @Test
284 public void testNameIsSet_null() {
285 fixture.setName((String) null);
286
287 boolean result = fixture.nameIsSet();
288 assertFalse(result);
289 }
290
291 /**
292 * Run the boolean streamIsSet() method test.
293 */
294 @Test
295 public void testStreamIsSet() {
296 boolean result = fixture.streamIsSet();
297 assertTrue(result);
298 }
299
300 /**
301 * Run the boolean streamIsSet() method test.
302 */
303 @Test
304 public void testStreamIsSet_null() {
305 fixture.setStream((CTFStream) null);
306
307 boolean result = fixture.streamIsSet();
308 assertEquals(false, result);
309 }
310
311 /**
312 * Test for the EventDefinition class
313 *
314 * @throws CTFReaderException
315 */
316 @Test
317 public void testEventDefinition() throws CTFReaderException {
318 try (CTFTrace trace = testTrace.getTrace();) {
319 EventDefinition ed = null;
320 try (CTFTraceReader tr = new CTFTraceReader(trace);) {
321 tr.advance();
322 ed = tr.getCurrentEventDef();
323 }
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
340 EventDeclaration e1;
341 EventDeclaration e2;
342
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 = EventDeclaration.getLostEventDeclaration();
353 assertFalse(e1.equals(new Long(23L)));
354 }
355
356 @Test
357 public void testEquals3(){
358 e1 = EventDeclaration.getLostEventDeclaration();
359 assertEquals(e1,e1);
360 }
361
362 @Test
363 public void testEquals4(){
364 e1 = EventDeclaration.getLostEventDeclaration();
365 e2 = EventDeclaration.getLostEventDeclaration();
366 assertEquals(e1,e2);
367 }
368
369 @Test
370 public void testEquals5(){
371 e1 = EventDeclaration.getLostEventDeclaration();
372 e2 = new EventDeclaration();
373 assertFalse(e1.equals(e2));
374 }
375 }
This page took 0.047354 seconds and 5 git commands to generate.