public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: New JComboBox test
@ 2007-01-07 20:52 Roman Kennke
  0 siblings, 0 replies; only message in thread
From: Roman Kennke @ 2007-01-07 20:52 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 401 bytes --]

I'm adding a test for GNU Classpath PR30337. This checks how the
JComboBox behaves when getEditor() returns null.

2007-01-07  Roman Kennke <kennke@aicas.com>

	* gnu/testlet/javax/swing/JComboBox/getEditor.java
	(TestComboBox): New inner class for testing.
	(test): Moved code to testDefault() and add testPR30337().
	(testDefault): Code moved from test() to here.
	(testPR30337): New test.

/Roman


[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 3440 bytes --]

Index: gnu/testlet/javax/swing/JComboBox/getEditor.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/JComboBox/getEditor.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 getEditor.java
--- gnu/testlet/javax/swing/JComboBox/getEditor.java	18 Oct 2005 15:51:41 -0000	1.1
+++ gnu/testlet/javax/swing/JComboBox/getEditor.java	7 Jan 2007 20:48:32 -0000
@@ -12,55 +12,121 @@
 // 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.
 
 package gnu.testlet.javax.swing.JComboBox;
 
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
 import javax.swing.ComboBoxEditor;
 import javax.swing.JComboBox;
+import javax.swing.JFrame;
 import javax.swing.UIManager;
 import javax.swing.plaf.UIResource;
 import javax.swing.plaf.metal.MetalComboBoxEditor;
 
 /**
  * Some checks for the getEditor() method in the {@link JComboBox} class.
  */
 public class getEditor 
   implements Testlet
 {
 
   /**
    * Runs the test using the specified harness.
    * 
    * @param harness  the test harness (<code>null</code> not permitted).
    */
   public void test(TestHarness harness)      
   {   
+    testDefault(harness);
+    testPR30337(harness);
+  }
+
+  /**
+   * Tests the default value.
+   *
+   * @param harness the test harness to use
+   */
+  private void testDefault(TestHarness harness)
+  {
     // use a known look and feel
     try
       {
         UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
       }
     catch (Exception e)
       {
         harness.fail("Problem setting MetalLookAndFeel");
       }
     
     JComboBox c1 = new JComboBox(new Object[] {"A", "B", "C"});
     ComboBoxEditor editor = c1.getEditor();
     
     // check default value
     harness.check(editor instanceof MetalComboBoxEditor.UIResource);
     
     c1.setEditor(new MetalComboBoxEditor());
     harness.check(!(c1.getEditor() instanceof UIResource));
+
+  }
+
+  /**
+   * A combo box that returns null for getEditor(). This is used in the
+   * following test.
+   */
+  private class TestComboBox extends JComboBox
+  {
+    public ComboBoxEditor getEditor()
+    {
+      return null;
+    }
+  }
+
+  /**
+   * The Classpath PR30337 overrides getEditor() to return null and expects
+   * the JComboBox to not throw an NPE.
+   *
+   * @param h the test harness
+   */
+  private void testPR30337(TestHarness h)
+  {
+    // Test with default (non-editable) combo box. No NPE is thrown.
+    JComboBox cb = new TestComboBox();
+    JFrame f = new JFrame();
+    boolean pass = true;
+    try
+      {
+        f.getContentPane().add(cb);
+        f.setVisible(true);
+      }
+    catch (NullPointerException ex)
+      {
+        pass = false;
+      }
+    h.check(pass);
+
+    // Test with editable combo box (NPE is thrown).
+    cb = new TestComboBox();
+    f = new JFrame();
+    pass = false;
+    try
+      {
+        cb.setEditable(true);
+        f.getContentPane().add(cb);
+        f.setVisible(true);
+      }
+    catch (NullPointerException ex)
+      {
+        pass = true;
+      }
+    h.check(pass);
+
   }
   
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-01-07 20:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-07 20:52 FYI: New JComboBox test Roman Kennke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).