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: DefaultComboBoxModel.setSelectedItem


I committed this patch to enhance the checks for the setSelectedItem() method in the DefaultComboBoxModel class:

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

   * gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java
   (index0): removed,
   (index1): likewise,
   (eventType): likewise,
   (events): new field,
   (contentsChanged): add event to events list,
   (intervalAdded): likewise,
   (intervalRemoved): likewise,
   (test): revised tests to use new events list, and added several new
   checks.

A patch to GNU Classpath will be committed in a moment to make all these checks pass.

Regards,

Dave
Index: gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java,v
retrieving revision 1.1
diff -u -r1.1 setSelectedItem.java
--- gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java	23 Sep 2005 16:18:05 -0000	1.1
+++ gnu/testlet/javax/swing/DefaultComboBoxModel/setSelectedItem.java	11 Oct 2005 20:26:13 -0000
@@ -22,6 +22,8 @@
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import java.util.List;
+
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.event.ListDataEvent;
 import javax.swing.event.ListDataListener;
@@ -33,29 +35,21 @@
 public class setSelectedItem 
   implements Testlet, ListDataListener 
 {
-  int index0;
-  int index1;
-  int eventType;
+  List events = new java.util.ArrayList();
   
   public void contentsChanged(ListDataEvent event) 
   {
-    eventType = event.getType();
-    index0 = event.getIndex0();
-    index1 = event.getIndex1();
+    events.add(event);
   }
   
   public void intervalAdded(ListDataEvent event) 
   {
-    eventType = event.getType();
-    index0 = event.getIndex0();
-    index1 = event.getIndex1();
+    events.add(event);
   }
   
   public void intervalRemoved(ListDataEvent event) 
   {
-    eventType = event.getType();
-    index0 = event.getIndex0();
-    index1 = event.getIndex1();
+    events.add(event);
   }
 
   /**
@@ -65,34 +59,55 @@
    */
   public void test(TestHarness harness)      
   {   
-    DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", "C"});
+    DefaultComboBoxModel m = new DefaultComboBoxModel(new Object[] {"A", "B", 
+            "C"});
     harness.check(m.getSelectedItem(), "A");
     
+    m.addListDataListener(this);
+
+    // first set the selected item to one of the elements in the list...
     m.setSelectedItem("C");
+    harness.check(events.size(), 1);
     harness.check(m.getSelectedItem(), "C");
-    harness.check(eventType, ListDataEvent.CONTENTS_CHANGED);
-    harness.check(index0, 0);
-    harness.check(index1, 0);
+    ListDataEvent event = (ListDataEvent) events.get(0);
+    harness.check(event.getType(), ListDataEvent.CONTENTS_CHANGED);
+    harness.check(event.getIndex0(), -1);
+    harness.check(event.getIndex1(), -1);
+    events.clear();
     
-    eventType = -1;
-    index0 = -1;
-    index1 = -1;
+    // now set the selected item to null...
     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;
+    harness.check(events.size(), 1);
+    event = (ListDataEvent) events.get(0);
+    harness.check(event.getType(), ListDataEvent.CONTENTS_CHANGED);
+    harness.check(event.getIndex0(), -1);
+    harness.check(event.getIndex1(), -1);
+    events.clear();
+
+    // now set the selected item to something not in the list...
     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);
+    harness.check(events.size(), 1);
+    event = (ListDataEvent) events.get(0);
+    harness.check(event.getType(), ListDataEvent.CONTENTS_CHANGED);
+    harness.check(event.getIndex0(), -1);
+    harness.check(event.getIndex1(), -1);
+    events.clear();
+    
+    // now set the selected item to the same value - no event should be 
+    // generated...
+    m.setSelectedItem("Z");
+    harness.check(events.size(), 0);
+    
+    // make sure setting null when already null doesn't generate an event
+    m.setSelectedItem(null);
+    events.clear();
+    m.setSelectedItem(null);
+    harness.check(events.size(), 0);
+    
   }
 }
 

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