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