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