tmf/lttng: Update 2014 copyrights
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / BaseEventInfoTest.java
index b8520aec02f767447ab91ec161f67bba680fbcde..42dc097c39816ec7f8e1850e16604fbf962b5d8c 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * 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
@@ -8,25 +8,35 @@
  *
  * 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;
 
@@ -35,36 +45,22 @@ public class BaseEventInfoTest extends TestCase {
     // ------------------------------------------------------------------------
     /**
      * 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);
@@ -75,7 +71,7 @@ public class BaseEventInfoTest extends TestCase {
         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());
@@ -87,17 +83,28 @@ public class BaseEventInfoTest extends TestCase {
     /**
      * 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;
@@ -111,10 +118,8 @@ public class BaseEventInfoTest extends TestCase {
 
     /**
      * Run the TraceEventType getEventType() method test.
-     *
-     * @throws Exception
-     *
      */
+    @Test
     public void testGetEventType_1() {
         BaseEventInfo fixture = new BaseEventInfo("event");
         fixture.setEventType("unknown");
@@ -125,14 +130,14 @@ public class BaseEventInfoTest extends TestCase {
         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();
@@ -158,12 +163,21 @@ public class BaseEventInfoTest extends TestCase {
         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);
@@ -183,7 +197,7 @@ public class BaseEventInfoTest extends TestCase {
         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();
@@ -201,13 +215,22 @@ public class BaseEventInfoTest extends TestCase {
         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);
@@ -234,8 +257,8 @@ public class BaseEventInfoTest extends TestCase {
     /**
      * 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);
@@ -391,11 +414,72 @@ public class BaseEventInfoTest extends TestCase {
         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");
@@ -412,6 +496,10 @@ public class BaseEventInfoTest extends TestCase {
     // equals
     // ------------------------------------------------------------------------
 
+    /**
+     * Test the .equals() method.
+     */
+    @Test
     public void testEqualsReflexivity() {
         assertTrue("equals", fEventInfo1.equals(fEventInfo1));
         assertTrue("equals", fEventInfo2.equals(fEventInfo2));
@@ -420,6 +508,10 @@ public class BaseEventInfoTest extends TestCase {
         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);
@@ -431,6 +523,10 @@ public class BaseEventInfoTest extends TestCase {
         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);
@@ -441,6 +537,10 @@ public class BaseEventInfoTest extends TestCase {
         assertTrue("equals", info1.equals(info3));
     }
 
+    /**
+     * Test the .equals() method.
+     */
+    @Test
     public void testEqualsNull() {
         assertTrue("equals", !fEventInfo1.equals(null));
         assertTrue("equals", !fEventInfo2.equals(null));
@@ -450,6 +550,10 @@ public class BaseEventInfoTest extends TestCase {
     // hashCode
     // ------------------------------------------------------------------------
 
+    /**
+     * Test the hashCode() method.
+     */
+    @Test
     public void testHashCode() {
         BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1);
         BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2);
This page took 0.03023 seconds and 5 git commands to generate.