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
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
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
.CTFTrace
;
28 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFStream
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFStreamInput
;
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
.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
;
50 * Perform pre-test initialization.
52 * @throws CTFReaderException
55 public void setUp() throws CTFReaderException
{
56 assumeTrue(testTrace
.exists());
57 fixture
= new CTFStream(testTrace
.getTrace());
58 fixture
.setEventContext(new StructDeclaration(1L));
59 fixture
.setPacketContext(new StructDeclaration(1L));
60 fixture
.setEventHeader(new StructDeclaration(1L));
62 fixture
.addInput(new CTFStreamInput(new CTFStream(testTrace
.getTrace()), createFile()));
65 private static File
createFile() {
66 File path
= new File(testTrace
.getPath());
67 return path
.listFiles(new FilenameFilter() {
69 public boolean accept(File dir
, String name
) {
70 if (name
.contains("hann")) {
79 * Run the Stream(CTFTrace) constructor test.
81 * @throws CTFReaderException
84 public void testStream() throws CTFReaderException
{
85 CTFTrace trace
= testTrace
.getTrace();
86 CTFStream result
= new CTFStream(trace
);
87 assertNotNull(result
);
91 * Run the void addEvent(EventDeclaration) method test with the basic event.
93 * @throws ParseException
96 public void testAddEvent_base() throws ParseException
{
97 EventDeclaration event
= new EventDeclaration();
98 fixture
.addEvent(event
);
102 * Run the boolean eventContextIsSet() method test.
105 public void testEventContextIsSet() {
106 assertTrue(fixture
.isEventContextSet());
110 * Run the boolean eventContextIsSet() method test.
113 public void testToString() {
114 assertNotNull(fixture
.toString());
118 * Run the boolean eventHeaderIsSet() method test.
121 public void testEventHeaderIsSet() {
122 assertTrue(fixture
.isEventHeaderSet());
126 * Run the StructDeclaration getEventContextDecl() method test.
129 public void testGetEventContextDecl() {
130 assertNotNull(fixture
.getEventContextDecl());
134 * Run the StructDeclaration getEventHeaderDecl() method test.
137 public void testGetEventHeaderDecl() {
138 assertNotNull(fixture
.getEventHeaderDecl());
142 * Run the HashMap<Long, EventDeclaration> getEvents() method test.
145 public void testGetEvents() {
146 Map
<Long
, IEventDeclaration
> result
= fixture
.getEvents();
147 assertNotNull(result
);
151 * Run the Long getId() method test.
154 public void testGetId() {
155 Long result
= fixture
.getId();
156 assertNotNull(result
);
160 * Run the StructDeclaration getPacketContextDecl() method test.
163 public void testGetPacketContextDecl() {
164 StructDeclaration result
= fixture
.getPacketContextDecl();
165 assertNotNull(result
);
169 * Run the Set<StreamInput> getStreamInputs() method test.
172 public void testGetStreamInputs() {
173 Set
<CTFStreamInput
> result
= fixture
.getStreamInputs();
174 assertNotNull(result
);
178 * Run the CTFTrace getTrace() method test.
181 public void testGetTrace() {
182 try (CTFTrace result
= fixture
.getTrace();) {
183 assertNotNull(result
);
188 * Run the boolean idIsSet() method test.
191 public void testIdIsSet() {
192 boolean result
= fixture
.isIdSet();
197 * Run the boolean packetContextIsSet() method test.
200 public void testPacketContextIsSet() {
201 boolean result
= fixture
.isPacketContextSet();
206 * Run the void setEventContext(StructDeclaration) method test.
209 public void testSetEventContext() {
210 StructDeclaration eventContext
= new StructDeclaration(1L);
211 fixture
.setEventContext(eventContext
);
215 * Run the void setEventHeader(StructDeclaration) method test.
218 public void testSetEventHeader() {
219 StructDeclaration eventHeader
= new StructDeclaration(1L);
220 fixture
.setEventHeader(eventHeader
);
224 * Run the void setId(long) method test.
227 public void testSetId() {
233 * Run the void setPacketContext(StructDeclaration) method test.
236 public void testSetPacketContext() {
237 StructDeclaration packetContext
= new StructDeclaration(1L);
238 fixture
.setPacketContext(packetContext
);