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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertTrue
;
18 import java
.io
.FilenameFilter
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IDeclaration
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTraceUtils
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStreamInput
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
28 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.EventDeclaration
;
29 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.exceptions
.ParseException
;
30 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
.CTFStream
;
31 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
36 * The class <code>StreamTest</code> contains tests for the class
37 * <code>{@link CTFStream}</code>.
40 * @version $Revision: 1.0 $
42 @SuppressWarnings("javadoc")
43 public class CTFStreamTest
{
45 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
47 private CTFStream fixture
;
49 private CTFStreamInput fInput
;
52 * Perform pre-test initialization.
54 * @throws CTFException
57 public void setUp() throws CTFException
{
58 fixture
= new CTFStream(CtfTestTraceUtils
.getTrace(testTrace
));
59 fixture
.setEventContext(new StructDeclaration(1L));
60 fixture
.setPacketContext(new StructDeclaration(1L));
61 fixture
.setEventHeader(new StructDeclaration(1L));
63 fInput
= new CTFStreamInput(new CTFStream(CtfTestTraceUtils
.getTrace(testTrace
)), createFile());
64 fixture
.addInput(fInput
);
67 private static @NonNull File
createFile() throws CTFException
{
68 File path
= new File(CtfTestTraceUtils
.getTrace(testTrace
).getPath());
69 final File
[] listFiles
= path
.listFiles(new FilenameFilter() {
71 public boolean accept(File dir
, String name
) {
72 if (name
.contains("hann")) {
78 assertNotNull(listFiles
);
79 final File returnFile
= listFiles
[0];
80 assertNotNull(returnFile
);
85 * Run the Stream(CTFTrace) constructor test.
87 * @throws CTFException
90 public void testStream() throws CTFException
{
91 CTFTrace trace
= CtfTestTraceUtils
.getTrace(testTrace
);
92 CTFStream result
= new CTFStream(trace
);
93 assertNotNull(result
);
97 * Run the void addEvent(EventDeclaration) method test with the basic event.
99 * @throws ParseException
102 public void testAddEvent_base() throws ParseException
{
103 EventDeclaration event
= new EventDeclaration();
104 fixture
.addEvent(event
);
108 * Run the boolean eventContextIsSet() method test.
111 public void testEventContextIsSet() {
112 assertTrue(fixture
.isEventContextSet());
116 * Run the boolean eventContextIsSet() method test.
119 public void testToString() {
120 assertNotNull(fixture
.toString());
124 * Run the boolean eventHeaderIsSet() method test.
127 public void testEventHeaderIsSet() {
128 assertTrue(fixture
.isEventHeaderSet());
132 * Run the StructDeclaration getEventContextDecl() method test.
135 public void testGetEventContextDecl() {
136 assertNotNull(fixture
.getEventContextDecl());
140 * Run the StructDeclaration getEventHeaderDecl() method test.
143 public void testGetEventHeaderDecl() {
144 IDeclaration eventHeaderDecl
= fixture
.getEventHeaderDeclaration();
145 assertNotNull(eventHeaderDecl
);
149 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
152 public void testGetEvents() {
153 assertNotNull(fixture
.getEventDeclarations());
157 * Run the Long getId() method test.
160 public void testGetId() {
161 Long result
= fixture
.getId();
162 assertNotNull(result
);
166 * Run the StructDeclaration getPacketContextDecl() method test.
169 public void testGetPacketContextDecl() {
170 StructDeclaration result
= fixture
.getPacketContextDecl();
171 assertNotNull(result
);
175 * Run the Set<StreamInput> getStreamInputs() method test.
178 public void testGetStreamInputs() {
179 Set
<CTFStreamInput
> result
= fixture
.getStreamInputs();
180 assertNotNull(result
);
184 * Run the CTFTrace getTrace() method test.
187 public void testGetTrace() {
188 CTFTrace result
= fixture
.getTrace();
189 assertNotNull(result
);
193 * Run the boolean idIsSet() method test.
196 public void testIdIsSet() {
197 boolean result
= fixture
.isIdSet();
202 * Run the boolean packetContextIsSet() method test.
205 public void testPacketContextIsSet() {
206 boolean result
= fixture
.isPacketContextSet();
211 * Run the void setEventContext(StructDeclaration) method test.
214 public void testSetEventContext() {
215 StructDeclaration eventContext
= new StructDeclaration(1L);
216 fixture
.setEventContext(eventContext
);
220 * Run the void setEventHeader(StructDeclaration) method test.
223 public void testSetEventHeader() {
224 StructDeclaration eventHeader
= new StructDeclaration(1L);
225 fixture
.setEventHeader(eventHeader
);
229 * Run the void setId(long) method test.
232 public void testSetId() {
238 * Run the void setPacketContext(StructDeclaration) method test.
241 public void testSetPacketContext() {
242 StructDeclaration packetContext
= new StructDeclaration(1L);
243 fixture
.setPacketContext(packetContext
);