ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFStreamTest.java
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
12 package org.eclipse.linuxtools.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.io.File;
19 import java.io.FilenameFilter;
20 import java.io.IOException;
21 import java.util.Set;
22
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
25 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
26 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
27 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
28 import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
29 import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput;
30 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
31 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
32 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37
38 /**
39 * The class <code>StreamTest</code> contains tests for the class
40 * <code>{@link CTFStream}</code>.
41 *
42 * @author ematkho
43 * @version $Revision: 1.0 $
44 */
45 @SuppressWarnings("javadoc")
46 public class CTFStreamTest {
47
48 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
49
50 private CTFStream fixture;
51
52 private CTFStreamInput fInput;
53
54 @BeforeClass
55 public static void initialize() {
56 assumeTrue(testTrace.exists());
57 }
58
59 /**
60 * Perform pre-test initialization.
61 *
62 * @throws CTFReaderException
63 */
64 @Before
65 public void setUp() throws CTFReaderException {
66 fixture = new CTFStream(testTrace.getTrace());
67 fixture.setEventContext(new StructDeclaration(1L));
68 fixture.setPacketContext(new StructDeclaration(1L));
69 fixture.setEventHeader(new StructDeclaration(1L));
70 fixture.setId(1L);
71 fInput = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
72 fixture.addInput(fInput);
73 }
74
75 @After
76 public void tearDown() throws IOException {
77 fInput.close();
78 }
79
80 @NonNull
81 private static File createFile() {
82 File path = new File(testTrace.getPath());
83 final File[] listFiles = path.listFiles(new FilenameFilter() {
84 @Override
85 public boolean accept(File dir, String name) {
86 if (name.contains("hann")) {
87 return true;
88 }
89 return false;
90 }
91 });
92 assertNotNull(listFiles);
93 final File returnFile = listFiles[0];
94 assertNotNull(returnFile);
95 return returnFile;
96 }
97
98 /**
99 * Run the Stream(CTFTrace) constructor test.
100 *
101 * @throws CTFReaderException
102 */
103 @Test
104 public void testStream() throws CTFReaderException {
105 try (CTFTrace trace = testTrace.getTrace()) {
106 CTFStream result = new CTFStream(trace);
107 assertNotNull(result);
108 }
109 }
110
111 /**
112 * Run the void addEvent(EventDeclaration) method test with the basic event.
113 *
114 * @throws ParseException
115 */
116 @Test
117 public void testAddEvent_base() throws ParseException {
118 EventDeclaration event = new EventDeclaration();
119 fixture.addEvent(event);
120 }
121
122 /**
123 * Run the boolean eventContextIsSet() method test.
124 */
125 @Test
126 public void testEventContextIsSet() {
127 assertTrue(fixture.isEventContextSet());
128 }
129
130 /**
131 * Run the boolean eventContextIsSet() method test.
132 */
133 @Test
134 public void testToString() {
135 assertNotNull(fixture.toString());
136 }
137
138 /**
139 * Run the boolean eventHeaderIsSet() method test.
140 */
141 @Test
142 public void testEventHeaderIsSet() {
143 assertTrue(fixture.isEventHeaderSet());
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() {
159 IDeclaration eventHeaderDecl = fixture.getEventHeaderDeclaration();
160 assertNotNull(eventHeaderDecl);
161 }
162
163 /**
164 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
165 */
166 @Test
167 public void testGetEvents() {
168 assertNotNull(fixture.getEventDeclarations());
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() {
194 Set<CTFStreamInput> result = fixture.getStreamInputs();
195 assertNotNull(result);
196 }
197
198 /**
199 * Run the CTFTrace getTrace() method test.
200 */
201 @Test
202 public void testGetTrace() {
203 try (CTFTrace result = fixture.getTrace();) {
204 assertNotNull(result);
205 }
206 }
207
208 /**
209 * Run the boolean idIsSet() method test.
210 */
211 @Test
212 public void testIdIsSet() {
213 boolean result = fixture.isIdSet();
214 assertTrue(result);
215 }
216
217 /**
218 * Run the boolean packetContextIsSet() method test.
219 */
220 @Test
221 public void testPacketContextIsSet() {
222 boolean result = fixture.isPacketContextSet();
223 assertTrue(result);
224 }
225
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 }
261 }
This page took 0.036029 seconds and 5 git commands to generate.