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