jdk/test/java/awt/datatransfer/ConstructFlavoredObjectTest/ConstructFlavoredObjectTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 36511 9d0388c6b336
child 42936 2b8cc27c159c
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
import java.awt.Toolkit;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.awt.datatransfer.Clipboard;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.awt.datatransfer.DataFlavor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.awt.datatransfer.SystemFlavorMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.Reader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import javax.swing.JLabel;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import javax.swing.TransferHandler;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 36511
diff changeset
    33
 * @key headful
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @bug 8130329
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 * @summary  Audit Core Reflection in module java.desktop AWT/Miscellaneous area
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 *           for places that will require changes to work with modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * @author Alexander Scherbatiy
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
public class ConstructFlavoredObjectTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
    private static final String TEST_MIME_TYPE = "text/plain;class="
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
            + MyStringReader.class.getName();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        final DataFlavor dataFlavor = new DataFlavor(TEST_MIME_TYPE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        SystemFlavorMap systemFlavorMap = (SystemFlavorMap) SystemFlavorMap.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
                getDefaultFlavorMap();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        systemFlavorMap.addUnencodedNativeForFlavor(dataFlavor, "TEXT");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        systemFlavorMap.addFlavorForUnencodedNative("TEXT", dataFlavor);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        TransferHandler transferHandler = new TransferHandler("Test Handler");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        transferHandler.exportToClipboard(new JLabel("Test"), clipboard,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                TransferHandler.COPY);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Object clipboardData = clipboard.getData(dataFlavor);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        if (!(clipboardData instanceof MyStringReader)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            throw new RuntimeException("Wrong clipboard data!");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    public static class MyStringReader extends Reader {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        public MyStringReader(Reader reader) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        public int read(char[] cbuf, int off, int len) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            throw new UnsupportedOperationException("Not supported yet.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        public void close() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            throw new UnsupportedOperationException("Not supported yet.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
}