1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertFalse
;
5 import static org
.junit
.Assert
.assertNotNull
;
6 import static org
.junit
.Assert
.assertNull
;
7 import static org
.junit
.Assert
.assertTrue
;
9 import java
.nio
.channels
.FileChannel
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDeclaration
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
19 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.Stream
;
20 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.StreamInput
;
21 import org
.junit
.After
;
22 import org
.junit
.Before
;
23 import org
.junit
.Test
;
26 * The class <code>EventDeclarationTest</code> contains tests for the class
27 * <code>{@link EventDeclaration}</code>.
30 * @version $Revision: 1.0 $
32 public class EventDeclarationTest
{
34 private EventDeclaration fixture
;
40 * the command line arguments
42 public static void main(String
[] args
) {
43 new org
.junit
.runner
.JUnitCore().run(EventDeclarationTest
.class);
47 * Perform pre-test initialization.
49 * @throws CTFReaderException
52 public void setUp() throws CTFReaderException
{
53 fixture
= new EventDeclaration();
54 fixture
.setContext(new StructDeclaration(1L));
56 fixture
.setFields(new StructDeclaration(1L));
57 fixture
.setStream(new Stream(TestParams
.createTrace()));
58 fixture
.setName(""); //$NON-NLS-1$
62 * Perform post-test clean-up.
65 public void tearDown() {
66 // Add additional tear down code here
70 * Run the EventDeclaration() constructor test.
73 public void testEventDeclaration() {
74 EventDeclaration result
= new EventDeclaration();
75 assertNotNull(result
);
79 * Run the boolean contextIsSet() method test.
82 public void testContextIsSet() {
83 boolean result
= fixture
.contextIsSet();
88 * Run the boolean contextIsSet() method test.
91 public void testContextIsSet_null() {
92 fixture
.setContext((StructDeclaration
) null);
94 boolean result
= fixture
.contextIsSet();
99 * Run the EventDefinition createDefinition(StreamInputReader) method test.
101 * @throws CTFReaderException
104 public void testCreateDefinition() throws CTFReaderException
{
105 StreamInputReader streamInputReader
= new StreamInputReader(
106 new StreamInput(new Stream(TestParams
.createTrace()),
107 (FileChannel
) null, TestParams
.getTraceFile()));
109 EventDefinition result
= fixture
.createDefinition(streamInputReader
);
110 assertNotNull(result
);
114 * Run the boolean equals(Object) method test.
116 * @throws CTFReaderException
119 public void testEquals() throws CTFReaderException
{
120 EventDeclaration obj
= new EventDeclaration();
121 obj
.setContext(new StructDeclaration(1L));
123 obj
.setFields(new StructDeclaration(1L));
124 obj
.setStream(new Stream(TestParams
.createTrace()));
125 obj
.setName(""); //$NON-NLS-1$
127 assertTrue(fixture
.equals(fixture
));
128 boolean result
= fixture
.equals(obj
);
133 * Run the boolean equals(Object) method test.
136 public void testEquals_null() {
139 boolean result
= fixture
.equals(obj
);
144 * Run the boolean equals(Object) method test.
147 public void testEquals_emptyObject() {
148 Object obj
= new Object();
150 boolean result
= fixture
.equals(obj
);
155 * Run the boolean equals(Object) method test.
158 public void testEquals_other1() {
159 EventDeclaration obj
= new EventDeclaration();
160 obj
.setContext(fixture
.getContext());
162 boolean result
= fixture
.equals(obj
);
167 * Run the boolean equals(Object) method test.
170 public void testEquals_other2() {
171 EventDeclaration obj
= new EventDeclaration();
172 obj
.setContext(new StructDeclaration(1L));
173 obj
.setFields(new StructDeclaration(1L));
175 boolean result
= fixture
.equals(obj
);
180 * Run the boolean equals(Object) method test.
183 public void testEquals_other3() {
184 EventDeclaration obj
= new EventDeclaration();
185 obj
.setContext(new StructDeclaration(1L));
187 obj
.setFields(new StructDeclaration(1L));
189 boolean result
= fixture
.equals(obj
);
194 * Run the boolean equals(Object) method test.
197 public void testEquals_other4() {
198 EventDeclaration obj
= new EventDeclaration();
199 obj
.setContext(new StructDeclaration(1L));
201 obj
.setFields(new StructDeclaration(1L));
202 obj
.setName(""); //$NON-NLS-1$
204 boolean result
= fixture
.equals(obj
);
209 * Run the boolean fieldsIsSet() method test.
212 public void testFieldsIsSet() {
213 boolean result
= fixture
.fieldsIsSet();
218 * Run the boolean fieldsIsSet() method test.
221 public void testFieldsIsSet_null() {
222 fixture
.setFields((StructDeclaration
) null);
224 boolean result
= fixture
.fieldsIsSet();
229 * Run the StructDeclaration getFields() method test.
232 public void testGetFields() {
233 StructDeclaration result
= fixture
.getFields();
234 assertNotNull(result
);
238 * Run the Long getId() method test.
241 public void testGetId() {
242 Long result
= fixture
.getId();
243 assertNotNull(result
);
247 * Run the String getName() method test.
250 public void testGetName() {
251 String result
= fixture
.getName();
252 assertNotNull(result
);
256 * Run the Stream getStream() method test.
259 public void testGetStream() {
260 Stream result
= fixture
.getStream();
261 assertNotNull(result
);
265 * Run the int hashCode() method test.
268 public void testHashCode() {
269 int result
= fixture
.hashCode();
270 assertTrue(0 != result
);
274 * Run the int hashCode() method test.
277 public void testHashCode_null() {
278 fixture
.setStream((Stream
) null);
279 fixture
.setName((String
) null);
281 int result
= fixture
.hashCode();
282 assertTrue(0 != result
);
286 * Run the boolean idIsSet() method test.
289 public void testIdIsSet() {
290 boolean result
= fixture
.idIsSet();
295 * Run the boolean nameIsSet() method test.
298 public void testNameIsSet() {
299 boolean result
= fixture
.nameIsSet();
304 * Run the boolean nameIsSet() method test.
307 public void testNameIsSet_null() {
308 fixture
.setName((String
) null);
310 boolean result
= fixture
.nameIsSet();
315 * Run the boolean streamIsSet() method test.
318 public void testStreamIsSet() {
319 boolean result
= fixture
.streamIsSet();
324 * Run the boolean streamIsSet() method test.
327 public void testStreamIsSet_null() {
328 fixture
.setStream((Stream
) null);
330 boolean result
= fixture
.streamIsSet();
331 assertEquals(false, result
);
335 * Test for the EventDefinition class
337 * @throws CTFReaderException
340 public void testEventDefinition() throws CTFReaderException
{
341 CTFTrace trace
= TestParams
.createTrace();
342 CTFTraceReader tr
= new CTFTraceReader(trace
);
344 EventDefinition ed
= new EventDefinition(null, null);
345 ed
= tr
.getCurrentEventDef();
347 assertNotNull(ed
.getPath());
348 assertNotNull(ed
.getDeclaration());
349 assertNotNull(ed
.getFields());
350 assertNull(ed
.getContext());
351 assertNotNull(ed
.getPacketContext());
352 assertNotNull(ed
.getCPU());
353 assertNotNull(ed
.getPacketContext());
354 assertNotNull(ed
.getStreamInputReader());
355 assertNull(ed
.lookupDefinition("context")); //$NON-NLS-1$
356 assertNotNull(ed
.lookupDefinition("fields")); //$NON-NLS-1$
357 assertNull(ed
.lookupDefinition("other")); //$NON-NLS-1$
358 assertNotNull(ed
.toString());
359 ed
.setContext( ed
.getFields());
360 assertNotNull(ed
.toString());
368 public void testEquals1(){
369 e1
= new EventDeclaration();
370 assertFalse(e1
.equals(null));
374 public void testEquals2(){
375 e1
= EventDeclaration
.getLostEventDeclaration();
376 assertFalse(e1
.equals(new Long(23L)));
380 public void testEquals3(){
381 e1
= EventDeclaration
.getLostEventDeclaration();
386 public void testEquals4(){
387 e1
= EventDeclaration
.getLostEventDeclaration();
388 e2
= EventDeclaration
.getLostEventDeclaration();
393 public void testEquals5(){
394 e1
= EventDeclaration
.getLostEventDeclaration();
395 e2
= new EventDeclaration();
396 assertFalse(e1
.equals(e2
));