import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assume.assumeTrue;
import java.util.Set;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.junit.Before;
import org.junit.BeforeClass;
*/
public class CtfTmfEventTest {
+ private static final int TRACE_INDEX = 0;
+
private static CtfTmfEvent nullEvent;
private CtfTmfEvent fixture;
/**
* Perform pre-test initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Before
- public void setUp() throws TmfTraceException {
- CtfTmfTrace trace = TestParams.createTrace();
+ public void setUp() {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
+ CtfTmfTrace trace = CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
CtfIterator tr = new CtfIterator(trace);
tr.advance();
fixture = tr.getCurrentEvent();
@Test
public void testGetEventName() {
String result = nullEvent.getEventName();
- assertEquals("Empty CTF event", result); //$NON-NLS-1$
+ assertEquals("Empty CTF event", result);
}
/**
*/
@Test
public void testGetFieldValue() {
- String fieldName = "pid"; //$NON-NLS-1$
+ String fieldName = "pid";
ITmfEventField result = fixture.getContent().getField(fieldName);
assertNotNull(result);
assertArrayEquals(fields2, fields);
}
+ /**
+ * Run the ITmfEventField getSubFieldValue(String[]) method test.
+ */
+ @Test
+ public void testGetSubFieldValue() {
+ /* Field exists */
+ String[] names = { "pid" };
+ assertNotNull(fixture.getContent().getSubField(names));
+
+ /* First field exists, not the second */
+ String[] names2 = { "pid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names2));
+
+ /* Both field do not exist */
+ String[] names3 = { "pfid", "abcd" };
+ assertNull(fixture.getContent().getSubField(names3));
+
+ /* TODO Missing case of embedded field, need event for it */
+ }
+
/**
* Run the long getID() method test.
*/
String reference = fixture.getReference();
String source = fixture.getSource();
ITmfEventType type = fixture.getType();
- assertEquals(rank, ITmfContext.UNKNOWN_RANK);
- assertEquals(trace.getName(), "test"); //$NON-NLS-1$
- assertEquals(reference,"channel0_1"); //$NON-NLS-1$
- assertEquals(source, "1"); //$NON-NLS-1$
- assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
+ assertEquals(ITmfContext.UNKNOWN_RANK, rank);
+ assertEquals("test", trace.getName());
+ assertEquals("channel0_1", reference);
+ assertEquals("1", source);
+ assertEquals("lttng_statedump_vm_map", type.toString());
}
/**
Set<String> attributes = fixture.listCustomAttributes();
assertEquals(0, attributes.size());
- String attrib = fixture.getCustomAttribute("bozo"); //$NON-NLS-1$
+ String attrib = fixture.getCustomAttribute("bozo");
assertNull(attrib);
}
@Test
public void testToString() {
String s = fixture.getContent().toString();
- assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
+ assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
}
/**
assertSame(nullEvent2, nullEvent);
assertNotNull(nullEvent);
assertEquals(-1, nullEvent.getCPU());
- assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
- assertEquals("No stream", nullEvent.getReference()); //$NON-NLS-1$
+ assertEquals("Empty CTF event", nullEvent.getEventName());
+ assertEquals("No stream", nullEvent.getReference());
assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
assertEquals(-1L, nullEvent.getID());
assertEquals(-1L, nullEvent.getTimestamp().getValue());