From 5ca0b08a7505d5c210d906e76c2a4cfc3eed64aa Mon Sep 17 00:00:00 2001 From: Phil Race Date: Thu, 4 May 2023 16:44:24 +0000 Subject: [PATCH] 8307133: Open source some JTable jtreg tests Reviewed-by: serb --- .../swing/JTable/4170447/bug4170447.java | 102 ++++++++++++++++++ .../swing/JTable/4170447/swing.small.gif | Bin 0 -> 1136 bytes test/jdk/javax/swing/JTable/bug4098201.java | 41 +++++++ test/jdk/javax/swing/JTable/bug4130356.java | 43 ++++++++ test/jdk/javax/swing/JTable/bug4159300.java | 92 ++++++++++++++++ test/jdk/javax/swing/JTable/bug4243159.java | 38 +++++++ test/jdk/javax/swing/JTable/bug4243313.java | 38 +++++++ test/jdk/javax/swing/JTable/bug4247487.java | 73 +++++++++++++ test/jdk/javax/swing/JTable/bug4248070.java | 59 ++++++++++ 9 files changed, 486 insertions(+) create mode 100644 test/jdk/javax/swing/JTable/4170447/bug4170447.java create mode 100644 test/jdk/javax/swing/JTable/4170447/swing.small.gif create mode 100644 test/jdk/javax/swing/JTable/bug4098201.java create mode 100644 test/jdk/javax/swing/JTable/bug4130356.java create mode 100644 test/jdk/javax/swing/JTable/bug4159300.java create mode 100644 test/jdk/javax/swing/JTable/bug4243159.java create mode 100644 test/jdk/javax/swing/JTable/bug4243313.java create mode 100644 test/jdk/javax/swing/JTable/bug4247487.java create mode 100644 test/jdk/javax/swing/JTable/bug4248070.java diff --git a/test/jdk/javax/swing/JTable/4170447/bug4170447.java b/test/jdk/javax/swing/JTable/4170447/bug4170447.java new file mode 100644 index 00000000000..b49b5422495 --- /dev/null +++ b/test/jdk/javax/swing/JTable/4170447/bug4170447.java @@ -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; + } + } + } +} diff --git a/test/jdk/javax/swing/JTable/4170447/swing.small.gif b/test/jdk/javax/swing/JTable/4170447/swing.small.gif new file mode 100644 index 0000000000000000000000000000000000000000..14a489ff4e7df0b4a268582701a1e7ef655047fa GIT binary patch literal 1136 zcmV-$1dsbiNk%w1VL$*t0QCR>_xJa}z`*bC@8{>|*4EagrKOCFjD&=QeSLjeT3Tac zW0aJXwY9ZrX=zeYQZX?xDJdx!7#Ii$2mk;85D*X{AtA=b#@^oEb8~Y_N=iaPLanW> zoSdAhs;ZWjmSb94)6>&TOiV%u7-I+_F&GGx5HWKYDV!lftvOoo@bFR?5PKL1jD&=* zudk()gq(X?j9M{!N-29vA%ts6b5c2DLLr=lbG@aU|Ns9|LNQt~5K=J^LLmrBDF{+2 z5IG?TA^8LW00031EC2ui06+jh000L5z<_W_EE5BEk63?u2XB#Ki+2bU6B-(+VV7|Ys1pivl9>%6B$wrjDnqEyr{Dp!$}Mc z5q+OT$x<1{$I(T95vY$GhC{0riB}G>s0vLRtEdn~23A8DvlIaa4GtL%!A%USvl8w~ z2qch8P-K)KW8_eUW0I!9g9!wcFqoEb;ie)R5+;1`Pv3(G8?13CmawCiA__Dnl=oy` zL?i|TYGgU&3y}laRFZ?jL4p1+m^x_{DK%uAN}0N#EWq&72!^1&3O<^qVUYm?9MEuB zB>~C-bVnLcpddkni4h`@HYjpS2!{#glyzj1NkP6%5dt(AQKD~&6EYW`^j1sFEezcP z9FV{O2L!);Q+Pm?j{zGY4Io&f(w4&k&k{HQ!0`ie2^1(qOxVWAK!wdyo(b7Ep#hHD z8CI+?o%Ye?1r+Xv;Z_8~g8{d3bReM{@`MTn11zW@oK!vx5(p&60RRE>z9vW{m4g6T zAXfo6gx;RKfQAYxG;GMQZU}=1l?)SkpkXxo+W`27Lk5M-lYvF1z_Azz|1~(^I^2*^ zoqlIjfPjDwCKtj4bN-}(-X4FXVL$}hWyoF#_3@!e05$~x0S6}jmqSw*X)?)l7sSZk zjP@ZIM>_#zfB|wkCYM79LrkK{8w|WwLkzIM!~WoH0h(A==?pdK;DgH_f84{v zJVYF@nJd~?K)E!u{IbVA$jrmc5r2>~6D_z { + 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; + } +} diff --git a/test/jdk/javax/swing/JTable/bug4243159.java b/test/jdk/javax/swing/JTable/bug4243159.java new file mode 100644 index 00000000000..7259cb3425d --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4243159.java @@ -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(); + } +} diff --git a/test/jdk/javax/swing/JTable/bug4243313.java b/test/jdk/javax/swing/JTable/bug4243313.java new file mode 100644 index 00000000000..079fed93814 --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4243313.java @@ -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"); + } +} diff --git a/test/jdk/javax/swing/JTable/bug4247487.java b/test/jdk/javax/swing/JTable/bug4247487.java new file mode 100644 index 00000000000..3a5cfcfdcd8 --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4247487.java @@ -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(); + } +} diff --git a/test/jdk/javax/swing/JTable/bug4248070.java b/test/jdk/javax/swing/JTable/bug4248070.java new file mode 100644 index 00000000000..ffb0a2097b2 --- /dev/null +++ b/test/jdk/javax/swing/JTable/bug4248070.java @@ -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