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