rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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.tracecompass.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.util.Set;
21
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.tracecompass.ctf.core.CTFException;
24 import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
25 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
26 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
27 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
28 import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput;
29 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
30 import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
31 import org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 /**
37 * The class <code>StreamTest</code> contains tests for the class
38 * <code>{@link CTFStream}</code>.
39 *
40 * @author ematkho
41 * @version $Revision: 1.0 $
42 */
43 @SuppressWarnings("javadoc")
44 public class CTFStreamTest {
45
46 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
47
48 private CTFStream fixture;
49
50 private CTFStreamInput fInput;
51
52 @BeforeClass
53 public static void initialize() {
54 assumeTrue(testTrace.exists());
55 }
56
57 /**
58 * Perform pre-test initialization.
59 *
60 * @throws CTFException
61 */
62 @Before
63 public void setUp() throws CTFException {
64 fixture = new CTFStream(testTrace.getTrace());
65 fixture.setEventContext(new StructDeclaration(1L));
66 fixture.setPacketContext(new StructDeclaration(1L));
67 fixture.setEventHeader(new StructDeclaration(1L));
68 fixture.setId(1L);
69 fInput = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
70 fixture.addInput(fInput);
71 }
72
73 @NonNull
74 private static File createFile() {
75 File path = new File(testTrace.getPath());
76 final File[] listFiles = path.listFiles(new FilenameFilter() {
77 @Override
78 public boolean accept(File dir, String name) {
79 if (name.contains("hann")) {
80 return true;
81 }
82 return false;
83 }
84 });
85 assertNotNull(listFiles);
86 final File returnFile = listFiles[0];
87 assertNotNull(returnFile);
88 return returnFile;
89 }
90
91 /**
92 * Run the Stream(CTFTrace) constructor test.
93 *
94 * @throws CTFException
95 */
96 @Test
97 public void testStream() throws CTFException {
98 CTFTrace trace = testTrace.getTrace();
99 CTFStream result = new CTFStream(trace);
100 assertNotNull(result);
101 }
102
103 /**
104 * Run the void addEvent(EventDeclaration) method test with the basic event.
105 *
106 * @throws ParseException
107 */
108 @Test
109 public void testAddEvent_base() throws ParseException {
110 EventDeclaration event = new EventDeclaration();
111 fixture.addEvent(event);
112 }
113
114 /**
115 * Run the boolean eventContextIsSet() method test.
116 */
117 @Test
118 public void testEventContextIsSet() {
119 assertTrue(fixture.isEventContextSet());
120 }
121
122 /**
123 * Run the boolean eventContextIsSet() method test.
124 */
125 @Test
126 public void testToString() {
127 assertNotNull(fixture.toString());
128 }
129
130 /**
131 * Run the boolean eventHeaderIsSet() method test.
132 */
133 @Test
134 public void testEventHeaderIsSet() {
135 assertTrue(fixture.isEventHeaderSet());
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() {
151 IDeclaration eventHeaderDecl = fixture.getEventHeaderDeclaration();
152 assertNotNull(eventHeaderDecl);
153 }
154
155 /**
156 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
157 */
158 @Test
159 public void testGetEvents() {
160 assertNotNull(fixture.getEventDeclarations());
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() {
186 Set<CTFStreamInput> result = fixture.getStreamInputs();
187 assertNotNull(result);
188 }
189
190 /**
191 * Run the CTFTrace getTrace() method test.
192 */
193 @Test
194 public void testGetTrace() {
195 CTFTrace result = fixture.getTrace();
196 assertNotNull(result);
197 }
198
199 /**
200 * Run the boolean idIsSet() method test.
201 */
202 @Test
203 public void testIdIsSet() {
204 boolean result = fixture.isIdSet();
205 assertTrue(result);
206 }
207
208 /**
209 * Run the boolean packetContextIsSet() method test.
210 */
211 @Test
212 public void testPacketContextIsSet() {
213 boolean result = fixture.isPacketContextSet();
214 assertTrue(result);
215 }
216
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 }
252 }
This page took 0.037491 seconds and 5 git commands to generate.