Path: blob/master/test/jdk/sun/awt/datatransfer/SuplementaryCharactersTransferTest.java
41152 views
/*1* Copyright (c) 2013, 2015, 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 687749525@summary JTextField and JTextArea does not support supplementary characters26@author Alexander Scherbatiy27@modules java.datatransfer/sun.datatransfer28java.desktop/sun.awt.datatransfer29@run main SuplementaryCharactersTransferTest30*/313233import java.io.*;34import java.util.*;35import java.awt.*;36import java.awt.datatransfer.*;37import sun.awt.datatransfer.*;38import sun.awt.datatransfer.DataTransferer.ReencodingInputStream;39import sun.datatransfer.DataFlavorUtil;4041public class SuplementaryCharactersTransferTest {4243public static final long TEXT_FORMAT = 13;4445public static void main(String[] args) throws Exception {4647DataTransferer dataTransferer = new TestDataTransferer();48dataTransferer.registerTextFlavorProperties("UNICODE TEXT", "utf-16le", "\r\n", "2");49ByteTransferable transferable = new ByteTransferable();50ReencodingInputStream is = dataTransferer.new ReencodingInputStream(transferable.getByteInputStream(), TEXT_FORMAT,51DataFlavorUtil.getTextCharset(transferable.getDataFlavor()), transferable);5253byte[] bytes = transferable.getBytes();54byte[] result = new byte[bytes.length];5556is.read(result);5758for (int i = 0; i < bytes.length; i++) {59if (bytes[i] != result[i]) {60throw new RuntimeException("Characters are not equal!");61}62}6364}6566static class ByteTransferable implements Transferable, ClipboardOwner {6768private final DataFlavor dataFlavor;6970public ByteTransferable() throws Exception {71dataFlavor = DataFlavor.getTextPlainUnicodeFlavor();72}7374public DataFlavor getDataFlavor() {75return dataFlavor;76}7778public DataFlavor[] getTransferDataFlavors() {79return new DataFlavor[]{dataFlavor};80}8182public boolean isDataFlavorSupported(DataFlavor flavor) {83return flavor.equals(dataFlavor);84}8586public byte[] getBytes() {87return new byte[]{97, 0, 64, -40, 32, -36, 98, 0};88}8990public InputStream getByteInputStream() {91return new ByteArrayInputStream(getBytes());92}9394public Object getTransferData(DataFlavor flavor)95throws UnsupportedFlavorException, IOException {96if (flavor.equals(dataFlavor)) {97return getByteInputStream();98} else {99throw new UnsupportedFlavorException(flavor);100}101}102103public void lostOwnership(Clipboard clipboard, Transferable contents) {104}105}106107static class TestDataTransferer extends DataTransferer {108109@Override110public String getDefaultUnicodeEncoding() {111throw new UnsupportedOperationException("Not supported yet.");112}113114@Override115public boolean isLocaleDependentTextFormat(long format) {116return false;117}118119@Override120public boolean isFileFormat(long format) {121throw new UnsupportedOperationException("Not supported yet.");122}123124@Override125public boolean isImageFormat(long format) {126throw new UnsupportedOperationException("Not supported yet.");127}128129@Override130protected Long getFormatForNativeAsLong(String str) {131return TEXT_FORMAT;132}133134@Override135protected String getNativeForFormat(long format) {136throw new UnsupportedOperationException("Not supported yet.");137}138139@Override140protected ByteArrayOutputStream convertFileListToBytes(141ArrayList<String> fileList) throws IOException {142throw new UnsupportedOperationException("Not supported yet.");143}144145@Override146protected String[] dragQueryFile(byte[] bytes) {147throw new UnsupportedOperationException("Not supported yet.");148}149150@Override151protected byte[] imageToPlatformBytes(Image image, long format)152throws IOException {153throw new UnsupportedOperationException("Not supported yet.");154}155156@Override157public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {158throw new UnsupportedOperationException("Not supported yet.");159}160161@Override162protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException {163throw new UnsupportedOperationException("Not supported yet.");164}165}166}167168169170