9b3c96c915fc533903b713fc0db6e02a258319cd
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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.types
;
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
;
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
;
35 * The class <code>EventDeclarationTest</code> contains tests for the class
36 * <code>{@link EventDeclaration}</code>.
39 * @version $Revision: 1.0 $
41 @SuppressWarnings("javadoc")
42 public class EventDeclarationTest
{
44 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
46 private EventDeclaration fixture
;
49 * Perform pre-test initialization.
51 * @throws CTFException
54 public void setUp() throws CTFException
{
55 fixture
= new EventDeclaration();
56 fixture
.setContext(new StructDeclaration(1L));
58 fixture
.setFields(new StructDeclaration(1L));
59 fixture
.setStream(new CTFStream(CtfTestTraceUtils
.getTrace(testTrace
)));
64 * Run the EventDeclaration() constructor test.
67 public void testEventDeclaration() {
68 EventDeclaration result
= new EventDeclaration();
69 assertNotNull(result
);
73 * Run the boolean contextIsSet() method test.
76 public void testContextIsSet() {
77 boolean result
= fixture
.contextIsSet();
82 * Run the boolean contextIsSet() method test.
85 public void testContextIsSet_null() {
86 fixture
.setContext((StructDeclaration
) null);
88 boolean result
= fixture
.contextIsSet();
93 * Run the boolean equals(Object) method test.
95 * @throws CTFException
98 public void testEquals() throws CTFException
{
99 EventDeclaration obj
= new EventDeclaration();
100 obj
.setContext(new StructDeclaration(1L));
102 obj
.setFields(new StructDeclaration(1L));
103 obj
.setStream(new CTFStream(CtfTestTraceUtils
.getTrace(testTrace
)));
106 assertTrue(fixture
.equals(fixture
));
107 boolean result
= fixture
.equals(obj
);
112 * Run the boolean equals(Object) method test.
115 public void testEquals_null() {
118 boolean result
= fixture
.equals(obj
);
123 * Run the boolean equals(Object) method test.
126 public void testEquals_emptyObject() {
127 Object obj
= new Object();
129 boolean result
= fixture
.equals(obj
);
134 * Run the boolean equals(Object) method test.
137 public void testEquals_other1() {
138 EventDeclaration obj
= new EventDeclaration();
139 obj
.setContext(fixture
.getContext());
141 boolean result
= fixture
.equals(obj
);
146 * Run the boolean equals(Object) method test.
149 public void testEquals_other2() {
150 EventDeclaration obj
= new EventDeclaration();
151 obj
.setContext(new StructDeclaration(1L));
152 obj
.setFields(new StructDeclaration(1L));
154 boolean result
= fixture
.equals(obj
);
159 * Run the boolean equals(Object) method test.
162 public void testEquals_other3() {
163 EventDeclaration obj
= new EventDeclaration();
164 obj
.setContext(new StructDeclaration(1L));
166 obj
.setFields(new StructDeclaration(1L));
168 boolean result
= fixture
.equals(obj
);
173 * Run the boolean equals(Object) method test.
176 public void testEquals_other4() {
177 EventDeclaration obj
= new EventDeclaration();
178 obj
.setContext(new StructDeclaration(1L));
180 obj
.setFields(new StructDeclaration(1L));
183 boolean result
= fixture
.equals(obj
);
188 * Run the boolean fieldsIsSet() method test.
191 public void testFieldsIsSet() {
192 boolean result
= fixture
.fieldsIsSet();
197 * Run the boolean fieldsIsSet() method test.
200 public void testFieldsIsSet_null() {
201 fixture
.setFields((StructDeclaration
) null);
203 boolean result
= fixture
.fieldsIsSet();
208 * Run the StructDeclaration getFields() method test.
211 public void testGetFields() {
212 StructDeclaration result
= fixture
.getFields();
213 assertNotNull(result
);
217 * Run the Long getId() method test.
220 public void testGetId() {
221 assertEquals(1, fixture
.id());
225 * Run the String getName() method test.
228 public void testGetName() {
229 String result
= fixture
.getName();
230 assertNotNull(result
);
234 * Run the Stream getStream() method test.
237 public void testGetStream() {
238 CTFStream result
= fixture
.getStream();
239 assertNotNull(result
);
243 * Run the int hashCode() method test.
246 public void testHashCode() {
247 int result
= fixture
.hashCode();
248 assertTrue(0 != result
);
252 * Run the int hashCode() method test.
255 public void testHashCode_null() {
256 fixture
.setStream((CTFStream
) null);
257 fixture
.setName((String
) null);
259 int result
= fixture
.hashCode();
260 assertTrue(0 != result
);
264 * Run the boolean idIsSet() method test.
267 public void testIdIsSet() {
268 boolean result
= fixture
.idIsSet();
273 * Run the boolean nameIsSet() method test.
276 public void testNameIsSet() {
277 boolean result
= fixture
.nameIsSet();
282 * Run the boolean nameIsSet() method test.
285 public void testNameIsSet_null() {
286 fixture
.setName((String
) null);
288 boolean result
= fixture
.nameIsSet();
293 * Run the boolean streamIsSet() method test.
296 public void testStreamIsSet() {
297 boolean result
= fixture
.streamIsSet();
302 * Run the boolean streamIsSet() method test.
305 public void testStreamIsSet_null() {
306 fixture
.setStream((CTFStream
) null);
308 boolean result
= fixture
.streamIsSet();
309 assertEquals(false, result
);
313 * Test for the EventDefinition class
315 * @throws CTFException
318 public void testEventDefinition() throws CTFException
{
319 CTFTrace trace
= CtfTestTraceUtils
.getTrace(testTrace
);
320 EventDefinition ed
= null;
321 try (CTFTraceReader tr
= new CTFTraceReader(trace
);) {
323 ed
= tr
.getCurrentEventDef();
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());
339 IEventDeclaration e1
;
340 IEventDeclaration e2
;
343 public void testEquals1() {
344 e1
= new EventDeclaration();
345 assertFalse(e1
.equals(null));
349 public void testEquals2() {
350 e1
= LostEventDeclaration
.INSTANCE
;
351 assertFalse(e1
.equals(new Long(23L)));
355 public void testEquals3() {
356 e1
= LostEventDeclaration
.INSTANCE
;
357 assertEquals(e1
, e1
);
361 public void testEquals4() {
362 e1
= LostEventDeclaration
.INSTANCE
;
363 e2
= LostEventDeclaration
.INSTANCE
;
364 assertEquals(e1
, e2
);
368 public void testEquals5() {
369 e1
= LostEventDeclaration
.INSTANCE
;
370 e2
= new EventDeclaration();
371 assertFalse(e1
.equals(e2
));
This page took 0.042247 seconds and 4 git commands to generate.