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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.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
.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
;
33 * The class <code>EventDeclarationTest</code> contains tests for the class
34 * <code>{@link EventDeclaration}</code>.
37 * @version $Revision: 1.0 $
39 @SuppressWarnings("javadoc")
40 public class EventDeclarationTest
{
42 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
44 private EventDeclaration fixture
;
47 * Perform pre-test initialization.
49 * @throws CTFReaderException
52 public void setUp() throws CTFReaderException
{
53 assumeTrue(testTrace
.exists());
54 fixture
= new EventDeclaration();
55 fixture
.setContext(new StructDeclaration(1L));
57 fixture
.setFields(new StructDeclaration(1L));
58 fixture
.setStream(new CTFStream(testTrace
.getTrace()));
63 * Run the EventDeclaration() constructor test.
66 public void testEventDeclaration() {
67 EventDeclaration result
= new EventDeclaration();
68 assertNotNull(result
);
72 * Run the boolean contextIsSet() method test.
75 public void testContextIsSet() {
76 boolean result
= fixture
.contextIsSet();
81 * Run the boolean contextIsSet() method test.
84 public void testContextIsSet_null() {
85 fixture
.setContext((StructDeclaration
) null);
87 boolean result
= fixture
.contextIsSet();
92 * Run the boolean equals(Object) method test.
94 * @throws CTFReaderException
97 public void testEquals() throws CTFReaderException
{
98 EventDeclaration obj
= new EventDeclaration();
99 obj
.setContext(new StructDeclaration(1L));
101 obj
.setFields(new StructDeclaration(1L));
102 obj
.setStream(new CTFStream(testTrace
.getTrace()));
105 assertTrue(fixture
.equals(fixture
));
106 boolean result
= fixture
.equals(obj
);
111 * Run the boolean equals(Object) method test.
114 public void testEquals_null() {
117 boolean result
= fixture
.equals(obj
);
122 * Run the boolean equals(Object) method test.
125 public void testEquals_emptyObject() {
126 Object obj
= new Object();
128 boolean result
= fixture
.equals(obj
);
133 * Run the boolean equals(Object) method test.
136 public void testEquals_other1() {
137 EventDeclaration obj
= new EventDeclaration();
138 obj
.setContext(fixture
.getContext());
140 boolean result
= fixture
.equals(obj
);
145 * Run the boolean equals(Object) method test.
148 public void testEquals_other2() {
149 EventDeclaration obj
= new EventDeclaration();
150 obj
.setContext(new StructDeclaration(1L));
151 obj
.setFields(new StructDeclaration(1L));
153 boolean result
= fixture
.equals(obj
);
158 * Run the boolean equals(Object) method test.
161 public void testEquals_other3() {
162 EventDeclaration obj
= new EventDeclaration();
163 obj
.setContext(new StructDeclaration(1L));
165 obj
.setFields(new StructDeclaration(1L));
167 boolean result
= fixture
.equals(obj
);
172 * Run the boolean equals(Object) method test.
175 public void testEquals_other4() {
176 EventDeclaration obj
= new EventDeclaration();
177 obj
.setContext(new StructDeclaration(1L));
179 obj
.setFields(new StructDeclaration(1L));
182 boolean result
= fixture
.equals(obj
);
187 * Run the boolean fieldsIsSet() method test.
190 public void testFieldsIsSet() {
191 boolean result
= fixture
.fieldsIsSet();
196 * Run the boolean fieldsIsSet() method test.
199 public void testFieldsIsSet_null() {
200 fixture
.setFields((StructDeclaration
) null);
202 boolean result
= fixture
.fieldsIsSet();
207 * Run the StructDeclaration getFields() method test.
210 public void testGetFields() {
211 StructDeclaration result
= fixture
.getFields();
212 assertNotNull(result
);
216 * Run the Long getId() method test.
219 public void testGetId() {
220 assertEquals(1,fixture
.id());
224 * Run the String getName() method test.
227 public void testGetName() {
228 String result
= fixture
.getName();
229 assertNotNull(result
);
233 * Run the Stream getStream() method test.
236 public void testGetStream() {
237 CTFStream result
= fixture
.getStream();
238 assertNotNull(result
);
242 * Run the int hashCode() method test.
245 public void testHashCode() {
246 int result
= fixture
.hashCode();
247 assertTrue(0 != result
);
251 * Run the int hashCode() method test.
254 public void testHashCode_null() {
255 fixture
.setStream((CTFStream
) null);
256 fixture
.setName((String
) null);
258 int result
= fixture
.hashCode();
259 assertTrue(0 != result
);
263 * Run the boolean idIsSet() method test.
266 public void testIdIsSet() {
267 boolean result
= fixture
.idIsSet();
272 * Run the boolean nameIsSet() method test.
275 public void testNameIsSet() {
276 boolean result
= fixture
.nameIsSet();
281 * Run the boolean nameIsSet() method test.
284 public void testNameIsSet_null() {
285 fixture
.setName((String
) null);
287 boolean result
= fixture
.nameIsSet();
292 * Run the boolean streamIsSet() method test.
295 public void testStreamIsSet() {
296 boolean result
= fixture
.streamIsSet();
301 * Run the boolean streamIsSet() method test.
304 public void testStreamIsSet_null() {
305 fixture
.setStream((CTFStream
) null);
307 boolean result
= fixture
.streamIsSet();
308 assertEquals(false, result
);
312 * Test for the EventDefinition class
314 * @throws CTFReaderException
317 public void testEventDefinition() throws CTFReaderException
{
318 try (CTFTrace trace
= testTrace
.getTrace();) {
319 EventDefinition ed
= null;
320 try (CTFTraceReader tr
= new CTFTraceReader(trace
);) {
322 ed
= tr
.getCurrentEventDef();
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());
345 public void testEquals1(){
346 e1
= new EventDeclaration();
347 assertFalse(e1
.equals(null));
351 public void testEquals2(){
352 e1
= EventDeclaration
.getLostEventDeclaration();
353 assertFalse(e1
.equals(new Long(23L)));
357 public void testEquals3(){
358 e1
= EventDeclaration
.getLostEventDeclaration();
363 public void testEquals4(){
364 e1
= EventDeclaration
.getLostEventDeclaration();
365 e2
= EventDeclaration
.getLostEventDeclaration();
370 public void testEquals5(){
371 e1
= EventDeclaration
.getLostEventDeclaration();
372 e2
= new EventDeclaration();
373 assertFalse(e1
.equals(e2
));
This page took 0.047354 seconds and 5 git commands to generate.