Path: blob/master/test/jdk/javax/swing/DataTransfer/8059739/bug8059739.java
41154 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 805973925@summary Dragged and Dropped data is corrupted for two data types26@author Anton Nashatyrev27*/2829import javax.swing.*;30import java.awt.datatransfer.Clipboard;31import java.awt.datatransfer.DataFlavor;32import java.io.BufferedReader;33import java.io.InputStream;34import java.io.InputStreamReader;3536public class bug8059739 {3738private static boolean passed = true;3940public static void main(String[] args) throws Exception {41SwingUtilities.invokeAndWait(new Runnable() {42@Override43public void run() {44try {45runTest();46} catch (Exception e) {47e.printStackTrace();48passed = false;49}50}51});5253if (!passed) {54throw new RuntimeException("Test FAILED.");55} else {56System.out.println("Passed.");57}58}5960private static void runTest() throws Exception {61String testString = "my string";62JTextField tf = new JTextField(testString);63tf.selectAll();64Clipboard clipboard = new Clipboard("clip");65tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);66DataFlavor[] dfs = clipboard.getAvailableDataFlavors();67for (DataFlavor df: dfs) {68String charset = df.getParameter("charset");69if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) &&70charset != null) {71BufferedReader br = new BufferedReader(new InputStreamReader(72(InputStream) clipboard.getData(df), charset));73String s = br.readLine();74System.out.println("Content: '" + s + "'");75passed &= s.contains(testString);76}77}78}79}808182