* FYI: New JTable tests
@ 2005-10-28 13:47 Roman Kennke
0 siblings, 0 replies; 2+ messages in thread
From: Roman Kennke @ 2005-10-28 13:47 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
Hi,
I implemented some new tests for JTable.
2005-10-28 Roman Kennke <kennke@aicas.com>
* gnu/testlet/javax/swing/JTable/setModel.java
(testPropertyFired): New test method.
(testSelectionModel): New test method.
(testLeadAnchorSelectionUpdate): New test method.
/Roman
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: JTable-test.diff --]
[-- Type: text/x-patch; name="JTable-test.diff", Size: 5772 bytes --]
Index: gnu/testlet/javax/swing/JTable/setModel.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/JTable/setModel.java,v
retrieving revision 1.2
diff -u -r1.2 setModel.java
--- gnu/testlet/javax/swing/JTable/setModel.java 6 Jul 2005 09:30:34 -0000 1.2
+++ gnu/testlet/javax/swing/JTable/setModel.java 28 Oct 2005 13:45:04 -0000
@@ -22,9 +22,12 @@
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.Arrays;
import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
@@ -34,6 +37,23 @@
*/
public class setModel implements Testlet {
+ class PropertyChangeHandler implements PropertyChangeListener
+ {
+
+ /**
+ * Receives notification when a property changes.
+ *
+ * @param e the property change event
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ propertyChangeFired = true;
+ }
+
+ }
+
+ boolean propertyChangeFired;
+
/**
* Runs the test using the specified harness.
*
@@ -43,6 +63,9 @@
{
test1(harness);
test2(harness);
+ testLeadAnchorSelectionUpdate(harness);
+ testSelectionModel(harness);
+ testPropertyFired(harness);
}
public void test1(TestHarness harness)
@@ -106,4 +129,108 @@
harness.check(t.getColumnName(0), "DD");
harness.check(t.getColumnName(1), "CC");
}
+
+ /**
+ * Tests if setModel updates the lead and anchor selection indices correctly.
+ *
+ * @param the test harness to use
+ */
+ private void testLeadAnchorSelectionUpdate(TestHarness harness)
+ {
+ harness.checkPoint("leadAnchorSelectionUpdate");
+
+ JTable table = new JTable(0, 0);
+
+ // Test a model with 0 rows and 0 columns.
+ table.setModel(new DefaultTableModel(0, 0));
+ try { Thread.sleep(500); } catch (InterruptedException ex) {}
+ harness.check(table.getSelectionModel().getLeadSelectionIndex(), -1);
+ harness.check(table.getSelectionModel().getAnchorSelectionIndex(), -1);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getLeadSelectionIndex(), -1);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getAnchorSelectionIndex(), -1);
+
+ // Test a model with 1 row and 0 columns.
+ table.setModel(new DefaultTableModel(1, 0));
+ try { Thread.sleep(500); } catch (InterruptedException ex) {}
+ harness.check(table.getSelectionModel().getLeadSelectionIndex(), 0);
+ harness.check(table.getSelectionModel().getAnchorSelectionIndex(), 0);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getLeadSelectionIndex(), -1);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getAnchorSelectionIndex(), -1);
+
+ // Test a model with 0 rows and 1 column.
+ table.setModel(new DefaultTableModel(0, 1));
+ try { Thread.sleep(500); } catch (InterruptedException ex) {}
+ harness.check(table.getSelectionModel().getLeadSelectionIndex(), -1);
+ harness.check(table.getSelectionModel().getAnchorSelectionIndex(), -1);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getLeadSelectionIndex(), 0);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getAnchorSelectionIndex(), 0);
+
+ // Test a model with 1 row and 1 columns.
+ table.setModel(new DefaultTableModel(1, 1));
+ try { Thread.sleep(500); } catch (InterruptedException ex) {}
+ harness.check(table.getSelectionModel().getLeadSelectionIndex(), 0);
+ harness.check(table.getSelectionModel().getAnchorSelectionIndex(), 0);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getLeadSelectionIndex(), 0);
+ harness.check(table.getColumnModel().getSelectionModel()
+ .getAnchorSelectionIndex(), 0);
+ }
+
+ /**
+ * Tests if the selectionModel is changes when the table's model
+ * changes. The test shows that the selectionModel is not replaced but the
+ * selection is cleared.
+ *
+ * @oaram harness the test harness to use
+ */
+ private void testSelectionModel(TestHarness harness)
+ {
+ harness.checkPoint("selectionModel");
+ JTable table = new JTable();
+ ListSelectionModel m1 = table.getSelectionModel();
+ m1.addSelectionInterval(1, 1);
+ harness.check(m1.isSelectedIndex(1), true);
+ table.setModel(new DefaultTableModel());
+ harness.check(table.getSelectionModel() == m1);
+ harness.check(m1.isSelectedIndex(1), false);
+ }
+
+ /**
+ * Tests if changing this property fires a property change event.
+ *
+ * @param harness the test harness to use
+ */
+ private void testPropertyFired(TestHarness harness)
+ {
+ harness.checkPoint("propertyFired");
+ JTable table = new JTable();
+ table.addPropertyChangeListener(new PropertyChangeHandler());
+ DefaultTableModel m1 = new DefaultTableModel();
+ DefaultTableModel m2 = new DefaultTableModel();
+ propertyChangeFired = false;
+ table.setModel(m1);
+ harness.check(propertyChangeFired, true);
+ propertyChangeFired = false;
+ table.setModel(m1);
+ harness.check(propertyChangeFired, false);
+ propertyChangeFired = false;
+ table.setModel(m2);
+ harness.check(propertyChangeFired, true);
+ try
+ {
+ table.setModel(null);
+ harness.fail("IllegalArgumenException must be fired");
+ }
+ catch (IllegalArgumentException ex)
+ {
+ harness.check(true);
+ }
+
+ }
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* FYI: New JTable tests
@ 2005-10-26 15:08 Roman Kennke
0 siblings, 0 replies; 2+ messages in thread
From: Roman Kennke @ 2005-10-26 15:08 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 253 bytes --]
Hi,
I committed two new tests for JTable.
2005-10-26 Roman Kennke <kennke@aicas.com>
* gnu/testlet/javax/swing/JTable/isRowSelected.java: New test.
* gnu/testlet/javax/swing/JTable/isColumnSelected.java: New test.
/Roman
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: isRowSelected.java --]
[-- Type: text/x-java; name="isRowSelected.java", Size: 2777 bytes --]
// Tags: JDK1.2
// Copyright (C) 2005 Roman Kennke <kennke@aicas.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.JTable;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
/**
* Tests the functionality of the method isRowSelected in JTable. This test
* shows that isRowSelected() returns true exactly when the requested row index
* is set as selected in the table's selectionModel, independent of the
* rowSelectionAllowed property.
*
* @author Roman Kennke (kennke@aicas.com)
*/
public class isRowSelected implements Testlet
{
/**
* Starts the test run.
*
* @param harness the test harness to use
*/
public void test(TestHarness harness)
{
testRowSelectionAllowed(harness);
testRowSelectionNotAllowed(harness);
}
/**
* Tests the case when the rowSelectionAllowed property is true.
*
* @param harness the test harness to use
*/
private void testRowSelectionAllowed(TestHarness harness)
{
JTable table = createTestTable();
table.setRowSelectionAllowed(true);
ListSelectionModel selModel = table.getSelectionModel();
// Select row#1 in the selection model.
selModel.setSelectionInterval(1, 1);
harness.check(table.isRowSelected(1), true);
}
/**
* Tests the case when the rowSelectionAllowed property is false.
*
* @param harness the test harness to use
*/
private void testRowSelectionNotAllowed(TestHarness harness)
{
JTable table = createTestTable();
table.setRowSelectionAllowed(false);
ListSelectionModel selModel = table.getSelectionModel();
// Select row#1 in the selection model.
selModel.setSelectionInterval(1, 1);
harness.check(table.isRowSelected(1), true);
}
/**
* Creates a JTable used for testing.
*
* @return the test table
*/
private JTable createTestTable()
{
return new JTable(new Object[][] {{"1", "2", "3"}, {"4", "5", "6"},
{"7", "8", "9"}},
new Object[] {"1", "2", "3"});
}
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: isColumnSelected.java --]
[-- Type: text/x-java; name="isColumnSelected.java", Size: 2867 bytes --]
// Tags: JDK1.2
// Copyright (C) 2005 Roman Kennke <kennke@aicas.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.JTable;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
/**
* Tests the functionality of the method isColumnSelected in JTable. This test
* shows that isColumnSelected() returns true exactly when the requested
* column index is set as selected in the tableModel's selectionModel,
* independent of the columnSelectionAllowed property.
*
* @author Roman Kennke (kennke@aicas.com)
*/
public class isColumnSelected implements Testlet
{
/**
* Starts the test run.
*
* @param harness the test harness to use
*/
public void test(TestHarness harness)
{
testColumnSelectionAllowed(harness);
testColumnSelectionNotAllowed(harness);
}
/**
* Tests the case when the columnSelectionAllowed property is true.
*
* @param harness the test harness to use
*/
private void testColumnSelectionAllowed(TestHarness harness)
{
JTable table = createTestTable();
table.setColumnSelectionAllowed(true);
ListSelectionModel selModel = table.getColumnModel().getSelectionModel();
// Select column#1 in the selection model.
selModel.setSelectionInterval(1, 1);
harness.check(table.isColumnSelected(1), true);
}
/**
* Tests the case when the columnSelectionAllowed property is false.
*
* @param harness the test harness to use
*/
private void testColumnSelectionNotAllowed(TestHarness harness)
{
JTable table = createTestTable();
table.setColumnSelectionAllowed(false);
ListSelectionModel selModel = table.getColumnModel().getSelectionModel();
// Select column#1 in the selection model.
selModel.setSelectionInterval(1, 1);
harness.check(table.isColumnSelected(1), true);
}
/**
* Creates a JTable used for testing.
*
* @return the test table
*/
private JTable createTestTable()
{
return new JTable(new Object[][] {{"1", "2", "3"}, {"4", "5", "6"},
{"7", "8", "9"}},
new Object[] {"1", "2", "3"});
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-10-28 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-28 13:47 FYI: New JTable tests Roman Kennke
-- strict thread matches above, loose matches on Subject: below --
2005-10-26 15:08 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).