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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.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
;
20 import java
.io
.IOException
;
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
;
39 * The class <code>StreamTest</code> contains tests for the class
40 * <code>{@link CTFStream}</code>.
43 * @version $Revision: 1.0 $
45 @SuppressWarnings("javadoc")
46 public class CTFStreamTest
{
48 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
50 private CTFStream fixture
;
52 private CTFStreamInput fInput
;
55 public static void initialize() {
56 assumeTrue(testTrace
.exists());
60 * Perform pre-test initialization.
62 * @throws CTFReaderException
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));
71 fInput
= new CTFStreamInput(new CTFStream(testTrace
.getTrace()), createFile());
72 fixture
.addInput(fInput
);
76 public void tearDown() throws IOException
{
81 private static File
createFile() {
82 File path
= new File(testTrace
.getPath());
83 final File
[] listFiles
= path
.listFiles(new FilenameFilter() {
85 public boolean accept(File dir
, String name
) {
86 if (name
.contains("hann")) {
92 assertNotNull(listFiles
);
93 final File returnFile
= listFiles
[0];
94 assertNotNull(returnFile
);
99 * Run the Stream(CTFTrace) constructor test.
101 * @throws CTFReaderException
104 public void testStream() throws CTFReaderException
{
105 try (CTFTrace trace
= testTrace
.getTrace()) {
106 CTFStream result
= new CTFStream(trace
);
107 assertNotNull(result
);
112 * Run the void addEvent(EventDeclaration) method test with the basic event.
114 * @throws ParseException
117 public void testAddEvent_base() throws ParseException
{
118 EventDeclaration event
= new EventDeclaration();
119 fixture
.addEvent(event
);
123 * Run the boolean eventContextIsSet() method test.
126 public void testEventContextIsSet() {
127 assertTrue(fixture
.isEventContextSet());
131 * Run the boolean eventContextIsSet() method test.
134 public void testToString() {
135 assertNotNull(fixture
.toString());
139 * Run the boolean eventHeaderIsSet() method test.
142 public void testEventHeaderIsSet() {
143 assertTrue(fixture
.isEventHeaderSet());
147 * Run the StructDeclaration getEventContextDecl() method test.
150 public void testGetEventContextDecl() {
151 assertNotNull(fixture
.getEventContextDecl());
155 * Run the StructDeclaration getEventHeaderDecl() method test.
158 public void testGetEventHeaderDecl() {
159 IDeclaration eventHeaderDecl
= fixture
.getEventHeaderDeclaration();
160 assertNotNull(eventHeaderDecl
);
164 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
167 public void testGetEvents() {
168 assertNotNull(fixture
.getEventDeclarations());
172 * Run the Long getId() method test.
175 public void testGetId() {
176 Long result
= fixture
.getId();
177 assertNotNull(result
);
181 * Run the StructDeclaration getPacketContextDecl() method test.
184 public void testGetPacketContextDecl() {
185 StructDeclaration result
= fixture
.getPacketContextDecl();
186 assertNotNull(result
);
190 * Run the Set<StreamInput> getStreamInputs() method test.
193 public void testGetStreamInputs() {
194 Set
<CTFStreamInput
> result
= fixture
.getStreamInputs();
195 assertNotNull(result
);
199 * Run the CTFTrace getTrace() method test.
202 public void testGetTrace() {
203 try (CTFTrace result
= fixture
.getTrace();) {
204 assertNotNull(result
);
209 * Run the boolean idIsSet() method test.
212 public void testIdIsSet() {
213 boolean result
= fixture
.isIdSet();
218 * Run the boolean packetContextIsSet() method test.
221 public void testPacketContextIsSet() {
222 boolean result
= fixture
.isPacketContextSet();
227 * Run the void setEventContext(StructDeclaration) method test.
230 public void testSetEventContext() {
231 StructDeclaration eventContext
= new StructDeclaration(1L);
232 fixture
.setEventContext(eventContext
);
236 * Run the void setEventHeader(StructDeclaration) method test.
239 public void testSetEventHeader() {
240 StructDeclaration eventHeader
= new StructDeclaration(1L);
241 fixture
.setEventHeader(eventHeader
);
245 * Run the void setId(long) method test.
248 public void testSetId() {
254 * Run the void setPacketContext(StructDeclaration) method test.
257 public void testSetPacketContext() {
258 StructDeclaration packetContext
= new StructDeclaration(1L);
259 fixture
.setPacketContext(packetContext
);