Improve test coverage.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 9 May 2012 19:02:27 +0000 (15:02 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 9 May 2012 20:16:25 +0000 (16:16 -0400)
Fix EventDeclaration.equals()

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java

index 2f7bfdd5ac84f0a053b24d0f6d6cb816c9e92d0e..28a58309143916eb95d07fd948f18a3e69afd458 100644 (file)
@@ -1,5 +1,7 @@
 package org.eclipse.linuxtools.ctf.core.tests.trace;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -21,7 +23,7 @@ import org.junit.Test;
 /**
  * The class <code>StreamInputTest</code> contains tests for the class
  * <code>{@link StreamInput}</code>.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
@@ -31,7 +33,7 @@ public class StreamInputTest {
 
     /**
      * Launch the test.
-     * 
+     *
      * @param args
      *            the command line arguments
      */
@@ -41,8 +43,8 @@ public class StreamInputTest {
 
     /**
      * Perform pre-test initialization.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -73,8 +75,8 @@ public class StreamInputTest {
 
     /**
      * Run the FileChannel getFileChannel() method test.
-     * 
-     * @throws IOException 
+     *
+     * @throws IOException
      */
     @Test
     public void testGetFileChannel() throws IOException {
@@ -145,5 +147,66 @@ public class StreamInputTest {
     @Test
     public void testSetTimestampEnd() {
         fixture.setTimestampEnd(1L);
+        assertEquals(fixture.getTimestampEnd(), 1L);
+    }
+
+    StreamInput s1;
+    StreamInput s2;
+
+
+    @Test
+    public void testEquals1() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        assertFalse(s1.equals(null));
+    }
+
+    @Test
+    public void testEquals2() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        assertFalse(s1.equals(new Long(23L)));
+
+    }
+    @Test
+    public void testEquals3() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        assertEquals(s1,s1);
+
+    }
+    @Test
+    public void testEquals4() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        s2 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        assertEquals(s1,s2);
+    }
+    @Test
+    public void testEquals5() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        s2 = new StreamInput(new Stream(null),
+                (FileChannel) null, new File("")); //$NON-NLS-1$
+        assertFalse(s1.equals(s2));
+    }
+    @Test
+    public void testEquals6(){
+        s1 = new StreamInput(new Stream(null),
+                (FileChannel) null, null);
+        s2 = new StreamInput(new Stream(null),
+                (FileChannel) null, new File("")); //$NON-NLS-1$
+
+
+        assertFalse(s1.equals(s2));
+    }
+    @Test
+    public void testEquals7() throws CTFReaderException{
+        s1 = new StreamInput(new Stream(null),
+                (FileChannel) null, new File("")); //$NON-NLS-1$
+        s2 = new StreamInput(new Stream(TestParams.createTrace()),
+                (FileChannel) null, createFile());
+        assertFalse(s1.equals(s2));
     }
 }
\ No newline at end of file
index c2ea934f223eb7142640d09ef5199cce5ced2df1..42130794264d44679e2cb542c76467007f3495c5 100644 (file)
@@ -358,6 +358,41 @@ public class EventDeclarationTest {
         assertNotNull(ed.toString());
         ed.setContext( ed.getFields());
         assertNotNull(ed.toString());
+    }
+
+    EventDeclaration e1;
+    EventDeclaration e2;
+
+
+    @Test
+    public void testEquals1(){
+        e1 = new EventDeclaration();
+        assertFalse(e1.equals(null));
+    }
+
+    @Test
+    public void testEquals2(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        assertFalse(e1.equals(new Long(23L)));
+    }
+
+    @Test
+    public void testEquals3(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        assertEquals(e1,e1);
+    }
 
+    @Test
+    public void testEquals4(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        e2 = EventDeclaration.getLostEventDeclaration();
+        assertEquals(e1,e2);
+    }
+
+    @Test
+    public void testEquals5(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        e2 = new EventDeclaration();
+        assertFalse(e1.equals(e2));
     }
 }
index 271a3fba2a9e924d43293546796379223ac9884d..1772c9076b9ebc4c311aeb581ed6f83a26d0d56a 100644 (file)
@@ -87,4 +87,45 @@ public class StructDeclaration implements IDeclaration {
         return "[declaration] struct[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
     }
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = (prime * result)
+                + ((fieldsList == null) ? 0 : fieldsList.hashCode());
+        result = (prime * result) + (int) (maxAlign ^ (maxAlign >>> 32));
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof StructDeclaration)) {
+            return false;
+        }
+        StructDeclaration other = (StructDeclaration) obj;
+        if (fieldsList == null) {
+            if (other.fieldsList != null) {
+                return false;
+            }
+        } else if (!fieldsList.equals(other.fieldsList)) {
+            return false;
+        }
+        if (maxAlign != other.maxAlign) {
+            return false;
+        }
+        return true;
+    }
+
 }
This page took 0.027928 seconds and 5 git commands to generate.