8307133: Open source some JTable jtreg tests

Reviewed-by: serb
This commit is contained in:
Phil Race 2023-05-04 16:44:24 +00:00
parent 2adb3b409e
commit 5ca0b08a75
9 changed files with 486 additions and 0 deletions

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4170447
@summary JTable: non-Icon data in Icon column.
@key headful
*/
import java.io.File;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
public class bug4170447 {
static volatile boolean failed = false;
static volatile JFrame frame = null;
public static void main(String args[]) throws Exception {
SwingUtilities.invokeAndWait(bug4170447::createUI);
Thread.sleep(5000);
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
if (failed) {
throw new RuntimeException("Some exception occurred...");
}
}
static void createUI() {
String imgDir = System.getProperty("test.src", ".");
String imgPath = imgDir + File.separator + "swing.small.gif";
ImageIcon icn = new ImageIcon(imgPath,"test");
final Object data[][] = {
{"CELL 0 0", icn},
{"CELL 1 0", "String"}
};
String[] str = {"Column 0", "Column 1"};
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return 2; }
public int getRowCount() { return 2; }
public Object getValueAt(int row, int col) {return data[row][col];}
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
public boolean isCellEditable(int row, int col) {return getColumnClass(col) == String.class;}
public void setValueAt(Object aValue, int row, int column) {data[row][column] = aValue;}
};
MyTable tbl = new MyTable(dataModel);
JScrollPane sp = new JScrollPane(tbl);
frame = new JFrame("bug4170447");
frame.getContentPane().add(sp);
frame.pack();
frame.setVisible(true);
}
static class MyTable extends JTable {
public MyTable(TableModel tm) {
super(tm);
}
public Component prepareRenderer(TableCellRenderer rend, int row, int col) {
try {
return super.prepareRenderer(rend, row, col);
} catch (Exception e) {
e.printStackTrace();
failed = true;
return null;
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4098201
@summary Tests setRowHeight(int row, int height).
*/
import javax.swing.JTable;
public class bug4098201 {
public static void main(String args[]) {
JTable table = new JTable(4,3);
table.setRowHeight(1, table.getRowHeight()*2);
if (table.getRowHeight(0) * 2 != table.getRowHeight(1)) {
throw new Error("Can't set height for specified row...");
}
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4130356
@summary JTable.setRowSelectionInterval(int, int) shouldn't accept invalid range
*/
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
public class bug4130356 {
public static void main(String[] argv) {
JTable table = new JTable(4,3);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try {
table.setRowSelectionInterval(10,13);
throw new Error("Invalid arguments supported!!!");
} catch (IllegalArgumentException iae) {}
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4159300
@summary Tests that JTable processes tableChanged events quickly
@key headful
*/
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class bug4159300 {
static volatile JFrame frame = null;
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(bug4159300::createUI);
Thread.sleep(3000);
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
static void createUI() {
frame = new JFrame("bug4159300");
Container c = frame.getContentPane();
c.setLayout(new BorderLayout());
// create table
Object[] columnNames = {"only column"};
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
Object[] row = makeRow(model.getRowCount());
model.addRow(row);
JTable table = new JTable(model);
c.add(new JScrollPane(table), BorderLayout.CENTER);
// create button
JButton immediateButton = new JButton("Add row");
immediateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rowCount = model.getRowCount();
Object[] row = makeRow(rowCount);
model.addRow(row);
int rows = model.getRowCount();
int lastRow = rows - 1;
table.setRowSelectionInterval(lastRow, lastRow);
Rectangle r = table.getCellRect(lastRow, 0, false);
table.scrollRectToVisible(r);
}
});
c.add(immediateButton, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
static Object[] makeRow(int rowNumber) {
Object[] row = { ""+rowNumber };
return row;
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4243159
@summary Tests that JTable() do not throw ArrayIndexOutOfBoundsException
*/
import javax.swing.JTable;
public class bug4243159 {
/* Looks boring, but tests the no-args constructor works */
public static void main(String[] argv) {
JTable table = new JTable();
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4243313
@summary Tests that instantiating JTable through reflection
does not throw ClassNotFoundException
*/
import java.beans.Beans;
public class bug4243313 {
public static void main(String[] argv) throws Exception {
Object table = Beans.instantiate(null, "javax.swing.JTable");
}
}

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4247487
@summary Tests that the following methods of JTable are public:
int getAccessibleColumnAtIndex(int)
int getAccessibleRowAtIndex(int)
int getAccessibleIndexAt(int, int)
*/
import javax.swing.JTable;
public class bug4247487 {
static class TestTable extends JTable {
public TestTable() {
super(new Object[][]{{"one", "two"}},
new Object[]{"A", "B"});
}
public void test() {
int[] rowIndices = {0, 0, 1, 1};
int[] colIndices = {0, 1, 0, 1};
JTable.AccessibleJTable at =
(JTable.AccessibleJTable)getAccessibleContext();
for (int i=0; i<4; i++) {
if (at.getAccessibleRowAtIndex(i) != rowIndices[i]) {
throw new Error("Failed: wrong row index");
}
if (at.getAccessibleColumnAtIndex(i) != colIndices[i]) {
throw new Error("Failed: wrong column index");
}
}
if (at.getAccessibleIndexAt(0,0) != 0 ||
at.getAccessibleIndexAt(0,1) != 1 ||
at.getAccessibleIndexAt(1,0) != 2 ||
at.getAccessibleIndexAt(1,1) != 3) {
throw new Error("Failed: wrong index");
}
}
}
public static void main(String[] argv) {
TestTable test = new TestTable();
test.test();
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 4248070
@summary cellEditor bound in JTable.
*/
import javax.swing.JTable;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
public class bug4248070 {
public static void main(String[] argv) {
BeanInfo bi = null;
try {
bi = Introspector.getBeanInfo(JTable.class);
} catch (IntrospectionException e) {
}
PropertyDescriptor[] pd = bi.getPropertyDescriptors();
int i;
for (i=0; i<pd.length; i++) {
if (pd[i].getName().equals("cellEditor")) {
break;
}
}
if (!pd[i].isBound()) {
throw new RuntimeException("cellEditor property of JTable isn't flagged as bound in bean info...");
}
}
}