changeset 14833:23520a0d3d88

8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK Reviewed-by: pchelko Contributed-by: Dmitriy Ermashov <dmitriy.ermashov@oracle.com>
author yan
date Fri, 04 Jul 2014 13:40:55 +0400
parents 069ac8d783d8
children 0336e02549c5
files test/java/awt/datatransfer/Clipboard/BasicClipboardTest.java test/java/awt/datatransfer/Clipboard/GetContentsInterruptedTest.java test/java/awt/datatransfer/ImageTransfer/ImageTransferTest.java test/java/awt/datatransfer/Independence/IndependenceAWTTest.java test/java/awt/datatransfer/Independence/IndependenceSwingTest.java test/java/awt/datatransfer/SystemFlavorMap/AddFlavorForNativeTest.java test/java/awt/datatransfer/SystemFlavorMap/AddFlavorTest.java test/java/awt/datatransfer/SystemFlavorMap/AddNativeForFlavorTest.java test/java/awt/datatransfer/SystemFlavorMap/AddNativeTest.java test/java/awt/datatransfer/SystemFlavorMap/GetFlavorsForNewNativeTest.java test/java/awt/datatransfer/SystemFlavorMap/GetNativesForNewFlavorTest.java test/java/awt/datatransfer/SystemFlavorMap/InvalidMapArgumentsTest.java test/java/awt/datatransfer/SystemFlavorMap/ManyFlavorMapTest.java test/java/awt/datatransfer/SystemFlavorMap/SetDataFlavorsTest.java test/java/awt/datatransfer/SystemFlavorMap/SetFlavorsForNativeTest.java test/java/awt/datatransfer/SystemFlavorMap/SetNativesForFlavor.java test/java/awt/datatransfer/SystemFlavorMap/SetNativesTest.java test/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java test/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java
diffstat 19 files changed, 2962 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/Clipboard/BasicClipboardTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2002, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.*;
+
+/*
+ * @test
+ * @summary To test the basic Clipboard functions
+ * @author Kanishk Jethi (kanishk.jethi@sun.com) area=Clipboard
+ * @run main BasicClipboardTest
+ */
+
+public class BasicClipboardTest implements ClipboardOwner {
+
+    StringSelection strSelect = new StringSelection("Transferable String Selection");
+    StringSelection strCheck;
+    String clipName = "Test Clipboard";
+    Clipboard clip = new Clipboard(clipName);
+    DataFlavor dataFlavor, testDataFlavor ;
+    DataFlavor dataFlavorArray[];
+    Object testObject;
+    String strTest = null;
+
+    public static void main (String[] args) throws Exception {
+        new BasicClipboardTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        dataFlavor = new DataFlavor(DataFlavor.javaRemoteObjectMimeType, null, this.getClass().getClassLoader());
+        // test for null return of selectBestTextFlavor if input is null or
+        // of zero length
+        testDataFlavor = DataFlavor.selectBestTextFlavor(dataFlavorArray);
+        if (testDataFlavor != null)
+            throw new RuntimeException("\n***Error in selectBestTextFlavor");
+
+        dataFlavorArray = new DataFlavor[0];
+
+        testDataFlavor = DataFlavor.selectBestTextFlavor(dataFlavorArray);
+        if (testDataFlavor != null)
+            throw new RuntimeException("\n***Error in selectBestTextFlavor");
+
+        // test for null return when there are no text flavors in array
+        dataFlavorArray = new DataFlavor[1];
+        dataFlavorArray[0] = new DataFlavor(DataFlavor.javaSerializedObjectMimeType + ";class=java.io.Serializable");
+
+        testDataFlavor = DataFlavor.selectBestTextFlavor(dataFlavorArray);
+        if (testDataFlavor != null)
+            throw new RuntimeException("\n***Error in selectBestTextFlavor");
+
+        if (clip.getName() != clipName)
+            throw new RuntimeException("\n*** Error in Clipboard.getName()");
+
+        // set the owner of the clipboard to null to check branch coverage
+        // of the setContents method
+        clip.setContents(null, null);
+
+        //set the owner of the clipboard to something valid to check branch
+        //coverage of the setContents method
+        clip.setContents(null, new BasicClipboardTest());
+
+        //set the owner of the clipboard to this to check branch coverage
+        // of the setContents method
+        clip.setContents(null, this);
+
+        //set the contents of the clipboard
+        clip.setContents(strSelect, this);
+
+        //get the contents of the clipboard
+        strCheck = (StringSelection)clip.getContents(this);
+        if (!strCheck.equals(strSelect))
+            throw new RuntimeException("\n***The contents of the clipboard are "
+            + "not the same as those that were set");
+
+        //Check if getReaderForText throws IAE when the Transferable has
+        //null TransferData
+        dataFlavor = DataFlavor.stringFlavor;
+        strSelect = new StringSelection(null);
+        try {
+            testObject = dataFlavor.getReaderForText(strSelect);
+            throw new RuntimeException("\n***Error in getReaderForText. An IAE should have been thrown");
+        } catch (IllegalArgumentException iae) {
+            // do nothing as this is expected
+        }
+
+        //Check getParameter
+        dataFlavor.setHumanPresentableName("String Flavor");
+        if (!(dataFlavor.getParameter("humanPresentableName")).equals("String Flavor"))
+            throw new RuntimeException("\n***Error in getParameter");
+
+        //Check equals
+        try {
+            if (dataFlavor.isMimeTypeEqual(strTest))
+                throw new RuntimeException("\n***Error in DataFlavor.equals(String s)");
+        } catch (NullPointerException e) {
+            //do nothing as it is expected
+        }
+
+        if (!(dataFlavor.isMimeTypeEqual(dataFlavor.getMimeType())))
+            throw new RuntimeException("\n***Error in DataFlavor.equals(String s)");
+
+        //Check isMimeTypeSerializedObject
+        if (!dataFlavorArray[0].isMimeTypeSerializedObject())
+            throw new RuntimeException("\n***Error in isMimeTypeSerializedObject()");
+        System.out.println(dataFlavorArray[0].getDefaultRepresentationClass());
+        System.out.println(dataFlavorArray[0].getDefaultRepresentationClassAsString());
+        //Check isFlavorRemoteObjectType
+        if (dataFlavor.isFlavorRemoteObjectType())
+            System.out.println("The DataFlavor is a remote object type");
+
+        //Check clone()
+        testDataFlavor = (DataFlavor)dataFlavor.clone();
+    }
+
+    public void lostOwnership (Clipboard clipboard, Transferable contents) { }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/Clipboard/GetContentsInterruptedTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+/*
+ * @test
+ * @bug 4532299 4648733
+ * @summary Tests that getting clipboard contents on the interrupted thread will
+ *          not cause deadlock.Also check that lostOwnership event occurs while
+ *          cross-JVM interaction
+ * @author Kanishk Jethi
+ * @run main GetContentsInterruptedTest
+ */
+
+public class GetContentsInterruptedTest implements ClipboardOwner {
+
+    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+    final Transferable transferable = new StringSelection("TEXT");
+    private final Object o = new Object();
+
+    public static void main(String args[]) throws Exception {
+        if (System.getProperty("os.name").startsWith("Mac")) {
+            System.out.println("This tests should not be run on OS X. " +
+                    "See CR 7124344 for more info");
+        } else {
+            boolean subTestFlag = false;
+            for (String arg : args) {
+                if (arg.indexOf("SubTest") != -1)
+                    subTestFlag = true;
+            }
+
+            if (!subTestFlag) {
+                new GetContentsInterruptedTest().performTest();
+            } else {
+                new GetContentsInterruptedTest().execute();
+            }
+        }
+    }
+
+    private void performTest() throws Exception {
+        int retCode;
+        String javaPath = System.getProperty("java.home", "");
+        String javaClasspath = System.getProperty("java.class.path", ".");
+        String command = javaPath + File.separator + "bin" +
+            File.separator + "java -classpath " + javaClasspath +
+            " GetContentsInterruptedTest SubTest";
+        System.out.println(command);
+        boolean processExit = false;
+
+        clipboard.setContents(transferable, this);
+        Process process = Runtime.getRuntime().exec(command);
+        synchronized (o) {
+            o.wait(10000);
+        }
+
+        try {
+            retCode = process.exitValue();
+            processExit = true;
+        }catch (IllegalThreadStateException e){
+            throw new RuntimeException(e);
+        }
+        System.out.println("[RESULT] : " +
+                "The sub process has cleanly exited : PASS");
+
+        System.out.println("[RESULT] : Child returned: " + retCode );
+
+        InputStream errorStream = process.getErrorStream();
+        System.out.println("========= Child process stderr ========");
+        dumpStream(errorStream);
+        System.out.println("=======================================");
+
+        InputStream processInputStream = process.getInputStream();
+        System.out.println("========= Child process output ========");
+        dumpStream(processInputStream);
+        System.out.println("=======================================");
+
+        if (!processExit) {
+            process.destroy();
+            throw new RuntimeException("[RESULT] : " +
+                    "The sub process has not exited : FAIL");
+        }
+    }
+
+    /*
+     * execute is run through another instance of this class.
+     * it acquires the systemClipboard through another JVM.
+     */
+    public void execute() {
+        System.out.println("Hello world");
+        final ClipboardOwner clipboardOwner = new ClipboardOwner() {
+            public void lostOwnership(Clipboard clipboard, Transferable contents) {
+                System.exit(0);
+            }
+        };
+        clipboard.setContents(transferable, clipboardOwner);
+        synchronized (o) {
+            try {
+                o.wait();
+            } catch (InterruptedException ie) {
+                ie.printStackTrace();
+            }
+        }
+    }
+
+    public void dumpStream(InputStream in) throws IOException {
+        String tempString;
+        int count = in.available();
+        while (count > 0) {
+            byte[] b = new byte[count];
+            in.read(b);
+            tempString = new String(b);
+            if (tempString.indexOf("Exception") != -1 )
+                throw new RuntimeException("[RESULT] :" +
+                        " Exception in child process : FAIL");
+            System.out.println(tempString);
+            count = in.available();
+        }
+    }
+
+    public void lostOwnership(Clipboard clip, Transferable contents) {
+        new Thread(() -> {
+            try {
+                Thread.sleep(3000);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+            clipboard.getContents(null);
+            Thread.currentThread().interrupt();
+            clipboard.getContents(null);
+            clipboard.setContents(transferable, null);
+        }).start();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/ImageTransfer/ImageTransferTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To check Whether java.awt.Image can be transferred through the
+ *          system clipboard
+ * @author Jitender(jitender.singh@eng.sun.com) area=AWT
+ * @author dmitriy.ermashov@oracle.com
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main ImageTransferTest
+ */
+
+public class ImageTransferTest  {
+
+    TestFrame frame1, frame2;
+    Image image1, image2;
+    DataFlavor imageFlavor;
+
+    public static void main(String[] args) throws Exception {
+        new ImageTransferTest().doTest();
+    }
+
+    class TestFrame extends Frame {
+        boolean show;
+        Image img;
+        public TestFrame(boolean show, Image img){
+            this.show = show;
+            this.img = img;
+        }
+
+        public void paint( Graphics g ){
+            if (show)
+                g.drawImage( this.img, 30, 30, this );
+        }
+    }
+
+    class TransferableObject implements Transferable, ClipboardOwner {
+
+        Object data;
+        DataFlavor[] dfs;
+
+        public TransferableObject(Object data) throws Exception {
+            Vector v = new Vector();
+            imageFlavor = new DataFlavor("image/x-java-Image;class=java.awt.Image");
+            imageFlavor.setHumanPresentableName("Java Image Flavor Object");
+
+            if( data instanceof java.awt.Image )
+                v.addElement(imageFlavor);
+
+            dfs = new DataFlavor[v.size()];
+            v.copyInto(dfs);
+
+            for (int j = 0; j < dfs.length; j++)
+                System.out.println(" in constructor flavor : " + dfs[j]);
+
+            this.data = data;
+        }
+
+        public Object getTransferData(DataFlavor flavor)
+                throws UnsupportedFlavorException,IOException {
+
+            System.out.println(" **************");
+            System.out.println(" The flavor passed to retrive the data :-" + flavor);
+            System.out.println(" The flavors supported");
+            for (int j = 0; j < dfs.length; j++)
+                System.out.println(" jitu flavor : " + dfs[j]);
+
+            System.out.println(" **************");
+
+            if(!isDataFlavorSupported(flavor))
+                throw new UnsupportedFlavorException(flavor);
+
+            if(imageFlavor.equals(flavor)){
+                if( data instanceof java.awt.Image )
+                    return data;
+            }
+            return null;
+
+        }
+
+        public DataFlavor[] getTransferDataFlavors() { return dfs; }
+
+        public boolean isDataFlavorSupported(DataFlavor flavor) {
+            for (int i = 0 ; i < dfs.length; i++)
+                if (dfs[i].match(flavor)) return true;
+            return false;
+        }
+
+        public void lostOwnership(Clipboard clip,Transferable contents) {
+            System.out.println(" LostOwnership is invoked");
+        }
+    }
+
+    ImageTransferTest() throws Exception {
+        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
+        Graphics g = img.createGraphics();
+        g.setColor(Color.WHITE);
+        g.fillRect(0, 0, 100, 100);
+        g.setColor(Color.RED);
+        g.fillRect(20, 20, 60, 60);
+        g.dispose();
+
+        image1 = img;
+        frame1 = new TestFrame(true, image1);
+        frame2 = new TestFrame(false, null);
+
+        System.out.println("Inside contrucor...");
+
+        imageFlavor = new DataFlavor("image/x-java-Image;class=java.awt.Image");
+        imageFlavor.setHumanPresentableName("Java Image Flavor Object");
+
+        frame1.setBounds(10,350,200,200);
+        frame2.setBounds(250,350,200,200);
+        frame1.setVisible(true);
+        frame2.setVisible(true);
+        frame1.repaint();
+    }
+
+    public void compareImages() {
+        if (image2 == image1)
+            System.out.println("Pasted Image is same as that one copied !");
+        else
+            if (image2 != image1)
+                throw new RuntimeException("Image retreived from the Clipboard is not the same " +
+                        "image that was set to the Clipboard");
+    }
+
+
+    public void doTest() throws Exception {
+        ExtendedRobot robot = new ExtendedRobot();
+        robot.waitForIdle(2000);
+        TransferableObject imagedata = new TransferableObject(image1);
+
+        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
+        System.out.println("copying image...");
+        if (imagedata != null) {
+            clip.setContents(imagedata, imagedata);
+        } else {
+            System.out.println("Transferable object is null");
+        }
+
+        Transferable content = clip.getContents(this);
+        if (content != null && (content.isDataFlavorSupported(imageFlavor))) {
+            System.out.println("jitu after paste" + content);
+            image2 = (Image) content.getTransferData(imageFlavor);
+        } else {
+            System.out.println("Contents of the clipboard is null");
+        }
+
+        frame2.img = image2;
+        frame2.show = true;
+        frame2.repaint();
+
+        robot.waitForIdle(2000);
+
+        compareImages();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/Independence/IndependenceAWTTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.event.*;
+import java.util.Properties;
+
+/*
+ * @test
+ * @summary To make sure that System & Primary clipboards should behave independently
+ * @author Jitender(jitender.singh@eng.sun.com) area=AWT
+ * @author dmitriy.ermashov@oracle.com
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main IndependenceAWTTest
+ */
+
+public class IndependenceAWTTest {
+
+    Frame frame;
+    Panel panel;
+    TextField tf1, tf2, tf3;
+    Clipboard sClip, pClip;
+
+    public static void main (String[] args) throws Exception {
+        new IndependenceAWTTest().doTest();
+    }
+
+    public IndependenceAWTTest() {
+
+        frame = new Frame();
+        frame.setSize(200, 200);
+
+        // This textfield will be used to update the contents of clipboards
+        tf1 = new TextField();
+        tf1.addFocusListener(new FocusAdapter() {
+            public void focusGained(FocusEvent fe) {
+                tf1.setText("Clipboards_Independance_Testing");
+            }
+        });
+
+        // TextFields to get the contents of clipboard
+        tf2 = new TextField();
+        tf3 = new TextField();
+
+        panel = new Panel();
+        panel.setLayout(new BorderLayout());
+
+        panel.add(tf2, BorderLayout.NORTH);
+        panel.add(tf3, BorderLayout.SOUTH);
+
+        frame.add(tf1, BorderLayout.NORTH);
+        frame.add(panel, BorderLayout.CENTER);
+
+        frame.setVisible(true);
+        tf1.requestFocus();
+    }
+
+    public void checkSecurity() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm == null)  {
+            System.out.println("security manager is not there");
+            getPrimaryClipboard();
+        } else {
+            sm.checkPermission(new AWTPermission("accessClipboard"));
+            getPrimaryClipboard();
+        }
+    }
+
+    // Get System Selection i.e. Primary Clipboard
+    private void getPrimaryClipboard() {
+        Properties ps = System.getProperties();
+        String operSys = ps.getProperty("os.name");
+        try {
+            pClip = Toolkit.getDefaultToolkit().getSystemSelection();
+            if (pClip == null)
+                if ((operSys.substring(0,3)).equalsIgnoreCase("Win") || operSys.toLowerCase().contains("os x"))
+                    System.out.println(operSys + "Operating system does not support system selection ");
+                else
+                    throw new RuntimeException("Method getSystemSelection() is returning null on X11 platform");
+        } catch(HeadlessException e) {
+            System.out.println("Headless exception thrown " + e);
+        }
+    }
+
+    // Method to get the contents of both of the clipboards
+    public void getClipboardsContent() throws Exception {
+        sClip = Toolkit.getDefaultToolkit().getSystemClipboard();
+        Transferable tp;
+        Transferable ts;
+
+        StringSelection content = new StringSelection(tf1.getText());
+        sClip.setContents(content,content);
+
+        tp = pClip.getContents(this);
+        ts = sClip.getContents(this);
+
+        // Paste the contents of System clipboard on textfield tf2 while the paste the contents of
+        // of primary clipboard on textfiled tf3
+        if ((ts != null) && (ts.isDataFlavorSupported(DataFlavor.stringFlavor))) {
+            tf2.setBackground(Color.white);
+            tf2.setForeground(Color.black);
+            tf2.setText((String) ts.getTransferData(DataFlavor.stringFlavor));
+        }
+
+        if ((tp != null) && (tp.isDataFlavorSupported(DataFlavor.stringFlavor))) {
+            tf3.setBackground(Color.white);
+            tf3.setForeground(Color.black);
+            tf3.setText((String) tp.getTransferData(DataFlavor.stringFlavor));
+        }
+    }
+
+    // Method to compare the Contents return by system & primary clipboard
+    public void compareText (boolean mustEqual) {
+        if ((tf2.getText()).equals(tf3.getText())) {
+            if (mustEqual)
+                System.out.println("Selected text & clipboard contents are same\n");
+            else
+                throw new RuntimeException("Selected text & clipboard contents are same\n");
+        } else {
+            if (mustEqual)
+                throw new RuntimeException("Selected text & clipboard contents differs\n");
+            else
+                System.out.println("Selected text & clipboard contents differs\n");
+        }
+    }
+
+    public void doTest() throws Exception {
+        checkSecurity();
+        ExtendedRobot robot = new ExtendedRobot();
+        robot.waitForIdle(1000);
+        frame.setLocation(100, 100);
+        robot.waitForIdle(1000);
+
+        if (pClip != null) {
+            Point ttf1Center = tf1.getLocationOnScreen();
+            ttf1Center.translate(tf1.getWidth()/2, tf1.getHeight()/2);
+
+            robot.glide(new Point(0, 0), ttf1Center);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardsContent();
+            compareText(true);
+
+            //Change the text selection to update the contents of primary clipboard
+            robot.mouseMove(ttf1Center);
+            robot.mousePress(MouseEvent.BUTTON1_MASK);
+            robot.delay(200);
+            robot.mouseMove(ttf1Center.x + 15, ttf1Center.y);
+            robot.mouseRelease(MouseEvent.BUTTON1_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardsContent();
+            compareText(false);
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/Independence/IndependenceSwingTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.util.Properties;
+
+/*
+ * @test
+ * @summary To make sure that System & Primary clipboards should behave independently
+ * @author Jitender(jitender.singh@eng.sun.com) area=AWT
+ * @author dmitriy.ermashov@oracle.com
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main IndependenceSwingTest
+ */
+
+public class IndependenceSwingTest {
+
+    JFrame frame;
+    JPanel panel;
+    JTextField tf1, tf2, tf3;
+    Clipboard sClip, pClip;
+
+    public static void main (String[] args) throws Exception {
+        new IndependenceSwingTest().doTest();
+    }
+
+    public IndependenceSwingTest() {
+
+        frame = new JFrame();
+        frame.setSize(200, 200);
+
+        // This textfield will be used to update the contents of clipboards
+        tf1 = new JTextField();
+        tf1.addFocusListener(new FocusAdapter() {
+            public void focusGained(FocusEvent fe) {
+                tf1.setText("Clipboards_Independance_Testing");
+            }
+        });
+
+        // TextFields to get the contents of clipboard
+        tf2 = new JTextField();
+        tf3 = new JTextField();
+
+        panel = new JPanel();
+        panel.setLayout(new BorderLayout());
+
+        panel.add(tf2, BorderLayout.NORTH);
+        panel.add(tf3, BorderLayout.SOUTH);
+
+        frame.add(tf1, BorderLayout.NORTH);
+        frame.add(panel, BorderLayout.CENTER);
+
+        frame.setVisible(true);
+        tf1.requestFocus();
+    }
+
+    public void checkSecurity() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm == null)  {
+            System.out.println("security manager is not there");
+            getPrimaryClipboard();
+        } else {
+            sm.checkPermission(new AWTPermission("accessClipboard"));
+            getPrimaryClipboard();
+        }
+    }
+
+    // Get System Selection i.e. Primary Clipboard
+    private void getPrimaryClipboard() {
+        Properties ps = System.getProperties();
+        String operSys = ps.getProperty("os.name");
+        try {
+            pClip = Toolkit.getDefaultToolkit().getSystemSelection();
+            if (pClip == null)
+                if ((operSys.substring(0,3)).equalsIgnoreCase("Win") || operSys.toLowerCase().contains("os x"))
+                    System.out.println(operSys + "Operating system does not support system selection ");
+                else
+                    throw new RuntimeException("Method getSystemSelection() is returning null on X11 platform");
+        } catch(HeadlessException e) {
+            System.out.println("Headless exception thrown " + e);
+        }
+    }
+
+    // Method to get the contents of both of the clipboards
+    public void getClipboardsContent() throws Exception {
+        sClip = Toolkit.getDefaultToolkit().getSystemClipboard();
+        Transferable tp;
+        Transferable ts;
+
+        StringSelection content = new StringSelection(tf1.getText());
+        sClip.setContents(content,content);
+
+        tp = pClip.getContents(this);
+        ts = sClip.getContents(this);
+
+        // Paste the contents of System clipboard on textfield tf2 while the paste the contents of
+        // of primary clipboard on textfiled tf3
+        if ((ts != null) && (ts.isDataFlavorSupported(DataFlavor.stringFlavor))) {
+            tf2.setBackground(Color.white);
+            tf2.setForeground(Color.black);
+            tf2.setText((String) ts.getTransferData(DataFlavor.stringFlavor));
+        }
+
+        if ((tp != null) && (tp.isDataFlavorSupported(DataFlavor.stringFlavor))) {
+            tf3.setBackground(Color.white);
+            tf3.setForeground(Color.black);
+            tf3.setText((String) tp.getTransferData(DataFlavor.stringFlavor));
+        }
+    }
+
+    // Method to compare the Contents return by system & primary clipboard
+    public void compareText (boolean mustEqual) {
+        if ((tf2.getText()).equals(tf3.getText())) {
+            if (mustEqual)
+                System.out.println("Selected text & clipboard contents are same\n");
+            else
+                throw new RuntimeException("Selected text & clipboard contents are same\n");
+        } else {
+            if (mustEqual)
+                throw new RuntimeException("Selected text & clipboard contents differs\n");
+            else
+                System.out.println("Selected text & clipboard contents differs\n");
+        }
+    }
+
+    public void doTest() throws Exception {
+        checkSecurity();
+        ExtendedRobot robot = new ExtendedRobot();
+        robot.waitForIdle(1000);
+        frame.setLocation(100, 100);
+        robot.waitForIdle(1000);
+
+        if (pClip != null) {
+            Point ttf1Center = tf1.getLocationOnScreen();
+            ttf1Center.translate(tf1.getWidth()/2, tf1.getHeight()/2);
+
+            robot.glide(new Point(0, 0), ttf1Center);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardsContent();
+            compareText(true);
+
+            //Change the text selection to update the contents of primary clipboard
+            robot.mouseMove(ttf1Center);
+            robot.mousePress(MouseEvent.BUTTON1_MASK);
+            robot.delay(200);
+            robot.mouseMove(ttf1Center.x + 15, ttf1Center.y);
+            robot.mouseRelease(MouseEvent.BUTTON1_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardsContent();
+            compareText(false);
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/AddFlavorForNativeTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          addFlavorForUnencodedNative(String nat, DataFlavor flav)
+ *          with valid natives and DataFlavors. Specifically test for
+ *          adding new mappings, one-way and two-way, and to update
+ *          existing mappings.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main AddFlavorForNativeTest
+ */
+
+public class AddFlavorForNativeTest {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3;
+    Hashtable hash;
+    int hashSize;
+
+    String test_native;
+    String[] test_natives_set;
+    DataFlavor test_flavor1, test_flavor2, test_flavor3, test_flavor4;
+    DataFlavor[] test_flavors_set1, test_flavors_set2;
+
+    public static void main(String[] args) throws Exception {
+        new AddFlavorForNativeTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // Setup One-way Mappings
+        System.out.println("One-way Mappings Test");
+        flavorMap.addFlavorForUnencodedNative(test_native, test_flavor1);
+        flavorMap.addFlavorForUnencodedNative(test_native, test_flavor2);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set1));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After setting up one-way mapping" +
+                "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("One-way: Test Passes");
+
+        // Setup Two-way Mapping
+        System.out.println("Two-way Mappings Test");
+        flavorMap.addUnencodedNativeForFlavor(test_flavor1, test_native);
+        flavorMap.addUnencodedNativeForFlavor(test_flavor2, test_native);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+        comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (String native): Test Passes");
+
+        // Check first native mapping
+        comp1 = new Vector(Arrays.asList(test_flavors_set1));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (DataFlavor): Test Passes");
+
+        // Modify an existing mapping test
+        System.out.println("Modify Existing Mappings Test");
+        flavorMap.addFlavorForUnencodedNative(test_native, test_flavor3);
+        flavorMap.addFlavorForUnencodedNative(test_native, test_flavor4);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set2));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After modifying an existing mapping" +
+                "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\nupdated mappings.");
+        } else
+           System.out.println("Modify Existing Mappings: Test Passes");
+    }
+
+    public void initMappings() throws Exception {
+      //create String natives
+      test_native = "TEST1";
+
+      test_flavor1 = new DataFlavor(Class.forName("java.awt.Label"), "test1");
+      test_flavor2 = new DataFlavor(Class.forName("java.awt.Button"), "test2");
+      test_flavor3 = new DataFlavor(Class.forName("java.awt.Checkbox"), "test3");
+      test_flavor4 = new DataFlavor(Class.forName("java.awt.List"), "test4");
+
+      //create and initialize DataFlavor arrays
+      test_flavors_set1 = new DataFlavor[] {test_flavor1, test_flavor2};
+      test_flavors_set2 = new DataFlavor[] {test_flavor1, test_flavor2, test_flavor3, test_flavor4};
+
+      //create and initialize String native arrays
+      test_natives_set = new String[] {test_native};
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/AddFlavorTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 sun.awt.datatransfer.DataTransferer;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.*;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method:
+ *          addFlavorForUnencodedNative(String nat, DataFlavor flav)
+ *          with valid natives and DataFlavors. This stress test will
+ *          define numerous mappings of valid String natives and
+ *          DataFlavors.  The mappings will be verified by examining
+ *          that all entries are present, and order is maintained.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @author dmitriy.ermashov@oracle.com
+ * @run main AddFlavorTest
+ */
+
+public class AddFlavorTest {
+
+    SystemFlavorMap flavorMap;
+    Hashtable<String, List<DataFlavor>> hashVerify;
+
+    public static void main (String[] args) throws Exception {
+        new AddFlavorTest().doTest();
+    }
+
+    void doTest() throws Exception {
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Test addFlavorForUnencodedNative(String nat, DataFlavor flav);
+        //
+        // Enumerate through all the system defined String natives,
+        // and for each String native, define it again to the SystemFlavorMap
+        // with a slightly modified String native (name).
+        //
+        // As a list of DataFlavors will be returned for each String native,
+        // the method addFlavorForUnencodedNative will be called for each
+        // DataFlavor in the list.
+        hashVerify = new Hashtable();
+
+        for (String key : flavorMap.getFlavorsForNatives(null).keySet()) {
+            Set<DataFlavor> flavorsSet = new HashSet<>(flavorMap.getFlavorsForNative(key));
+            // construct a unique String native
+            key = key.concat("TEST");
+
+            for (DataFlavor element : flavorsSet)
+                flavorMap.addFlavorForUnencodedNative(key, element);
+
+            // This part is valid only for X-based graphical systems
+            if (!System.getProperty("os.name").startsWith("Win") && !System.getProperty("os.name").startsWith("Mac") ) {
+                if (key.contains("/")) {
+                    Set<DataFlavor> fls = DataTransferer.getInstance().getPlatformMappingsForNative(key);
+                    flavorsSet.addAll(fls);
+                    if (!fls.isEmpty() && key.startsWith("text/"))
+                        flavorsSet.addAll(convertMimeTypeToDataFlavors(key));
+                }
+            }
+            hashVerify.put(key, new Vector(flavorsSet));
+        }
+
+        // Assertions: After establishing "new" mappings, verify that the defined
+        //             DataFlavors can be retrieved and that the List is preserved.
+        verifyNewMappings();
+    }
+
+    // Verify getFlavorsForNative(String nat) is returning the correct list
+    // of DataFlavors (for the new mappings).
+    void verifyNewMappings() {
+        // Enumerate through all natives
+        System.out.println("*** native size = " + hashVerify.size());
+        for (Enumeration e = hashVerify.keys() ; e.hasMoreElements() ;) {
+            String key = (String)e.nextElement();
+            compareFlavors(hashVerify.get(key), flavorMap.getFlavorsForNative(key), key);
+            compareFlavors(flavorMap.getFlavorsForNative(key), hashVerify.get(key), key);
+        }
+    }
+
+    void compareFlavors(List<DataFlavor> flavors1, List<DataFlavor> flavors2, String key){
+        DataTransferer.DataFlavorComparator comparator = new DataTransferer.DataFlavorComparator();
+        for (DataFlavor flavor1 : flavors1) {
+            boolean result = false;
+            for (DataFlavor flavor2 : flavors2) {
+                if (comparator.compare(flavor1, flavor2) == 0)
+                    result = true;
+            }
+            if (!result)
+                throw new RuntimeException("\n*** Error in verifyNewMappings()" +
+                        "\nmethod1: addFlavorForUnencodedNative(String nat, DataFlavor flav)"  +
+                        "\nmethod2: List getFlavorsForNative(String nat)" +
+                        "\nString native: " + key +
+                        "\nAfter adding several mappings with addFlavorForUnencodedNative," +
+                        "\nthe returned list did not match the mappings that were added." +
+                        "\nEither the mapping was not included in the list, or the order was incorect.");
+        }
+
+    }
+
+    Set<DataFlavor> convertMimeTypeToDataFlavors(String baseType) throws Exception {
+        Set<DataFlavor> result = new LinkedHashSet<>();
+
+        for (String charset : DataTransferer.standardEncodings()) {
+            for (String txtClass : new String[]{"java.io.InputStream", "java.nio.ByteBuffer", "\"[B\""}) {
+                String mimeType = baseType + ";charset=" + charset + ";class=" + txtClass;
+
+                if ("text/html".equals(baseType)) {
+                    for (String documentType : new String[]{"all", "selection", "fragment"})
+                        result.add(new DataFlavor(mimeType + ";document=" + documentType));
+                } else {
+                    DataFlavor df = new DataFlavor(mimeType);
+                    if (df.equals(DataFlavor.plainTextFlavor))
+                        df = DataFlavor.plainTextFlavor;
+                    result.add(df);
+                }
+            }
+        }
+        return result;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/AddNativeForFlavorTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          addUnencodedNativeForFlavor(DataFlavor flav, String nat)
+ *          with valid natives and DataFlavors. Specifically test for
+ *          adding new mappings, one-way and two-way, and to update
+ *          existing mappings.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main AddNativeForFlavorTest
+ */
+
+public class AddNativeForFlavorTest {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3;
+    Hashtable hash;
+    int hashSize;
+
+    String test_native1, test_native2, test_native3, test_native4;
+    String[] test_natives_set1, test_natives_set2;
+    DataFlavor test_flav;
+    DataFlavor[] test_flavors_set;
+
+    public static void main(String[] args) throws Exception {
+        new AddNativeForFlavorTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // Setup One-way Mappings
+        System.out.println("One-way Mappings Test");
+        flavorMap.addUnencodedNativeForFlavor(test_flav, test_native1);
+        flavorMap.addUnencodedNativeForFlavor(test_flav, test_native2);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set1));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After setting up one-way mapping" +
+                "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("One-way: Test Passes");
+
+        // Setup Two-way Mapping
+        System.out.println("Two-way Mappings Test");
+        flavorMap.addFlavorForUnencodedNative(test_native1, test_flav);
+        flavorMap.addFlavorForUnencodedNative(test_native2, test_flav);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+        comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (DataFlavor): Test Passes");
+
+        // Check first native mapping
+        comp1 = new Vector(Arrays.asList(test_natives_set1));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (String native): Test Passes");
+
+        // Modify an existing mapping test
+        System.out.println("Modify Existing Mappings Test");
+        flavorMap.addUnencodedNativeForFlavor(test_flav, test_native3);
+        flavorMap.addUnencodedNativeForFlavor(test_flav, test_native4);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set2));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));
+
+        if ( !comp1.equals(comp2)) {
+            throw new RuntimeException("\n*** After modifying an existing mapping" +
+                "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\nupdated mappings.");
+        }
+        else
+           System.out.println("Modify Existing Mappings: Test Passes");
+
+    }
+
+    public void initMappings() throws Exception {
+      //create String natives
+      test_native1 = "TEST1";
+      test_native2 = "TEST2";
+      test_native3 = "TEST3";
+      test_native4 = "TEST4";
+
+      test_flav = new DataFlavor(Class.forName("java.awt.Label"), "test1");
+
+      //create and initialize DataFlavor arrays
+      test_flavors_set = new DataFlavor[] {test_flav};
+
+      //create and initialize String native arrays
+      test_natives_set1 = new String[] {test_native1, test_native2};
+      test_natives_set2 = new String[] {test_native1, test_native2, test_native3, test_native4};
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/AddNativeTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.*;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method:
+ *          addUnencodedNativeForFlavor(DataFlavor flav, String nat)
+ *          with valid natives and DataFlavors. This stress test will
+ *          define numerous mappings of valid String natives and
+ *          DataFlavors.  The mappings will be verified by examining
+ *          that all entries are present.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main AddNativeTest
+ */
+
+public class AddNativeTest {
+
+    SystemFlavorMap flavorMap;
+    Hashtable hashVerify;
+
+    Map mapFlavors;
+    Map mapNatives;
+
+    Hashtable hashFlavors;
+    Hashtable hashNatives;
+
+    public static void main(String[] args) {
+        new AddNativeTest().doTest();
+    }
+
+    public void doTest() {
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get SystemFlavorMap Maps of String Natives and DataFlavors
+        mapFlavors = flavorMap.getNativesForFlavors(null);
+        mapNatives = flavorMap.getFlavorsForNatives(null);
+
+        hashFlavors = new Hashtable(mapFlavors);
+        hashNatives = new Hashtable(mapNatives);
+
+        // Test addUnencodedNativeForFlavor(DataFlavor flav, String nat);
+        //
+        // Enumerate through all the system defined DataFlavors,
+        // and for each DataFlavor, define it again to the SystemFlavorMap
+        // with a slightly modified Mime Type.
+        //
+        // As a list of String natives will be returned for each DataFlavor,
+        // the method addUnencodedNativeForFlavor will be called for each
+        // String native in the list.
+        //
+        // For verification, a seperate Hashtable (Map) will be maintained with changes.
+        DataFlavor key;
+        hashVerify = new Hashtable();
+
+        for (Enumeration e = hashFlavors.keys() ; e.hasMoreElements() ;) {
+            key = (DataFlavor)e.nextElement();
+
+            java.util.List listNatives = flavorMap.getNativesForFlavor(key);
+            Vector vectorNatives = new Vector(listNatives);
+
+            // Construct a new DataFlavor from an existing DataFlavor's MimeType
+            // Example:
+            // Original MimeType: "text/plain; class=java.io.Reader; charset=Unicode"
+            // Modified MimeType: "text/plain-TEST; class=java.io.Reader; charset=Unicode"
+
+            StringBuffer mimeType = new StringBuffer(key.getMimeType());
+            mimeType.insert(mimeType.indexOf(";"),"-TEST");
+
+            DataFlavor testFlavor = new DataFlavor(mimeType.toString(), "Test DataFlavor");
+
+            for (ListIterator i = vectorNatives.listIterator() ; i.hasNext() ;) {
+                String element = (String)i.next();
+                flavorMap.addUnencodedNativeForFlavor(testFlavor, element);
+            }
+
+            //Added following 4 lines - Aruna Samji - 07/22/2003
+            Vector existingNatives = new Vector(flavorMap.getNativesForFlavor(testFlavor));
+            existingNatives.addAll(vectorNatives);
+            vectorNatives = existingNatives;
+            hashVerify.put(testFlavor, vectorNatives);
+        }
+
+        // Assertions: After establishing "new" mappings, verify that the defined
+        //             DataFlavors can be retrieved.
+        verifyNewMappings();
+    }
+
+    // Verify getFlavorsForNative(String nat) is returning the correct list
+    // of DataFlavors (for the new mappings).
+    public boolean verifyNewMappings() {
+        boolean result = true;
+
+        // Enumerate through all DataFlavors
+        for (Enumeration e = hashVerify.keys() ; e.hasMoreElements() ;) {
+            DataFlavor key = (DataFlavor)e.nextElement();
+
+            java.util.List listNatives = flavorMap.getNativesForFlavor(key);
+            Vector vectorNatives = new Vector(listNatives);
+
+            // Compare the list of Natives
+            //Next line changed by Kanishk to comply with bug 4696522
+            //if ( !vectorNatives.equals((Vector)hashVerify.get(key))) {
+            if ( !(vectorNatives.containsAll((Vector)hashVerify.get(key)) && ((Vector)hashVerify.get(key)).containsAll(vectorNatives))) {
+                throw new RuntimeException("\n*** Error in verifyNewMappings()" +
+                    "\nmethod1: addUnencodedNativeForFlavor(DataFlavor flav, String nat)"  +
+                    "\nmethod2: List getNativesForFlavor(DataFlavor flav)" +
+                    "\nDataFlavor: " + key.getMimeType() +
+                    "\nAfter adding several mappings with addUnencodedNativeForFlavor," +
+                    "\nthe returned list did not match the mappings that were added." +
+                    "\nThe mapping was not included in the list.");
+            }
+        }
+        System.out.println("*** DataFlavor size = " + hashVerify.size());
+        System.out.println("*** verifyNewMappings result: " + result + "\n");
+        return result;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/GetFlavorsForNewNativeTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          getFlavorsForNative(String nat)
+ *          with unknown String natives.  Specifically test for
+ *          unknown Unencoded String native in which an empty list is
+ *          returned, and with unknown Encoded String native where
+ *          two-way mapping should be established.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main GetFlavorsForNewNativeTest
+ */
+
+public class GetFlavorsForNewNativeTest {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3, comp4;
+    Hashtable hash;
+    int hashSize;
+
+    String test_native1, test_encoded;
+    DataFlavor test_flavor1, test_flavor2;
+    String[] test_natives_set;
+    DataFlavor[] test_flavors_set;
+
+    public static void main (String[] args) throws Exception {
+        new GetFlavorsForNewNativeTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        flavorMap = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // GetFlavorsForNative using Unencoded Native
+        //
+        // If a new Unencoded native is specified as a parameter, the String
+        // native should be ignored and no mapping established.
+        System.out.println("GetFlavorsForNative using Unencoded Native Test");
+
+        comp1 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+
+        if (comp1.size() != 0) {
+            throw new RuntimeException("\n*** After passing a new Unencoded native" +
+                    "\nwith getFlavorsForNative(String nat)" +
+                    "\nthe String native should be ignored and no mapping established.");
+        } else
+            System.out.println("GetFlavorsForNative using Unencoded Native Test: Test Passes");
+
+
+        // GetFlavorsForNative using Encoded Native (verify 2-way mapping)
+        //
+        // If a new Encoded native is specified, the method should establish a mapping
+        // in both directions between specified native and DataFlavor whose MIME type
+        // is a decoded version of the native.
+        System.out.println("GetFlavorsForNative using Encoded Native Test");
+
+        comp1 = new Vector(Arrays.asList(test_flavors_set));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_encoded));
+
+        comp3 = new Vector(Arrays.asList(test_natives_set));
+        comp4 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if (!comp1.equals(comp2) || !comp3.equals(comp4)) {
+            throw new RuntimeException("\n*** After passing a new Encoded native" +
+                    "\nwith getFlavorsForNative(String nat)" +
+                    "\nthe mapping in both directions was not established.");
+        } else
+            System.out.println("GetFlavorsForNative using Encoded Native: Test Passes");
+    }
+
+    public void initMappings() throws Exception {
+       //initialize mapping variables used in this test
+      //create an Unencoded String native
+      test_native1 = "TEST1";
+
+      //create a DataFlavor from Button class
+      test_flavor1 = new DataFlavor(Class.forName("java.awt.Button"), "Button");
+
+      //create an Encoded String native using Button class MIME Type
+      String buttonMIME = test_flavor1.getMimeType();
+      test_encoded = SystemFlavorMap.encodeJavaMIMEType(buttonMIME);
+
+      //create a DataFlavor from the Encoded String native
+      test_flavor2 = SystemFlavorMap.decodeDataFlavor(test_encoded);
+
+      //create and initialize DataFlavor arrays
+      test_flavors_set = new DataFlavor[] {test_flavor2};
+
+      //create and initialize String native arrays
+      test_natives_set = new String[] {test_encoded};
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/GetNativesForNewFlavorTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          getNativesForFlavor(DataFlavor flav)
+ *          with unknown DataFlavor.  Specifically test for
+ *          passing an unknown DataFlavor where two-way mapping
+ *          should be established.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main GetNativesForNewFlavorTest
+ */
+
+public class GetNativesForNewFlavorTest {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3, comp4;
+    Hashtable hash;
+    int hashSize;
+
+    String test_encoded;
+    DataFlavor test_flavor1, test_flavor2;
+    String[] test_natives_set;
+    DataFlavor[] test_flavors_set;
+
+    public static void main (String[] args) throws Exception {
+        new GetNativesForNewFlavorTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        boolean passed = true;
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // GetNativesForFlavor using unknown DataFlavor (verify 2-way mapping)
+        //
+        // If a new DataFlavor is specified, the method should establish a mapping
+        // in both directions between specified DataFlavor and an encoded
+        // version of its MIME type as its native.
+        System.out.println("GetNativesForFlavor using new DataFlavor");
+
+        comp1 = new Vector(Arrays.asList(test_natives_set));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+
+        comp3 = new Vector(Arrays.asList(test_flavors_set));
+        comp4 = new Vector(flavorMap.getFlavorsForNative(test_encoded));
+
+        if ( !comp1.equals(comp2) || !comp3.equals(comp4) ) {
+            throw new RuntimeException("\n*** After passing a new DataFlavor" +
+                "\nwith getNativesForFlavor(DataFlavor flav)" +
+                "\nthe mapping in both directions was not established.");
+        }
+        else
+           System.out.println("GetNativesForFlavor using new DataFlavor: Test Passes");
+    }
+
+    public void initMappings() throws Exception {
+        //initialize mapping variables used in this test
+        //create a DataFlavor from Button class
+        test_flavor1 = new DataFlavor(Class.forName("java.awt.Button"), "Button");
+
+        //create an Encoded String native using Button class MIME Type
+        String buttonMIME = test_flavor1.getMimeType();
+        test_encoded = SystemFlavorMap.encodeJavaMIMEType(buttonMIME);
+
+        //create a DataFlavor from the Encoded String native
+        test_flavor2 = SystemFlavorMap.decodeDataFlavor(test_encoded);
+
+        //create and initialize DataFlavor arrays
+        test_flavors_set = new DataFlavor[] {test_flavor1};
+
+        //create and initialize String native arrays
+        test_natives_set = new String[] {test_encoded};
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/InvalidMapArgumentsTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+
+/*
+ * @test
+ * @summary To check for error handling with new Clipboard/SystemFlavorMap
+ *          methods, and insure that the appropriate exceptions are being thrown.
+ *          Specifically check for null variables in the methods:
+ *          - addFlavorForUnencodedNative(String nat, DataFlavor flav)
+ *          - addUnencodedNativeForFlavor(DataFlavor flav, String nat)
+ *          - setNativesForFlavor(DataFlavor flav, String[] natives)
+ *          - setFlavorsForNative(String nat, DataFlavor[] flavors)
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main InvalidMapArgumentsTest
+ */
+
+public class InvalidMapArgumentsTest {
+
+    SystemFlavorMap flavorMap;
+    String test_nat;
+    String[] test_natives;
+    DataFlavor test_flav;
+    DataFlavor[] test_flavors;
+
+    public static void main (String[] args){
+        new InvalidMapArgumentsTest().doTest();
+    }
+
+    public void doTest (){
+        //Get things going.  Request focus, set size, et cetera
+        initMappings();
+
+        // Test for combinations of null values for
+        // addFlavorForUnencodedNative(String nat, DataFlavor flav)
+        addFlavorForUnencodedNativeTest(null, null, "both String nat and DataFlavor flav set to null. ");
+        addFlavorForUnencodedNativeTest(null, test_flav, "String nat set to null. ");
+        addFlavorForUnencodedNativeTest(test_nat, null, "DataFlavor flav set to null. ");
+
+
+        // Test for combinations of null values for
+        // addUnencodedNativeForFlavor(DataFlavor flav, String nat)
+        addUnencodedNativeForFlavorTest(null, null, "both DataFlavor flav and String nat set to null. ");
+        addUnencodedNativeForFlavorTest(null, test_nat, "DataFlavor flav set to null. ");
+        addUnencodedNativeForFlavorTest(test_flav, null, "String nat set to null. ");
+
+
+        // Test for combinations of null values for
+        // setNativesForFlavor(DataFlavor flav, String[] natives)
+        setNativesForFlavorTest(null, null, "both DataFlavor flav and String[] natives set to null. ");
+        setNativesForFlavorTest(null, test_natives, "DataFlavor flav set to null. ");
+        setNativesForFlavorTest(test_flav, null, "String[] natives set to null. ");
+
+
+        // Test for combinations of null values for
+        // setFlavorsForNative(String nat, DataFlavor[] flavors)
+        setFlavorsForNativeTest(null, null, "both String nat and DataFlavor[] flavors set to null. ");
+        setFlavorsForNativeTest(null, test_flavors, "String nat set to null. ");
+        setFlavorsForNativeTest(test_nat, null, "DataFlavor[] flavors set to null. ");
+    }
+
+    public void initMappings() {
+        //initialize mapping variables used in this test
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        //create a DataFlavor with valid parameters (mimeType, humanPresentableName)
+        test_flav = new DataFlavor("text/plain; charset=ascii","ASCII Flavor");
+
+        //create a String native
+        test_nat = "TEXT_TEST";
+
+        //create a DataFlavor array
+        test_flavors = new DataFlavor[] {test_flav};
+
+        //create a String native array
+        test_natives = new String[] {test_nat};
+    }
+
+    public void setNativesForFlavorTest(DataFlavor flav, String[] natives, String errmsg) {
+        try{
+            flavorMap.setNativesForFlavor(flav, natives);
+            throw new RuntimeException("NullPointerException is not thrown for method "+
+                    "setNativesForFlavor with "+errmsg);
+        } catch (NullPointerException  e) {
+        }
+    }
+
+    public void setFlavorsForNativeTest(String nat, DataFlavor[] flavors, String errmsg) {
+        try{
+            flavorMap.setFlavorsForNative(nat, flavors);
+            throw new RuntimeException("NullPointerException is not thrown for method "+
+                    "setFlavorsForNative with "+errmsg);
+        } catch (NullPointerException  e) {
+        }
+    }
+
+    public void addFlavorForUnencodedNativeTest(String nat, DataFlavor flav, String errmsg) {
+        try{
+            flavorMap.addFlavorForUnencodedNative(nat, flav);
+            throw new RuntimeException("NullPointerException is not thrown for method "+
+                    "addFlavorForUnencodedNative with "+errmsg);
+        } catch (NullPointerException  e) {
+        }
+    }
+
+    public void addUnencodedNativeForFlavorTest(DataFlavor flav, String nat, String errmsg) {
+        try{
+            flavorMap.addUnencodedNativeForFlavor(flav, nat);
+            throw new RuntimeException("NullPointerException is not thrown for method "+
+                    "addUnencodedNativeForFlavor with "+errmsg);
+        } catch (NullPointerException  e) {
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/ManyFlavorMapTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.*;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap methods
+ *          List getFlavorsForNative(String nat)
+ *          List getNativesForFlavor(DataFlavor flav)
+ *          with valid natives and DataFlavors, including null.
+ *          This test will verify that the returned mappings
+ *          include all entries and that the correct order is
+ *          maintained.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main ManyFlavorMapTest
+ */
+
+public class ManyFlavorMapTest {
+
+    SystemFlavorMap flavorMap;
+
+    Map mapFlavors;
+    Map mapNatives;
+
+    Hashtable hashFlavors;
+    Hashtable hashNatives;
+
+    public static void main (String[] args) {
+        new ManyFlavorMapTest().doTest();
+    }
+
+    public void doTest() {
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get SystemFlavorMap Maps of String Natives and DataFlavors
+        mapFlavors = flavorMap.getNativesForFlavors(null);
+        mapNatives = flavorMap.getFlavorsForNatives(null);
+
+        hashFlavors = new Hashtable(mapFlavors);
+        hashNatives = new Hashtable(mapNatives);
+
+        // Assertion: Verify getNativesForFlavors(null) is returning the full list
+        //            of String Native entries
+        List listNatives = flavorMap.getNativesForFlavor(null);
+        verifyListAllNativeEntries(listNatives);
+
+        // Assertion: Verify getFlavorsForNatives(null) is returning the full list
+        //            of DataFlavor entries
+        List listFlavors = flavorMap.getFlavorsForNative(null);
+        verifyListAllDataFlavorEntries(listFlavors);
+
+        // Assertion: Verify getNativesForFlavor(DataFlavor flav) is returning the list
+        //            of Native Strings (for all supported DataFlavors)
+        //
+        //            Verify that the first list item is the most preferred Native
+        verifyListNativeEntries();
+
+        // Assertion: Verify getFlavorsForNative(String nat) is returning the list
+        //            of DataFlavors(for all supported natives)
+        //
+        //            Verify that the first list item is the most preferred DataFlavor
+        verifyListDataFlavorEntries();
+    }
+
+    // Verify getFlavorsForNative(String nat) is returning the list
+    // of DataFlavors(for all supported natives)
+    public void verifyListDataFlavorEntries() {
+        // Enumerate through all natives
+        for (Enumeration e = hashNatives.keys() ; e.hasMoreElements() ;) {
+            String key = (String)e.nextElement();
+
+            // SystemFlavorMap preferred value
+            DataFlavor value = (DataFlavor)hashNatives.get(key);
+
+            java.util.List listFlavors = flavorMap.getFlavorsForNative(key);
+            Vector vectorFlavors = new Vector(listFlavors);
+
+            // First element should be preferred value
+            DataFlavor prefFlavor = (DataFlavor)vectorFlavors.firstElement();
+            if ( value != prefFlavor ) {
+                throw new RuntimeException("\n*** Error in verifyListDataFlavorEntries()" +
+                    "\nAPI Test: List getFlavorsForNative(String nat)" +
+                    "\native: " + key +
+                    "\nSystemFlavorMap preferred native: " + value.getMimeType() +
+                    "\nList first entry: " + prefFlavor.getMimeType() +
+                    "\nTest failed because List first entry does not match preferred");
+            }
+        }
+        System.out.println("*** native size = " + hashNatives.size());
+    }
+
+    // Verify getNativesForFlavor(DataFlavor flav) is returning the list
+    // of Native Strings (for all supported DataFlavors)
+    public void verifyListNativeEntries() {
+        // Enumerate through all DataFlavors
+        for (Enumeration e = hashFlavors.keys() ; e.hasMoreElements() ;) {
+            DataFlavor key = (DataFlavor)e.nextElement();
+
+            // SystemFlavorMap preferred value
+            String value = (String)hashFlavors.get(key);
+
+            java.util.List listNatives = flavorMap.getNativesForFlavor(key);
+            Vector vectorNatives = new Vector(listNatives);
+
+            // First element should be preferred value
+            String prefNative = (String)vectorNatives.firstElement();
+            if ( value != prefNative ) {
+                throw new RuntimeException("\n*** Error in verifyListNativeEntries()" +
+                    "\nAPI Test: List getNativesForFlavor(DataFlavor flav)" +
+                    "\nDataFlavor: " + key.getMimeType() +
+                    "\nSystemFlavorMap preferred native: " + value +
+                    "\nList first entry: " + prefNative +
+                    "\nTest failed because List first entry does not match preferred");
+            }
+        }
+        System.out.println("*** DataFlavor size = " + hashFlavors.size());
+    }
+
+    // Compare List of Natives with list from SystemFlavorMap
+    //
+    // Verification will be done by comparing the two results as sets
+    public void verifyListAllNativeEntries(java.util.List listNatives) {
+
+        HashSet hashSetMap = new HashSet(mapNatives.keySet());
+        HashSet hashSetList = new HashSet(listNatives);
+
+        System.out.println("*** hashSetMap size = " + hashSetMap.size());
+        System.out.println("*** hashSetList size = " + hashSetList.size());
+
+        if (!hashSetMap.equals(hashSetList)) {
+            throw new RuntimeException("\n*** Error in verifyListAllNativeEntries()" +
+                "\nAPI Test: List getNativesForFlavor(null)" +
+                "\nTest failed because the returned List does not exactly" +
+                "\nmatch objects returned from SystemFlavorMap.");
+        }
+    }
+
+    // Compare List of DataFlavors with list from SystemFlavorMap
+    //
+    // Verification will be done by comparing the two results as sets
+    public void verifyListAllDataFlavorEntries(java.util.List listFlavors) {
+
+        HashSet hashSetMap = new HashSet(mapFlavors.keySet());
+        HashSet hashSetList = new HashSet(listFlavors);
+
+        System.out.println("*** hashSetMap size = " + hashSetMap.size());
+        System.out.println("*** hashSetList size = " + hashSetList.size());
+
+        if (!hashSetMap.equals(hashSetList)) {
+            throw new RuntimeException("\n*** Error in verifyListAllDataFlavorEntries()" +
+                "\nAPI Test: List getFlavorsForNative(null)" +
+                "\nTest failed because the returned List does not exactly" +
+                "\nmatch objects returned from SystemFlavorMap.");
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/SetDataFlavorsTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method:
+ *          setNativesForFlavor(DataFlavor flav, String[] natives)
+ *          with valid natives and DataFlavors. This stress test will
+ *          define numerous mappings of valid String natives and
+ *          DataFlavors.  The mappings will be verified by examining
+ *          that all entries are present, and order is maintained.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main SetDataFlavorsTest
+ */
+
+public class SetDataFlavorsTest {
+
+    SystemFlavorMap flavorMap;
+    Hashtable hashVerify;
+
+    Map mapFlavors;
+    Map mapNatives;
+
+    Hashtable hashFlavors;
+    Hashtable hashNatives;
+
+    public static void main (String[] args) {
+        new SetDataFlavorsTest().doTest();
+    }
+
+    public void doTest() {
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get SystemFlavorMap Maps of String Natives and DataFlavors
+        mapFlavors = flavorMap.getNativesForFlavors(null);
+        mapNatives = flavorMap.getFlavorsForNatives(null);
+
+        hashFlavors = new Hashtable(mapFlavors);
+        hashNatives = new Hashtable(mapNatives);
+
+
+        // Test setNativesForFlavor(DataFlavors flav, String[] natives);
+        //
+        // Enumerate through all the system defined DataFlavors,
+        // and for each DataFlavor, define it again to the SystemFlavorMap
+        // with a slightly modified MimeType.
+        //
+        // For verification, a seperate Hashtable will be maintained of the additions.
+        DataFlavor key;
+        hashVerify = new Hashtable();
+
+        for (Enumeration e = hashFlavors.keys() ; e.hasMoreElements() ;) {
+            key = (DataFlavor)e.nextElement();
+
+            java.util.List listNatives = flavorMap.getNativesForFlavor(key);
+            Vector vectorNatives = new Vector(listNatives);
+            String[] arrayNatives = (String[])vectorNatives.toArray(new String[0]);
+
+            // Construct a new DataFlavor from an existing DataFlavor's MimeType
+            // Example:
+            // Original MimeType: "text/plain; class=java.io.Reader; charset=Unicode"
+            // Modified MimeType: "text/plain-TEST; class=java.io.Reader; charset=Unicode"
+
+            StringBuffer mimeType = new StringBuffer(key.getMimeType());
+            mimeType.insert(mimeType.indexOf(";"),"-TEST");
+
+            DataFlavor testFlav = new DataFlavor(mimeType.toString(), "Test DataFlavor");
+
+                                        // define the new String native entry
+            flavorMap.setNativesForFlavor(testFlav, arrayNatives);
+                                        // keep track of this new native entry
+            hashVerify.put(testFlav, vectorNatives);
+        }
+
+        // After establishing "new" mappings, verify that the defined
+        // Natives can be retrieved and that the List (order) is preserved.
+        verifyNewMappings();
+    }
+
+    // Verify getNativesForFlavor(DataFlavor flav) is returning the correct list
+    // of Natives (for the new mappings).
+    public void verifyNewMappings() {
+        // Enumerate through all DataFlavors
+        for (Enumeration e = hashVerify.keys() ; e.hasMoreElements() ;) {
+            DataFlavor key = (DataFlavor)e.nextElement();
+
+            java.util.List listNatives = flavorMap.getNativesForFlavor(key);
+            Vector vectorFlavors = new Vector(listNatives);
+
+            // Compare the list of Natives
+            if ( !vectorFlavors.equals(hashVerify.get(key))) {
+                throw new RuntimeException("\n*** Error in verifyNewMappings()" +
+                    "\nmethod1: setNativesForFlavor(DataFlavor flav, String[] natives)" +
+                    "\nmethod2: List getNativesForFlavor(DataFlavor flav)" +
+                    "\nDataFlavor: " + key.getMimeType() +
+                    "\nThe Returned List did not match the original set of Natives.");
+            }
+        }
+        System.out.println("*** DataFlavor size = " + hashVerify.size());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/SetFlavorsForNativeTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          setFlavorsForNative(String nat, DataFlavor[] flavors)
+ *          with valid natives and DataFlavors. Specifically test for
+ *          adding new mappings, one-way and two-way, and to update
+ *          existing mappings.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main SetFlavorsForNativeTest
+ */
+
+public class SetFlavorsForNativeTest {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3;
+    Hashtable hash;
+    int hashSize;
+
+    String test_native1, test_native2, test_native3, test_native4;
+    String[] test_natives_set1, test_natives_set2;
+    DataFlavor test_flavor1, test_flavor2, test_flavor3, test_flavor4;
+    DataFlavor[] test_flavors_set1, test_flavors_set2;
+
+    public static void main (String[] args) throws Exception {
+        new SetFlavorsForNativeTest().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // Setup One-way Mappings
+        System.out.println("One-way Mappings Test");
+        flavorMap.setFlavorsForNative(test_native1, test_flavors_set1);
+        flavorMap.setFlavorsForNative(test_native2, test_flavors_set1);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set1));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+        comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up one-way mapping" +
+                "\nwith setFlavorsForNative(String nat, DataFlavors[] flavors)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("One-way: Test Passes");
+
+        // Setup Two-way Mapping
+        System.out.println("Two-way Mappings Test");
+        flavorMap.setNativesForFlavor(test_flavor1, test_natives_set1);
+        flavorMap.setNativesForFlavor(test_flavor2, test_natives_set1);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set1));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+        comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith setNativesForFlavor(DataFlavor flav, String[] natives)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (DataFlavor): Test Passes");
+
+        // Check first native mapping
+        comp1 = new Vector(Arrays.asList(test_flavors_set1));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+        comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith setFlavorsForNative(String nat, DataFlavors[] flavors)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (String native): Test Passes");
+
+        //
+        // Modify an existing mapping test
+        System.out.println("Modify Existing Mappings Test");
+        flavorMap.setFlavorsForNative(test_native1, test_flavors_set2);
+        flavorMap.setFlavorsForNative(test_native2, test_flavors_set2);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set2));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+        comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After modifying an existing mapping" +
+                "\nwith setFlavorsForNative(String nat, DataFlavors[] flavors)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Modify Existing Mappings: Test Passes");
+
+    }
+
+    // Initialize mapping variables used in this test
+    public void initMappings() throws Exception {
+        //create String natives
+        test_native1 = "TEST1";
+        test_native2 = "TEST2";
+        test_native3 = "TEST3";
+        test_native4 = "TEST4";
+
+        test_flavor1 = new DataFlavor(Class.forName("java.awt.Label"), "test1");
+        test_flavor2 = new DataFlavor(Class.forName("java.awt.Button"), "test2");
+        test_flavor3 = new DataFlavor(Class.forName("java.awt.Checkbox"), "test3");
+        test_flavor4 = new DataFlavor(Class.forName("java.awt.List"), "test4");
+
+        //create and initialize DataFlavor arrays
+        test_flavors_set1 = new DataFlavor[] {test_flavor1, test_flavor2};
+        test_flavors_set2 = new DataFlavor[] {test_flavor3, test_flavor4};
+
+        //create and initialize String native arrays
+        test_natives_set1 = new String[] {test_native1, test_native2};
+        test_natives_set2 = new String[] {test_native3, test_native4};
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/SetNativesForFlavor.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method
+ *          setNativesForFlavor(DataFlavor flav, String[] natives)
+ *          with valid natives and DataFlavors. Specifically test for
+ *          adding new mappings, one-way and two-way, and to update
+ *          existing mappings.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main SetNativesForFlavorTest
+ */
+
+public class SetNativesForFlavor {
+
+    SystemFlavorMap flavorMap;
+    Vector comp1, comp2, comp3;
+    Hashtable hash;
+    int hashSize;
+
+    String test_native1, test_native2, test_native3, test_native4;
+    String[] test_natives_set1, test_natives_set2;
+    DataFlavor test_flavor1, test_flavor2, test_flavor3, test_flavor4;
+    DataFlavor[] test_flavors_set1, test_flavors_set2;
+
+    public static void main (String[] args) throws Exception {
+        new SetNativesForFlavor().doTest();
+    }
+
+    public void doTest() throws Exception {
+        // Initialize DataFlavors and arrays used for test data
+        initMappings();
+
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get all the native strings and preferred DataFlavor mappings
+        hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
+        hashSize = hash.size();
+
+        // Setup One-way Mappings
+        System.out.println("One-way Mappings Test");
+        flavorMap.setNativesForFlavor(test_flavor1, test_natives_set1);
+        flavorMap.setNativesForFlavor(test_flavor2, test_natives_set1);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set1));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+        comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up one-way mapping" +
+                "\nwith setNativesForFlavor(DataFlavor flav, String[] natives)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("One-way: Test Passes");
+
+        // Setup Two-way Mapping
+        System.out.println("Two-way Mappings Test");
+        flavorMap.setFlavorsForNative(test_native1, test_flavors_set1);
+        flavorMap.setFlavorsForNative(test_native2, test_flavors_set1);
+
+        // Confirm mapping with getFlavorsForNative
+        comp1 = new Vector(Arrays.asList(test_flavors_set1));
+        comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
+        comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith setFlavorsForNative(string nat, DataFlavor[] flavors)" +
+                "\nthe mappings returned from getFlavorsForNative() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (DataFlavor): Test Passes");
+
+        // Check first native mapping
+        comp1 = new Vector(Arrays.asList(test_natives_set1));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+        comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After setting up two-way mapping" +
+                "\nwith setNativesForFlavor(DataFlavor flav, String[] natives)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Two-way (String native): Test Passes");
+
+        // Modify an existing mapping test
+        System.out.println("Modify Existing Mappings Test");
+        flavorMap.setNativesForFlavor(test_flavor1, test_natives_set2);
+        flavorMap.setNativesForFlavor(test_flavor2, test_natives_set2);
+
+        // Confirm mapping with getNativesForFlavor
+        comp1 = new Vector(Arrays.asList(test_natives_set2));
+        comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
+        comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));
+
+        if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
+            throw new RuntimeException("\n*** After modifying an existing mapping" +
+                "\nwith setNativesForFlavor(DataFlavor flav, String[] natives)" +
+                "\nthe mappings returned from getNativesForFlavor() do not match" +
+                "\noriginal mappings.");
+        }
+        else
+           System.out.println("Modify Existing Mappings: Test Passes");
+
+    }
+
+    // Initialize mapping variables used in this test
+    public void initMappings() throws Exception {
+        //create String natives
+        test_native1 = "TEST1";
+        test_native2 = "TEST2";
+        test_native3 = "TEST3";
+        test_native4 = "TEST4";
+
+        test_flavor1 = new DataFlavor(Class.forName("java.awt.Label"), "test1");
+        test_flavor2 = new DataFlavor(Class.forName("java.awt.Button"), "test2");
+        test_flavor3 = new DataFlavor(Class.forName("java.awt.Checkbox"), "test3");
+        test_flavor4 = new DataFlavor(Class.forName("java.awt.List"), "test4");
+
+        //create and initialize DataFlavor arrays
+        test_flavors_set1 = new DataFlavor[] {test_flavor1, test_flavor2};
+        test_flavors_set2 = new DataFlavor[] {test_flavor3, test_flavor4};
+
+        //create and initialize String native arrays
+        test_natives_set1 = new String[] {test_native1, test_native2};
+        test_natives_set2 = new String[] {test_native3, test_native4};
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/SetNativesTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2001, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+/*
+ * @test
+ * @summary To test SystemFlavorMap method:
+ *          setFlavorsForNative(String nat, DataFlavors[] flavors)
+ *          with valid natives and DataFlavors. This stress test will
+ *          define numerous mappings of valid String natives and
+ *          DataFlavors.  The mappings will be verified by examining
+ *          that all entries are present, and order is maintained.
+ * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard
+ * @run main SetNativesTest
+ */
+
+public class SetNativesTest {
+
+    SystemFlavorMap flavorMap;
+    Hashtable hashVerify;
+
+    Map mapFlavors;
+    Map mapNatives;
+
+    Hashtable hashFlavors;
+    Hashtable hashNatives;
+
+    public static void main (String[] args){
+        new SetNativesTest().doTest();
+    }
+
+    public void doTest() {
+        flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+        // Get SystemFlavorMap Maps of String Natives and DataFlavors
+        mapFlavors = flavorMap.getNativesForFlavors(null);
+        mapNatives = flavorMap.getFlavorsForNatives(null);
+
+        hashFlavors = new Hashtable(mapFlavors);
+        hashNatives = new Hashtable(mapNatives);
+
+
+        // Test setFlavorsForNative(String nat, DataFlavors[] flavors);
+        //
+        // Enumerate through all the system defined String natives,
+        // and for each String native, define it again to the SystemFlavorMap
+        // with a slightly modified String native (name).
+        //
+        // For verification, a seperate Hashtable will be maintained of the additions.
+        String key;
+        hashVerify = new Hashtable();
+
+        for (Enumeration e = hashNatives.keys() ; e.hasMoreElements() ;) {
+            key = (String)e.nextElement();
+
+            java.util.List listFlavors = flavorMap.getFlavorsForNative(key);
+            Vector vectorFlavors = new Vector(listFlavors);
+            DataFlavor[] arrayFlavors = (DataFlavor[])vectorFlavors.toArray(new DataFlavor[0]);
+
+            key = key.concat("TEST");   // construct a unique String native
+                                        // define the new String native entry
+            flavorMap.setFlavorsForNative(key, arrayFlavors);
+                                        // keep track of this new native entry
+            hashVerify.put(key, vectorFlavors);
+        }
+
+        // After establishing "new" mappings, verify that the defined
+        // DataFlavors can be retrieved and that the List (order) is preserved.
+        verifyNewMappings();
+    }
+
+    // Verify getFlavorsForNative(String nat) is returning the correct list
+    // of DataFlavors (for the new mappings).
+    public void verifyNewMappings() {
+        // Enumerate through all natives
+        for (Enumeration e = hashVerify.keys() ; e.hasMoreElements() ;) {
+            String key = (String)e.nextElement();
+
+            java.util.List listFlavors = flavorMap.getFlavorsForNative(key);
+            Vector vectorFlavors = new Vector(listFlavors);
+
+            // Compare the list of DataFlavors
+            if ( !vectorFlavors.equals((Vector)hashVerify.get(key))) {
+                throw new RuntimeException("\n*** Error in verifyNewMappings()" +
+                    "\nmethod1: setFlavorsForNative(String nat, DataFlavors[] flavors)" +
+                    "\nmethod2: List getFlavorsForNative(String nat)" +
+                    "\nString native: " + key +
+                    "\nThe Returned List did not match the original set of DataFlavors.");
+            }
+        }
+        System.out.println("*** native size = " + hashVerify.size());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemSelection/SystemSelectionAWTTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
+import java.util.Properties;
+
+/*
+ * @test
+ * @summary To check the functionality of newly added API getSystemSelection & make sure
+ *          that it's mapped to primary clipboard
+ * @author Jitender(jitender.singh@eng.sun.com) area=AWT
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main SystemSelectionAWTTest
+ */
+
+public class SystemSelectionAWTTest {
+
+    Frame frame;
+    TextField tf1, tf2;
+    Clipboard clip;
+    Transferable t;
+
+    public static void main(String[] args) throws Exception {
+        new SystemSelectionAWTTest().doTest();
+    }
+
+    SystemSelectionAWTTest() {
+        frame = new Frame();
+        frame.setSize(200, 200);
+
+        tf1 = new TextField();
+        tf1.addFocusListener( new FocusAdapter() {
+            public void focusGained(FocusEvent fe) {
+                fe.getSource();
+            }
+        });
+
+        tf2 = new TextField();
+
+        frame.add(tf2, BorderLayout.NORTH);
+        frame.add(tf1, BorderLayout.CENTER);
+
+        frame.setVisible(true);
+        frame.toFront();
+        tf1.requestFocus();
+        tf1.setText("Selection Testing");
+    }
+
+    // Check whether Security manager is there
+    public void checkSecurity() {
+        SecurityManager sm = System.getSecurityManager();
+
+        if (sm == null) {
+            System.out.println("security manager is not there");
+            getPrimaryClipboard();
+        } else {
+            try {
+                sm.checkPermission(new AWTPermission("accessClipboard"));
+                getPrimaryClipboard();
+            } catch(SecurityException e) {
+                clip = null;
+                System.out.println("Access to System selection is not allowed");
+            }
+        }
+    }
+
+    // Get the contents from the clipboard
+    void getClipboardContent() throws Exception {
+        t = clip.getContents(this);
+        if ( (t != null) && (t.isDataFlavorSupported(DataFlavor.stringFlavor) )) {
+            tf2.setBackground(Color.red);
+            tf2.setForeground(Color.black);
+            tf2.setText((String) t.getTransferData(DataFlavor.stringFlavor));
+        }
+    }
+
+    // Get System Selection i.e. Primary Clipboard
+    private void getPrimaryClipboard() {
+        Properties ps = System.getProperties();
+        String operSys = ps.getProperty("os.name");
+        clip = Toolkit.getDefaultToolkit().getSystemSelection();
+        if (clip == null) {
+            if ((operSys.substring(0,3)).equalsIgnoreCase("Win") ||
+                    (operSys.substring(0,3)).equalsIgnoreCase("Mac"))
+                System.out.println(operSys + " operating system does not support system selection ");
+            else
+                throw new RuntimeException("Method getSystemSelection() is returning null on X11 platform");
+        }
+    }
+
+    // Compare the selected text with one pasted from the clipboard
+    public void compareText() {
+        if ((tf2.getText()).equals(tf1.getSelectedText()) &&
+                System.getProperties().getProperty("os.name").substring(0,3) != "Win") {
+            System.out.println("Selected text & clipboard contents are same\n");
+        } else  {
+            throw new RuntimeException("Selected text & clipboard contents differs\n");
+        }
+    }
+
+    public void doTest() throws Exception {
+        ExtendedRobot robot = new ExtendedRobot();
+
+        frame.setLocation(100, 100);
+        robot.waitForIdle(2000);
+
+        Point tf1Location = tf1.getLocationOnScreen();
+        Dimension tf1Size = tf1.getSize();
+        checkSecurity();
+
+        if (clip != null) {
+            robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2);
+            robot.waitForIdle(2000);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardContent();
+            compareText();
+
+            robot.mouseMove(tf1Location.x + tf1Size.width / 2, tf1Location.y + tf1Size.height / 2);
+            robot.waitForIdle(2000);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardContent();
+            compareText();
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemSelection/SystemSelectionSwingTest.java	Fri Jul 04 13:40:55 2014 +0400
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1999, 2014, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
+import java.util.Properties;
+
+/*
+ * @test
+ * @summary To check the functionality of newly added API getSystemSelection & make sure
+ *          that it's mapped to primary clipboard
+ * @author Jitender(jitender.singh@eng.sun.com) area=AWT
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main SystemSelectionSwingTest
+ */
+
+public class SystemSelectionSwingTest {
+
+    JFrame jframe;
+    JTextField jtf1, jtf2;
+    Clipboard clip;
+    Transferable t;
+
+    public static void main(String[] args) throws Exception {
+        new SystemSelectionSwingTest().doTest();
+    }
+
+    SystemSelectionSwingTest() {
+        jframe = new JFrame();
+        jframe.setSize(200, 200);
+
+        jtf1 = new JTextField();
+        jtf1.addFocusListener( new FocusAdapter() {
+            public void focusGained(FocusEvent fe) {
+                fe.getSource();
+            }
+        });
+
+        jtf2 = new JTextField();
+
+        jframe.add(jtf2, BorderLayout.NORTH);
+        jframe.add(jtf1, BorderLayout.CENTER);
+
+        jframe.setVisible(true);
+        jframe.toFront();
+        jtf1.requestFocus();
+        jtf1.setText("Selection Testing");
+    }
+
+    // Check whether Security manager is there
+    public void checkSecurity() {
+        SecurityManager sm = System.getSecurityManager();
+
+        if (sm == null) {
+            System.out.println("security manager is not there");
+            getPrimaryClipboard();
+        } else {
+            try {
+                sm.checkPermission(new AWTPermission("accessClipboard"));
+                getPrimaryClipboard();
+            } catch(SecurityException e) {
+                clip = null;
+                System.out.println("Access to System selection is not allowed");
+            }
+        }
+    }
+
+    // Get the contents from the clipboard
+    void getClipboardContent() throws Exception {
+        t = clip.getContents(this);
+        if ( (t != null) && (t.isDataFlavorSupported(DataFlavor.stringFlavor) )) {
+            jtf2.setBackground(Color.red);
+            jtf2.setForeground(Color.black);
+            jtf2.setText((String) t.getTransferData(DataFlavor.stringFlavor));
+        }
+    }
+
+
+    // Get System Selection i.e. Primary Clipboard
+    private void getPrimaryClipboard() {
+        Properties ps = System.getProperties();
+        String operSys = ps.getProperty("os.name");
+        clip = Toolkit.getDefaultToolkit().getSystemSelection();
+        if (clip == null) {
+            if ((operSys.substring(0,3)).equalsIgnoreCase("Win") ||
+                    (operSys.substring(0,3)).equalsIgnoreCase("Mac"))
+                System.out.println(operSys + " operating system does not support system selection ");
+            else
+                throw new RuntimeException("Method getSystemSelection() is returning null on X11 platform");
+        }
+    }
+
+    // Compare the selected text with one pasted from the clipboard
+    public void compareText() {
+        if ((jtf2.getText()).equals(jtf1.getSelectedText()) &&
+                System.getProperties().getProperty("os.name").substring(0,3) != "Win") {
+            System.out.println("Selected text & clipboard contents are same\n");
+        } else  {
+            throw new RuntimeException("Selected text & clipboard contents differs\n");
+        }
+    }
+
+    public void doTest() throws Exception {
+        ExtendedRobot robot = new ExtendedRobot();
+
+        jframe.setLocation(100, 100);
+        robot.waitForIdle(2000);
+
+        Point tf1Location = jtf1.getLocationOnScreen();
+        Dimension tf1Size = jtf1.getSize();
+        checkSecurity();
+
+        if (clip != null) {
+            robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2);
+            robot.waitForIdle(2000);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardContent();
+            compareText();
+
+            robot.mouseMove(tf1Location.x + tf1Size.width / 2, tf1Location.y + tf1Size.height / 2);
+            robot.waitForIdle(2000);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(20);
+            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+            robot.waitForIdle(2000);
+
+            getClipboardContent();
+            compareText();
+        }
+    }
+}
+