+/*******************************************************************************
+ * Copyright (c) 2012-2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial generation with CodePro tools
+ * Alexandre Montplaisir - Clean up, consolidate redundant tests
+ *******************************************************************************/
+
package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
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.io.FileNotFoundException;
+import java.util.Set;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.junit.After;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
/**
- * The class <code>CTFEventTest</code> contains tests for the class
- * <code>{@link CTFEvent}</code>.
+ * The class <code>CtfTmfEventTest</code> contains tests for the class
+ * <code>{@link CtfTmfEvent}</code>.
*
* @author ematkho
* @version $Revision: 1.0 $
*/
public class CtfTmfEventTest {
+ private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
+
+ private static CtfTmfEvent nullEvent;
private CtfTmfEvent fixture;
/**
- * Launch the test.
- *
- * @param args
- * the command line arguments
+ * Test class initialization
*/
- public static void main(String[] args) {
- new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class);
+ @BeforeClass
+ public static void initialize() {
+ nullEvent = CtfTmfEventFactory.getNullEvent();
}
/**
* Perform pre-test initialization.
- *
- * @throws FileNotFoundException
*/
@Before
- public void setUp() throws TmfTraceException {
- CtfTmfTrace trace = TestParams.createTrace();
+ public void setUp() {
+ assumeTrue(testTrace.exists());
+ CtfTmfTrace trace = testTrace.getTrace();
CtfIterator tr = new CtfIterator(trace);
tr.advance();
fixture = tr.getCurrentEvent();
}
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- // Add additional tear down code here
- }
-
/**
* Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
*/
*/
@Test
public void testGetCPU() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
int result = nullEvent.getCPU();
-
assertEquals(-1, result);
}
- /**
- * Run the String getChannelName() method test.
- */
- @Test
- public void testGetChannelName() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
- String result = nullEvent.getChannelName();
-
- assertEquals("No stream", result); //$NON-NLS-1$
- }
-
/**
* Run the String getEventName() method test.
*/
@Test
public void testGetEventName() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
String result = nullEvent.getEventName();
-
- assertEquals("Empty CTF event", result); //$NON-NLS-1$
+ assertEquals("Empty CTF event", result);
}
/**
*/
@Test
public void testGetFieldValue() {
- String fieldName = "id"; //$NON-NLS-1$
- Object result = fixture.getContent().getField(fieldName).getValue();
+ String fieldName = "pid";
+ ITmfEventField result = fixture.getContent().getField(fieldName);
assertNotNull(result);
+ assertNotNull(result.getValue());
}
/**
*/
@Test
public void testGetFields() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
ITmfEventField[] fields = nullEvent.getContent().getFields();
+ ITmfEventField[] fields2 = new ITmfEventField[0];
+ assertArrayEquals(fields2, fields);
+ }
+
+ /**
+ * Run the ITmfEventField getSubFieldValue(String[]) method test.
+ */
+ @Test
+ public void testGetSubFieldValue() {
+ /* Field exists */
+ String[] names = { "pid" };
+ assertNotNull(fixture.getContent().getSubField(names));
- assertArrayEquals(null, fields);
+ /* 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 */
}
/**
*/
@Test
public void testGetID() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
long result = nullEvent.getID();
+ assertEquals(-1L, result);
+ }
+ /**
+ * Run the long getTimestamp() method test.
+ */
+ @Test
+ public void testGetTimestamp() {
+ long result = nullEvent.getTimestamp().getValue();
assertEquals(-1L, result);
}
+ /**
+ * Test the getters for the reference, source and type.
+ */
+ @Test
+ public void testGetters() {
+ long rank = fixture.getRank();
+ CtfTmfTrace trace = fixture.getTrace();
+ String reference = fixture.getReference();
+ String source = fixture.getSource();
+ ITmfEventType type = fixture.getType();
+ assertEquals(ITmfContext.UNKNOWN_RANK, rank);
+ assertEquals("kernel", trace.getName());
+ assertEquals("channel0_1", reference);
+ assertEquals("1", source);
+ assertEquals("lttng_statedump_vm_map", type.toString());
+ }
/**
- * Run the CTFEvent getNullEvent() method test.
+ * Test the custom CTF attributes methods. The test trace doesn't have any,
+ * so the list of attributes should be empty.
*/
@Test
- public void testGetNullEvent() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
+ public void testCustomAttributes() {
+ Set<String> attributes = fixture.listCustomAttributes();
+ assertEquals(0, attributes.size());
- assertNotNull(nullEvent);
- assertEquals(-1, nullEvent.getCPU());
- assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
- assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$
- assertArrayEquals(null, nullEvent.getContent().getFields());
- assertEquals(-1L, nullEvent.getID());
- assertEquals(-1L, nullEvent.getTimestampValue());
+ String attrib = fixture.getCustomAttribute("bozo");
+ assertNull(attrib);
}
/**
- * Run the long getTimestamp() method test.
- *
+ * Test the toString() method
*/
@Test
- public void testGetTimestamp() {
- CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
- long result = nullEvent.getTimestampValue();
+ public void testToString() {
+ String s = fixture.getContent().toString();
+ assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
+ }
- assertEquals(-1L, result);
+ /**
+ * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
+ * nullEvent's values.
+ */
+ @Test
+ public void testNullEvent() {
+ CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent();
+ assertSame(nullEvent2, nullEvent);
+ assertNotNull(nullEvent);
+ assertEquals(-1, nullEvent.getCPU());
+ 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());
}
}