This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
Re: RFC: JDWP filter tests
- From: Kyle Galloway <kgallowa at redhat dot com>
- To: mauve-patches <mauve-patches at sources dot redhat dot com>
- Date: Fri, 09 Jun 2006 11:05:05 -0400
- Subject: Re: RFC: JDWP filter tests
- References: <44898BC3.9050704@redhat.com>
Kyle Galloway wrote:
Here are 5 tests for JDWP filters.
ChangeLog:
2006-06-05 Kyle Galloway <kgallowa@redhat.com>
*
gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassMatchFilter.java:
New file.
*
gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassExcludeFilter.java:
New file.
*
gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfInstanceOnlyFilter.java:
New file.
*
gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfCountFilter.java:
New file.
*
gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassOnlyFilter.java:
New file.
Reposting with Tags properly set, sorry about that...
-Kyle
Index: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassExcludeFilter.java
===================================================================
RCS file: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassExcludeFilter.java
diff -N gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassExcludeFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassExcludeFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,97 @@
+/* TestOfClassExcludeFilter.java -- test of ClassExcludeFilter
+
+ Written by Kyle Galloway (kgallowa@redhat.com)
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ */
+
+// Tags: JDK 1.4
+
+
+package gnu.testlet.gnu.classpath.jdwp.events.filters;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import gnu.classpath.jdwp.event.filters.ClassExcludeFilter;
+import gnu.classpath.jdwp.event.ClassPrepareEvent;
+import gnu.classpath.jdwp.exception.InvalidStringException;
+
+public class TestOfClassExcludeFilter
+ extends TestOfClassMatchFilter
+ implements Testlet
+{
+ /**
+ * Tests the <code>ClassExcludeFilter</code> method matches
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testMatches(TestHarness harness)
+ {
+ harness.checkPoint("matches method");
+ String[] validStrings = { "java.lang.Integer", "*nteger", "java.lang.*",
+ "*" };
+ String[] invalidStrings = { "Float", "Double", "AWT" };
+
+ ClassExcludeFilter testCEF = null;
+
+ // create an event to use as a test
+ ClassPrepareEvent testEvent = new ClassPrepareEvent(Thread.currentThread(),
+ Integer.class, 0);
+ // check to see that the valid strings match the class name
+ for (int i = 0; i < validStrings.length; i++)
+ {
+ try
+ {
+ testCEF = new ClassExcludeFilter(validStrings[i]);
+ harness.check(testCEF.matches(testEvent), false, "for string: "
+ + validStrings[i]);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(false, "String: " + validStrings[i] + " threw " + ex);
+ }
+ }
+ // check to see that the invalid strings don't match the class name
+ for (int i = 0; i < invalidStrings.length; i++)
+ {
+ try
+ {
+ testCEF = new ClassExcludeFilter(invalidStrings[i]);
+ harness.check(testCEF.matches(testEvent), true, "for string: "
+ + invalidStrings[i]);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(false, "String: " + validStrings[i] + " threw " + ex);
+ }
+ }
+ }
+
+ /**
+ * Test the <code>ClassMatchFilter</code> class
+ *
+ * @param harness the TestHarness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testConstructor(harness);
+ testMatches(harness);
+ }
+}
Index: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassMatchFilter.java
===================================================================
RCS file: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassMatchFilter.java
diff -N gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassMatchFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassMatchFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,146 @@
+/* TestOfClassMatchFilter.java -- test of ClassMatchFilter
+
+ Written by Kyle Galloway (kgallowa@redhat.com)
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ */
+
+// Tags: JDK1.4
+
+
+package gnu.testlet.gnu.classpath.jdwp.events.filters;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import gnu.classpath.jdwp.event.filters.ClassMatchFilter;
+import gnu.classpath.jdwp.event.ClassPrepareEvent;
+import gnu.classpath.jdwp.exception.InvalidStringException;
+
+/**
+ * @author Kyle Galloway (kgallowa@redhat.com)
+ */
+public class TestOfClassMatchFilter
+ implements Testlet
+{
+
+ /**
+ * Tests the <code>ClassMatchFilter</code> constructor
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testConstructor(TestHarness harness)
+ {
+ harness.checkPoint("Constructor");
+
+ ClassMatchFilter testCMF = null;
+
+ String[] validStrings = { "SomeString", "", "*omeString", "SomeStr*" };
+ String[] invalidStrings = { "Som*String", "SomeStri*g" };
+
+ // check to see if the valid strings don't throw exceptions
+ for (int i = 0; i < validStrings.length; i++)
+ {
+ try
+ {
+ testCMF = new ClassMatchFilter(validStrings[i]);
+ harness.check(true);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(false, "constructor threw exception for valid "
+ + "string: " + validStrings[i]);
+ }
+ }
+
+ // check that invalid strings throw exceptions
+ for (int i = 0; i < invalidStrings.length; i++)
+ {
+ try
+ {
+ testCMF = new ClassMatchFilter(invalidStrings[i]);
+ harness.check(false, "constructor didn't throw exception for "
+ + "invalid string: " + invalidStrings[i]);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(true);
+ }
+ }
+ }
+
+ /**
+ * Tests the <code>ClassMatchFilter</code> method matches
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testMatches(TestHarness harness)
+ {
+ harness.checkPoint("matches method");
+ String[] validStrings = { "java.lang.Integer", "*nteger", "java.lang.*",
+ "*" };
+ String[] invalidStrings = { "Float", "Double", "AWT" };
+
+ ClassMatchFilter testCMF = null;
+
+ // create an event to use as a test
+ ClassPrepareEvent testEvent = new ClassPrepareEvent(Thread.currentThread(),
+ Integer.class, 0);
+ // check to see that the valid strings match the class name
+ for (int i = 0; i < validStrings.length; i++)
+ {
+ try
+ {
+ testCMF = new ClassMatchFilter(validStrings[i]);
+ harness.check(testCMF.matches(testEvent), true, "for string: "
+ + validStrings[i]);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(false, "String: " + validStrings[i] + " threw " + ex);
+ }
+ }
+ // check to see that the invalid strings don't match the class name
+ for (int i = 0; i < invalidStrings.length; i++)
+ {
+ try
+ {
+ testCMF = new ClassMatchFilter(invalidStrings[i]);
+ harness.check(testCMF.matches(testEvent), false,
+ "for string: " + invalidStrings[i]);
+ }
+ catch (InvalidStringException ex)
+ {
+ harness.check(false, "String: " + validStrings[i] + " threw " + ex);
+ }
+ }
+ }
+
+ /**
+ * Test the <code>ClassMatchFilter</code> class
+ *
+ * @param harness the TestHarness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testConstructor(harness);
+ testMatches(harness);
+ }
+
+}
Index: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassOnlyFilter.java
===================================================================
RCS file: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassOnlyFilter.java
diff -N gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassOnlyFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfClassOnlyFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,105 @@
+/* TestOfClassOnlyFilter.java -- test of ClassOnlyFilter
+
+ Written by Kyle Galloway (kgallowa@redhat.com)
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ */
+
+// Tags: JDK1.4
+
+
+package gnu.testlet.gnu.classpath.jdwp.events.filters;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import gnu.classpath.jdwp.event.filters.ClassOnlyFilter;
+import gnu.classpath.jdwp.event.ClassPrepareEvent;
+import gnu.classpath.jdwp.id.ReferenceTypeId;
+import gnu.classpath.jdwp.id.ClassReferenceTypeId;
+import gnu.classpath.jdwp.exception.InvalidClassException;
+
+import java.lang.ref.SoftReference;
+
+public class TestOfClassOnlyFilter
+ implements Testlet
+{
+ /**
+ * Tests the <code>ClassOnlyFilter</code> constructor
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testConstructor(TestHarness harness)
+ {
+ harness.checkPoint("Constructor");
+ for (int i = 0; i < 3; i++)
+ {
+ ReferenceTypeId testId = new ClassReferenceTypeId();
+ SoftReference testSR = new SoftReference(Integer.class);
+ testId.setReference(testSR);
+
+ try
+ {
+ ClassOnlyFilter testCOF = new ClassOnlyFilter(testId);
+ }
+ catch (InvalidClassException ex)
+ {
+ harness.check(false, "Constructor failed with exception" + ex);
+ }
+ }
+ }
+
+ /**
+ * Tests the <code>ClassOnlyFilter</code> matches method
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testMatches(TestHarness harness)
+ {
+ harness.checkPoint("matches method");
+ ReferenceTypeId testId = new ClassReferenceTypeId();
+ SoftReference testSR = new SoftReference(Integer.class);
+ testId.setReference(testSR);
+ try
+ {
+ ClassOnlyFilter testCOF = new ClassOnlyFilter(testId);
+ ClassPrepareEvent testEvent = new ClassPrepareEvent(
+ Thread.currentThread(),
+ Integer.class, 0);
+
+ harness.check(testCOF.matches(testEvent), "matches method");
+ }
+ catch (InvalidClassException ex)
+ {
+ harness.check(false, "Constructor(in methods test) failed with"
+ + "exception" + ex);
+ }
+ }
+
+ /**
+ * Test the <code>ClassOnlyFilter</code> class
+ *
+ * @param harness the TestHarness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testConstructor(harness);
+ testMatches(harness);
+ }
+}
Index: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfCountFilter.java
===================================================================
RCS file: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfCountFilter.java
diff -N gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfCountFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfCountFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,120 @@
+/*/* TestOfClassMatchFilter.java -- test of CountFilter
+
+ Written by Kyle Galloway (kgallowa@redhat.com)
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ */
+
+// Tags: JDK1.4
+
+
+package gnu.testlet.gnu.classpath.jdwp.events.filters;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import gnu.classpath.jdwp.event.filters.CountFilter;
+import gnu.classpath.jdwp.event.ClassPrepareEvent;
+import gnu.classpath.jdwp.exception.InvalidCountException;
+
+/**
+ * @author Kyle Galloway (kgallowa@redhat.com)
+ */
+public class TestOfCountFilter
+ implements Testlet
+{
+
+ public final int COUNT = 5;
+ public final int INVALID_COUNT = -1;
+
+ /**
+ * Tests the <code>ClountFilter</code> constructor
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testConstructor(TestHarness harness)
+ {
+
+
+ harness.checkPoint("Constructor");
+
+ try
+ {
+ CountFilter testCF = new CountFilter(COUNT);
+ harness.check(true, "Constructor passed test");
+ }
+ catch(InvalidCountException ex)
+ {
+ harness.check(false, "Constructor failed for valid count");
+ }
+
+ try
+ {
+ CountFilter testCF = new CountFilter(INVALID_COUNT);
+ harness.check(false, "Constructor threw no exception for invalid count");
+ }
+ catch(InvalidCountException ex)
+ {
+ harness.check(true, "Constructor failed correctly for invalid count");
+ }
+ }
+
+ /**
+ * Tests the <code>CountFilter</code> method matches
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testMatches(TestHarness harness)
+ {
+ boolean matched = false;
+ harness.checkPoint("matches method");
+
+ try
+ {
+ CountFilter testCF = new CountFilter(COUNT);
+ for (int i = 0; i < COUNT; i++)
+ {
+ matched = testCF.matches(new ClassPrepareEvent(Thread.currentThread(),
+ Integer.class, 0));
+ if(i < COUNT-1)
+ harness.check(!matched, "Matches returns false for < count");
+ else
+ harness.check(matched, "Matches returns true after count # of"
+ + "events");
+ }
+ }
+ catch(InvalidCountException ex)
+ {
+ harness.check(false, "Constructor failed for valid count");
+ }
+ }
+
+ /**
+ * Test the <code>CountFilter</code> class
+ *
+ * @param harness the TestHarness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testConstructor(harness);
+ testMatches(harness);
+ }
+
+}
+
Index: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfInstanceOnlyFilter.java
===================================================================
RCS file: gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfInstanceOnlyFilter.java
diff -N gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfInstanceOnlyFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/gnu/classpath/jdwp/events/filters/TestOfInstanceOnlyFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,105 @@
+/* TestOfInstanceOnlyFilter.java -- tests the InstanceOnly Filter
+
+ Written By Kyle Galloway (kgallowa@redhat.com)
+
+ This file is part of Mauve.
+
+ Mauve is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Mauve is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Mauve; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ */
+
+// Tags: JDK 1.4
+
+
+package gnu.testlet.gnu.classpath.jdwp.events.filters;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import gnu.classpath.jdwp.id.ObjectId;
+import gnu.classpath.jdwp.VMIdManager;
+import gnu.classpath.jdwp.event.filters.InstanceOnlyFilter;
+import gnu.classpath.jdwp.event.BreakpointEvent;
+import gnu.classpath.jdwp.exception.InvalidObjectException;
+
+/**
+ * Tests the functionality of the InstanceOnlyFilter of JDWP
+ *
+ * @author Kyle Galloway (kgallowa@redhat.com)
+ */
+public class TestOfInstanceOnlyFilter
+ implements Testlet
+{
+ /**
+ * Tests the <code>InstanceOnlyFilter</code> constructor
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testConstructor(TestHarness harness)
+ {
+ harness.checkPoint("Constructor");
+ VMIdManager idm = VMIdManager.getDefault();
+
+ Integer testInt = new Integer(6);
+
+ ObjectId testOID = idm.getObjectId(testInt);
+
+ try
+ {
+ InstanceOnlyFilter testIOF = new InstanceOnlyFilter(testOID);
+ harness.check(true, "Constructor successful");
+ }
+ catch (InvalidObjectException ex)
+ {
+ harness.check(false, "constructor failed for valid ObjectId");
+ }
+
+ }
+
+ /**
+ * Tests the <code>InstanceOnlyFilter</code> matches method
+ *
+ * @param harness the TestHarness to use
+ */
+ public void testMatches(TestHarness harness)
+ {
+ harness.checkPoint("matches method");
+
+ VMIdManager idm = VMIdManager.getDefault();
+
+ Integer testInt = new Integer(6);
+
+ ObjectId testOID = idm.getObjectId(testInt);
+
+ try
+ {
+ InstanceOnlyFilter testIOF = new InstanceOnlyFilter(testOID);
+ BreakpointEvent testEvent = new BreakpointEvent(Thread.currentThread(),
+ null, testInt);
+ harness.check(testIOF.matches(testEvent), "testing Instance match");
+ }
+ catch (InvalidObjectException ex)
+ {
+ harness.check(false, "constructor failed for valid ObjectId");
+ }
+ }
+
+ public void test(TestHarness harness)
+ {
+ testConstructor(harness);
+ testMatches(harness);
+ }
+}