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
;
16 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.io
.FilenameFilter
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
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
.CtfTestTrace
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFReaderException
;
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
;
37 * The class <code>StreamTest</code> contains tests for the class
38 * <code>{@link CTFStream}</code>.
41 * @version $Revision: 1.0 $
43 @SuppressWarnings("javadoc")
44 public class CTFStreamTest
{
46 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
48 private CTFStream fixture
;
50 private CTFStreamInput fInput
;
53 public static void initialize() {
54 assumeTrue(testTrace
.exists());
58 * Perform pre-test initialization.
60 * @throws CTFReaderException
63 public void setUp() throws CTFReaderException
{
64 fixture
= new CTFStream(testTrace
.getTrace());
65 fixture
.setEventContext(new StructDeclaration(1L));
66 fixture
.setPacketContext(new StructDeclaration(1L));
67 fixture
.setEventHeader(new StructDeclaration(1L));
69 fInput
= new CTFStreamInput(new CTFStream(testTrace
.getTrace()), createFile());
70 fixture
.addInput(fInput
);
74 private static File
createFile() {
75 File path
= new File(testTrace
.getPath());
76 final File
[] listFiles
= path
.listFiles(new FilenameFilter() {
78 public boolean accept(File dir
, String name
) {
79 if (name
.contains("hann")) {
85 assertNotNull(listFiles
);
86 final File returnFile
= listFiles
[0];
87 assertNotNull(returnFile
);
92 * Run the Stream(CTFTrace) constructor test.
94 * @throws CTFReaderException
97 public void testStream() throws CTFReaderException
{
98 CTFTrace trace
= testTrace
.getTrace();
99 CTFStream result
= new CTFStream(trace
);
100 assertNotNull(result
);
104 * Run the void addEvent(EventDeclaration) method test with the basic event.
106 * @throws ParseException
109 public void testAddEvent_base() throws ParseException
{
110 EventDeclaration event
= new EventDeclaration();
111 fixture
.addEvent(event
);
115 * Run the boolean eventContextIsSet() method test.
118 public void testEventContextIsSet() {
119 assertTrue(fixture
.isEventContextSet());
123 * Run the boolean eventContextIsSet() method test.
126 public void testToString() {
127 assertNotNull(fixture
.toString());
131 * Run the boolean eventHeaderIsSet() method test.
134 public void testEventHeaderIsSet() {
135 assertTrue(fixture
.isEventHeaderSet());
139 * Run the StructDeclaration getEventContextDecl() method test.
142 public void testGetEventContextDecl() {
143 assertNotNull(fixture
.getEventContextDecl());
147 * Run the StructDeclaration getEventHeaderDecl() method test.
150 public void testGetEventHeaderDecl() {
151 IDeclaration eventHeaderDecl
= fixture
.getEventHeaderDeclaration();
152 assertNotNull(eventHeaderDecl
);
156 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
159 public void testGetEvents() {
160 assertNotNull(fixture
.getEventDeclarations());
164 * Run the Long getId() method test.
167 public void testGetId() {
168 Long result
= fixture
.getId();
169 assertNotNull(result
);
173 * Run the StructDeclaration getPacketContextDecl() method test.
176 public void testGetPacketContextDecl() {
177 StructDeclaration result
= fixture
.getPacketContextDecl();
178 assertNotNull(result
);
182 * Run the Set<StreamInput> getStreamInputs() method test.
185 public void testGetStreamInputs() {
186 Set
<CTFStreamInput
> result
= fixture
.getStreamInputs();
187 assertNotNull(result
);
191 * Run the CTFTrace getTrace() method test.
194 public void testGetTrace() {
195 CTFTrace result
= fixture
.getTrace();
196 assertNotNull(result
);
200 * Run the boolean idIsSet() method test.
203 public void testIdIsSet() {
204 boolean result
= fixture
.isIdSet();
209 * Run the boolean packetContextIsSet() method test.
212 public void testPacketContextIsSet() {
213 boolean result
= fixture
.isPacketContextSet();
218 * Run the void setEventContext(StructDeclaration) method test.
221 public void testSetEventContext() {
222 StructDeclaration eventContext
= new StructDeclaration(1L);
223 fixture
.setEventContext(eventContext
);
227 * Run the void setEventHeader(StructDeclaration) method test.
230 public void testSetEventHeader() {
231 StructDeclaration eventHeader
= new StructDeclaration(1L);
232 fixture
.setEventHeader(eventHeader
);
236 * Run the void setId(long) method test.
239 public void testSetId() {
245 * Run the void setPacketContext(StructDeclaration) method test.
248 public void testSetPacketContext() {
249 StructDeclaration packetContext
= new StructDeclaration(1L);
250 fixture
.setPacketContext(packetContext
);