Improve unit tests
authorFrancois Chouinard <fchouinard@gmail.com>
Sat, 3 Mar 2012 16:49:16 +0000 (11:49 -0500)
committerFrancois Chouinard <fchouinard@gmail.com>
Sat, 3 Mar 2012 16:49:16 +0000 (11:49 -0500)
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventType.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomEvent.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomTxtEvent.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/parsers/custom/CustomXmlEvent.java

index 310c84449a25ecc234c23572d5cd0b6c927fa9ef..713fb3713d1f6790b8204a699010c6590e94051e 100644 (file)
@@ -223,18 +223,32 @@ public class TmfEventFieldTest extends TestCase {
     // clone
     // ------------------------------------------------------------------------
 
-    public void testClone() throws Exception {
-        ITmfEventField clone = fStructTerminalField1.clone();
-        assertEquals("clone", fStructTerminalField1, clone);
-
-        clone = fField1.clone();
+    public void testFieldClone() throws Exception {
+        TmfEventField clone = fField1.clone();
+        assertTrue("clone", fField1.clone().equals(fField1));
+        assertTrue("clone", clone.clone().equals(clone));
         assertEquals("clone", fField1, clone);
+        assertEquals("clone", clone, fField1);
 
         clone = fRootField.clone();
+        assertTrue("clone", fRootField.clone().equals(fRootField));
+        assertTrue("clone", clone.clone().equals(clone));
         assertEquals("clone", fRootField, clone);
+        assertEquals("clone", clone, fRootField);
+    }
+
+    public void testStructFieldClone() throws Exception {
+        TmfEventField clone = fStructTerminalField1.clone();
+        assertTrue("clone", fStructTerminalField1.clone().equals(fStructTerminalField1));
+        assertTrue("clone", clone.clone().equals(clone));
+        assertEquals("clone", fStructTerminalField1, clone);
+        assertEquals("clone", clone, fStructTerminalField1);
 
         clone = fStructRootField.clone();
+        assertTrue("clone", fStructRootField.clone().equals(fStructRootField));
+        assertTrue("clone", clone.clone().equals(clone));
         assertEquals("clone", fStructRootField, clone);
+        assertEquals("clone", clone, fStructRootField);
     }
 
     // ------------------------------------------------------------------------
index a563c1839b52d5f658ee1eb929279a97a796582e..a1dd5a3df51f1adfaad193603beb0e43cce1b627 100644 (file)
@@ -64,7 +64,7 @@ public class TmfEventTest extends TestCase {
     private final ITmfEventField fContent1 = new TmfEventField(fRawContent1, fFields1);
     private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, 2, 5);
     private final String fReference1 = "Some reference";
-    private final TmfEvent fEvent1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1);
+    private final ITmfEvent fEvent1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1);
 
     private final Object fValue2a = "Another string";
     private final Object fValue2b = Integer.valueOf(-4);
@@ -75,7 +75,7 @@ public class TmfEventTest extends TestCase {
     private final ITmfEventField fContent2 = new TmfEventField(fRawContent2, fFields2);
     private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, 2, 5);
     private final String fReference2 = "Some other reference";
-    private final TmfEvent fEvent2 = new TmfEvent(null, 1, fTimestamp2, fSource, fType, fContent2, fReference2);
+    private final ITmfEvent fEvent2 = new TmfEvent(null, 1, fTimestamp2, fSource, fType, fContent2, fReference2);
 
     private final String fTracePath = "testfiles" + File.separator + "A-Test-10K";
 
@@ -227,7 +227,7 @@ public class TmfEventTest extends TestCase {
 
     private class TestEvent extends TmfEvent {
         
-        public TestEvent(TmfEvent event) {
+        public TestEvent(ITmfEvent event) {
             super(event);
         }
 
@@ -403,14 +403,24 @@ public class TmfEventTest extends TestCase {
         }
     }
 
-    public void testClone() throws Exception {
+    public void testClone1() throws Exception {
         ITmfEvent clone = fEvent1.clone();
+
+        assertTrue("clone", fEvent1.clone().equals(fEvent1));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", fEvent1, clone);
+        assertEquals("clone", clone, fEvent1);
     }
 
     public void testClone2() throws Exception {
-        ITmfEvent event = new MyEvent();
-        ITmfEvent clone = event.clone();
+        TmfEvent event = new MyEvent();
+        TmfEvent clone = event.clone();
+
+        assertTrue("clone", event.clone().equals(event));
+        assertTrue("clone", clone.clone().equals(clone));
+
+        assertEquals("clone", event, clone);
         assertEquals("clone", clone, event);
     }
 
index 8d57b975e667ec4155d88cb409ffa9aa64599fc6..ed8a86c22f2f1e1f97fb395e8d92f19d1c3fa207 100644 (file)
@@ -44,10 +44,10 @@ public class TmfEventTypeTest extends TestCase {
     private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
     private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel1 };
 
-    private final TmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
-    private final TmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
-    private final TmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2));
-    private final TmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1));
+    private final ITmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
+    private final ITmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
+    private final ITmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2));
+    private final ITmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1));
 
     // ------------------------------------------------------------------------
     // Housekeeping
