From 4dd0eaede98b6bfba59f88d4658220c4cb1ca46c Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 9 May 2012 15:02:27 -0400 Subject: [PATCH] Improve test coverage. Fix EventDeclaration.equals() Signed-off-by: Matthew Khouzam --- .../ctf/core/tests/trace/StreamInputTest.java | 75 +++++++++++++++++-- .../tests/types/EventDeclarationTest.java | 35 +++++++++ .../core/event/types/StructDeclaration.java | 41 ++++++++++ 3 files changed, 145 insertions(+), 6 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java index 2f7bfdd5ac..28a5830914 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java @@ -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 StreamInputTest contains tests for the class * {@link StreamInput}. - * + * * @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 diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java index c2ea934f22..4213079426 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java @@ -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)); } } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java index 271a3fba2a..1772c9076b 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java @@ -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; + } + } -- 2.34.1