This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: JComponent.setPreferredSize()


I committed these new tests to back a fix I'm making to GNU Classpath:

2005-11-17 David Gilbert <david.gilbert@object-refinery.com>

   * gnu/testlet/javax/swing/JComponent/setPreferredSize.java
   (event): New field,
   (test): Call new test methods,
   (testGeneral): New test method,
   (testPropertyChangeEvent): New test method,
   (propertyChange): New method.

Regards,

Dave
Index: gnu/testlet/javax/swing/JComponent/setPreferredSize.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/JComponent/setPreferredSize.java,v
retrieving revision 1.1
diff -u -r1.1 setPreferredSize.java
--- gnu/testlet/javax/swing/JComponent/setPreferredSize.java	18 Oct 2005 14:39:25 -0000	1.1
+++ gnu/testlet/javax/swing/JComponent/setPreferredSize.java	18 Nov 2005 00:15:35 -0000
@@ -21,6 +21,11 @@
 package gnu.testlet.javax.swing.JComponent;
 
 import java.awt.Dimension;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JComponent;
+import javax.swing.JPanel;
 
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
@@ -30,8 +35,16 @@
  *
  * @author Roman Kennke (kennke@aicas.com)
  */
-public class setPreferredSize implements Testlet
+public class setPreferredSize implements Testlet, PropertyChangeListener
 {
+    
+  PropertyChangeEvent event;
+  
+  public void propertyChange(PropertyChangeEvent event) 
+  {
+    this.event = event;
+  }
+  
   /**
    * Starts the test run.
    *
@@ -39,11 +52,51 @@
    */
   public void test(TestHarness harness)
   {
+    testGeneral(harness);
+    testPropertyChangeEvent(harness);
     testRepaint(harness);
     testRevalidate(harness);
   }
 
   /**
+   * Some general checks.
+   * 
+   * @param harness  the test harness.
+   */
+  private void testGeneral(TestHarness harness) 
+  {
+    JComponent c = new JPanel();
+    harness.check(c.getPreferredSize(), new Dimension(10, 10));
+    Dimension d = new Dimension(123, 456);
+    c.setPreferredSize(d);
+    harness.check(c.getPreferredSize(), d);
+    harness.check(c.getPreferredSize() != d);
+    c.setPreferredSize(null);  // restores the default
+    harness.check(c.getPreferredSize(), new Dimension(10, 10));
+  }
+  
+  private void testPropertyChangeEvent(TestHarness harness) 
+  {
+    JComponent c = new JPanel();
+    c.addPropertyChangeListener(this);
+    c.setPreferredSize(new Dimension(1, 2));
+    harness.check(this.event.getPropertyName(), "preferredSize");
+    harness.check(this.event.getOldValue(), null);
+    harness.check(this.event.getNewValue(), new Dimension(1, 2));
+    this.event = null;
+    c.setPreferredSize(null);
+    harness.check(this.event.getOldValue(), new Dimension(1, 2));
+    harness.check(this.event.getNewValue(), null);
+    this.event = null;
+    c.setPreferredSize(null);
+    harness.check(this.event.getOldValue(), null);
+    harness.check(this.event.getNewValue(), null);
+    c.setPreferredSize(new Dimension(12, 34));
+    this.event = null;
+    c.setPreferredSize(new Dimension(12, 34));
+    harness.check(this.event, null);
+  }
+  /**
    * Tests if setPreferredSize triggers a repaint.
    *
    * @param harness the test harness to use

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]