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
.CTFTrace
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
17 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.Stream
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInput
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
20 import org
.junit
.After
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
25 * The class <code>EventDeclarationTest</code> contains tests for the class
26 * <code>{@link EventDeclaration}</code>.
29 * @version $Revision: 1.0 $
31 public class EventDeclarationTest
{
33 private EventDeclaration fixture
;
39 * the command line arguments
41 public static void main(String
[] args
) {
42 new org
.junit
.runner
.JUnitCore().run(EventDeclarationTest
.class);
46 * Perform pre-test initialization.
50 fixture
= new EventDeclaration();
51 fixture
.setContext(new StructDeclaration(1L));
53 fixture
.setFields(new StructDeclaration(1L));
54 fixture
.setStream(new Stream(TestParams
.createTrace()));
55 fixture
.setName(""); //$NON-NLS-1$
59 * Perform post-test clean-up.
62 public void tearDown() {
63 // Add additional tear down code here
67 * Run the EventDeclaration() constructor test.
70 public void testEventDeclaration() {
71 EventDeclaration result
= new EventDeclaration();
72 assertNotNull(result
);
76 * Run the boolean contextIsSet() method test.
79 public void testContextIsSet() {
80 boolean result
= fixture
.contextIsSet();
85 * Run the boolean contextIsSet() method test.
88 public void testContextIsSet_null() {
89 fixture
.setContext((StructDeclaration
) null);
91 boolean result
= fixture
.contextIsSet();
96 * Run the EventDefinition createDefinition(StreamInputReader) method test.
99 public void testCreateDefinition() {
100 StreamInputReader streamInputReader
= new StreamInputReader(
101 new StreamInput(new Stream(TestParams
.createTrace()),
102 (FileChannel
) null, TestParams
.getEmptyFile()));
104 EventDefinition result
= fixture
.createDefinition(streamInputReader
);
105 assertNotNull(result
);
109 * Run the boolean equals(Object) method test.
112 public void testEquals() {
113 EventDeclaration obj
= new EventDeclaration();
114 obj
.setContext(new StructDeclaration(1L));
116 obj
.setFields(new StructDeclaration(1L));
117 obj
.setStream(new Stream(TestParams
.createTrace()));
118 obj
.setName(""); //$NON-NLS-1$
120 assertTrue(fixture
.equals(fixture
));
121 boolean result
= fixture
.equals(obj
);
126 * Run the boolean equals(Object) method test.
129 public void testEquals_null() {
132 boolean result
= fixture
.equals(obj
);
137 * Run the boolean equals(Object) method test.
140 public void testEquals_emptyObject() {
141 Object obj
= new Object();
143 boolean result
= fixture
.equals(obj
);
148 * Run the boolean equals(Object) method test.
151 public void testEquals_other1() {
152 EventDeclaration obj
= new EventDeclaration();
153 obj
.setContext(fixture
.getContext());
155 boolean result
= fixture
.equals(obj
);
160 * Run the boolean equals(Object) method test.
163 public void testEquals_other2() {
164 EventDeclaration obj
= new EventDeclaration();
165 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_other3() {
177 EventDeclaration obj
= new EventDeclaration();
178 obj
.setContext(new StructDeclaration(1L));
180 obj
.setFields(new StructDeclaration(1L));
182 boolean result
= fixture
.equals(obj
);
187 * Run the boolean equals(Object) method test.
190 public void testEquals_other4() {
191 EventDeclaration obj
= new EventDeclaration();
192 obj
.setContext(new StructDeclaration(1L));
194 obj
.setFields(new StructDeclaration(1L));
195 obj
.setName(""); //$NON-NLS-1$
197 boolean result
= fixture
.equals(obj
);
202 * Run the boolean fieldsIsSet() method test.
205 public void testFieldsIsSet() {
206 boolean result
= fixture
.fieldsIsSet();
211 * Run the boolean fieldsIsSet() method test.
214 public void testFieldsIsSet_null() {
215 fixture
.setFields((StructDeclaration
) null);
217 boolean result
= fixture
.fieldsIsSet();
222 * Run the StructDeclaration getFields() method test.
225 public void testGetFields() {
226 StructDeclaration result
= fixture
.getFields();
227 assertNotNull(result
);
231 * Run the Long getId() method test.
234 public void testGetId() {
235 Long result
= fixture
.getId();
236 assertNotNull(result
);
240 * Run the String getName() method test.
243 public void testGetName() {
244 String result
= fixture
.getName();
245 assertNotNull(result
);
249 * Run the Stream getStream() method test.
252 public void testGetStream() {
253 Stream result
= fixture
.getStream();
254 assertNotNull(result
);
258 * Run the int hashCode() method test.
261 public void testHashCode() {
262 int result
= fixture
.hashCode();
263 assertTrue(0 != result
);
267 * Run the int hashCode() method test.
270 public void testHashCode_null() {
271 fixture
.setStream((Stream
) null);
272 fixture
.setName((String
) null);
274 int result
= fixture
.hashCode();
275 assertTrue(0 != result
);
279 * Run the boolean idIsSet() method test.
282 public void testIdIsSet() {
283 boolean result
= fixture
.idIsSet();
288 * Run the boolean nameIsSet() method test.
291 public void testNameIsSet() {
292 boolean result
= fixture
.nameIsSet();
297 * Run the boolean nameIsSet() method test.
300 public void testNameIsSet_null() {
301 fixture
.setName((String
) null);
303 boolean result
= fixture
.nameIsSet();
308 * Run the boolean streamIsSet() method test.
311 public void testStreamIsSet() {
312 boolean result
= fixture
.streamIsSet();
317 * Run the boolean streamIsSet() method test.
320 public void testStreamIsSet_null() {
321 fixture
.setStream((Stream
) null);
323 boolean result
= fixture
.streamIsSet();
324 assertEquals(false, result
);
328 * Test for the EventDefinition class
331 public void testEventDefinition() {
332 CTFTrace trace
= TestParams
.createTrace();
333 CTFTraceReader tr
= new CTFTraceReader(trace
);
335 EventDefinition ed
= new EventDefinition(null, null);
336 ed
= tr
.getCurrentEventDef();
338 assertNotNull(ed
.getPath());
339 assertNotNull(ed
.getDeclaration());
340 assertNotNull(ed
.getFields());
341 assertNull(ed
.getContext());
342 assertNotNull(ed
.getPacketContext());
343 assertNotNull(ed
.getCPU());
344 assertNotNull(ed
.getPacketContext());
345 assertNotNull(ed
.getStreamInputReader());
346 assertNull(ed
.lookupDefinition("context")); //$NON-NLS-1$
347 assertNotNull(ed
.lookupDefinition("fields")); //$NON-NLS-1$
348 assertNull(ed
.lookupDefinition("other")); //$NON-NLS-1$
349 assertNotNull(ed
.toString());
350 ed
.context
= ed
.getFields();
351 assertNotNull(ed
.toString());