diff options
author | John Keiser <shalom@gnu.org> | 1999-03-15 23:24:05 +0000 |
---|---|---|
committer | John Keiser <shalom@gnu.org> | 1999-03-15 23:24:05 +0000 |
commit | 5316c92bd66289bacdb4ce663fc2e9b845980bad (patch) | |
tree | c6b8d64afca353b2d462f7e88d7970086bb4f92b /test | |
parent | 4c0b8f02246c04d83e6b5973a4e2fdd802ef0231 (diff) | |
download | classpath-5316c92bd66289bacdb4ce663fc2e9b845980bad.tar.gz |
Cleanup, new test
Diffstat (limited to 'test')
-rw-r--r-- | test/java.beans/DescriptorTest.java | 83 | ||||
-rw-r--r-- | test/java.beans/IntrospectorTest.java | 194 | ||||
-rw-r--r-- | test/java.beans/PropertyChangeSupportTest.java | 200 |
3 files changed, 344 insertions, 133 deletions
diff --git a/test/java.beans/DescriptorTest.java b/test/java.beans/DescriptorTest.java index b2e18d5b3..31d2bd090 100644 --- a/test/java.beans/DescriptorTest.java +++ b/test/java.beans/DescriptorTest.java @@ -1,37 +1,48 @@ -import java.beans.*;
-
-public class DescriptorTest {
- public static void main(String[] args) {
- try {
- new PropertyDescriptor("class",java.lang.Object.class);
- System.out.println("PASSED: Property Object.class");
- } catch(IntrospectionException e) {
- System.out.println("FAILED: Property Object.class");
- e.printStackTrace();
- }
-
- try {
- new IndexedPropertyDescriptor("test",TestClass.class);
- System.out.println("PASSED: Indexed Property Component.location");
- } catch(IntrospectionException e) {
- System.out.println("FAILED: Indexed Property Component.location");
- e.printStackTrace();
- }
-
- try {
- new EventSetDescriptor(java.awt.Button.class,"action",java.awt.event.ActionListener.class,"actionPerformed");
- System.out.println("PASSED: Event Set Button.action");
- } catch(IntrospectionException e) {
- System.out.println("FAILED: Event Set Button.action");
- e.printStackTrace();
- }
-
- try {
- new MethodDescriptor(java.awt.Component.class.getMethod("getLocation",new Class[0]));
- System.out.println("PASSED: Method Component.getLocation");
- } catch(NoSuchMethodException e) {
- System.out.println("FAILED: No such method: Component.getLocation()");
- e.printStackTrace();
- }
- }
+import java.beans.*; + +public class DescriptorTest implements Runnable { + public static void main(String[] args) { + new DescriptorTest().run(); + } + + interface TestClass { + public String[] getTest(); + public void setTest(String[] test); + public String getTest(int i); + public void setTest(int i, String name); + } + + public void run() { + try { + new PropertyDescriptor("class",java.lang.Object.class); + System.out.println("PASSED: Property Object.class"); + } catch(IntrospectionException e) { + System.out.println("FAILED: Property Object.class"); + e.printStackTrace(); + } + + try { + new IndexedPropertyDescriptor("test",TestClass.class); + System.out.println("PASSED: Indexed Property Component.location"); + } catch(IntrospectionException e) { + System.out.println("FAILED: Indexed Property Component.location"); + e.printStackTrace(); + } + + try { + new EventSetDescriptor(java.awt.Button.class,"action",java.awt.event.ActionListener.class,"actionPerformed"); + System.out.println("PASSED: Event Set Button.action"); + } catch(IntrospectionException e) { + System.out.println("FAILED: Event Set Button.action"); + e.printStackTrace(); + } + + try { + new MethodDescriptor(java.awt.Component.class.getMethod("getLocation",new Class[0])); + System.out.println("PASSED: Method Component.getLocation"); + } catch(NoSuchMethodException e) { + System.out.println("FAILED: No such method: Component.getLocation()"); + e.printStackTrace(); + } + } }
\ No newline at end of file diff --git a/test/java.beans/IntrospectorTest.java b/test/java.beans/IntrospectorTest.java index d0ddfd9de..d78638224 100644 --- a/test/java.beans/IntrospectorTest.java +++ b/test/java.beans/IntrospectorTest.java @@ -1,97 +1,97 @@ -import java.beans.*;
-
-public class IntrospectorTest {
- public static void main(String[] args) {
- try {
- BeanInfo b = Introspector.getBeanInfo(java.awt.Component.class);
- if(b.getPropertyDescriptors().length == 6
- && b.getEventSetDescriptors().length == 5
- && b.getMethodDescriptors().length == 128) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Component.class)");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Component.class)");
- }
- b = Introspector.getBeanInfo(java.util.BitSet.class);
- if(b.getPropertyDescriptors().length == 2
- && b.getEventSetDescriptors().length == 0
- && b.getMethodDescriptors().length == 17) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.util.BitSet.class)");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.util.BitSet.class)");
- }
- b = Introspector.getBeanInfo(java.lang.Object.class);
- if(b.getPropertyDescriptors().length == 1
- && b.getEventSetDescriptors().length == 0
- && b.getMethodDescriptors().length == 9) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.lang.Object.class)");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.lang.Object.class)");
- }
- b = Introspector.getBeanInfo(java.applet.Applet.class);
- if(b.getPropertyDescriptors().length == 24
- && b.getEventSetDescriptors().length == 6
- && b.getMethodDescriptors().length == 168) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class)");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class)");
- }
- b = Introspector.getBeanInfo(java.awt.Button.class);
- if(b.getPropertyDescriptors().length == 8
- && b.getEventSetDescriptors().length == 6
- && b.getMethodDescriptors().length == 134) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Button.class)");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Button.class)");
- }
- b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class);
- if(b.getPropertyDescriptors().length == 8
- && b.getEventSetDescriptors().length == 0
- && b.getMethodDescriptors().length == 22) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)");
- } else {
- System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)");
- }
- b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class);
- if(b.getPropertyDescriptors().length == 18
- && b.getEventSetDescriptors().length == 1
- && b.getMethodDescriptors().length == 65) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)");
- } else {
- System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)");
- }
- b = Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class);
- if(b.getPropertyDescriptors().length == 24
- && b.getEventSetDescriptors().length == 6
- && b.getMethodDescriptors().length == 160) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
- } else {
- System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
- }
-
- b = Introspector.getBeanInfo(java.applet.Applet.class,null);
- if(b.getPropertyDescriptors().length == 24
- && b.getEventSetDescriptors().length == 6
- && b.getMethodDescriptors().length == 168) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
- } else {
- System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,null)");
- }
-
- b = Introspector.getBeanInfo(java.applet.Applet.class);
- if(b.getPropertyDescriptors().length == 24
- && b.getEventSetDescriptors().length == 6
- && b.getMethodDescriptors().length == 168) {
- System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time");
- } else {
- System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time");
- }
- } catch(IntrospectionException e) {
- System.out.println("FAILED: IntrospectionException");
- e.printStackTrace();
- }
- }
-}
+import java.beans.*; + +public class IntrospectorTest { + public static void main(String[] args) { + try { + BeanInfo b = Introspector.getBeanInfo(java.awt.Component.class); + if(b.getPropertyDescriptors().length == 6 + && b.getEventSetDescriptors().length == 5 + && b.getMethodDescriptors().length == 128) { + System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Component.class)"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Component.class)"); + } + b = Introspector.getBeanInfo(java.util.BitSet.class); + if(b.getPropertyDescriptors().length == 2 + && b.getEventSetDescriptors().length == 0 + && b.getMethodDescriptors().length == 17) { + System.out.println("PASSED: Introspector.getBeanInfo(java.util.BitSet.class)"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.util.BitSet.class)"); + } + b = Introspector.getBeanInfo(java.lang.Object.class); + if(b.getPropertyDescriptors().length == 1 + && b.getEventSetDescriptors().length == 0 + && b.getMethodDescriptors().length == 9) { + System.out.println("PASSED: Introspector.getBeanInfo(java.lang.Object.class)"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.lang.Object.class)"); + } + b = Introspector.getBeanInfo(java.applet.Applet.class); + if(b.getPropertyDescriptors().length == 24 + && b.getEventSetDescriptors().length == 6 + && b.getMethodDescriptors().length == 168) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class)"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class)"); + } + b = Introspector.getBeanInfo(java.awt.Button.class); + if(b.getPropertyDescriptors().length == 8 + && b.getEventSetDescriptors().length == 6 + && b.getMethodDescriptors().length == 134) { + System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Button.class)"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Button.class)"); + } + b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class); + if(b.getPropertyDescriptors().length == 8 + && b.getEventSetDescriptors().length == 0 + && b.getMethodDescriptors().length == 22) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)"); + } else { + System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length); + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)"); + } + b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class); + if(b.getPropertyDescriptors().length == 18 + && b.getEventSetDescriptors().length == 1 + && b.getMethodDescriptors().length == 65) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)"); + } else { + System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length); + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)"); + } + b = Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class); + if(b.getPropertyDescriptors().length == 24 + && b.getEventSetDescriptors().length == 6 + && b.getMethodDescriptors().length == 160) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)"); + } else { + System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length); + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)"); + } + + b = Introspector.getBeanInfo(java.applet.Applet.class,null); + if(b.getPropertyDescriptors().length == 24 + && b.getEventSetDescriptors().length == 6 + && b.getMethodDescriptors().length == 168) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)"); + } else { + System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length); + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,null)"); + } + + b = Introspector.getBeanInfo(java.applet.Applet.class); + if(b.getPropertyDescriptors().length == 24 + && b.getEventSetDescriptors().length == 6 + && b.getMethodDescriptors().length == 168) { + System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time"); + } else { + System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time"); + } + } catch(IntrospectionException e) { + System.out.println("FAILED: IntrospectionException"); + e.printStackTrace(); + } + } +} diff --git a/test/java.beans/PropertyChangeSupportTest.java b/test/java.beans/PropertyChangeSupportTest.java new file mode 100644 index 000000000..8db2af03f --- /dev/null +++ b/test/java.beans/PropertyChangeSupportTest.java @@ -0,0 +1,200 @@ +import java.beans.PropertyChangeSupport; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.util.Hashtable; + +public class PropertyChangeSupportTest implements Runnable { + class Source { + PropertyChangeSupport support = new PropertyChangeSupport(this); + public void addPropertyChangeListener(PropertyChangeListener l) { + support.addPropertyChangeListener(l); + } + public void addPropertyChangeListener(String s, PropertyChangeListener l) { + support.addPropertyChangeListener(s,l); + } + public void removePropertyChangeListener(PropertyChangeListener l) { + support.removePropertyChangeListener(l); + } + public void removePropertyChangeListener(String s, PropertyChangeListener l) { + support.removePropertyChangeListener(s,l); + } + + void changeProperty(String name) { + support.firePropertyChange(name,"old","new"); + + } + } + + class Listener implements PropertyChangeListener { + Hashtable numEventsReceived = new Hashtable(); + int getNumEvents(String propertyName) { + Integer i = (Integer)numEventsReceived.get(propertyName); + try { + return i.intValue(); + } catch(NullPointerException e) { + return 0; + } + } + + public void propertyChange(PropertyChangeEvent e) { + Integer i = (Integer)numEventsReceived.get(e.getPropertyName()); + try { + int newI = i.intValue() + 1; + numEventsReceived.put(e.getPropertyName(), new Integer(newI)); + } catch(NullPointerException exc) { + numEventsReceived.put(e.getPropertyName(), new Integer(1)); + } + } + + public void reset() { + numEventsReceived = new Hashtable(); + } + } + + public void setProperties(Source s) { + s.changeProperty("foo"); + s.changeProperty("foo"); + s.changeProperty("foo"); + s.changeProperty("bar"); + s.changeProperty("bar"); + s.changeProperty("foobar"); + } + + public void shouldEqual(Listener l, int foo, int bar, int foobar, String testName) { + String whatsWrong = ""; + if(l.getNumEvents("foo") != foo) { + whatsWrong += ("foo(" + l.getNumEvents("foo") + ") != " + foo); + } + if(l.getNumEvents("bar") != bar) { + whatsWrong += (" bar(" + l.getNumEvents("bar") + ") != " + bar); + } + if(l.getNumEvents("foobar") != foobar) { + whatsWrong += (" foobar(" + l.getNumEvents("foobar") + ") != " + foobar); + } + + if(!whatsWrong.equals("")) { + System.out.println("FAILURE: " + testName + ": " + whatsWrong); + } else { + System.out.println("Success: " + testName); + } + } + + public void run() { + Source s = new Source(); + + /* Test: single multi-property adds */ + Listener l = new Listener(); + s.addPropertyChangeListener(l); + setProperties(s); + shouldEqual(l, 3, 2, 1, "single multi-property adds"); + + /* Test: multiple listeners */ + Listener l2 = new Listener(); + s.addPropertyChangeListener(l2); + setProperties(s); + shouldEqual(l, 6, 4, 2, "multiple listeners-l"); + shouldEqual(l2, 3, 2, 1, "multiple listeners-l2"); + + /* Test: multiple multi-property adds */ + s.addPropertyChangeListener(l); + setProperties(s); + shouldEqual(l, 12, 8, 4, "multiple multi-property adds-l"); + shouldEqual(l2, 6, 4, 2, "multiple multi-property adds-l2"); + + /* Test: remove multi-property add */ + s.removePropertyChangeListener(l); + setProperties(s); + shouldEqual(l, 15, 10, 5, "remove multi-property add-l"); + shouldEqual(l2, 9, 6, 3, "remove multi-property add-l2"); + + + s.removePropertyChangeListener(l); + s.removePropertyChangeListener(l2); + l.reset(); + l2.reset(); + + /* ENABLE THIS IF YOU THINK RESET ISN'T HAPPENING + shouldEqual(l, 0, 0, 0, "RESET-l"); + shouldEqual(l2, 0, 0, 0, "RESET-l2"); + setProperties(s); + shouldEqual(l, 0, 0, 0, "RESET_AGAIN-l"); + shouldEqual(l2, 0, 0, 0, "RESET_AGAIN-l2"); + */ + + + /* Test: single property listener */ + s.addPropertyChangeListener("foo", l); + setProperties(s); + shouldEqual(l, 3, 0, 0, "single property listener"); + + /* Test: multiple different properties */ + s.addPropertyChangeListener("bar", l); + setProperties(s); + shouldEqual(l, 6, 2, 0, "multiple different properties"); + + /* Test: multiple of same property */ + s.addPropertyChangeListener("foo", l); + setProperties(s); + shouldEqual(l, 12, 4, 0, "multiple of same property"); + + /* Test: multiple single-property listeners */ + s.addPropertyChangeListener("foo", l2); + setProperties(s); + shouldEqual(l, 18, 6, 0, "multiple single-property listeners-l"); + shouldEqual(l2, 3, 0, 0, "multiple single-property listeners-l2"); + + /* Test: remove single-property add */ + s.removePropertyChangeListener("foo", l); + setProperties(s); + shouldEqual(l, 21, 8, 0, "remove single-property add-l"); + shouldEqual(l2, 6, 0, 0, "remove single-property add-l2"); + + + s.removePropertyChangeListener("foo", l); + s.removePropertyChangeListener("bar", l); + s.removePropertyChangeListener("foo", l2); + l.reset(); + l2.reset(); + + /* ENABLE THIS IF YOU THINK RESET ISN'T HAPPENING + shouldEqual(l, 0, 0, 0, "RESET-l"); + shouldEqual(l2, 0, 0, 0, "RESET-l2"); + setProperties(s); + shouldEqual(l, 0, 0, 0, "RESET_AGAIN-l"); + shouldEqual(l2, 0, 0, 0, "RESET_AGAIN-l2"); + */ + + /* Test: multiple- and single-property interaction */ + s.addPropertyChangeListener(l); + s.addPropertyChangeListener("foo", l); + setProperties(s); + shouldEqual(l, 6, 2, 1, "multiple- and single-property interaction"); + + /* Test: multiple- and single-property interaction: multiple-listener removal */ + s.removePropertyChangeListener(l); + setProperties(s); + shouldEqual(l, 9, 2, 1, "multiple- and single-property interaction: multiple-listener removal"); + + /* Test: hasListeners() with multiple cases */ + if(s.support.hasListeners("foo")) { + System.out.println("Success: hasListeners() returning true"); + } else { + System.out.println("FAILURE: hasListeners() returning true"); + } + if(s.support.hasListeners("bar")) { + System.out.println("FAILURE: hasListeners() returning false"); + } else { + System.out.println("Success: hasListeners() returning false"); + } + s.addPropertyChangeListener(l); + if(s.support.hasListeners("bar")) { + System.out.println("Success: hasListeners() with all-event listeners"); + } else { + System.out.println("FAILURE: hasListeners() with all-event listeners"); + } + } + + public static void main(String[] args) { + new PropertyChangeSupportTest().run(); + } +}
\ No newline at end of file |