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