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
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.shared
.CtfTestTrace
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFStream
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFStreamInput
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
30 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.EventDeclaration
;
31 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.metadata
.exceptions
.ParseException
;
32 import org
.junit
.After
;
33 import org
.junit
.Before
;
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 * Perform pre-test initialization.
55 * @throws CTFReaderException
58 public void setUp() throws CTFReaderException
{
59 assumeTrue(testTrace
.exists());
60 fixture
= new CTFStream(testTrace
.getTrace());
61 fixture
.setEventContext(new StructDeclaration(1L));
62 fixture
.setPacketContext(new StructDeclaration(1L));
63 fixture
.setEventHeader(new StructDeclaration(1L));
65 fInput
= new CTFStreamInput(new CTFStream(testTrace
.getTrace()), createFile());
66 fixture
.addInput(fInput
);
70 public void tearDown() throws IOException
{
74 private static File
createFile() {
75 File path
= new File(testTrace
.getPath());
76 return path
.listFiles(new FilenameFilter() {
78 public boolean accept(File dir
, String name
) {
79 if (name
.contains("hann")) {
88 * Run the Stream(CTFTrace) constructor test.
90 * @throws CTFReaderException
93 public void testStream() throws CTFReaderException
{
94 try (CTFTrace trace
= testTrace
.getTrace()) {
95 CTFStream result
= new CTFStream(trace
);
96 assertNotNull(result
);
101 * Run the void addEvent(EventDeclaration) method test with the basic event.
103 * @throws ParseException
106 public void testAddEvent_base() throws ParseException
{
107 EventDeclaration event
= new EventDeclaration();
108 fixture
.addEvent(event
);
112 * Run the boolean eventContextIsSet() method test.
115 public void testEventContextIsSet() {
116 assertTrue(fixture
.isEventContextSet());
120 * Run the boolean eventContextIsSet() method test.
123 public void testToString() {
124 assertNotNull(fixture
.toString());
128 * Run the boolean eventHeaderIsSet() method test.
131 public void testEventHeaderIsSet() {
132 assertTrue(fixture
.isEventHeaderSet());
136 * Run the StructDeclaration getEventContextDecl() method test.
139 public void testGetEventContextDecl() {
140 assertNotNull(fixture
.getEventContextDecl());
144 * Run the StructDeclaration getEventHeaderDecl() method test.
147 public void testGetEventHeaderDecl() {
148 IDeclaration eventHeaderDecl
= fixture
.getEventHeaderDeclaration();
149 assertNotNull(eventHeaderDecl
);
153 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
156 public void testGetEvents() {
157 assertNotNull(fixture
.getEventDeclarations());
161 * Run the Long getId() method test.
164 public void testGetId() {
165 Long result
= fixture
.getId();
166 assertNotNull(result
);
170 * Run the StructDeclaration getPacketContextDecl() method test.
173 public void testGetPacketContextDecl() {
174 StructDeclaration result
= fixture
.getPacketContextDecl();
175 assertNotNull(result
);
179 * Run the Set<StreamInput> getStreamInputs() method test.
182 public void testGetStreamInputs() {
183 Set
<CTFStreamInput
> result
= fixture
.getStreamInputs();
184 assertNotNull(result
);
188 * Run the CTFTrace getTrace() method test.
191 public void testGetTrace() {
192 try (CTFTrace result
= fixture
.getTrace();) {
193 assertNotNull(result
);
198 * Run the boolean idIsSet() method test.
201 public void testIdIsSet() {
202 boolean result
= fixture
.isIdSet();
207 * Run the boolean packetContextIsSet() method test.
210 public void testPacketContextIsSet() {
211 boolean result
= fixture
.isPacketContextSet();
216 * Run the void setEventContext(StructDeclaration) method test.
219 public void testSetEventContext() {
220 StructDeclaration eventContext
= new StructDeclaration(1L);
221 fixture
.setEventContext(eventContext
);
225 * Run the void setEventHeader(StructDeclaration) method test.
228 public void testSetEventHeader() {
229 StructDeclaration eventHeader
= new StructDeclaration(1L);
230 fixture
.setEventHeader(eventHeader
);
234 * Run the void setId(long) method test.
237 public void testSetId() {
243 * Run the void setPacketContext(StructDeclaration) method test.
246 public void testSetPacketContext() {
247 StructDeclaration packetContext
= new StructDeclaration(1L);
248 fixture
.setPacketContext(packetContext
);