1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.parsers
.custom
;
13 import java
.io
.IOException
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
21 import org
.junit
.After
;
22 import org
.junit
.Before
;
23 import org
.junit
.Test
;
26 * Abstract class to test custom traces
28 * @author Geneviève Bastien
30 public abstract class AbstractCustomTraceDataTest
{
33 * Time format use for event creation
35 protected static final String TIMESTAMP_FORMAT
= "dd/MM/yyyy HH:mm:ss:SSS";
38 * Block size used for the indexer
40 protected static final int BLOCK_SIZE
= 100;
42 /** The trace directory */
43 protected static final String TRACE_DIRECTORY
= TmfTraceManager
.getTemporaryDirPath() + File
.separator
+ "dummyTrace";
47 * Interface to be implemented by concrete test cases to get the necessary
50 * @author Geneviève Bastien
52 protected static interface ICustomTestData
{
54 * Get the trace for this test case
56 * @return The initialized trace
58 * If an exception occurred while getting the trace
59 * @throws TmfTraceException
60 * If an exception occurred while getting the trace
62 public ITmfTrace
getTrace() throws IOException
, TmfTraceException
;
65 * Validate the event for this test case. This method should contain the
69 * The event to validate
71 public void validateEvent(ITmfEvent event
);
74 * Validate the event count. This method will be called after reading
78 * The event count to validate
80 public void validateEventCount(int eventCount
);
83 private final @NonNull ICustomTestData fTestData
;
84 private ITmfTrace fTrace
;
90 * The custom trace test data
92 public AbstractCustomTraceDataTest(@NonNull ICustomTestData data
) {
98 * @throws Exception Exceptions that occurred during setup
101 public void setUp() throws Exception
{
105 private synchronized void setupTrace() throws Exception
{
106 File traceDirectory
= new File(TRACE_DIRECTORY
);
107 if (traceDirectory
.exists()) {
108 traceDirectory
.delete();
110 traceDirectory
.mkdir();
111 if (fTrace
== null) {
112 fTrace
= fTestData
.getTrace();
120 public void tearDown() {
121 String directory
= TmfTraceManager
.getSupplementaryFileDir(fTrace
);
126 File dir
= new File(directory
);
128 File
[] files
= dir
.listFiles();
129 for (File file
: files
) {
135 File trace
= new File(TRACE_DIRECTORY
);
136 if (trace
.exists()) {
144 * Test reading the events of the trace
147 public void testReadingEvents() {
148 ITmfTrace trace
= fTrace
;
150 ITmfContext ctx
= trace
.seekEvent(0L);
152 ITmfEvent event
= trace
.getNext(ctx
);
153 while (event
!= null) {
154 fTestData
.validateEvent(event
);
156 event
= trace
.getNext(ctx
);
158 fTestData
.validateEventCount(eventCount
);