import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
-import java.nio.channels.FileChannel;
-import java.util.HashMap;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Map;
import java.util.Set;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.Stream;
import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("javadoc")
public class StreamTest {
- private static final int TRACE_INDEX = 0;
+ private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
private Stream fixture;
- /**
- * Launch the test.
- *
- * @param args
- * the command line arguments
- */
- public static void main(String[] args) {
- new org.junit.runner.JUnitCore().run(StreamTest.class);
- }
-
/**
* Perform pre-test initialization.
*
*/
@Before
public void setUp() throws CTFReaderException {
- assumeTrue(CtfTestTraces.tracesExist());
- fixture = new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX));
+ assumeTrue(testTrace.exists());
+ fixture = new Stream(testTrace.getTrace());
fixture.setEventContext(new StructDeclaration(1L));
fixture.setPacketContext(new StructDeclaration(1L));
fixture.setEventHeader(new StructDeclaration(1L));
fixture.setId(1L);
- fixture.addInput(new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
- (FileChannel) null, CtfTestTraces.getEmptyFile()));
+ fixture.addInput(new StreamInput(new Stream(testTrace.getTrace()), createFile()));
}
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- // Add additional tear down code here
+ private static File createFile() {
+ File path = new File(testTrace.getPath());
+ return path.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ if (name.contains("hann")) {
+ return true;
+ }
+ return false;
+ }
+ })[0];
}
/**
*/
@Test
public void testStream() throws CTFReaderException {
- CTFTrace trace = CtfTestTraces.getTestTrace(TRACE_INDEX);
+ CTFTrace trace = testTrace.getTrace();
Stream result = new Stream(trace);
assertNotNull(result);
}
/**
- * Run the void addEvent(EventDeclaration) method test with the basic
- * event.
+ * Run the void addEvent(EventDeclaration) method test with the basic event.
+ *
* @throws ParseException
*/
@Test
public void testEventContextIsSet() {
assertTrue(fixture.isEventContextSet());
}
+
/**
* Run the boolean eventContextIsSet() method test.
*/
*/
@Test
public void testGetEvents() {
- HashMap<Long, IEventDeclaration> result = fixture.getEvents();
+ Map<Long, IEventDeclaration> result = fixture.getEvents();
assertNotNull(result);
}
assertTrue(result);
}
-
/**
* Run the void setEventContext(StructDeclaration) method test.
*/