tmf/lttng: Update 2014 copyrights
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputReaderTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.trace;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
e5acb357 16import static org.junit.Assume.assumeTrue;
866e5b51 17
9ac63b5b 18import java.io.File;
866e5b51
FC
19import java.nio.channels.FileChannel;
20import java.util.Set;
21
866e5b51
FC
22import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
23import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
9ac63b5b 24import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
866e5b51 25import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
6a5251eb 26import org.eclipse.linuxtools.ctf.core.trace.CTFResponse;
866e5b51 27import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
486efb2e
AM
28import org.eclipse.linuxtools.ctf.core.trace.Stream;
29import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
866e5b51 30import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
8e964be1 31import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
866e5b51
FC
32import org.junit.Before;
33import org.junit.Test;
34
35/**
36 * The class <code>StreamInputReaderTest</code> contains tests for the class
37 * <code>{@link StreamInputReader}</code>.
ce2388e0 38 *
866e5b51
FC
39 * @author ematkho
40 * @version $Revision: 1.0 $
41 */
be6df2d8 42@SuppressWarnings("javadoc")
866e5b51
FC
43public class StreamInputReaderTest {
44
9ac63b5b 45 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
32bf80d2 46
866e5b51
FC
47 private StreamInputReader fixture;
48
866e5b51
FC
49 /**
50 * Perform pre-test initialization.
ce2388e0
FC
51 *
52 * @throws CTFReaderException
866e5b51
FC
53 */
54 @Before
13be1a8f
AM
55 public void setUp() throws CTFReaderException {
56 fixture = getStreamInputReader();
866e5b51
FC
57 fixture.setName(1);
58 fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
13be1a8f 59 getStreamInputReader()));
866e5b51
FC
60 }
61
13be1a8f 62 private static StreamInputReader getStreamInputReader() throws CTFReaderException {
9ac63b5b
AM
63 assumeTrue(testTrace.exists());
64 CTFTrace trace = testTrace.getTrace();
866e5b51
FC
65 Stream s = trace.getStream((long) 0);
66 Set<StreamInput> streamInput = s.getStreamInputs();
67 StreamInputReader retVal = null;
68 for (StreamInput si : streamInput) {
69 /*
70 * For the tests, we'll use the stream input corresponding to the
71 * CPU 0
72 */
4a9c1f07 73 if (si.getFilename().endsWith("0_0")) {
866e5b51
FC
74 retVal = new StreamInputReader(si);
75 break;
76 }
77 }
78 return retVal;
79 }
80
81 /**
82 * Run the StreamInputReader(StreamInput) constructor test, with a valid
83 * trace.
84 */
85 @Test
86 public void testStreamInputReader_valid() {
87 assertNotNull(fixture);
88 }
89
90 /**
91 * Run the StreamInputReader(StreamInput) constructor test, with an invalid
92 * trace.
ce2388e0 93 *
866e5b51
FC
94 * @throws CTFReaderException
95 */
96 @Test(expected = CTFReaderException.class)
97 public void testStreamInputReader_invalid() throws CTFReaderException {
98 StreamInput streamInput = new StreamInput(
9ac63b5b 99 new Stream(new CTFTrace("")), (FileChannel) null, new File(""));
866e5b51
FC
100
101 StreamInputReader result = new StreamInputReader(streamInput);
102 assertNotNull(result);
103 }
104
105 /**
106 * Run the int getCPU() method test.
107 */
108 @Test
109 public void testGetCPU() {
110 int result = fixture.getCPU();
111 assertEquals(0, result);
112 }
113
114 /**
115 * Run the EventDefinition getCurrentEvent() method test.
116 */
117 @Test
118 public void testGetCurrentEvent() {
119 EventDefinition result = fixture.getCurrentEvent();
120 assertNotNull(result);
121 }
122
123 /**
124 * Run the StructDefinition getCurrentPacketContext() method test.
125 */
126 @Test
127 public void testGetCurrentPacketContext() {
128 StructDefinition result = fixture.getCurrentPacketContext();
129 assertNotNull(result);
130 }
131
132 /**
133 * Run the int getName() method test.
134 */
135 @Test
136 public void testGetName() {
137 int result = fixture.getName();
138 assertEquals(1, result);
139 }
140
866e5b51
FC
141 /**
142 * Run the void goToLastEvent() method test.
db8e8f7d 143 * @throws CTFReaderException error
866e5b51
FC
144 */
145 @Test
db8e8f7d 146 public void testGoToLastEvent1() throws CTFReaderException {
ec6f5beb
MK
147 final long endTimestamp = goToEnd();
148 final long endTime = 4287422460315L;
149 assertEquals(endTime , endTimestamp );
150 }
151
152 /**
153 * Run the void goToLastEvent() method test.
db8e8f7d 154 * @throws CTFReaderException error
ec6f5beb
MK
155 */
156 @Test
db8e8f7d 157 public void testGoToLastEvent2() throws CTFReaderException {
ec6f5beb 158 long timestamp = -1;
6a5251eb 159 while(fixture.readNextEvent().equals(CTFResponse.OK)) {
ec6f5beb
MK
160 timestamp = fixture.getCurrentEvent().getTimestamp();
161 }
162 long endTimestamp = goToEnd();
163 assertEquals(0 , timestamp- endTimestamp );
164 }
165
db8e8f7d 166 private long goToEnd() throws CTFReaderException {
866e5b51 167 fixture.goToLastEvent();
ec6f5beb 168 return fixture.getCurrentEvent().getTimestamp();
866e5b51
FC
169 }
170
171 /**
172 * Run the boolean readNextEvent() method test.
db8e8f7d 173 * @throws CTFReaderException error
866e5b51
FC
174 */
175 @Test
db8e8f7d 176 public void testReadNextEvent() throws CTFReaderException {
6a5251eb 177 assertEquals(CTFResponse.OK, fixture.readNextEvent());
866e5b51
FC
178 }
179
180 /**
181 * Run the void seek(long) method test. Seek by direct timestamp
db8e8f7d 182 * @throws CTFReaderException error
866e5b51
FC
183 */
184 @Test
db8e8f7d 185 public void testSeek_timestamp() throws CTFReaderException {
866e5b51
FC
186 long timestamp = 1L;
187 fixture.seek(timestamp);
188 }
189
190 /**
191 * Run the seek test. Seek by passing an EventDefinition to which we've
192 * given the timestamp we want.
ce2388e0
FC
193 *
194 * @throws CTFReaderException
866e5b51
FC
195 */
196 @Test
13be1a8f 197 public void testSeek_eventDefinition() throws CTFReaderException {
866e5b51 198 EventDefinition eventDefinition = new EventDefinition(
13be1a8f 199 new EventDeclaration(), getStreamInputReader());
aa572e22 200 eventDefinition.setTimestamp(1L);
866e5b51
FC
201 fixture.setCurrentEvent(eventDefinition);
202 }
203}
This page took 0.060568 seconds and 5 git commands to generate.