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
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.io
.IOException
;
22 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Definition
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Encoding
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.ICompositeDefinition
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StringDeclaration
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StringDefinition
;
29 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDefinition
;
31 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTrace
;
32 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFResponse
;
33 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStream
;
34 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStreamInput
;
35 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStreamInputReader
;
36 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
37 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.EventDeclaration
;
38 import org
.junit
.Before
;
39 import org
.junit
.Test
;
42 * The class <code>StreamInputReaderTest</code> contains tests for the class
43 * <code>{@link CTFStreamInputReader}</code>.
46 * @version $Revision: 1.0 $
48 @SuppressWarnings("javadoc")
49 public class CTFStreamInputReaderTest
{
51 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
53 private CTFStreamInputReader fixture
;
56 * Perform pre-test initialization.
58 * @throws CTFException
61 public void setUp() throws CTFException
{
62 fixture
= getStreamInputReader();
64 fixture
.setCurrentEvent(new EventDefinition(new EventDeclaration(),
65 getStreamInputReader(), 0, null, null,
67 new StructDeclaration(0),
70 new Definition
[] { new StringDefinition(StringDeclaration
.getStringDeclaration(Encoding
.UTF8
), null, "field", "test") }),
75 private static CTFStreamInputReader
getStreamInputReader() throws CTFException
{
76 assumeTrue(testTrace
.exists());
77 CTFTrace trace
= testTrace
.getTrace();
78 CTFStream s
= trace
.getStream((long) 0);
79 Set
<CTFStreamInput
> streamInput
= s
.getStreamInputs();
80 CTFStreamInputReader retVal
= null;
81 for (CTFStreamInput si
: streamInput
) {
83 * For the tests, we'll use the stream input corresponding to the
86 if (si
.getFilename().endsWith("0_0")) {
87 retVal
= new CTFStreamInputReader(si
);
95 * Run the StreamInputReader(StreamInput) constructor test, with a valid
99 public void testStreamInputReader_valid() {
100 assertNotNull(fixture
);
104 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
107 * @throws CTFException
108 * @throws IOException
110 @Test(expected
= CTFException
.class)
111 public void testStreamInputReader_invalid() throws CTFException
, IOException
{
112 CTFStreamInput streamInput
= new CTFStreamInput(new CTFStream(new CTFTrace("")), new File(""));
113 try (CTFStreamInputReader result
= new CTFStreamInputReader(streamInput
)) {
114 assertNotNull(result
);
119 * Run the int getCPU() method test.
122 public void testGetCPU() {
123 int result
= fixture
.getCPU();
124 assertEquals(0, result
);
128 * Run the EventDefinition getCurrentEvent() method test.
131 public void testGetCurrentEvent() {
132 EventDefinition result
= fixture
.getCurrentEvent();
133 assertNotNull(result
);
137 * Run the StructDefinition getCurrentPacketContext() method test.
140 public void testGetCurrentPacketContext() {
141 ICompositeDefinition result
= fixture
.getCurrentEvent().getPacketContext();
142 assertNotNull(result
);
146 * Run the int getName() method test.
149 public void testGetName() {
150 int result
= fixture
.getName();
151 assertEquals(1, result
);
155 * Run the void goToLastEvent() method test.
157 * @throws CTFException
161 public void testGoToLastEvent1() throws CTFException
{
162 final long endTimestamp
= goToEnd();
163 final long endTime
= 4287422460315L;
164 assertEquals(endTime
, endTimestamp
);
168 * Run the void goToLastEvent() method test.
170 * @throws CTFException
174 public void testGoToLastEvent2() throws CTFException
{
176 while (fixture
.readNextEvent().equals(CTFResponse
.OK
)) {
177 timestamp
= fixture
.getCurrentEvent().getTimestamp();
179 long endTimestamp
= goToEnd();
180 assertEquals(0, timestamp
- endTimestamp
);
183 private long goToEnd() throws CTFException
{
184 fixture
.goToLastEvent();
185 return fixture
.getCurrentEvent().getTimestamp();
189 * Run the boolean readNextEvent() method test.
191 * @throws CTFException
195 public void testReadNextEvent() throws CTFException
{
196 assertEquals(CTFResponse
.OK
, fixture
.readNextEvent());
200 * Run the void seek(long) method test. Seek by direct timestamp
202 * @throws CTFException
206 public void testSeek_timestamp() throws CTFException
{
208 fixture
.seek(timestamp
);
212 * Run the seek test. Seek by passing an EventDefinition to which we've
213 * given the timestamp we want.
215 * @throws CTFException
218 public void testSeek_eventDefinition() throws CTFException
{
219 EventDefinition eventDefinition
= new EventDefinition(
220 new EventDeclaration(), getStreamInputReader(), 1L, null, null, null, null);
221 fixture
.setCurrentEvent(eventDefinition
);