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]

RFC: JMenuBar tests


Hello,

Please find attached a number of new tests for the JMenuBar class.

Francis


2006-06-07  Francis Kung  <fkung@redhat.com>

	* gnu/testlet/javax/swing/JMenuBar/basic.java: New tests.
	* gnu/testlet/javax/swing/JMenuBar/constructors.java: New tests.
	* gnu/testlet/javax/swing/JMenuBar/getComponentIndex.java: New tests.
	* gnu/testlet/javax/swing/JMenuBar/getMenu.java: New tests.
	* gnu/testlet/javax/swing/JMenuBar/getSubElements.java: New tests.

Index: gnu/testlet/javax/swing/JMenuBar/basic.java
===================================================================
RCS file: gnu/testlet/javax/swing/JMenuBar/basic.java
diff -N gnu/testlet/javax/swing/JMenuBar/basic.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/JMenuBar/basic.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,122 @@
+// Tags: JDK1.4
+
+/* basic.java -- some checks for simple methods in the JMenuBar class
+   Copyright (C) 2006 Francis Kung <fkung@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.
+*/
+
+
+package gnu.testlet.javax.swing.JMenuBar;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Insets;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.basic.BasicMenuBarUI;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+import javax.swing.plaf.metal.MetalMenuBarUI;
+import javax.swing.plaf.multi.MultiMenuBarUI;
+
+/**
+ * Some checks for simple methods in the {@link JMenuBar} class.
+ */
+public class basic
+    implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)
+  {
+    setMargin(harness);
+
+    setUI(harness);
+
+    setBorderPainted(harness);
+
+    setSelected(harness);
+
+  }
+
+  public void setMargin(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    mb.setMargin(new Insets(5, 5, 5, 5));
+    harness.check(mb.getMargin(), new Insets(5, 5, 5, 5));
+
+    mb.setMargin(null);
+    harness.check(mb.getMargin(), new Insets(0, 0, 0, 0));
+  }
+
+  public void setUI(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    // make sure we're using the MetalLookAndFeel
+    try
+      {
+        UIManager.setLookAndFeel(new MetalLookAndFeel());
+      }
+    catch (UnsupportedLookAndFeelException e)
+      {
+        e.printStackTrace();
+      }
+
+    mb.setUI(new BasicMenuBarUI());
+    harness.check(mb.getUI() instanceof BasicMenuBarUI);
+
+    mb.setUI(new MultiMenuBarUI());
+    harness.check(mb.getUI() instanceof MultiMenuBarUI);
+
+    mb.updateUI();
+    harness.check(mb.getUI() instanceof MetalMenuBarUI);
+  }
+
+  public void setBorderPainted(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    mb.setBorderPainted(false);
+    harness.check(mb.isBorderPainted() == false);
+
+    mb.setBorderPainted(true);
+    harness.check(mb.isBorderPainted());
+  }
+
+  public void setSelected(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    harness.check(mb.isSelected() == false);
+
+    JMenu menu = new JMenu("menu");
+    mb.add(menu);
+    mb.setSelected(menu);
+    harness.check(mb.isSelected());
+  }
+
+}
Index: gnu/testlet/javax/swing/JMenuBar/constructors.java
===================================================================
RCS file: gnu/testlet/javax/swing/JMenuBar/constructors.java
diff -N gnu/testlet/javax/swing/JMenuBar/constructors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/JMenuBar/constructors.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,91 @@
+// Tags: JDK1.4
+
+/* constructors.java -- tests for the constructor of the JMenuBar class
+   Copyright (C) 2006 Francis Kung <fkung@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.
+*/
+
+
+package gnu.testlet.javax.swing.JMenuBar;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Insets;
+
+import javax.swing.JMenuBar;
+import javax.swing.SingleSelectionModel;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+import javax.swing.plaf.metal.MetalMenuBarUI;
+
+/**
+ * Some tests for the constructors in the {@link JMenuBar} class.
+ */
+public class constructors
+    implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)
+  {
+    // the default (and only) constructor is pretty boring,
+    // let's just test default values
+
+    harness.checkPoint("JMenuBar(constructor)");
+
+    // make sure we're using the MetalLookAndFeel
+    try
+      {
+        UIManager.setLookAndFeel(new MetalLookAndFeel());
+      }
+    catch (UnsupportedLookAndFeelException e)
+      {
+        e.printStackTrace();
+      }
+
+    JMenuBar mb = new JMenuBar();
+    harness.check(mb.getComponentCount(), 0);
+    harness.check(mb.getMenuCount(), 0);
+    harness.check(mb.getMargin(), new Insets(0, 0, 0, 0));
+
+    try
+      {
+        // This should throw an exception, not return null
+        mb.getMenu(0);
+        harness.check(false);
+      }
+    catch (ArrayIndexOutOfBoundsException e)
+      {
+        harness.check(true);
+      }
+
+    harness.check(mb.getSelectionModel() instanceof SingleSelectionModel);
+    harness.check(mb.getSubElements().length, 0);
+    harness.check(mb.getUI() instanceof MetalMenuBarUI);
+
+    harness.check(mb.isBorderPainted());
+    harness.check(mb.isSelected() == false);
+  }
+
+}
Index: gnu/testlet/javax/swing/JMenuBar/getComponentIndex.java
===================================================================
RCS file: gnu/testlet/javax/swing/JMenuBar/getComponentIndex.java
diff -N gnu/testlet/javax/swing/JMenuBar/getComponentIndex.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/JMenuBar/getComponentIndex.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,69 @@
+// Tags: JDK1.4
+
+/* getComponentIndex.java -- tests for the getComponentIndex() method
+       in the JMenuBar class
+   Copyright (C) 2006 Francis Kung <fkung@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.
+*/
+
+
+package gnu.testlet.javax.swing.JMenuBar;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.MenuElement;
+
+/**
+ * Some checks for the getMenu() method of the {@link JMenuBar} class.
+ */
+public class getComponentIndex
+    implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    JMenu menu1 = new JMenu("menu1");
+    mb.add(menu1);
+
+    JMenu menu2 = new JMenu("menu2");
+    mb.add(menu2);
+
+    JLabel label = new JLabel("label");
+    mb.add(label);
+
+    JMenu menu3 = new JMenu("menu3");
+    mb.add(menu3);
+
+    harness.check(mb.getComponentIndex(menu1), 0);
+    harness.check(mb.getComponentIndex(menu2), 1);
+    harness.check(mb.getComponentIndex(label), 2);
+    harness.check(mb.getComponentIndex(menu3), 3);
+  }
+
+}
Index: gnu/testlet/javax/swing/JMenuBar/getMenu.java
===================================================================
RCS file: gnu/testlet/javax/swing/JMenuBar/getMenu.java
diff -N gnu/testlet/javax/swing/JMenuBar/getMenu.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/JMenuBar/getMenu.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,86 @@
+// Tags: JDK1.4
+
+/* getMenu.java -- tests for getMenu() method in the JMenuBar class
+   Copyright (C) 2006 Francis Kung <fkung@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.
+*/
+
+
+package gnu.testlet.javax.swing.JMenuBar;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+
+/**
+ * Some checks for the getMenu() method of the {@link JMenuBar} class.
+ */
+public class getMenu
+    implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    // This doesn't seem ideal, but it's the excpected behaviour...
+    try
+      {
+        mb.add((JMenu) null);
+        harness.check(false);
+      }
+    catch (NullPointerException e)
+      {
+        harness.check(true);
+      }
+
+    JMenu menu1 = new JMenu("menu1");
+    mb.add(menu1);
+    harness.check(mb.getMenuCount(), 1);
+    harness.check(mb.getMenu(0), menu1);
+
+    JMenu menu2 = new JMenu("menu2");
+    mb.add(menu2);
+    harness.check(mb.getMenuCount(), 2);
+    harness.check(mb.getMenu(0), menu1);
+    harness.check(mb.getMenu(1), menu2);
+
+    JLabel label = new JLabel("label");
+    mb.add(label);
+    harness.check(mb.getMenuCount(), 3);
+    harness.check(mb.getMenu(2), null);
+
+    JMenu menu3 = new JMenu("menu3");
+    mb.add(menu3);
+    harness.check(mb.getMenuCount(), 4);
+    harness.check(mb.getMenu(0), menu1);
+    harness.check(mb.getMenu(1), menu2);
+    harness.check(mb.getMenu(2), null);
+    harness.check(mb.getMenu(3), menu3);
+
+  }
+
+}
Index: gnu/testlet/javax/swing/JMenuBar/getSubElements.java
===================================================================
RCS file: gnu/testlet/javax/swing/JMenuBar/getSubElements.java
diff -N gnu/testlet/javax/swing/JMenuBar/getSubElements.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/JMenuBar/getSubElements.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,84 @@
+// Tags: JDK1.4
+
+/* getSubElements.java -- tests for the getSubElements() method in the
+       JMenuBar class
+   Copyright (C) 2006 Francis Kung <fkung@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.
+*/
+
+
+package gnu.testlet.javax.swing.JMenuBar;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.MenuElement;
+
+/**
+ * Some checks for the getMenu() method of the {@link JMenuBar} class.
+ */
+public class getSubElements
+    implements Testlet
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)
+  {
+    JMenuBar mb = new JMenuBar();
+
+    // Basic test
+    JMenu menu1 = new JMenu("menu1");
+    mb.add(menu1);
+
+    JMenu menu2 = new JMenu("menu2");
+    mb.add(menu2);
+
+    MenuElement[] elements = mb.getSubElements();
+
+    harness.check(elements.length, 2);
+    harness.check(elements[0], menu1);
+    harness.check(elements[1], menu2);
+
+    // Add a component that is *not* an element
+    JLabel label = new JLabel("label");
+    mb.add(label);
+    elements = mb.getSubElements();
+
+    harness.check(elements.length, 2);
+    harness.check(elements[0], menu1);
+    harness.check(elements[1], menu2);
+
+    // Ensure we can still add elements after that
+    JMenu menu3 = new JMenu("menu3");
+    mb.add(menu3);
+    elements = mb.getSubElements();
+
+    harness.check(elements.length, 3);
+    harness.check(elements[0], menu1);
+    harness.check(elements[1], menu2);
+    harness.check(elements[2], menu3);
+  }
+
+}

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