OpenJDK / bsd-port / bsd-port / jdk
changeset 4913:3c97da8e33ec
Merge
author | michaelm |
---|---|
date | Mon, 30 Jan 2012 16:27:04 +0000 |
parents | cb029d9b830a 68a486672cf8 |
children | 58c548d6b53e |
files | src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java |
diffstat | 22 files changed, 2384 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/text/SimpleDateFormat.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/share/classes/java/text/SimpleDateFormat.java Mon Jan 30 16:27:04 2012 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, 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 @@ -1646,8 +1646,7 @@ // determine the local time. (6645292) int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0; if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) { - calb.set(Calendar.ZONE_OFFSET, tz.getRawOffset()) - .set(Calendar.DST_OFFSET, dstAmount); + calb.set(Calendar.DST_OFFSET, dstAmount); } return (start + zoneNames[nameIndex].length()); }
--- a/src/share/classes/java/util/Calendar.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/share/classes/java/util/Calendar.java Mon Jan 30 16:27:04 2012 +0000 @@ -2705,7 +2705,7 @@ * removed from the serialization stream; this will probably happen in the * near future. */ - private void writeObject(ObjectOutputStream stream) + private synchronized void writeObject(ObjectOutputStream stream) throws IOException { // Try to compute the time correctly, for the future (stream
--- a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java Mon Jan 30 16:27:04 2012 +0000 @@ -1115,9 +1115,8 @@ protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { Rectangle tabRect = rects[tabIndex]; - String propKey = (isSelected ? "selectedLabelShift" : "labelShift"); - int nudge = DefaultLookup.getInt( - tabPane, this, "TabbedPane." + propKey, 1); + int nudge = (isSelected ? DefaultLookup.getInt(tabPane, this, "TabbedPane.selectedLabelShift", -1) : + DefaultLookup.getInt(tabPane, this, "TabbedPane.labelShift", 1)); switch (tabPlacement) { case BOTTOM:
--- a/src/share/classes/sun/security/ssl/EngineArgs.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/share/classes/sun/security/ssl/EngineArgs.java Mon Jan 30 16:27:04 2012 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2012, 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 @@ -25,7 +25,6 @@ package sun.security.ssl; -import javax.net.ssl.*; import java.nio.*; /* @@ -157,6 +156,7 @@ int amount = Math.min(appData[i].remaining(), spaceLeft); appData[i].limit(appData[i].position() + amount); netData.put(appData[i]); + appRemaining -= amount; spaceLeft -= amount; } } @@ -209,10 +209,16 @@ /* * In the case of Exception, we want to reset the positions * to appear as though no data has been consumed or produced. + * + * Currently, this method is only called as we are preparing to + * fail out, and thus we don't need to actually recalculate + * appRemaining. If that assumption changes, that variable should + * be updated here. */ void resetPos() { netData.position(netPos); for (int i = offset; i < offset + len; i++) { + // See comment above about recalculating appRemaining. appData[i].position(appPoss[i]); } }
--- a/src/share/classes/sun/security/ssl/SSLEngineImpl.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/share/classes/sun/security/ssl/SSLEngineImpl.java Mon Jan 30 16:27:04 2012 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -1172,7 +1172,7 @@ ea.resetPos(); fatal(Alerts.alert_internal_error, - "problem unwrapping net record", e); + "problem wrapping app data", e); return null; // make compiler happy } finally { /*
--- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java Mon Jan 30 16:17:53 2012 +0000 +++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java Mon Jan 30 16:27:04 2012 +0000 @@ -255,6 +255,20 @@ } } + if (owner != null || isSimpleWindow()) { + XToolkit.awtLock(); + try { + XNETProtocol protocol = XWM.getWM().getNETProtocol(); + if (protocol != null && protocol.active()) { + XAtomList net_wm_state = getNETWMState(); + net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR); + setNETWMState(net_wm_state); + } + } finally { + XToolkit.awtUnlock(); + } + } + // Init warning window(for applets) if (((Window)target).getWarningString() != null) { // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip @@ -480,14 +494,6 @@ bounds.x, bounds.y, bounds.width, bounds.height); XWM.setMotifDecor(this, false, 0, 0); - XNETProtocol protocol = XWM.getWM().getNETProtocol(); - if (protocol != null && protocol.active()) { - XAtomList net_wm_state = getNETWMState(); - net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR); - setNETWMState(net_wm_state); - } - - boolean isResized = !bounds.getSize().equals(oldBounds.getSize()); boolean isMoved = !bounds.getLocation().equals(oldBounds.getLocation()); if (isMoved || isResized) {
--- a/src/windows/lib/tzmappings Mon Jan 30 16:17:53 2012 +0000 +++ b/src/windows/lib/tzmappings Mon Jan 30 16:27:04 2012 +0000 @@ -191,5 +191,6 @@ Magadan Standard Time:924,924::Asia/Magadan: Kaliningrad Standard Time:925,925:RU:Europe/Kaliningrad: Turkey Standard Time:926,926::Asia/Istanbul: -Western Brazilian Standard Time:927,927:BR:America/Rio_Branco: -Armenian Standard Time:928,928:AM:Asia/Yerevan: +Bahia Standard Time:927,927::America/Bahia: +Western Brazilian Standard Time:928,928:BR:America/Rio_Branco: +Armenian Standard Time:929,929:AM:Asia/Yerevan:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/text/Format/DateFormat/Bug7130335.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, 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 7130335 + * @summary Make sure that round-trip conversion (format/parse) works + * with old timestamps in Europe/Moscow. + */ +import java.text.*; +import java.util.*; + +public class Bug7130335 { + private static final TimeZone MOSCOW = TimeZone.getTimeZone("Europe/Moscow"); + + public static void main(String[] args) throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z", Locale.US); + sdf.setTimeZone(MOSCOW); + Calendar cal = new GregorianCalendar(MOSCOW); + cal.clear(); + // Try both +03:00 and +02:00 + cal.set(1922, Calendar.SEPTEMBER, 30); + test(sdf, cal); + cal.add(Calendar.DAY_OF_YEAR, 1); + test(sdf, cal); + cal.set(1991, Calendar.MARCH, 31); + // in daylight saving time + test(sdf, cal); + cal.add(Calendar.DAY_OF_YEAR, 1); + test(sdf, cal); + // Try the current timestamp + cal.setTimeInMillis(System.currentTimeMillis()); + test(sdf, cal); + } + + private static void test(SimpleDateFormat sdf, Calendar cal) throws Exception { + Date d = cal.getTime(); + String f = sdf.format(d); + System.out.println(f); + Date pd = sdf.parse(f); + String p = sdf.format(pd); + if (!d.equals(pd) || !f.equals(p)) { + throw new RuntimeException("format: " + f + ", parse: " + p); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/Calendar/Bug7017458.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 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 7017458 + * @summary Test of multithreaded serialization/deserialization of Calendar. + */ + +import java.io.*; +import java.util.Calendar; + +public class Bug7017458 { + + static volatile boolean err = false; + + public static void main(String[] args) { + try { + new Bug7017458().perform(); + } + catch (Exception e) { + e.printStackTrace(); + err = true; + } + + if (err) { + throw new RuntimeException("Multithreaded serialization/deserialization test failed."); + } else { + System.out.println("Multithreaded serialization/deserialization test passed."); + } + } + + public void perform() throws Exception { + int nbThreads = 8; + Calendar cal = Calendar.getInstance(); + SerializationThread[] threads = new SerializationThread[nbThreads]; + for (int i = 0; i < nbThreads; i++) { + threads[i] = new SerializationThread(cal); + } + for (int i = 0; i < nbThreads; i++) { + threads[i].start(); + } + for (int i = 0; i < nbThreads; i++) { + threads[i].join(); + } + + DeserializationThread[] threads2 = new DeserializationThread[nbThreads]; + for (int i = 0; i < nbThreads; i++) { + threads2[i] = new DeserializationThread(threads[i].data); + } + for (int i = 0; i < nbThreads; i++) { + threads2[i].start(); + } + for (int i = 0; i < nbThreads; i++) { + threads2[i].join(); + } + } + + public class SerializationThread extends Thread { + private Calendar cal; + public byte[] data; + + public SerializationThread(Calendar cal) { + this.cal = cal; + } + + public void run() { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(cal); + oos.flush(); + oos.close(); + data = baos.toByteArray(); + } + catch (Exception e) { + e.printStackTrace(); + err = true; + } + } + } + + public class DeserializationThread extends Thread { + public Calendar cal; + public byte[] data; + + public DeserializationThread(byte[] data) { + this.data = data; + } + + public void run() { + try { + ByteArrayInputStream bais = new ByteArrayInputStream(data); + ObjectInputStream ois = new ObjectInputStream(bais); + cal = (Calendar) ois.readObject(); + ois.close(); + } + catch (Exception e) { + e.printStackTrace(); + err = true; + } + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JList/6462008/bug6462008.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2011, 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 6462008 + * @summary Tests that mouse/keyboard work properly on JList with lead < 0 or > list.getModel().getSize() + * @author Shannon Hickey + * @run main bug6462008 + */ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; +import sun.awt.SunToolkit; + +public class bug6462008 { + + private static final int DONT_CARE = -2; + private static int anchorLead; + private static boolean isAquaLAF; + private static int controlKey; + private static JList list; + private static SunToolkit toolkit; + private static Robot robot; + + public static void main(String[] args) throws Exception { + toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(100); + + isAquaLAF = "Aqua".equals(UIManager.getLookAndFeel().getID()); + controlKey = isAquaLAF ? KeyEvent.VK_META : KeyEvent.VK_CONTROL; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + setAnchorLead(-1); + toolkit.realSync(); + + testListSelection(); + + setAnchorLead(100); + toolkit.realSync(); + + testListSelection(); + } + + public static void testListSelection() throws Exception { + + // Space + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Control + Space + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_CONTROL); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Shift + Space + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SHIFT); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + // Control + Shift + Space + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SPACE); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.keyRelease(KeyEvent.VK_CONTROL); + + toolkit.realSync(); + checkSelection(); + resetList(); + toolkit.realSync(); + + + // Control + A Multiple Selection + + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + resetList(); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + toolkit.realSync(); + + // Control + A Single Selection + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + setSelectionInterval(5, 5); + toolkit.realSync(); + + + // Control + A Selection interval (5, 5) + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelection(5); + resetList(); + toolkit.realSync(); + + // Page Down + // Not applicable for the Aqua L&F + if (!isAquaLAF) { + robot.keyPress(KeyEvent.VK_PAGE_DOWN); + robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + + toolkit.realSync(); + checkSelection(9, 9, 9); + resetList(); + toolkit.realSync(); + } + + // Shift + Page Down + /* + * We really want to use robot here, but there seems to be a bug in AWT's + * robot implementation (see 6463168). For now, we'll invoke the action + * directly instead. When the bug is fixed, we'll use the following four + * lines instead: + * robot.keyPress(KeyEvent.VK_SHIFT); + * robot.keyPress(KeyEvent.VK_PAGE_DOWN); + * robot.keyRelease(KeyEvent.VK_PAGE_DOWN); + * robot.keyRelease(KeyEvent.VK_SHIFT); + */ + + scrollDownExtendSelection(); + + toolkit.realSync(); + checkSelection(0, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + resetList(); + toolkit.realSync(); + + // Down + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + toolkit.realSync(); + + // L + robot.keyPress(KeyEvent.VK_L); + robot.keyRelease(KeyEvent.VK_L); + + toolkit.realSync(); + checkSelectionAL(0, 0, 0); + resetList(); + toolkit.realSync(); + + // Click item 4 + Point p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + + toolkit.realSync(); + checkSelectionAL(4, 4, 4); + resetList(); + toolkit.realSync(); + + + // Control + Click item 4 + robot.keyPress(controlKey); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(controlKey); + + + toolkit.realSync(); + checkSelectionAL(4, 4, 4); + resetList(); + toolkit.realSync(); + + // Shift + Click item 4 + robot.keyPress(KeyEvent.VK_SHIFT); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(KeyEvent.VK_SHIFT); + + + toolkit.realSync(); + checkSelectionAL(0, 4, 0, 1, 2, 3, 4); + resetList(); + toolkit.realSync(); + + + // Control + Shift + Click item 4 + robot.keyPress(controlKey); + robot.keyPress(KeyEvent.VK_SHIFT); + p = clickItem4(); + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(KeyEvent.VK_SHIFT); + robot.keyRelease(controlKey); + + toolkit.realSync(); + checkSelectionAL(0, 4); + resetList(); + toolkit.realSync(); + } + + private static DefaultListModel getModel() { + DefaultListModel listModel = new DefaultListModel(); + for (int i = 0; i < 10; i++) { + listModel.addElement("List Item " + i); + } + return listModel; + } + + private static Point clickItem4() throws Exception { + + final Point[] result = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Rectangle r = list.getCellBounds(4, 4); + Point p = new Point(r.x + r.width / 2, r.y + r.height / 2); + SwingUtilities.convertPointToScreen(p, list); + result[0] = p; + } + }); + + return result[0]; + } + + private static void resetList() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + list.getSelectionModel().clearSelection(); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void scrollDownExtendSelection() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getActionMap().get("scrollDownExtendSelection"). + actionPerformed(new ActionEvent(list, + ActionEvent.ACTION_PERFORMED, null)); + } + }); + } + + private static void setSelectionMode(final int selectionMode) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionMode(selectionMode); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setSelectionInterval(final int index0, final int index1) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + list.getSelectionModel().setSelectionInterval(index0, index1); + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setAnchorLead(final int anchorLeadValue) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + anchorLead = anchorLeadValue; + setAnchorLeadNonThreadSafe(); + } + }); + } + + private static void setAnchorLeadNonThreadSafe() { + list.getSelectionModel().setAnchorSelectionIndex(anchorLead); + ((DefaultListSelectionModel) list.getSelectionModel()).moveLeadSelectionIndex(anchorLead); + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("bug6462008"); + frame.setSize(200, 500); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + list = new JList(getModel()); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(list); + frame.getContentPane().add(panel); + + frame.setVisible(true); + } + + private static void checkSelection(int... sels) throws Exception { + checkSelectionAL(DONT_CARE, DONT_CARE, sels); + } + + private static void checkSelectionAL(final int anchor, final int lead, final int... sels) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + checkSelectionNonThreadSafe(anchor, lead, sels); + } + }); + } + + private static void checkSelectionNonThreadSafe(int anchor, int lead, int... sels) { + ListSelectionModel lsm = list.getSelectionModel(); + + int actualAnchor = lsm.getAnchorSelectionIndex(); + int actualLead = lsm.getLeadSelectionIndex(); + + if (anchor != DONT_CARE && actualAnchor != anchor) { + throw new RuntimeException("anchor is " + actualAnchor + ", should be " + anchor); + } + + if (lead != DONT_CARE && actualLead != lead) { + throw new RuntimeException("lead is " + actualLead + ", should be " + lead); + } + + Arrays.sort(sels); + boolean[] checks = new boolean[list.getModel().getSize()]; + for (int i : sels) { + checks[i] = true; + } + + int index0 = Math.min(lsm.getMinSelectionIndex(), 0); + int index1 = Math.max(lsm.getMaxSelectionIndex(), list.getModel().getSize() - 1); + + for (int i = index0; i <= index1; i++) { + if (lsm.isSelectedIndex(i)) { + if (i < 0 || i >= list.getModel().getSize() || !checks[i]) { + throw new RuntimeException(i + " is selected when it should not be"); + } + } else if (i >= 0 && i < list.getModel().getSize() && checks[i]) { + throw new RuntimeException(i + " is supposed to be selected"); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JPopupMenu/4966112/bug4966112.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2011, 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 4966112 + * @summary Some Composite components does not show the Context Popup. + * @library ../../regtesthelpers + * @build Util + * @author Alexander Zuev + * @run main bug4966112 + */ +import javax.swing.*; +import javax.swing.event.PopupMenuListener; +import javax.swing.event.PopupMenuEvent; +import java.awt.*; +import java.awt.event.*; +import sun.awt.SunToolkit; + +public class bug4966112 { + + private static final int NO_MOUSE_BUTTON = -1; + private static volatile boolean shown = false; + private static volatile int popupButton = NO_MOUSE_BUTTON; + private static volatile JButton testButton; + private static volatile JSplitPane jsp; + private static volatile JSpinner spin; + private static volatile JFileChooser filec; + private static int buttonMask; + private static Robot robot; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(100); + + createAndShowButton(); + toolkit.realSync(); + + setClickPoint(testButton); + clickMouse(InputEvent.BUTTON1_MASK); + clickMouse(InputEvent.BUTTON2_MASK); + clickMouse(InputEvent.BUTTON3_MASK); + + toolkit.realSync(); + closeFrame(); + + if (popupButton == NO_MOUSE_BUTTON) { + System.out.println("Test can't identify the popup trigger button. Test skipped"); + return; + } + + setButtonMask(); + + // Test Split Pane + createAndShowSplitPane(); + toolkit.realSync(); + + clickMouse(jsp); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on splitpane"); + } + + // Test Spinner + createAndShowSpinner(); + toolkit.realSync(); + + clickMouse(spin); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on spinner"); + } + + // Test File Chooser + createAndShowFileChooser(); + toolkit.realSync(); + + clickMouse(filec); + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_ESCAPE); + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_ESCAPE); + toolkit.realSync(); + closeFrame(); + + if (!shown) { + throw new RuntimeException("Popup was not shown on filechooser"); + } + } + + private static void clickMouse(JComponent c) throws Exception { + setClickPoint(c); + clickMouse(buttonMask); + } + + private static void clickMouse(int buttons) { + robot.mousePress(buttons); + robot.mouseRelease(buttons); + } + + private static void setButtonMask() { + switch (popupButton) { + case MouseEvent.BUTTON1: + buttonMask = InputEvent.BUTTON1_MASK; + break; + case MouseEvent.BUTTON2: + buttonMask = InputEvent.BUTTON2_MASK; + break; + case MouseEvent.BUTTON3: + buttonMask = InputEvent.BUTTON3_MASK; + break; + } + } + + private static void setClickPoint(final JComponent c) throws Exception { + final Point[] result = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Point p = c.getLocationOnScreen(); + Dimension size = c.getSize(); + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } + }); + + robot.mouseMove(result[0].x, result[0].y); + } + + private static JPopupMenu createJPopupMenu() { + JPopupMenu jpm = new JPopupMenu(); + jpm.add("One"); + jpm.add("Two"); + jpm.add("Three"); + jpm.addPopupMenuListener(new PopupMenuListener() { + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + shown = true; + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }); + + AutoClosable.INSTANCE.setPopup(jpm); + return jpm; + } + + private static void createAndShowButton() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("Button Frame"); + frame.setLayout(new BorderLayout()); + testButton = new JButton("Popup Tester"); + + testButton.addMouseListener(new MouseAdapter() { + + void setPopupTrigger(MouseEvent e) { + if (e.isPopupTrigger()) { + popupButton = e.getButton(); + } + } + + public void mouseClicked(MouseEvent e) { + setPopupTrigger(e); + } + + public void mousePressed(MouseEvent e) { + setPopupTrigger(e); + } + + public void mouseReleased(MouseEvent e) { + setPopupTrigger(e); + } + }); + + frame.add(testButton, BorderLayout.CENTER); + frame.pack(); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowSplitPane() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("Test SplitPane"); + frame.setSize(250, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLayout(new BorderLayout()); + + shown = false; + jsp = new JSplitPane(); + jsp.setRightComponent(new JPanel()); + jsp.setLeftComponent(new JPanel()); + jsp.setComponentPopupMenu(createJPopupMenu()); + + frame.add(jsp, BorderLayout.CENTER); + + jsp.setDividerLocation(150); + + frame.setLocation(400, 300); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowSpinner() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("JSpinner Test"); + frame.setLayout(new BorderLayout()); + frame.setSize(200, 100); + shown = false; + spin = new JSpinner(); + spin.setComponentPopupMenu(createJPopupMenu()); + frame.add(spin, BorderLayout.CENTER); + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void createAndShowFileChooser() throws Exception { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + JFrame frame = new JFrame("FileChooser test dialog"); + frame.setSize(100, 100); + + shown = false; + filec = new JFileChooser(); + filec.setComponentPopupMenu(createJPopupMenu()); + filec.showOpenDialog(frame); + + frame.setVisible(true); + AutoClosable.INSTANCE.setFrame(frame); + } + }); + } + + private static void closeFrame() { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + AutoClosable.INSTANCE.close(); + } + }); + } + + private static class AutoClosable { + + static final AutoClosable INSTANCE = new AutoClosable(); + private JFrame frame; + private JPopupMenu popup; + + public void setFrame(JFrame frame) { + this.frame = frame; + } + + public void setPopup(JPopupMenu popup) { + this.popup = popup; + } + + public void close() { + frame.dispose(); + if (popup != null) { + popup.setVisible(false); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JPopupMenu/6827786/bug6827786.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2007, 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 6827786 + * @summary Tests duplicate mnemonics + * @author Peter Zhelezniakov + * @library ../../regtesthelpers + * @build Util + * @run main bug6827786 + */ +import java.awt.*; +import java.awt.event.KeyEvent; +import javax.swing.*; +import sun.awt.SunToolkit; + +public class bug6827786 { + + private static JMenu menu; + private static Component focusable; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + focusable.requestFocus(); + } + }); + + toolkit.realSync(); + checkfocus(); + + // select menu + Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_F); + // select submenu + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // verify submenu is selected + verify(1); + + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // verify last item is selected + verify(2); + + Util.hitKeys(robot, KeyEvent.VK_S); + toolkit.realSync(); + // selection should wrap to first item + verify(0); + + System.out.println("PASSED"); + + } + + private static void checkfocus() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + if (!focusable.isFocusOwner()) { + throw new RuntimeException("Button is not the focus owner."); + } + } + }); + } + + private static void verify(final int index) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + MenuElement[] path = + MenuSelectionManager.defaultManager().getSelectedPath(); + MenuElement item = path[3]; + if (item != menu.getMenuComponent(index)) { + System.err.println("Selected: " + item); + System.err.println("Should be: " + + menu.getMenuComponent(index)); + throw new RuntimeException("Test Failed"); + } + } + }); + } + + private static JMenuBar createMenuBar() { + menu = new JMenu("File"); + menu.setMnemonic('F'); + + menu.add(new JMenuItem("Save", 'S')); + + JMenu sub = new JMenu("Submenu"); + sub.setMnemonic('S'); + sub.add(new JMenuItem("Sub Item")); + menu.add(sub); + + menu.add(new JMenuItem("Special", 'S')); + + JMenuBar bar = new JMenuBar(); + bar.add(menu); + return bar; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("bug6827786"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setJMenuBar(createMenuBar()); + focusable = new JButton("Set Focus Here"); + frame.add(focusable); + frame.pack(); + frame.setVisible(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTabbedPane/7010561/bug7010561.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 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. + */ + +import javax.swing.*; +import javax.swing.plaf.basic.BasicTabbedPaneUI; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.lang.reflect.Method; + +/* @test + @bug 7010561 + @summary Tab text position with Synth based LaF is different to Java 5/6 + @author Pavel Porvatov +*/ +public class bug7010561 { + private static int[] TAB_PLACEMENT = { + SwingConstants.BOTTOM, + SwingConstants.BOTTOM, + SwingConstants.TOP, + SwingConstants.TOP, + + }; + + private static boolean[] IS_SELECTED = { + false, + true, + false, + true + }; + + private static int[] RETURN_VALUE = { + -1, + 1, + 1, + -1 + }; + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel(new SynthLookAndFeel()); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + JTabbedPane tabbedPane = new JTabbedPane(); + + tabbedPane.addTab("Tab 1", new JLabel("Tab 1")); + + // Ensure internal TabbedPane fields are initialized + tabbedPane.doLayout(); + + BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI(); + + try { + Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class, + int.class, boolean.class); + + method.setAccessible(true); + + for (int i = 0; i < 4; i++) { + int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0, + IS_SELECTED[i])).intValue(); + + if (res != RETURN_VALUE[i]) { + throw new RuntimeException("Test bug7010561 failed on index " + i); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + System.out.println("Test bug7010561 passed"); + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTree/6263446/bug6263446.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2011, 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 6263446 + * @summary Tests that double-clicking to edit a cell doesn't select the content. + * @author Shannon Hickey + * @run main bug6263446 + */ +import java.awt.*; +import java.awt.event.InputEvent; +import java.lang.reflect.Field; +import javax.swing.*; +import javax.swing.tree.*; +import sun.awt.SunToolkit; + +public class bug6263446 { + + private static final String FIRST = "AAAAAAAAAAA"; + private static final String SECOND = "BB"; + private static final String ALL = FIRST + " " + SECOND; + private static JTree tree; + private static Robot robot; + private static SunToolkit toolkit; + + public static void main(String[] args) throws Exception { + toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point point = getClickPoint(); + robot.mouseMove(point.x, point.y); + + // click count 3 + click(1); + assertNotEditing(); + + click(2); + assertNotEditing(); + + click(3); + assertEditing(); + cancelCellEditing(); + assertNotEditing(); + + click(4); + checkSelectedText(FIRST); + + click(5); + checkSelectedText(ALL); + + // click count 4 + setClickCountToStart(4); + + click(1); + assertNotEditing(); + + click(2); + assertNotEditing(); + + click(3); + assertNotEditing(); + + click(4); + assertEditing(); + cancelCellEditing(); + assertNotEditing(); + + click(5); + checkSelectedText(FIRST); + + click(6); + checkSelectedText(ALL); + + // start path editing + startPathEditing(); + assertEditing(); + + click(1); + checkSelection(null); + + click(2); + checkSelection(FIRST); + + click(3); + checkSelection(ALL); + } + + private static void click(int times) { + robot.delay(500); + for (int i = 0; i < times; i++) { + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + } + + private static Point getClickPoint() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Rectangle rect = tree.getRowBounds(0); + // UPDATE !!! + Point p = new Point(rect.x + rect.width / 2, rect.y + 2); + SwingUtilities.convertPointToScreen(p, tree); + result[0] = p; + + } + }); + + return result[0]; + } + + private static TreeModel createTreeModel() { + return new DefaultTreeModel(new DefaultMutableTreeNode(ALL)); + } + + private static void createAndShowGUI() { + + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + tree = new JTree(createTreeModel()); + tree.setRootVisible(true); + tree.setEditable(true); + + + frame.getContentPane().add(tree); + frame.pack(); + frame.setVisible(true); + } + + private static void setClickCountToStart(final int clicks) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + DefaultTreeCellEditor editor = + (DefaultTreeCellEditor) tree.getCellEditor(); + Field field = DefaultTreeCellEditor.class.getDeclaredField("realEditor"); + field.setAccessible(true); + DefaultCellEditor ce = (DefaultCellEditor) field.get(editor); + ce.setClickCountToStart(clicks); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + }); + + toolkit.realSync(); + + } + + private static void startPathEditing() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + tree.startEditingAtPath(tree.getPathForRow(0)); + } + }); + } + + private static void cancelCellEditing() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + tree.getCellEditor().cancelCellEditing(); + } + }); + } + + private static void checkSelection(final String sel) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + DefaultTreeCellEditor editor = + (DefaultTreeCellEditor) tree.getCellEditor(); + Field field = DefaultTreeCellEditor.class.getDeclaredField("realEditor"); + field.setAccessible(true); + DefaultCellEditor ce = (DefaultCellEditor) field.get(editor); + JTextField tf = (JTextField) ce.getComponent(); + String text = tf.getSelectedText(); + + if (sel == null) { + if (text != null && text.length() != 0) { + throw new RuntimeException("Nothing should be selected, but \"" + text + "\" is selected."); + } + } else if (!sel.equals(text)) { + throw new RuntimeException("\"" + sel + "\" should be selected, but \"" + text + "\" is selected."); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + }); + } + + private static void checkSelectedText(String sel) throws Exception { + assertEditing(); + checkSelection(sel); + cancelCellEditing(); + assertNotEditing(); + } + + private static void assertEditing() throws Exception { + assertEditingNoTreeLock(true); + } + + private static void assertNotEditing() throws Exception { + assertEditingNoTreeLock(false); + } + + private static void assertEditingNoTreeLock(final boolean editing) throws Exception { + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + if (editing && !tree.isEditing()) { + throw new RuntimeException("Tree should be editing"); + } + if (!editing && tree.isEditing()) { + throw new RuntimeException("Tree should not be editing"); + } + } + }); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/SwingUtilities/4917669/bug4917669.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,106 @@ + +/* + * Copyright (c) 2008, 2012, 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 4917669 + * @summary 1.4 REGRESSION: MenuItem accelerator doesn't work if parent menu is in JDialog + * @author Alexander Zuev + * @library ../../regtesthelpers + * @run main bug4917669 + */ + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import sun.awt.SunToolkit; + +public class bug4917669 { + + private static volatile boolean passed = false; + private static JFrame mainFrame; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(500); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowDialog(); + } + }); + + toolkit.realSync(); + + Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_O); + toolkit.realSync(); + + if (!passed) { + throw new RuntimeException("Action did not received by menu item."); + } + } + + private static void createAndShowDialog() { + JDialog dialog = new JDialog(mainFrame, "Test Dialog", false); + JMenuBar mb = new JMenuBar(); + JMenu file = new JMenu("File"); + JMenuItem menuItem = new JMenuItem("Open"); + menuItem.setAccelerator(KeyStroke.getKeyStroke("control O")); + menuItem.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + passed = true; + } + }); + file.add(menuItem); + mb.add(file); + dialog.setJMenuBar(mb); + + dialog.setSize(100, 100); + dialog.setLocation(200, 200); + dialog.setVisible(true); + } + + private static void createAndShowGUI() { + mainFrame = new JFrame("Bug4917669"); + mainFrame.setLayout(new BorderLayout()); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainFrame.setSize(50, 50); + mainFrame.setVisible(true); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/UITest/UITest.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2012, 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 4843282 4886871 + * @summary Makes sure windows is only listed on Windows platform, and + * GTK is not on Windows and Mac. + * added as tabs + * @author Scott Violet + */ +import javax.swing.*; +import javax.swing.UIManager.LookAndFeelInfo; +import sun.awt.OSInfo; +import sun.awt.OSInfo.OSType; + +public class UITest { + + public static void main(String[] args) { + OSType os = OSInfo.getOSType(); + LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels(); + + switch (os) { + case WINDOWS: + + // Make sure we don't have GTK. + if (hasLAF("gtk", lafInfo)) { + throw new RuntimeException("On windows, but GTK is present"); + } + + // Make sure we don't have Aqua. + if (hasLAF("mac", lafInfo)) { + throw new RuntimeException("On windows, but Aqua is present"); + } + + // Make sure we have Windows. + if (!hasLAF("windows", lafInfo)) { + throw new RuntimeException("On windows and don't have Windows"); + } + + break; + + case MACOSX: + + // Make sure we don't have GTK. + if (hasLAF("gtk", lafInfo)) { + throw new RuntimeException("On mac, but GTK is present"); + } + + // Make sure we don't have Windows. + if (hasLAF("windows", lafInfo)) { + throw new RuntimeException("On mac, but Windows is present"); + } + + // Make sure we have Aqua. + if (!hasLAF("mac", lafInfo)) { + throw new RuntimeException("On mac and don't have Aqua"); + } + + break; + + default: + // Not windows and mac + + // Make sure we don't have Windows. + if (hasLAF("windows", lafInfo)) { + throw new RuntimeException("Not on windows and have Windows"); + } + + // Make sure we don't have Aqua. + if (hasLAF("mac", lafInfo)) { + throw new RuntimeException("Not on mac and have Aqua"); + } + + // Make sure we have GTK. + if (!hasLAF("gtk", lafInfo)) { + throw new RuntimeException( + "Not on Windows and Mac and don't have GTK!"); + } + } + + } + + public static boolean hasLAF(String name, LookAndFeelInfo[] lafInfo) { + + for (int counter = 0; counter < lafInfo.length; counter++) { + if (lafInfo[counter].getName().toLowerCase().indexOf(name) != -1) { + return true; + } + } + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/plaf/basic/BasicHTML/4251579/bug4251579.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,100 @@ + +/* + * Copyright (c) 2008, 2012, 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 4251579 + * @summary Tests if style sheets are working in JLabel + * @author Denis Sharypov + * @run main bug4251579 + */ +import java.awt.*; +import javax.swing.*; + +import sun.awt.SunToolkit; + +public class bug4251579 { + + private static JLabel htmlComponent; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + final Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + boolean passed = false; + + Point p = htmlComponent.getLocationOnScreen(); + Dimension d = htmlComponent.getSize(); + int x0 = p.x; + int y = p.y + d.height / 2; + + for (int x = x0; x < x0 + d.width; x++) { + if (robot.getPixelColor(x, y).equals(Color.blue)) { + passed = true; + break; + } + } + + if (!passed) { + throw new RuntimeException("Test failed."); + } + + } + }); + } + + private static void createAndShowGUI() { + + String htmlText = + "<html>" + + "<head><style> .blue{ color:blue; } </style></head>" + + "<body" + + "<P class=\"blue\"> should be rendered with BLUE class definition</P>" + + "</body>"; + + JFrame mainFrame = new JFrame("bug4251579"); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + htmlComponent = new JLabel(htmlText); + mainFrame.getContentPane().add(htmlComponent); + + mainFrame.pack(); + mainFrame.setVisible(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/text/html/CSS/4530474/bug4530474.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2008, 2012, 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 4530474 + * @summary Tests if background-color CSS attribute in HTML font tag in class attribute + * @author Denis Sharypov + * @run main bug4530474 + */ + +import java.awt.*; +import javax.swing.*; + +import java.io.*; + +import sun.awt.SunToolkit; + +public class bug4530474 { + + private static final Color TEST_COLOR = Color.BLUE; + private static JEditorPane jep; + + public static void main(String args[]) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + final Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + boolean passed = false; + + Point p = jep.getLocationOnScreen(); + Dimension d = jep.getSize(); + int x0 = p.x; + int y = p.y + d.height / 3; + + StringBuilder builder = new StringBuilder("Test color: "); + builder.append(TEST_COLOR.toString()); + builder.append(" resut colors: "); + + for (int x = x0; x < x0 + d.width; x++) { + Color color = robot.getPixelColor(x, y); + builder.append(color); + + if (TEST_COLOR.equals(color)) { + passed = true; + break; + } + } + + if (!passed) { + throw new RuntimeException("Test Fail. " + builder.toString()); + } + } + }); + + } + + private static void createAndShowGUI() { + + JFrame mainFrame = new JFrame("bug4530474"); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jep = new JEditorPane(); + + try { + File file = new File(System.getProperty("test.src", "."), "test.html"); + jep.setPage(file.toURL()); + } catch (Exception e) { + throw new RuntimeException(e); + } + + mainFrame.getContentPane().add(jep); + + mainFrame.pack(); + mainFrame.setVisible(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/text/html/CSS/4530474/test.css Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,4 @@ +font.blackwhite { + background-color: blue; + color: #FFFFFF; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/text/html/CSS/4530474/test.html Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,7 @@ +<html> +<head> +<LINK REL="StyleSheet" type="text/css" HREF=test.css> +<body> + <font class="blackwhite">www</font> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.java Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2003, 2011, 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 7126889 + * @summary Incorrect SSLEngine debug output + * + * Debug output was reporting n+1 bytes of data was written when it was + * really was n. + * + * SunJSSE does not support dynamic system properties, no way to re-use + * system properties in samevm/agentvm mode. + */ + +/** + * A SSLEngine usage example which simplifies the presentation + * by removing the I/O and multi-threading concerns. + * + * The test creates two SSLEngines, simulating a client and server. + * The "transport" layer consists two byte buffers: think of them + * as directly connected pipes. + * + * Note, this is a *very* simple example: real code will be much more + * involved. For example, different threading and I/O models could be + * used, transport mechanisms could close unexpectedly, and so on. + * + * When this application runs, notice that several messages + * (wrap/unwrap) pass before any application data is consumed or + * produced. (For more information, please see the SSL/TLS + * specifications.) There may several steps for a successful handshake, + * so it's typical to see the following series of operations: + * + * client server message + * ====== ====== ======= + * wrap() ... ClientHello + * ... unwrap() ClientHello + * ... wrap() ServerHello/Certificate + * unwrap() ... ServerHello/Certificate + * wrap() ... ClientKeyExchange + * wrap() ... ChangeCipherSpec + * wrap() ... Finished + * ... unwrap() ClientKeyExchange + * ... unwrap() ChangeCipherSpec + * ... unwrap() Finished + * ... wrap() ChangeCipherSpec + * ... wrap() Finished + * unwrap() ... ChangeCipherSpec + * unwrap() ... Finished + */ + +import javax.net.ssl.*; +import javax.net.ssl.SSLEngineResult.*; +import java.io.*; +import java.security.*; +import java.nio.*; + +public class DebugReportsOneExtraByte { + + /* + * Enables logging of the SSLEngine operations. + */ + private static boolean logging = true; + + /* + * Enables the JSSE system debugging system property: + * + * -Djavax.net.debug=all + * + * This gives a lot of low-level information about operations underway, + * including specific handshake messages, and might be best examined + * after gaining some familiarity with this application. + */ + private static boolean debug = false; + + private SSLContext sslc; + + private SSLEngine clientEngine; // client Engine + private ByteBuffer clientOut; // write side of clientEngine + private ByteBuffer clientIn; // read side of clientEngine + + private SSLEngine serverEngine; // server Engine + private ByteBuffer serverOut; // write side of serverEngine + private ByteBuffer serverIn; // read side of serverEngine + + /* + * For data transport, this example uses local ByteBuffers. This + * isn't really useful, but the purpose of this example is to show + * SSLEngine concepts, not how to do network transport. + */ + private ByteBuffer cTOs; // "reliable" transport client->server + private ByteBuffer sTOc; // "reliable" transport server->client + + /* + * The following is to set up the keystores. + */ + private static String pathToStores = "../../../../../../../etc"; + private static String keyStoreFile = "keystore"; + private static String trustStoreFile = "truststore"; + private static String passwd = "passphrase"; + + private static String keyFilename = + System.getProperty("test.src", ".") + "/" + pathToStores + + "/" + keyStoreFile; + private static String trustFilename = + System.getProperty("test.src", ".") + "/" + pathToStores + + "/" + trustStoreFile; + + /* + * Main entry point for this test. + */ + public static void main(String args[]) throws Exception { + if (debug) { + System.setProperty("javax.net.debug", "all"); + } + + DebugReportsOneExtraByte test = new DebugReportsOneExtraByte(); + test.runTest(); + + System.out.println("Test Passed."); + } + + /* + * Create an initialized SSLContext to use for these tests. + */ + public DebugReportsOneExtraByte() throws Exception { + + KeyStore ks = KeyStore.getInstance("JKS"); + KeyStore ts = KeyStore.getInstance("JKS"); + + char[] passphrase = "passphrase".toCharArray(); + + ks.load(new FileInputStream(keyFilename), passphrase); + ts.load(new FileInputStream(trustFilename), passphrase); + + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, passphrase); + + TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); + tmf.init(ts); + + SSLContext sslCtx = SSLContext.getInstance("TLS"); + + sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); + + sslc = sslCtx; + } + + /* + * Run the test. + * + * Sit in a tight loop, both engines calling wrap/unwrap regardless + * of whether data is available or not. We do this until both engines + * report back they are closed. + * + * The main loop handles all of the I/O phases of the SSLEngine's + * lifetime: + * + * initial handshaking + * application data transfer + * engine closing + * + * One could easily separate these phases into separate + * sections of code. + */ + private void runTest() throws Exception { + boolean dataDone = false; + + createSSLEngines(); + createBuffers(); + + SSLEngineResult clientResult; // results from client's last operation + SSLEngineResult serverResult; // results from server's last operation + + /* + * Examining the SSLEngineResults could be much more involved, + * and may alter the overall flow of the application. + * + * For example, if we received a BUFFER_OVERFLOW when trying + * to write to the output pipe, we could reallocate a larger + * pipe, but instead we wait for the peer to drain it. + */ + + /* + * Write one byte in first application packet, the rest + * will come later. + */ + serverOut.limit(1); + + while (!isEngineClosed(clientEngine) || + !isEngineClosed(serverEngine)) { + + log("================"); + + clientResult = clientEngine.wrap(clientOut, cTOs); + log("client wrap: ", clientResult); + runDelegatedTasks(clientResult, clientEngine); + + serverResult = serverEngine.wrap(serverOut, sTOc); + log("server wrap: ", serverResult); + runDelegatedTasks(serverResult, serverEngine); + + // Next wrap will split. + if (serverOut.position() == 1) { + serverOut.limit(serverOut.capacity()); + } + + cTOs.flip(); + sTOc.flip(); + + log("----"); + + clientResult = clientEngine.unwrap(sTOc, clientIn); + log("client unwrap: ", clientResult); + runDelegatedTasks(clientResult, clientEngine); + + serverResult = serverEngine.unwrap(cTOs, serverIn); + log("server unwrap: ", serverResult); + runDelegatedTasks(serverResult, serverEngine); + + cTOs.compact(); + sTOc.compact(); + + /* + * After we've transfered all application data between the client + * and server, we close the clientEngine's outbound stream. + * This generates a close_notify handshake message, which the + * server engine receives and responds by closing itself. + */ + if (!dataDone && (clientOut.limit() == serverIn.position()) && + (serverOut.limit() == clientIn.position())) { + + /* + * A sanity check to ensure we got what was sent. + */ + checkTransfer(serverOut, clientIn); + checkTransfer(clientOut, serverIn); + + log("\tClosing clientEngine's *OUTBOUND*..."); + clientEngine.closeOutbound(); + dataDone = true; + } + } + } + + /* + * Using the SSLContext created during object creation, + * create/configure the SSLEngines we'll use for this test. + */ + private void createSSLEngines() throws Exception { + /* + * Configure the serverEngine to act as a server in the SSL/TLS + * handshake. Also, require SSL client authentication. + */ + serverEngine = sslc.createSSLEngine(); + serverEngine.setUseClientMode(false); + serverEngine.setNeedClientAuth(true); + + // Force a block-oriented ciphersuite. + serverEngine.setEnabledCipherSuites( + new String [] {"TLS_RSA_WITH_AES_128_CBC_SHA"}); + + /* + * Similar to above, but using client mode instead. + */ + clientEngine = sslc.createSSLEngine("client", 80); + clientEngine.setUseClientMode(true); + } + + /* + * Create and size the buffers appropriately. + */ + private void createBuffers() { + + /* + * We'll assume the buffer sizes are the same + * between client and server. + */ + SSLSession session = clientEngine.getSession(); + int appBufferMax = session.getApplicationBufferSize(); + int netBufferMax = session.getPacketBufferSize(); + + /* + * We'll make the input buffers a bit bigger than the max needed + * size, so that unwrap()s following a successful data transfer + * won't generate BUFFER_OVERFLOWS. + * + * We'll use a mix of direct and indirect ByteBuffers for + * tutorial purposes only. In reality, only use direct + * ByteBuffers when they give a clear performance enhancement. + */ + clientIn = ByteBuffer.allocate(appBufferMax + 50); + serverIn = ByteBuffer.allocate(appBufferMax + 50); + + cTOs = ByteBuffer.allocateDirect(netBufferMax); + sTOc = ByteBuffer.allocateDirect(netBufferMax); + + // No need to write anything on the client side, it will + // just confuse the output. + clientOut = ByteBuffer.wrap("".getBytes()); + // 10 bytes long + serverOut = ByteBuffer.wrap("Hi Client!".getBytes()); + } + + /* + * If the result indicates that we have outstanding tasks to do, + * go ahead and run them in this thread. + */ + private static void runDelegatedTasks(SSLEngineResult result, + SSLEngine engine) throws Exception { + + if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) { + Runnable runnable; + while ((runnable = engine.getDelegatedTask()) != null) { + log("\trunning delegated task..."); + runnable.run(); + } + HandshakeStatus hsStatus = engine.getHandshakeStatus(); + if (hsStatus == HandshakeStatus.NEED_TASK) { + throw new Exception( + "handshake shouldn't need additional tasks"); + } + log("\tnew HandshakeStatus: " + hsStatus); + } + } + + private static boolean isEngineClosed(SSLEngine engine) { + return (engine.isOutboundDone() && engine.isInboundDone()); + } + + /* + * Simple check to make sure everything came across as expected. + */ + private static void checkTransfer(ByteBuffer a, ByteBuffer b) + throws Exception { + a.flip(); + b.flip(); + + if (!a.equals(b)) { + throw new Exception("Data didn't transfer cleanly"); + } else { + log("\tData transferred cleanly"); + } + + a.position(a.limit()); + b.position(b.limit()); + a.limit(a.capacity()); + b.limit(b.capacity()); + } + + /* + * Logging code + */ + private static boolean resultOnce = true; + + private static void log(String str, SSLEngineResult result) { + if (!logging) { + return; + } + if (resultOnce) { + resultOnce = false; + System.out.println("The format of the SSLEngineResult is: \n" + + "\t\"getStatus() / getHandshakeStatus()\" +\n" + + "\t\"bytesConsumed() / bytesProduced()\"\n"); + } + HandshakeStatus hsStatus = result.getHandshakeStatus(); + log(str + + result.getStatus() + "/" + hsStatus + ", " + + result.bytesConsumed() + "/" + result.bytesProduced() + + " bytes"); + if (hsStatus == HandshakeStatus.FINISHED) { + log("\t...ready for application data"); + } + } + + private static void log(String str) { + if (logging) { + System.out.println(str); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/EngineArgs/DebugReportsOneExtraByte.sh Mon Jan 30 16:27:04 2012 +0000 @@ -0,0 +1,80 @@ +#! /bin/sh + +# +# Copyright (c) 2011, 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 7126889 +# @summary Incorrect SSLEngine debug output +# +# ${TESTJAVA} is pointing to the JDK under test. +# +# set platform-dependent variables + +OS=`uname -s` +case "$OS" in + SunOS ) + PS=":" + FS="/" + ;; + Linux ) + PS=":" + FS="/" + ;; + CYGWIN* ) + PS=";" + FS="/" + ;; + Windows* ) + PS=";" + FS="\\" + ;; + * ) + echo "Unrecognized system!" + exit 1; + ;; +esac + +${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}DebugReportsOneExtraByte.java + +STRING='main, WRITE: TLSv1 Application Data, length = 8' + +echo "Examining debug output for the string:" +echo "${STRING}" +echo "=========" + +${TESTJAVA}${FS}bin${FS}java -Djavax.net.debug=all \ + -Dtest.src=${TESTSRC} \ + DebugReportsOneExtraByte 2>&1 | \ + grep "${STRING}" +RETVAL=$? + +echo "=========" + +if [ ${RETVAL} -ne 0 ]; then + echo "Did NOT see the expected debug output." + exit 1 +else + echo "Received the expected debug output." + exit 0 +fi