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
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assume
.assumeTrue
;
20 import java
.nio
.channels
.FileChannel
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
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
.Stream
;
29 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInput
;
30 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
31 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.EventDeclaration
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
36 * The class <code>StreamInputReaderTest</code> contains tests for the class
37 * <code>{@link StreamInputReader}</code>.
40 * @version $Revision: 1.0 $
42 @SuppressWarnings("javadoc")
43 public class StreamInputReaderTest
{
45 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
47 private StreamInputReader fixture
;
50 * Perform pre-test initialization.
52 * @throws CTFReaderException
55 public void setUp() throws CTFReaderException
{
56 fixture
= getStreamInputReader();
58 fixture
.setCurrentEvent(new EventDefinition(new EventDeclaration(),
59 getStreamInputReader()));
62 private static StreamInputReader
getStreamInputReader() throws CTFReaderException
{
63 assumeTrue(testTrace
.exists());
64 CTFTrace trace
= testTrace
.getTrace();
65 Stream s
= trace
.getStream((long) 0);
66 Set
<StreamInput
> streamInput
= s
.getStreamInputs();
67 StreamInputReader retVal
= null;
68 for (StreamInput si
: streamInput
) {
70 * For the tests, we'll use the stream input corresponding to the
73 if (si
.getFilename().endsWith("0_0")) {
74 retVal
= new StreamInputReader(si
);
82 * Run the StreamInputReader(StreamInput) constructor test, with a valid
86 public void testStreamInputReader_valid() {
87 assertNotNull(fixture
);
91 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
94 * @throws CTFReaderException
96 @Test(expected
= CTFReaderException
.class)
97 public void testStreamInputReader_invalid() throws CTFReaderException
{
98 StreamInput streamInput
= new StreamInput(
99 new Stream(new CTFTrace("")), (FileChannel
) null, new File(""));
101 StreamInputReader result
= new StreamInputReader(streamInput
);
102 assertNotNull(result
);
106 * Run the int getCPU() method test.
109 public void testGetCPU() {
110 int result
= fixture
.getCPU();
111 assertEquals(0, result
);
115 * Run the EventDefinition getCurrentEvent() method test.
118 public void testGetCurrentEvent() {
119 EventDefinition result
= fixture
.getCurrentEvent();
120 assertNotNull(result
);
124 * Run the StructDefinition getCurrentPacketContext() method test.
127 public void testGetCurrentPacketContext() {
128 StructDefinition result
= fixture
.getCurrentPacketContext();
129 assertNotNull(result
);
133 * Run the int getName() method test.
136 public void testGetName() {
137 int result
= fixture
.getName();
138 assertEquals(1, result
);
142 * Run the void goToLastEvent() method test.
145 public void testGoToLastEvent1() {
146 final long endTimestamp
= goToEnd();
147 final long endTime
= 4287422460315L;
148 assertEquals(endTime
, endTimestamp
);
152 * Run the void goToLastEvent() method test.
155 public void testGoToLastEvent2() {
157 while(fixture
.readNextEvent()) {
158 timestamp
= fixture
.getCurrentEvent().getTimestamp();
160 long endTimestamp
= goToEnd();
161 assertEquals(0 , timestamp
- endTimestamp
);
164 private long goToEnd() {
165 fixture
.goToLastEvent();
166 return fixture
.getCurrentEvent().getTimestamp();
170 * Run the boolean readNextEvent() method test.
173 public void testReadNextEvent() {
174 boolean result
= fixture
.readNextEvent();
179 * Run the void seek(long) method test. Seek by direct timestamp
182 public void testSeek_timestamp() {
184 fixture
.seek(timestamp
);
188 * Run the seek test. Seek by passing an EventDefinition to which we've
189 * given the timestamp we want.
191 * @throws CTFReaderException
194 public void testSeek_eventDefinition() throws CTFReaderException
{
195 EventDefinition eventDefinition
= new EventDefinition(
196 new EventDeclaration(), getStreamInputReader());
197 eventDefinition
.setTimestamp(1L);
198 fixture
.setCurrentEvent(eventDefinition
);