Analysis: Add unit tests for the critical path module
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamTest.java
CommitLineData
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 12package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51
FC
13
14import static org.junit.Assert.assertNotNull;
15import static org.junit.Assert.assertTrue;
e5acb357 16import static org.junit.Assume.assumeTrue;
866e5b51 17
9ac63b5b 18import java.io.File;
8e15b929 19import java.io.FilenameFilter;
866e5b51
FC
20import java.util.Set;
21
b3151232 22import org.eclipse.jdt.annotation.NonNull;
680f9173 23import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
24import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
25import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
26import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
f357bcd4
AM
27import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
28import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput;
29import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
30import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
31import org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException;
866e5b51 32import org.junit.Before;
edc60ea1 33import org.junit.BeforeClass;
866e5b51
FC
34import org.junit.Test;
35
36/**
37 * The class <code>StreamTest</code> contains tests for the class
d84419e1 38 * <code>{@link CTFStream}</code>.
e291b8c8 39 *
866e5b51
FC
40 * @author ematkho
41 * @version $Revision: 1.0 $
42 */
be6df2d8 43@SuppressWarnings("javadoc")
d84419e1 44public class CTFStreamTest {
866e5b51 45
9ac63b5b 46 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
32bf80d2 47
d84419e1 48 private CTFStream fixture;
866e5b51 49
6c7592e1
MK
50 private CTFStreamInput fInput;
51
edc60ea1
MAL
52 @BeforeClass
53 public static void initialize() {
54 assumeTrue(testTrace.exists());
55 }
56
866e5b51
FC
57 /**
58 * Perform pre-test initialization.
788ddcbc 59 *
680f9173 60 * @throws CTFException
866e5b51
FC
61 */
62 @Before
680f9173 63 public void setUp() throws CTFException {
d84419e1 64 fixture = new CTFStream(testTrace.getTrace());
866e5b51
FC
65 fixture.setEventContext(new StructDeclaration(1L));
66 fixture.setPacketContext(new StructDeclaration(1L));
67 fixture.setEventHeader(new StructDeclaration(1L));
68 fixture.setId(1L);
6c7592e1
MK
69 fInput = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
70 fixture.addInput(fInput);
71 }
72
b3151232 73 @NonNull
8e15b929
MK
74 private static File createFile() {
75 File path = new File(testTrace.getPath());
b3151232 76 final File[] listFiles = path.listFiles(new FilenameFilter() {
8e15b929
MK
77 @Override
78 public boolean accept(File dir, String name) {
79 if (name.contains("hann")) {
80 return true;
81 }
82 return false;
83 }
b3151232
MK
84 });
85 assertNotNull(listFiles);
86 final File returnFile = listFiles[0];
87 assertNotNull(returnFile);
88 return returnFile;
866e5b51
FC
89 }
90
866e5b51
FC
91 /**
92 * Run the Stream(CTFTrace) constructor test.
788ddcbc 93 *
680f9173 94 * @throws CTFException
866e5b51
FC
95 */
96 @Test
680f9173 97 public void testStream() throws CTFException {
b562a24f
MK
98 CTFTrace trace = testTrace.getTrace();
99 CTFStream result = new CTFStream(trace);
100 assertNotNull(result);
866e5b51
FC
101 }
102
103 /**
8e15b929
MK
104 * Run the void addEvent(EventDeclaration) method test with the basic event.
105 *
e291b8c8 106 * @throws ParseException
866e5b51
FC
107 */
108 @Test
109 public void testAddEvent_base() throws ParseException {
110 EventDeclaration event = new EventDeclaration();
111 fixture.addEvent(event);
112 }
113
866e5b51
FC
114 /**
115 * Run the boolean eventContextIsSet() method test.
116 */
117 @Test
118 public void testEventContextIsSet() {
9ac2eb62 119 assertTrue(fixture.isEventContextSet());
866e5b51 120 }
8e15b929 121
e291b8c8
MK
122 /**
123 * Run the boolean eventContextIsSet() method test.
124 */
125 @Test
126 public void testToString() {
127 assertNotNull(fixture.toString());
128 }
866e5b51
FC
129
130 /**
131 * Run the boolean eventHeaderIsSet() method test.
132 */
133 @Test
134 public void testEventHeaderIsSet() {
9ac2eb62 135 assertTrue(fixture.isEventHeaderSet());
866e5b51
FC
136 }
137
138 /**
139 * Run the StructDeclaration getEventContextDecl() method test.
140 */
141 @Test
142 public void testGetEventContextDecl() {
143 assertNotNull(fixture.getEventContextDecl());
144 }
145
146 /**
147 * Run the StructDeclaration getEventHeaderDecl() method test.
148 */
149 @Test
150 public void testGetEventHeaderDecl() {
6c7592e1
MK
151 IDeclaration eventHeaderDecl = fixture.getEventHeaderDeclaration();
152 assertNotNull(eventHeaderDecl);
866e5b51
FC
153 }
154
155 /**
156 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
157 */
158 @Test
159 public void testGetEvents() {
5f715709 160 assertNotNull(fixture.getEventDeclarations());
866e5b51
FC
161 }
162
163 /**
164 * Run the Long getId() method test.
165 */
166 @Test
167 public void testGetId() {
168 Long result = fixture.getId();
169 assertNotNull(result);
170 }
171
172 /**
173 * Run the StructDeclaration getPacketContextDecl() method test.
174 */
175 @Test
176 public void testGetPacketContextDecl() {
177 StructDeclaration result = fixture.getPacketContextDecl();
178 assertNotNull(result);
179 }
180
181 /**
182 * Run the Set<StreamInput> getStreamInputs() method test.
183 */
184 @Test
185 public void testGetStreamInputs() {
d84419e1 186 Set<CTFStreamInput> result = fixture.getStreamInputs();
866e5b51
FC
187 assertNotNull(result);
188 }
189
190 /**
191 * Run the CTFTrace getTrace() method test.
192 */
193 @Test
194 public void testGetTrace() {
b562a24f
MK
195 CTFTrace result = fixture.getTrace();
196 assertNotNull(result);
866e5b51
FC
197 }
198
199 /**
200 * Run the boolean idIsSet() method test.
201 */
202 @Test
203 public void testIdIsSet() {
9ac2eb62 204 boolean result = fixture.isIdSet();
866e5b51
FC
205 assertTrue(result);
206 }
207
208 /**
209 * Run the boolean packetContextIsSet() method test.
210 */
211 @Test
212 public void testPacketContextIsSet() {
9ac2eb62 213 boolean result = fixture.isPacketContextSet();
866e5b51
FC
214 assertTrue(result);
215 }
216
866e5b51
FC
217 /**
218 * Run the void setEventContext(StructDeclaration) method test.
219 */
220 @Test
221 public void testSetEventContext() {
222 StructDeclaration eventContext = new StructDeclaration(1L);
223 fixture.setEventContext(eventContext);
224 }
225
226 /**
227 * Run the void setEventHeader(StructDeclaration) method test.
228 */
229 @Test
230 public void testSetEventHeader() {
231 StructDeclaration eventHeader = new StructDeclaration(1L);
232 fixture.setEventHeader(eventHeader);
233 }
234
235 /**
236 * Run the void setId(long) method test.
237 */
238 @Test
239 public void testSetId() {
240 long id = 1L;
241 fixture.setId(id);
242 }
243
244 /**
245 * Run the void setPacketContext(StructDeclaration) method test.
246 */
247 @Test
248 public void testSetPacketContext() {
249 StructDeclaration packetContext = new StructDeclaration(1L);
250 fixture.setPacketContext(packetContext);
251 }
05ce5fef 252}
This page took 0.074577 seconds and 5 git commands to generate.