/**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*
* Contributors:
* Bernd Hufmann - Initial API and implementation
+ * Alexandre Montplaisir - Port to JUnit4
**********************************************************************/
+
package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import java.util.LinkedList;
+import java.util.List;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo;
+import org.junit.Before;
+import org.junit.Test;
/**
- * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
+ * The class <code>BaseEventInfoTest</code> contains test for the class
+ * <code>{@link BaseEventInfo}</code>.
*/
-@SuppressWarnings({"nls", "javadoc"})
-public class BaseEventInfoTest extends TestCase {
+public class BaseEventInfoTest {
// ------------------------------------------------------------------------
// Test data
// ------------------------------------------------------------------------
+
private IBaseEventInfo fEventInfo1 = null;
private IBaseEventInfo fEventInfo2 = null;
// ------------------------------------------------------------------------
/**
* Perform pre-test initialization.
- *
- * @throws Exception if the initialization fails for some reason
- *
*/
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
ModelImplFactory factory = new ModelImplFactory();
fEventInfo1 = factory.getBaseEventInfo1();
fEventInfo2 = factory.getBaseEventInfo2();
}
- /**
- * Perform post-test clean-up.
- *
- * @throws Exception if the clean-up fails for some reason
- *
- */
- @Override
- public void tearDown() throws Exception {
- }
-
// ------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------
/**
* Run the BaseEventInfo() constructor test.
- *
*/
+ @Test
public void testBaseEventInfo() {
BaseEventInfo fixture = new BaseEventInfo("event");
assertNotNull(fixture);
assertEquals("unknown", result.getInName());
assertEquals("UNKNOWN", result.name());
assertEquals("UNKNOWN", result.toString());
- assertEquals(3, result.ordinal());
+ assertEquals(4, result.ordinal());
TraceLogLevel level = fixture.getLogLevel();
assertEquals("TRACE_DEBUG", level.getInName());
/**
* Test Copy Constructor
*/
+ @Test
public void testEventInfoCopy() {
BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo1);
assertEquals(fEventInfo1.getName(), info.getName());
assertEquals(fEventInfo1.getEventType(), info.getEventType());
assertEquals(fEventInfo1.getLogLevel(), info.getLogLevel());
+ assertEquals(fEventInfo1.getFilterExpression(), info.getFilterExpression());
+
+ IFieldInfo[] orignalFields = fEventInfo1.getFields();
+ IFieldInfo[] copiedFields = info.getFields();
+ assertEquals(orignalFields.length, copiedFields.length);
+
+ for (int i = 0; i < copiedFields.length; i++) {
+ assertEquals(orignalFields[i], copiedFields[i]);
+ }
}
/**
* Test Copy Constructor
*/
+ @Test
public void testEventCopy2() {
try {
BaseEventInfo info = null;
/**
* Run the TraceEventType getEventType() method test.
- *
- * @throws Exception
- *
*/
+ @Test
public void testGetEventType_1() {
BaseEventInfo fixture = new BaseEventInfo("event");
fixture.setEventType("unknown");
assertEquals("unknown", result.getInName());
assertEquals("UNKNOWN", result.name());
assertEquals("UNKNOWN", result.toString());
- assertEquals(3, result.ordinal());
+ assertEquals(4, result.ordinal());
fixture.setEventType("");
result = fixture.getEventType();
assertEquals("unknown", result.getInName());
assertEquals("UNKNOWN", result.name());
assertEquals("UNKNOWN", result.toString());
- assertEquals(3, result.ordinal());
+ assertEquals(4, result.ordinal());
fixture.setEventType("tracepoint");
result = fixture.getEventType();
assertEquals("PROBE", result.toString());
assertEquals(2, result.ordinal());
+ fixture.setEventType("function");
+ result = fixture.getEventType();
+ assertNotNull(result);
+ assertEquals("function", result.getInName());
+ assertEquals("FUNCTION", result.name());
+ assertEquals("FUNCTION", result.toString());
+ assertEquals(3, result.ordinal());
+
+
}
/**
* Run the void setEventType(TraceEventType) method test.
- *
*/
+ @Test
public void testSetEventType_2() {
BaseEventInfo fixture = new BaseEventInfo("event");
fixture.setEventType(TraceEventType.TRACEPOINT);
assertEquals("unknown", result.getInName());
assertEquals("UNKNOWN", result.name());
assertEquals("UNKNOWN", result.toString());
- assertEquals(3, result.ordinal());
+ assertEquals(4, result.ordinal());
fixture.setEventType(TraceEventType.SYSCALL);
result = fixture.getEventType();
assertEquals("PROBE", result.toString());
assertEquals(2, result.ordinal());
+ fixture.setEventType(TraceEventType.FUNCTION);
+ result = fixture.getEventType();
+ assertNotNull(result);
+ assertEquals("function", result.getInName());
+ assertEquals("FUNCTION", result.name());
+ assertEquals("FUNCTION", result.toString());
+ assertEquals(3, result.ordinal());
+
+
}
/**
* Run the void setLogLevel(TraceLogLevel) method test.
* Run the TraceLogLevel getLogLevel() method test
- *
*/
+ @Test
public void testSetLogLevel1() {
BaseEventInfo fixture = new BaseEventInfo("event");
fixture.setEventType(TraceEventType.TRACEPOINT);
/**
* Run the void setLogLevel(String) method test.
* Run the TraceLogLevel getLogLevel() method test
- *
*/
+ @Test
public void testSetLogLevel2() {
BaseEventInfo fixture = new BaseEventInfo("event");
fixture.setEventType(TraceEventType.TRACEPOINT);
assertEquals(14, result.ordinal());
}
+ /**
+ * test filter expression
+ */
+ @Test
+ public void testSetFields() {
+ BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
+ info.setFilterExpression("stringfield==test");
+ assertEquals("stringfield==test", info.getFilterExpression());
+ }
+
+
+ /**
+ * test add field
+ */
+ @Test
+ public void testAddField() {
+ BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
+
+ IFieldInfo field = new FieldInfo("intfield");
+ field.setFieldType("int");
+
+ info.addField(field);
+
+ // Verify the stored events
+ IFieldInfo[] result = info.getFields();
+
+ assertNotNull(result);
+ assertEquals(1, result.length);
+ assertNotNull(result[0]);
+ assertTrue(field.equals(result[0]));
+ }
+
+ /**
+ * test set fields
+ */
+ @Test
+ public void testFields() {
+ BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo2);
+
+ IFieldInfo field1 = new FieldInfo("intfield");
+ field1.setFieldType("int");
+
+ IFieldInfo field2 = new FieldInfo("stringfield");
+ field2.setFieldType("string");
+
+ List<IFieldInfo> fields = new LinkedList<>();
+ fields.add(field1);
+ fields.add(field2);
+ info.setFields(fields);
+
+ // Verify the stored events
+ IFieldInfo[] result = info.getFields();
+
+ assertNotNull(result);
+ assertEquals(2, result.length);
+
+ for (int i = 0; i < result.length; i++) {
+ assertNotNull(result[i]);
+ assertTrue(fields.get(i).equals(result[i]));
+ }
+ }
/**
* Run the String toString() method test.
- *
*/
+ @Test
public void testToString_1() {
BaseEventInfo fixture = new BaseEventInfo("event");
fixture.setName("testName");
// equals
// ------------------------------------------------------------------------
+ /**
+ * Test the .equals() method.
+ */
+ @Test
public void testEqualsReflexivity() {
assertTrue("equals", fEventInfo1.equals(fEventInfo1));
assertTrue("equals", fEventInfo2.equals(fEventInfo2));
assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
}
+ /**
+ * Test the .equals() method.
+ */
+ @Test
public void testEqualsSymmetry() {
BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2);
assertTrue("equals", fEventInfo2.equals(info2));
}
+ /**
+ * Test the .equals() method.
+ */
+ @Test
public void testEqualsTransivity() {
BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
assertTrue("equals", info1.equals(info3));
}
+ /**
+ * Test the .equals() method.
+ */
+ @Test
public void testEqualsNull() {
assertTrue("equals", !fEventInfo1.equals(null));
assertTrue("equals", !fEventInfo2.equals(null));
// hashCode
// ------------------------------------------------------------------------
+ /**
+ * Test the hashCode() method.
+ */
+ @Test
public void testHashCode() {
BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2);