This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: DefaultComboBoxModel tests
- From: David Gilbert <david dot gilbert at object-refinery dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Fri, 23 Sep 2005 17:20:23 +0000
- Subject: FYI: DefaultComboBoxModel tests
I committed these new tests, with some corresponding fixes to go into
GNU Classpath CVS shortly:
2005-09-23 David Gilbert <david.gilbert@object-refinery.com>
* gnu/testlet/javax/swing/DefaultComboBoxModel/addElement.java: new
test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/constructors.java:
new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/getElementAt.java:
new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/getIndexOf.java: new
test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/getSelectedItem.java:
new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/getSize.java: new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/insertElementAt.java:
new test,
*
gnu/testlet/javax/swing/DefaultComboBoxModel/removeAllElements.java: new
test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/removeElement.java:
new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/removeElementAt.java:
new test,
* gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java:
new test.
Regards,
Dave
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/addElement.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/addElement.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/addElement.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/addElement.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,97 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the addElement() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class addElement
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel();
+ m.addListDataListener(this);
+
+ m.addElement("A");
+ harness.check(m.getSize(), 1);
+ harness.check(m.getElementAt(0), "A");
+ harness.check(m.getSelectedItem(), "A");
+ harness.check(eventType, ListDataEvent.CONTENTS_CHANGED);
+ harness.check(index0, -1);
+ harness.check(index1, -1);
+
+ m.addElement("B");
+ harness.check(m.getSize(), 2);
+ harness.check(m.getElementAt(1), "B");
+ harness.check(m.getSelectedItem(), "A");
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 1);
+ harness.check(index1, 1);
+
+ m.addElement(null);
+ harness.check(m.getSize(), 3);
+ harness.check(m.getElementAt(2), null);
+ harness.check(m.getSelectedItem(), "A");
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 2);
+ harness.check(index1, 2);
+
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/constructors.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/constructors.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/constructors.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/constructors.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,103 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.util.Vector;
+
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * Some checks for the constructors in the {@link DefaultComboBoxModel} 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)
+ {
+ test1(harness);
+ test2(harness);
+ test3(harness);
+ }
+
+ public void test1(TestHarness harness)
+ {
+ harness.checkPoint("()");
+ DefaultComboBoxModel m = new DefaultComboBoxModel();
+ harness.check(m.getSelectedItem(), null);
+ harness.check(m.getSize(), 0);
+ }
+
+ public void test2(TestHarness harness)
+ {
+ harness.checkPoint("(Object[])");
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B"});
+ harness.check(m.getSize(), 2);
+ harness.check(m.getSelectedItem(), "A");
+ harness.check(m.getElementAt(0), "A");
+ harness.check(m.getElementAt(1), "B");
+
+ // try null
+ boolean pass = false;
+ try
+ {
+ m = new DefaultComboBoxModel((Object[]) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+
+ public void test3(TestHarness harness)
+ {
+ harness.checkPoint("(Vector)");
+ Vector v = new Vector();
+ v.add("A");
+ v.add("B");
+ DefaultComboBoxModel m = new DefaultComboBoxModel(v);
+ harness.check(m.getSize(), 2);
+ harness.check(m.getSelectedItem(), "A");
+ harness.check(m.getElementAt(0), "A");
+ harness.check(m.getElementAt(1), "B");
+
+ // try null
+ boolean pass = false;
+ try
+ {
+ m = new DefaultComboBoxModel((Vector) null);
+ }
+ catch (NullPointerException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/getElementAt.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/getElementAt.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/getElementAt.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/getElementAt.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,50 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * Some checks for the getElementAt() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class getElementAt
+ implements Testlet
+{
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ harness.check(m.getElementAt(0), "A");
+ harness.check(m.getElementAt(1), "B");
+ harness.check(m.getElementAt(2), "C");
+
+ harness.check(m.getElementAt(-1), null);
+ harness.check(m.getElementAt(3), null);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/getIndexOf.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/getIndexOf.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/getIndexOf.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/getIndexOf.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,52 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * Some checks for the getIndexOf() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class getIndexOf
+ implements Testlet
+{
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ harness.check(m.getIndexOf("A"), 0);
+ harness.check(m.getIndexOf("B"), 1);
+ harness.check(m.getIndexOf("C"), 2);
+ harness.check(m.getIndexOf("D"), -1);
+ harness.check(m.getIndexOf(null), -1);
+
+ m.addElement(null);
+ harness.check(m.getIndexOf(null), 3);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/getSelectedItem.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/getSelectedItem.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/getSelectedItem.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/getSelectedItem.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,49 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * Some checks for the getSelectedItem() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class getSelectedItem
+ implements Testlet
+{
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ harness.check(m.getSelectedItem(), "A");
+ m.setSelectedItem("C");
+ harness.check(m.getSelectedItem(), "C");
+ m.setSelectedItem(null);
+ harness.check(m.getSelectedItem(), null);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/getSize.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/getSize.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/getSize.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/getSize.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,47 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * Some checks for the getSize() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class getSize
+ implements Testlet
+{
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel();
+ harness.check(m.getSize(), 0);
+ m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ harness.check(m.getSize(), 3);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/insertElementAt.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/insertElementAt.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/insertElementAt.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/insertElementAt.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,128 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the insertElementAt() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class insertElementAt
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel();
+ m.addListDataListener(this);
+
+ m.insertElementAt("A", 0);
+ harness.check(m.getSize(), 1);
+ harness.check(m.getElementAt(0), "A");
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ m.insertElementAt("B", 1);
+ harness.check(m.getSize(), 2);
+ harness.check(m.getElementAt(1), "B");
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 1);
+ harness.check(index1, 1);
+
+ m.insertElementAt("C", 0);
+ harness.check(m.getSize(), 3);
+ harness.check(m.getElementAt(0), "C");
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ m.insertElementAt(null, 0);
+ harness.check(m.getSize(), 4);
+ harness.check(m.getElementAt(0), null);
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, ListDataEvent.INTERVAL_ADDED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ // try negative index
+ boolean pass = true;
+ try
+ {
+ m.insertElementAt("Z", -1);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ // try index too large
+ pass = false;
+ try
+ {
+ m.insertElementAt("Z", 5);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/removeAllElements.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/removeAllElements.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/removeAllElements.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/removeAllElements.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,93 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the removeAllElements() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class removeAllElements
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ m.addListDataListener(this);
+
+ harness.check(m.getSize(), 3);
+ harness.check(m.getSelectedItem(), "A");
+
+ m.removeAllElements();
+ harness.check(m.getSize(), 0);
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, ListDataEvent.INTERVAL_REMOVED);
+ harness.check(index0, 0);
+ harness.check(index1, 2);
+
+ // remove all elements from the empty list - is there an event?
+ eventType = -1;
+ index0 = -1;
+ index1 = -1;
+ m.removeAllElements();
+ harness.check(m.getSize(), 0);
+ harness.check(eventType, -1);
+ harness.check(index0, -1);
+ harness.check(index1, -1);
+
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/removeElement.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/removeElement.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/removeElement.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/removeElement.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,99 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the removeElement() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class removeElement
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ m.addListDataListener(this);
+
+ m.removeElement("A");
+ harness.check(m.getSize(), 2);
+ harness.check(m.getElementAt(0), "B");
+ harness.check(m.getSelectedItem(), "B");
+ harness.check(eventType, ListDataEvent.INTERVAL_REMOVED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ m.removeElement("C");
+ harness.check(m.getSize(), 1);
+ harness.check(m.getElementAt(0), "B");
+ harness.check(m.getSelectedItem(), "B");
+ harness.check(eventType, ListDataEvent.INTERVAL_REMOVED);
+ harness.check(index0, 1);
+ harness.check(index1, 1);
+
+ eventType = -1;
+ index0 = -1;
+ index1 = -1;
+ m.removeElement("Z");
+ harness.check(m.getSize(), 1);
+ harness.check(m.getSelectedItem(), "B");
+ harness.check(eventType, -1);
+ harness.check(index0, -1);
+ harness.check(index1, -1);
+
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/removeElementAt.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/removeElementAt.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/removeElementAt.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/removeElementAt.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,116 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the removeElementAt() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class removeElementAt
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ m.addListDataListener(this);
+
+ m.removeElementAt(0);
+ harness.check(m.getSize(), 2);
+ harness.check(m.getElementAt(0), "B");
+ harness.check(m.getSelectedItem(), "B");
+ harness.check(eventType, ListDataEvent.INTERVAL_REMOVED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ m.removeElementAt(1);
+ harness.check(m.getSize(), 1);
+ harness.check(m.getElementAt(0), "B");
+ harness.check(m.getSelectedItem(), "B");
+ harness.check(eventType, ListDataEvent.INTERVAL_REMOVED);
+ harness.check(index0, 1);
+ harness.check(index1, 1);
+
+ // try negative index
+ boolean pass = false;
+ try
+ {
+ m.removeElementAt(-1);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ pass = false;
+ try
+ {
+ m.removeElementAt(1);
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ pass = true;
+ }
+ harness.check(pass);
+
+ m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ m.setSelectedItem("B");
+ m.removeElementAt(1);
+ harness.check(m.getSelectedItem(), "A");
+ }
+}
+
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java
===================================================================
RCS file: gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java
diff -N gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java 23 Sep 2005 16:11:51 -0000
@@ -0,0 +1,98 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.DefaultComboBoxModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+/**
+ * Some checks for the setSelectedItem() method in the
+ * {@link DefaultComboBoxModel} class.
+ */
+public class setSelectedItem
+ implements Testlet, ListDataListener
+{
+ int index0;
+ int index1;
+ int eventType;
+
+ public void contentsChanged(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalAdded(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ public void intervalRemoved(ListDataEvent event)
+ {
+ eventType = event.getType();
+ index0 = event.getIndex0();
+ index1 = event.getIndex1();
+ }
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+ harness.check(m.getSelectedItem(), "A");
+
+ m.setSelectedItem("C");
+ harness.check(m.getSelectedItem(), "C");
+ harness.check(eventType, ListDataEvent.CONTENTS_CHANGED);
+ harness.check(index0, 0);
+ harness.check(index1, 0);
+
+ eventType = -1;
+ index0 = -1;
+ index1 = -1;
+ m.setSelectedItem(null);
+ harness.check(m.getSelectedItem(), null);
+ harness.check(eventType, -1);
+ harness.check(index0, -1);
+ harness.check(index1, -1);
+
+ eventType = -1;
+ index0 = -1;
+ index1 = -1;
+ m.setSelectedItem("Z");
+ harness.check(m.getSelectedItem(), "Z");
+ harness.check(m.getSize(), 3);
+ harness.check(m.getIndexOf("Z"), -1);
+ harness.check(eventType, -1);
+ harness.check(index0, -1);
+ harness.check(index1, -1);
+ }
+}
+