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
;
19 import static org
.junit
.Assume
.assumeTrue
;
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
;
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 assumeTrue(testTrace
.exists());
56 fixture
= new EventDeclaration();
57 fixture
.setContext(new StructDeclaration(1L));
59 fixture
.setFields(new StructDeclaration(1L));
60 fixture
.setStream(new CTFStream(testTrace
.getTrace()));
65 * Run the EventDeclaration() constructor test.
68 public void testEventDeclaration() {
69 EventDeclaration result
= new EventDeclaration();
70 assertNotNull(result
);
74 * Run the boolean contextIsSet() method test.
77 public void testContextIsSet() {
78 boolean result
= fixture
.contextIsSet();
83 * Run the boolean contextIsSet() method test.
86 public void testContextIsSet_null() {
87 fixture
.setContext((StructDeclaration
) null);
89 boolean result
= fixture
.contextIsSet();
94 * Run the boolean equals(Object) method test.
96 * @throws CTFException
99 public void testEquals() throws CTFException
{
100 EventDeclaration obj
= new EventDeclaration();
101 obj
.setContext(new StructDeclaration(1L));
103 obj
.setFields(new StructDeclaration(1L));
104 obj
.setStream(new CTFStream(testTrace
.getTrace()));
107 assertTrue(fixture
.equals(fixture
));
108 boolean result
= fixture
.equals(obj
);
113 * Run the boolean equals(Object) method test.
116 public void testEquals_null() {
119 boolean result
= fixture
.equals(obj
);
124 * Run the boolean equals(Object) method test.
127 public void testEquals_emptyObject() {
128 Object obj
= new Object();
130 boolean result
= fixture
.equals(obj
);
135 * Run the boolean equals(Object) method test.
138 public void testEquals_other1() {
139 EventDeclaration obj
= new EventDeclaration();
140 obj
.setContext(fixture
.getContext());
142 boolean result
= fixture
.equals(obj
);
147 * Run the boolean equals(Object) method test.
150 public void testEquals_other2() {
151 EventDeclaration obj
= new EventDeclaration();
152 obj
.setContext(new StructDeclaration(1L));
153 obj
.setFields(new StructDeclaration(1L));
155 boolean result
= fixture
.equals(obj
);
160 * Run the boolean equals(Object) method test.
163 public void testEquals_other3() {
164 EventDeclaration obj
= new EventDeclaration();
165 obj
.setContext(new StructDeclaration(1L));
167 obj
.setFields(new StructDeclaration(1L));
169 boolean result
= fixture
.equals(obj
);
174 * Run the boolean equals(Object) method test.
177 public void testEquals_other4() {
178 EventDeclaration obj
= new EventDeclaration();
179 obj
.setContext(new StructDeclaration(1L));
181 obj
.setFields(new StructDeclaration(1L));
184 boolean result
= fixture
.equals(obj
);
189 * Run the boolean fieldsIsSet() method test.
192 public void testFieldsIsSet() {
193 boolean result
= fixture
.fieldsIsSet();
198 * Run the boolean fieldsIsSet() method test.
201 public void testFieldsIsSet_null() {
202 fixture
.setFields((StructDeclaration
) null);
204 boolean result
= fixture
.fieldsIsSet();
209 * Run the StructDeclaration getFields() method test.
212 public void testGetFields() {
213 StructDeclaration result
= fixture
.getFields();
214 assertNotNull(result
);
218 * Run the Long getId() method test.
221 public void testGetId() {
222 assertEquals(1, fixture
.id());
226 * Run the String getName() method test.
229 public void testGetName() {
230 String result
= fixture
.getName();
231 assertNotNull(result
);
235 * Run the Stream getStream() method test.
238 public void testGetStream() {
239 CTFStream result
= fixture
.getStream();
240 assertNotNull(result
);
244 * Run the int hashCode() method test.
247 public void testHashCode() {
248 int result
= fixture
.hashCode();
249 assertTrue(0 != result
);
253 * Run the int hashCode() method test.
256 public void testHashCode_null() {
257 fixture
.setStream((CTFStream
) null);
258 fixture
.setName((String
) null);
260 int result
= fixture
.hashCode();
261 assertTrue(0 != result
);
265 * Run the boolean idIsSet() method test.
268 public void testIdIsSet() {
269 boolean result
= fixture
.idIsSet();
274 * Run the boolean nameIsSet() method test.
277 public void testNameIsSet() {
278 boolean result
= fixture
.nameIsSet();
283 * Run the boolean nameIsSet() method test.
286 public void testNameIsSet_null() {
287 fixture
.setName((String
) null);
289 boolean result
= fixture
.nameIsSet();
294 * Run the boolean streamIsSet() method test.
297 public void testStreamIsSet() {
298 boolean result
= fixture
.streamIsSet();
303 * Run the boolean streamIsSet() method test.
306 public void testStreamIsSet_null() {
307 fixture
.setStream((CTFStream
) null);
309 boolean result
= fixture
.streamIsSet();
310 assertEquals(false, result
);
314 * Test for the EventDefinition class
316 * @throws CTFException
319 public void testEventDefinition() throws CTFException
{
320 CTFTrace trace
= testTrace
.getTrace();
321 EventDefinition ed
= null;
322 try (CTFTraceReader tr
= new CTFTraceReader(trace
);) {
324 ed
= tr
.getCurrentEventDef();
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());
341 IEventDeclaration e1
;
342 IEventDeclaration e2
;
345 public void testEquals1() {
346 e1
= new EventDeclaration();
347 assertFalse(e1
.equals(null));
351 public void testEquals2() {
352 e1
= LostEventDeclaration
.INSTANCE
;
353 assertFalse(e1
.equals(new Long(23L)));
357 public void testEquals3() {
358 e1
= LostEventDeclaration
.INSTANCE
;
359 assertEquals(e1
, e1
);
363 public void testEquals4() {
364 e1
= LostEventDeclaration
.INSTANCE
;
365 e2
= LostEventDeclaration
.INSTANCE
;
366 assertEquals(e1
, e2
);
370 public void testEquals5() {
371 e1
= LostEventDeclaration
.INSTANCE
;
372 e2
= new EventDeclaration();
373 assertFalse(e1
.equals(e2
));
This page took 0.041786 seconds and 6 git commands to generate.