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