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