Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/awt/datatransfer/SuplementaryCharactersTransferTest.java
38839 views
/*1* Copyright (c) 2013, 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@run main SuplementaryCharactersTransferTest28*/293031import java.io.*;32import java.util.*;33import java.awt.*;34import java.awt.datatransfer.*;35import sun.awt.datatransfer.*;36import sun.awt.datatransfer.DataTransferer.ReencodingInputStream;3738public class SuplementaryCharactersTransferTest {3940public static final long TEXT_FORMAT = 13;4142public static void main(String[] args) throws Exception {4344DataTransferer dataTransferer = new TestDataTransferer();45dataTransferer.registerTextFlavorProperties("UNICODE TEXT", "utf-16le", "\r\n", "2");46ByteTransferable transferable = new ByteTransferable();47ReencodingInputStream is = dataTransferer.new ReencodingInputStream(transferable.getByteInputStream(), TEXT_FORMAT,48DataTransferer.getTextCharset(transferable.getDataFlavor()), transferable);4950byte[] bytes = transferable.getBytes();51byte[] result = new byte[bytes.length];5253is.read(result);5455for (int i = 0; i < bytes.length; i++) {56if (bytes[i] != result[i]) {57throw new RuntimeException("Characters are not equal!");58}59}6061}6263static class ByteTransferable implements Transferable, ClipboardOwner {6465private final DataFlavor dataFlavor;6667public ByteTransferable() throws Exception {68dataFlavor = DataFlavor.getTextPlainUnicodeFlavor();69}7071public DataFlavor getDataFlavor() {72return dataFlavor;73}7475public DataFlavor[] getTransferDataFlavors() {76return new DataFlavor[]{dataFlavor};77}7879public boolean isDataFlavorSupported(DataFlavor flavor) {80return flavor.equals(dataFlavor);81}8283public byte[] getBytes() {84return new byte[]{97, 0, 64, -40, 32, -36, 98, 0};85}8687public InputStream getByteInputStream() {88return new ByteArrayInputStream(getBytes());89}9091public Object getTransferData(DataFlavor flavor)92throws UnsupportedFlavorException, IOException {93if (flavor.equals(dataFlavor)) {94return getByteInputStream();95} else {96throw new UnsupportedFlavorException(flavor);97}98}99100public void lostOwnership(Clipboard clipboard, Transferable contents) {101}102}103104static class TestDataTransferer extends DataTransferer {105106@Override107public String getDefaultUnicodeEncoding() {108throw new UnsupportedOperationException("Not supported yet.");109}110111@Override112public boolean isLocaleDependentTextFormat(long format) {113return false;114}115116@Override117public boolean isFileFormat(long format) {118throw new UnsupportedOperationException("Not supported yet.");119}120121@Override122public boolean isImageFormat(long format) {123throw new UnsupportedOperationException("Not supported yet.");124}125126@Override127protected Long getFormatForNativeAsLong(String str) {128return TEXT_FORMAT;129}130131@Override132protected String getNativeForFormat(long format) {133throw new UnsupportedOperationException("Not supported yet.");134}135136@Override137protected ByteArrayOutputStream convertFileListToBytes(138ArrayList<String> fileList) throws IOException {139throw new UnsupportedOperationException("Not supported yet.");140}141142@Override143protected String[] dragQueryFile(byte[] bytes) {144throw new UnsupportedOperationException("Not supported yet.");145}146147@Override148protected byte[] imageToPlatformBytes(Image image, long format)149throws IOException {150throw new UnsupportedOperationException("Not supported yet.");151}152153@Override154public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {155throw new UnsupportedOperationException("Not supported yet.");156}157158@Override159protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException {160throw new UnsupportedOperationException("Not supported yet.");161}162}163}164165