Initial revision
From-SVN: r102074
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user