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.Before; |
30 | import org.junit.Test; | |
31 | ||
32 | /** | |
33 | * The class <code>EventDeclarationTest</code> contains tests for the class | |
34 | * <code>{@link EventDeclaration}</code>. | |
024373d7 | 35 | * |
866e5b51 FC |
36 | * @author ematkho |
37 | * @version $Revision: 1.0 $ | |
38 | */ | |
be6df2d8 | 39 | @SuppressWarnings("javadoc") |
866e5b51 FC |
40 | public class EventDeclarationTest { |
41 | ||
32bf80d2 AM |
42 | private static final int TRACE_INDEX = 0; |
43 | ||
866e5b51 FC |
44 | private EventDeclaration fixture; |
45 | ||
866e5b51 FC |
46 | /** |
47 | * Perform pre-test initialization. | |
024373d7 MK |
48 | * |
49 | * @throws CTFReaderException | |
866e5b51 FC |
50 | */ |
51 | @Before | |
13be1a8f | 52 | public void setUp() throws CTFReaderException { |
32bf80d2 | 53 | assumeTrue(CtfTestTraces.tracesExist()); |
866e5b51 FC |
54 | fixture = new EventDeclaration(); |
55 | fixture.setContext(new StructDeclaration(1L)); | |
56 | fixture.setId(1L); | |
57 | fixture.setFields(new StructDeclaration(1L)); | |
32bf80d2 | 58 | fixture.setStream(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX))); |
4a9c1f07 | 59 | fixture.setName(""); |
866e5b51 FC |
60 | } |
61 | ||
866e5b51 FC |
62 | /** |
63 | * Run the EventDeclaration() constructor test. | |
64 | */ | |
65 | @Test | |
66 | public void testEventDeclaration() { | |
67 | EventDeclaration result = new EventDeclaration(); | |
68 | assertNotNull(result); | |
69 | } | |
70 | ||
71 | /** | |
72 | * Run the boolean contextIsSet() method test. | |
73 | */ | |
74 | @Test | |
75 | public void testContextIsSet() { | |
76 | boolean result = fixture.contextIsSet(); | |
77 | assertTrue(result); | |
78 | } | |
79 | ||
80 | /** | |
81 | * Run the boolean contextIsSet() method test. | |
82 | */ | |
83 | @Test | |
84 | public void testContextIsSet_null() { | |
85 | fixture.setContext((StructDeclaration) null); | |
86 | ||
87 | boolean result = fixture.contextIsSet(); | |
88 | assertFalse(result); | |
89 | } | |
90 | ||
866e5b51 FC |
91 | /** |
92 | * Run the boolean equals(Object) method test. | |
024373d7 MK |
93 | * |
94 | * @throws CTFReaderException | |
866e5b51 FC |
95 | */ |
96 | @Test | |
13be1a8f | 97 | public void testEquals() throws CTFReaderException { |
866e5b51 FC |
98 | EventDeclaration obj = new EventDeclaration(); |
99 | obj.setContext(new StructDeclaration(1L)); | |
100 | obj.setId(1L); | |
101 | obj.setFields(new StructDeclaration(1L)); | |
32bf80d2 | 102 | obj.setStream(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX))); |
4a9c1f07 | 103 | obj.setName(""); |
866e5b51 FC |
104 | |
105 | assertTrue(fixture.equals(fixture)); | |
106 | boolean result = fixture.equals(obj); | |
107 | assertFalse(result); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Run the boolean equals(Object) method test. | |
112 | */ | |
113 | @Test | |
114 | public void testEquals_null() { | |
115 | Object obj = null; | |
116 | ||
117 | boolean result = fixture.equals(obj); | |
118 | assertFalse(result); | |
119 | } | |
120 | ||
121 | /** | |
122 | * Run the boolean equals(Object) method test. | |
123 | */ | |
124 | @Test | |
125 | public void testEquals_emptyObject() { | |
126 | Object obj = new Object(); | |
127 | ||
128 | boolean result = fixture.equals(obj); | |
129 | assertFalse(result); | |
130 | } | |
131 | ||
132 | /** | |
133 | * Run the boolean equals(Object) method test. | |
134 | */ | |
135 | @Test | |
136 | public void testEquals_other1() { | |
137 | EventDeclaration obj = new EventDeclaration(); | |
138 | obj.setContext(fixture.getContext()); | |
139 | ||
140 | boolean result = fixture.equals(obj); | |
141 | assertFalse(result); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Run the boolean equals(Object) method test. | |
146 | */ | |
147 | @Test | |
148 | public void testEquals_other2() { | |
149 | EventDeclaration obj = new EventDeclaration(); | |
150 | obj.setContext(new StructDeclaration(1L)); | |
151 | obj.setFields(new StructDeclaration(1L)); | |
152 | ||
153 | boolean result = fixture.equals(obj); | |
154 | assertFalse(result); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Run the boolean equals(Object) method test. | |
159 | */ | |
160 | @Test | |
161 | public void testEquals_other3() { | |
162 | EventDeclaration obj = new EventDeclaration(); | |
163 | obj.setContext(new StructDeclaration(1L)); | |
164 | obj.setId(1L); | |
165 | obj.setFields(new StructDeclaration(1L)); | |
166 | ||
167 | boolean result = fixture.equals(obj); | |
168 | assertFalse(result); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Run the boolean equals(Object) method test. | |
173 | */ | |
174 | @Test | |
175 | public void testEquals_other4() { | |
176 | EventDeclaration obj = new EventDeclaration(); | |
177 | obj.setContext(new StructDeclaration(1L)); | |
178 | obj.setId(1L); | |
179 | obj.setFields(new StructDeclaration(1L)); | |
4a9c1f07 | 180 | obj.setName(""); |
866e5b51 FC |
181 | |
182 | boolean result = fixture.equals(obj); | |
183 | assertFalse(result); | |
184 | } | |
185 | ||
186 | /** | |
187 | * Run the boolean fieldsIsSet() method test. | |
188 | */ | |
189 | @Test | |
190 | public void testFieldsIsSet() { | |
191 | boolean result = fixture.fieldsIsSet(); | |
192 | assertTrue(result); | |
193 | } | |
194 | ||
195 | /** | |
196 | * Run the boolean fieldsIsSet() method test. | |
197 | */ | |
198 | @Test | |
199 | public void testFieldsIsSet_null() { | |
200 | fixture.setFields((StructDeclaration) null); | |
201 | ||
202 | boolean result = fixture.fieldsIsSet(); | |
203 | assertFalse(result); | |
204 | } | |
205 | ||
206 | /** | |
207 | * Run the StructDeclaration getFields() method test. | |
208 | */ | |
209 | @Test | |
210 | public void testGetFields() { | |
211 | StructDeclaration result = fixture.getFields(); | |
212 | assertNotNull(result); | |
213 | } | |
214 | ||
215 | /** | |
216 | * Run the Long getId() method test. | |
217 | */ | |
218 | @Test | |
219 | public void testGetId() { | |
220 | Long result = fixture.getId(); | |
221 | assertNotNull(result); | |
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() { | |
238 | Stream result = fixture.getStream(); | |
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() { | |
256 | fixture.setStream((Stream) null); | |
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() { | |
306 | fixture.setStream((Stream) null); | |
307 | ||
308 | boolean result = fixture.streamIsSet(); | |
309 | assertEquals(false, result); | |
310 | } | |
311 | ||
312 | /** | |
313 | * Test for the EventDefinition class | |
024373d7 MK |
314 | * |
315 | * @throws CTFReaderException | |
866e5b51 FC |
316 | */ |
317 | @Test | |
13be1a8f | 318 | public void testEventDefinition() throws CTFReaderException { |
32bf80d2 | 319 | CTFTrace trace = CtfTestTraces.getTestTrace(TRACE_INDEX); |
866e5b51 FC |
320 | CTFTraceReader tr = new CTFTraceReader(trace); |
321 | tr.advance(); | |
322 | EventDefinition ed = new EventDefinition(null, null); | |
323 | ed = tr.getCurrentEventDef(); | |
324 | assertNotNull(ed); | |
325 | assertNotNull(ed.getPath()); | |
326 | assertNotNull(ed.getDeclaration()); | |
327 | assertNotNull(ed.getFields()); | |
328 | assertNull(ed.getContext()); | |
329 | assertNotNull(ed.getPacketContext()); | |
330 | assertNotNull(ed.getCPU()); | |
331 | assertNotNull(ed.getPacketContext()); | |
332 | assertNotNull(ed.getStreamInputReader()); | |
4a9c1f07 AM |
333 | assertNull(ed.lookupDefinition("context")); |
334 | assertNotNull(ed.lookupDefinition("fields")); | |
335 | assertNull(ed.lookupDefinition("other")); | |
866e5b51 | 336 | assertNotNull(ed.toString()); |
aa572e22 | 337 | ed.setContext( ed.getFields()); |
866e5b51 | 338 | assertNotNull(ed.toString()); |
4dd0eaed MK |
339 | } |
340 | ||
341 | EventDeclaration e1; | |
342 | EventDeclaration e2; | |
343 | ||
344 | ||
345 | @Test | |
346 | public void testEquals1(){ | |
347 | e1 = new EventDeclaration(); | |
348 | assertFalse(e1.equals(null)); | |
349 | } | |
350 | ||
351 | @Test | |
352 | public void testEquals2(){ | |
353 | e1 = EventDeclaration.getLostEventDeclaration(); | |
354 | assertFalse(e1.equals(new Long(23L))); | |
355 | } | |
356 | ||
357 | @Test | |
358 | public void testEquals3(){ | |
359 | e1 = EventDeclaration.getLostEventDeclaration(); | |
360 | assertEquals(e1,e1); | |
361 | } | |
866e5b51 | 362 | |
4dd0eaed MK |
363 | @Test |
364 | public void testEquals4(){ | |
365 | e1 = EventDeclaration.getLostEventDeclaration(); | |
366 | e2 = EventDeclaration.getLostEventDeclaration(); | |
367 | assertEquals(e1,e2); | |
368 | } | |
369 | ||
370 | @Test | |
371 | public void testEquals5(){ | |
372 | e1 = EventDeclaration.getLostEventDeclaration(); | |
373 | e2 = new EventDeclaration(); | |
374 | assertFalse(e1.equals(e2)); | |
866e5b51 FC |
375 | } |
376 | } |