@@ -174,13 +174,23 @@ public class TmfEventTypeTest extends TestCase {
 
     public void testClone() throws Exception {
         ITmfEventType clone = fType1.clone();
+
+        assertTrue("clone", fType1.clone().equals(fType1));
+        assertTrue("clone", clone.clone().equals(clone));
+
+        assertEquals("clone", clone, fType1);
         assertEquals("clone", fType1, clone);
     }
 
     public void testClone2() throws Exception {
         ITmfEventType type = new TmfEventType();
         ITmfEventType clone = type.clone();
+
+        assertTrue("clone", type.clone().equals(type));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", clone, type);
+        assertEquals("clone", type, clone);
     }
 
     // ------------------------------------------------------------------------
index 683ccd2c62f804b78fdfd805d20af53035b89c34..fb974c76857f0f67e6ef0eea77c0eaee1415c099 100644 (file)
@@ -124,14 +124,24 @@ public class TmfSimpleTimestampTest extends TestCase {
     }
 
     public void testClone() throws Exception {
-        ITmfTimestamp timestamp = ts0.clone();
-        assertEquals("clone", timestamp, ts0);
+        ITmfTimestamp clone = ts0.clone();
+
+        assertTrue("clone", ts0.clone().equals(ts0));
+        assertTrue("clone", clone.clone().equals(clone));
+
+        assertEquals("clone", clone, ts0);
+        assertEquals("clone", ts0, clone);
     }
 
     public void testClone2() throws Exception {
         MyTimestamp timestamp = new MyTimestamp();
         MyTimestamp clone = timestamp.clone();
+
+        assertTrue("clone", timestamp.clone().equals(timestamp));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", clone, timestamp);
+        assertEquals("clone", timestamp, clone);
     }
 
     // ------------------------------------------------------------------------
index 3ee4a673efe51e2042e6e5ec670ee236ccbd04bf..720d0870fc7c8ed1d9086a66597a0e97289b9e4f 100644 (file)
@@ -133,6 +133,9 @@ public class TmfTimeRangeTest extends TestCase {
         TmfTimeRange range = new TmfTimeRange(ts1, ts2);
         TmfTimeRange clone = range.clone();
 
+        assertTrue("clone", range.clone().equals(range));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", range, clone);
         assertEquals("clone", ts1, clone.getStartTime());
         assertEquals("clone", ts2, clone.getEndTime());
index fd9de9f46ccad35573b59481e595d80a6b88e15f..6b7dcea3326343fc16e863e8cb5ee944f9932ddd 100644 (file)
@@ -145,13 +145,23 @@ public class TmfTimestampTest extends TestCase {
 
     public void testClone() throws Exception {
         ITmfTimestamp clone = ts0.clone();
+
+        assertTrue("clone", ts0.clone().equals(ts0));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", clone, ts0);
+        assertEquals("clone", ts0, clone);
     }
 
     public void testClone2() throws Exception {
         MyTimestamp timestamp = new MyTimestamp();
         MyTimestamp clone = timestamp.clone();
+
+        assertTrue("clone", timestamp.clone().equals(timestamp));
+        assertTrue("clone", clone.clone().equals(clone));
+
         assertEquals("clone", clone, timestamp);
+        assertEquals("clone", timestamp, clone);
     }
 
     // ------------------------------------------------------------------------
index 5339bc9b9b7165b7d571004d288541c3ff2d27de..0972d52ce10434e189702f59e2ba76c1daa26590 100644 (file)
@@ -62,12 +62,12 @@ public class TmfEventType implements ITmfEventType {
         * 
         * @param type the other type
         */
-       public TmfEventType(TmfEventType type) {
+       public TmfEventType(ITmfEventType type) {
        if (type == null)
                throw new IllegalArgumentException();
-       fContext = type.fContext;
-               fTypeId  = type.fTypeId;
-               fRootField = type.fRootField;
+       fContext = type.getContext();
+               fTypeId  = type.getName();
+               fRootField = type.getRootField();
        }
 
     // ------------------------------------------------------------------------
index f471e076776857b4132b1f2279c7c6501a207c46..87e0cbac4c5ab00e73c229bcda176cfe04af1513 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.ui.parsers.custom;
 \r
 import java.text.ParseException;\r
 import java.text.SimpleDateFormat;\r
+import java.util.Arrays;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
@@ -94,4 +95,40 @@ public class CustomEvent extends TmfEvent {
         fData = null;\r
     }\r
 \r
+    /* (non-Javadoc)\r
+     * @see java.lang.Object#hashCode()\r
+     */\r
+    @Override\r
+    public int hashCode() {\r
+        final int prime = 31;\r
+        int result = super.hashCode();\r
+        result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());\r
+        return result;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see java.lang.Object#equals(java.lang.Object)\r
+     */\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj) {\r
+            return true;\r
+        }\r
+        if (!super.equals(obj)) {\r
+            return false;\r
+        }\r
+        if (!(obj instanceof CustomEvent)) {\r
+            return false;\r
+        }\r
+        CustomEvent other = (CustomEvent) obj;\r
+        if (fDefinition == null) {\r
+            if (other.fDefinition != null) {\r
+                return false;\r
+            }\r
+        } else if (!fDefinition.equals(other.fDefinition)) {\r
+            return false;\r
+        }\r
+        return true;\r
+    }\r
+\r
 }\r
index 086ba86f9cdb2b68c5a257c7dfa3ab99a32c9cac..4f98191002c4234fc20ba350f3e9184430f9966c 100644 (file)
@@ -39,7 +39,7 @@ public class CustomTxtEvent extends CustomEvent {
 \r
     @Override\r
     public void setContent(ITmfEventField content) {\r
-        setContent(content);\r
+        super.setContent(content);\r
     }\r
 \r
     public void processGroups(InputLine input, Matcher matcher) {\r
index e69b9d580929e8b646924fbc9f9543e6850d8460..c1f820f942ad837689ab183992da674cd915baf9 100644 (file)
@@ -35,7 +35,7 @@ public class CustomXmlEvent extends CustomEvent {
 \r
     @Override\r
     public void setContent(ITmfEventField content) {\r
-        setContent(content);\r
+        super.setContent(content);\r
     }\r
 \r
     public void parseInput(String value, String name, int inputAction, String inputFormat) {\r
This page took 0.031826 seconds and 5 git commands to generate.