ctf: Allow the test traces to be used by other plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / EventDeclarationTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.types;
2
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;
8 import static org.junit.Assume.assumeTrue;
9
10 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
11 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
12 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
13 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
14 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
15 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
16 import org.eclipse.linuxtools.ctf.core.trace.Stream;
17 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
18 import org.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21
22 /**
23 * The class <code>EventDeclarationTest</code> contains tests for the class
24 * <code>{@link EventDeclaration}</code>.
25 *
26 * @author ematkho
27 * @version $Revision: 1.0 $
28 */
29 @SuppressWarnings("javadoc")
30 public class EventDeclarationTest {
31
32 private static final int TRACE_INDEX = 0;
33
34 private EventDeclaration fixture;
35
36 /**
37 * Launch the test.
38 *
39 * @param args
40 * the command line arguments
41 */
42 public static void main(String[] args) {
43 new org.junit.runner.JUnitCore().run(EventDeclarationTest.class);
44 }
45
46 /**
47 * Perform pre-test initialization.
48 *
49 * @throws CTFReaderException
50 */
51 @Before
52 public void setUp() throws CTFReaderException {
53 assumeTrue(CtfTestTraces.tracesExist());
54 fixture = new EventDeclaration();
55 fixture.setContext(new StructDeclaration(1L));
56 fixture.setId(1L);
57 fixture.setFields(new StructDeclaration(1L));
58 fixture.setStream(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)));
59 fixture.setName(""); //$NON-NLS-1$
60 }
61
62 /**
63 * Perform post-test clean-up.
64 */
65 @After
66 public void tearDown() {
67 // Add additional tear down code here
68 }
69
70 /**
71 * Run the EventDeclaration() constructor test.
72 */
73 @Test
74 public void testEventDeclaration() {
75 EventDeclaration result = new EventDeclaration();
76 assertNotNull(result);
77 }
78
79 /**
80 * Run the boolean contextIsSet() method test.
81 */
82 @Test
83 public void testContextIsSet() {
84 boolean result = fixture.contextIsSet();
85 assertTrue(result);
86 }
87
88 /**
89 * Run the boolean contextIsSet() method test.
90 */
91 @Test
92 public void testContextIsSet_null() {
93 fixture.setContext((StructDeclaration) null);
94
95 boolean result = fixture.contextIsSet();
96 assertFalse(result);
97 }
98
99 /**
100 * Run the boolean equals(Object) method test.
101 *
102 * @throws CTFReaderException
103 */
104 @Test
105 public void testEquals() throws CTFReaderException {
106 EventDeclaration obj = new EventDeclaration();
107 obj.setContext(new StructDeclaration(1L));
108 obj.setId(1L);
109 obj.setFields(new StructDeclaration(1L));
110 obj.setStream(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)));
111 obj.setName(""); //$NON-NLS-1$
112
113 assertTrue(fixture.equals(fixture));
114 boolean result = fixture.equals(obj);
115 assertFalse(result);
116 }
117
118 /**
119 * Run the boolean equals(Object) method test.
120 */
121 @Test
122 public void testEquals_null() {
123 Object obj = null;
124
125 boolean result = fixture.equals(obj);
126 assertFalse(result);
127 }
128
129 /**
130 * Run the boolean equals(Object) method test.
131 */
132 @Test
133 public void testEquals_emptyObject() {
134 Object obj = new Object();
135
136 boolean result = fixture.equals(obj);
137 assertFalse(result);
138 }
139
140 /**
141 * Run the boolean equals(Object) method test.
142 */
143 @Test
144 public void testEquals_other1() {
145 EventDeclaration obj = new EventDeclaration();
146 obj.setContext(fixture.getContext());
147
148 boolean result = fixture.equals(obj);
149 assertFalse(result);
150 }
151
152 /**
153 * Run the boolean equals(Object) method test.
154 */
155 @Test
156 public void testEquals_other2() {
157 EventDeclaration obj = new EventDeclaration();
158 obj.setContext(new StructDeclaration(1L));
159 obj.setFields(new StructDeclaration(1L));
160
161 boolean result = fixture.equals(obj);
162 assertFalse(result);
163 }
164
165 /**
166 * Run the boolean equals(Object) method test.
167 */
168 @Test
169 public void testEquals_other3() {
170 EventDeclaration obj = new EventDeclaration();
171 obj.setContext(new StructDeclaration(1L));
172 obj.setId(1L);
173 obj.setFields(new StructDeclaration(1L));
174
175 boolean result = fixture.equals(obj);
176 assertFalse(result);
177 }
178
179 /**
180 * Run the boolean equals(Object) method test.
181 */
182 @Test
183 public void testEquals_other4() {
184 EventDeclaration obj = new EventDeclaration();
185 obj.setContext(new StructDeclaration(1L));
186 obj.setId(1L);
187 obj.setFields(new StructDeclaration(1L));
188 obj.setName(""); //$NON-NLS-1$
189
190 boolean result = fixture.equals(obj);
191 assertFalse(result);
192 }
193
194 /**
195 * Run the boolean fieldsIsSet() method test.
196 */
197 @Test
198 public void testFieldsIsSet() {
199 boolean result = fixture.fieldsIsSet();
200 assertTrue(result);
201 }
202
203 /**
204 * Run the boolean fieldsIsSet() method test.
205 */
206 @Test
207 public void testFieldsIsSet_null() {
208 fixture.setFields((StructDeclaration) null);
209
210 boolean result = fixture.fieldsIsSet();
211 assertFalse(result);
212 }
213
214 /**
215 * Run the StructDeclaration getFields() method test.
216 */
217 @Test
218 public void testGetFields() {
219 StructDeclaration result = fixture.getFields();
220 assertNotNull(result);
221 }
222
223 /**
224 * Run the Long getId() method test.
225 */
226 @Test
227 public void testGetId() {
228 Long result = fixture.getId();
229 assertNotNull(result);
230 }
231
232 /**
233 * Run the String getName() method test.
234 */
235 @Test
236 public void testGetName() {
237 String result = fixture.getName();
238 assertNotNull(result);
239 }
240
241 /**
242 * Run the Stream getStream() method test.
243 */
244 @Test
245 public void testGetStream() {
246 Stream result = fixture.getStream();
247 assertNotNull(result);
248 }
249
250 /**
251 * Run the int hashCode() method test.
252 */
253 @Test
254 public void testHashCode() {
255 int result = fixture.hashCode();
256 assertTrue(0 != result);
257 }
258
259 /**
260 * Run the int hashCode() method test.
261 */
262 @Test
263 public void testHashCode_null() {
264 fixture.setStream((Stream) null);
265 fixture.setName((String) null);
266
267 int result = fixture.hashCode();
268 assertTrue(0 != result);
269 }
270
271 /**
272 * Run the boolean idIsSet() method test.
273 */
274 @Test
275 public void testIdIsSet() {
276 boolean result = fixture.idIsSet();
277 assertTrue(result);
278 }
279
280 /**
281 * Run the boolean nameIsSet() method test.
282 */
283 @Test
284 public void testNameIsSet() {
285 boolean result = fixture.nameIsSet();
286 assertTrue(result);
287 }
288
289 /**
290 * Run the boolean nameIsSet() method test.
291 */
292 @Test
293 public void testNameIsSet_null() {
294 fixture.setName((String) null);
295
296 boolean result = fixture.nameIsSet();
297 assertFalse(result);
298 }
299
300 /**
301 * Run the boolean streamIsSet() method test.
302 */
303 @Test
304 public void testStreamIsSet() {
305 boolean result = fixture.streamIsSet();
306 assertTrue(result);
307 }
308
309 /**
310 * Run the boolean streamIsSet() method test.
311 */
312 @Test
313 public void testStreamIsSet_null() {
314 fixture.setStream((Stream) null);
315
316 boolean result = fixture.streamIsSet();
317 assertEquals(false, result);
318 }
319
320 /**
321 * Test for the EventDefinition class
322 *
323 * @throws CTFReaderException
324 */
325 @Test
326 public void testEventDefinition() throws CTFReaderException {
327 CTFTrace trace = CtfTestTraces.getTestTrace(TRACE_INDEX);
328 CTFTraceReader tr = new CTFTraceReader(trace);
329 tr.advance();
330 EventDefinition ed = new EventDefinition(null, null);
331 ed = tr.getCurrentEventDef();
332 assertNotNull(ed);
333 assertNotNull(ed.getPath());
334 assertNotNull(ed.getDeclaration());
335 assertNotNull(ed.getFields());
336 assertNull(ed.getContext());
337 assertNotNull(ed.getPacketContext());
338 assertNotNull(ed.getCPU());
339 assertNotNull(ed.getPacketContext());
340 assertNotNull(ed.getStreamInputReader());
341 assertNull(ed.lookupDefinition("context")); //$NON-NLS-1$
342 assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$
343 assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$
344 assertNotNull(ed.toString());
345 ed.setContext( ed.getFields());
346 assertNotNull(ed.toString());
347 }
348
349 EventDeclaration e1;
350 EventDeclaration e2;
351
352
353 @Test
354 public void testEquals1(){
355 e1 = new EventDeclaration();
356 assertFalse(e1.equals(null));
357 }
358
359 @Test
360 public void testEquals2(){
361 e1 = EventDeclaration.getLostEventDeclaration();
362 assertFalse(e1.equals(new Long(23L)));
363 }
364
365 @Test
366 public void testEquals3(){
367 e1 = EventDeclaration.getLostEventDeclaration();
368 assertEquals(e1,e1);
369 }
370
371 @Test
372 public void testEquals4(){
373 e1 = EventDeclaration.getLostEventDeclaration();
374 e2 = EventDeclaration.getLostEventDeclaration();
375 assertEquals(e1,e2);
376 }
377
378 @Test
379 public void testEquals5(){
380 e1 = EventDeclaration.getLostEventDeclaration();
381 e2 = new EventDeclaration();
382 assertFalse(e1.equals(e2));
383 }
384 }
This page took 0.039975 seconds and 6 git commands to generate.