< prev index next >

test/sun/awt/datatransfer/DataFlavorComparatorTest1.java

Print this page




  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 8058473
  26    @summary "Comparison method violates its general contract" when using Clipboard
  27             Ensure that DataFlavorComparator conforms to Comparator contract
  28    @author Anton Nashatyrev
  29    @modules java.datatransfer/sun.datatransfer
  30    @run main DataFlavorComparatorTest1
  31 */
  32 import sun.datatransfer.DataFlavorUtil;
  33 
  34 import java.awt.datatransfer.DataFlavor;
  35 import java.util.Comparator;
  36 
  37 public class DataFlavorComparatorTest1 {
  38 
  39     public static void main(String[] args) throws Exception {
  40         String[] mimes = new String[] {





























  41                 "text/plain",
  42                 "text/plain; charset=unicode",
  43                 "text/plain; charset=cp1251",
  44                 "text/plain; charset=unicode; class=java.io.InputStream",
  45                 "text/plain; charset=unicode; class=java.io.Serializable",
  46                 "text/plain; charset=unicode; class=java.lang.Object",
  47                 "text/plain; class=java.lang.String",
  48                 "text/plain; class=java.io.Reader",
  49                 "text/plain; class=java.lang.Object",
  50                 "text/html",
  51                 "text/html; charset=unicode",
  52                 "text/html; charset=cp1251",
  53                 "text/html; charset=unicode; class=java.io.InputStream",
  54                 "text/html; charset=unicode; class=java.io.Serializable",
  55                 "text/html; charset=unicode; class=java.lang.Object",
  56                 "text/html; class=java.lang.String",
  57                 "text/html; class=java.io.Reader",
  58                 "text/html; class=java.lang.Object",
  59                 "text/unknown",
  60                 "text/unknown; charset=unicode",
  61                 "text/unknown; charset=cp1251",
  62                 "text/unknown; charset=unicode; class=java.io.InputStream",
  63                 "text/unknown; charset=unicode; class=java.io.Serializable",
  64                 "text/unknown; charset=unicode; class=java.lang.Object",
  65                 "text/unknown; class=java.lang.String",
  66                 "text/unknown; class=java.io.Reader",
  67                 "text/unknown; class=java.lang.Object",
  68                 "application/unknown; class=java.io.InputStream",
  69                 "application/unknown; class=java.lang.Object",
  70                 "application/unknown",
  71                 "application/x-java-jvm-local-objectref; class=java.io.InputStream",
  72                 "application/x-java-jvm-local-objectref; class=java.lang.Object",
  73                 "application/x-java-jvm-local-objectref",
  74                 "unknown/flavor",
  75                 "unknown/flavor; class=java.io.InputStream",
  76                 "unknown/flavor; class=java.lang.Object",
  77         };
  78 
  79         DataFlavor[] flavors = new DataFlavor[mimes.length];
  80         for (int i = 0; i < flavors.length; i++) {
  81             flavors[i] = new DataFlavor(mimes[i]);
  82         }
  83 
  84         testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors);
  85 
  86         System.out.println("Passed.");
  87     }
  88 
  89     private static void testComparator(Comparator cmp, DataFlavor[] flavs)
  90             throws ClassNotFoundException {
  91 
  92         for (DataFlavor x: flavs) {
  93             for (DataFlavor y: flavs) {
  94                 if (Math.signum(cmp.compare(x,y)) != -Math.signum(cmp.compare(y,x))) {
  95                     throw new RuntimeException("Antisymmetry violated: " + x + ", " + y);
  96                 }


  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 8058473
  26    @summary "Comparison method violates its general contract" when using Clipboard
  27             Ensure that DataFlavorComparator conforms to Comparator contract
  28    @author Anton Nashatyrev
  29    @modules java.datatransfer/sun.datatransfer
  30    @run main DataFlavorComparatorTest1
  31 */
  32 import sun.datatransfer.DataFlavorUtil;
  33 
  34 import java.awt.datatransfer.DataFlavor;
  35 import java.util.Comparator;
  36 
  37 public class DataFlavorComparatorTest1 {
  38 
  39     public static void main(String[] args) throws Exception {
  40         String[] mimes = new String[] {
  41                 "text/plain;class=java.nio.ByteBuffer;charset=UTF-8",
  42                 "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-8",
  43                 "text/plain;class=java.nio.ByteBuffer;charset=UTF-16LE",
  44                 "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16LE",
  45                 "application/x-java-text-encoding",
  46                 "application/x-java-serialized-object;class=java.lang.String",
  47                 "text/plain;class=java.io.InputStream;charset=UTF-8",
  48                 "text/uri-list;class=java.io.InputStream;charset=UTF-8",
  49                 "text/plain;class=java.io.InputStream;charset=windows-1252",
  50                 "text/uri-list;class=java.io.InputStream;charset=windows-1252",
  51                 "application/x-java-url;class=java.net.URL",
  52                 "text/plain;class=java.io.Reader",
  53                 "text/plain;charset=windows-1252",
  54                 "text/uri-list;class=java.io.Reader",
  55                 "text/uri-list;charset=windows-1252",
  56                 "text/plain;charset=UTF-8",
  57                 "text/uri-list;charset=UTF-8",
  58                 "text/plain;class=java.io.InputStream;charset=US-ASCII",
  59                 "text/uri-list;class=java.io.InputStream;charset=US-ASCII",
  60                 "text/plain;class=java.io.InputStream;charset=UTF-16LE",
  61                 "text/plain;charset=US-ASCII",
  62                 "text/uri-list;class=java.io.InputStream;charset=UTF-16LE",
  63                 "text/uri-list;charset=US-ASCII",
  64                 "text/plain;charset=UTF-16LE",
  65                 "text/uri-list;charset=UTF-16LE",
  66                 "text/plain;class=java.nio.ByteBuffer;charset=UTF-16BE",
  67                 "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16BE",
  68                 "text/plain;class=java.nio.ByteBuffer;charset=ISO-8859-1",
  69                 "text/uri-list;class=java.nio.ByteBuffer;charset=ISO-8859-1",
  70                 "text/plain",
  71                 "text/uri-list",
  72                 "text/plain;class=java.nio.ByteBuffer;charset=UTF-16",
  73                 "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16",
  74                 "text/plain;class=java.io.InputStream;charset=unicode",
  75                 "text/uri-list;class=java.io.InputStream;charset=UTF-16",
  76                 "text/plain;class=java.nio.CharBuffer",
  77                 "text/uri-list;class=java.nio.CharBuffer",
  78                 "text/plain;class=java.lang.String",
  79                 "text/plain;charset=UTF-16BE",
  80                 "text/uri-list;class=java.lang.String",
  81                 "text/uri-list;charset=UTF-16BE",
  82                 "text/plain;charset=ISO-8859-1",
  83                 "text/uri-list;charset=ISO-8859-1",
  84                 "text/plain;class=java.io.InputStream;charset=UTF-16BE",
  85                 "text/uri-list;class=java.io.InputStream;charset=UTF-16BE",
  86                 "text/plain;class=java.nio.ByteBuffer;charset=US-ASCII",
  87                 "text/uri-list;class=java.nio.ByteBuffer;charset=US-ASCII",
  88                 "text/plain;class=java.io.InputStream;charset=ISO-8859-1",
  89                 "text/uri-list;class=java.io.InputStream;charset=ISO-8859-1",
  90                 "text/plain;charset=UTF-16",
  91                 "text/plain;class=java.nio.ByteBuffer;charset=windows-1252",
  92                 "text/uri-list;charset=UTF-16",
  93                 "text/uri-list;class=java.nio.ByteBuffer;charset=windows-1252",
  94                 "text/plain;class=java.io.InputStream;charset=windows-1252",
  95                 "text/uri-list;class=java.io.InputStream;charset=windows-1252",










  96         };
  97 
  98         DataFlavor[] flavors = new DataFlavor[mimes.length];
  99         for (int i = 0; i < flavors.length; i++) {
 100             flavors[i] = new DataFlavor(mimes[i]);
 101         }
 102 
 103         testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors);
 104 
 105         System.out.println("Passed.");
 106     }
 107 
 108     private static void testComparator(Comparator cmp, DataFlavor[] flavs)
 109             throws ClassNotFoundException {
 110 
 111         for (DataFlavor x: flavs) {
 112             for (DataFlavor y: flavs) {
 113                 if (Math.signum(cmp.compare(x,y)) != -Math.signum(cmp.compare(y,x))) {
 114                     throw new RuntimeException("Antisymmetry violated: " + x + ", " + y);
 115                 }
< prev index next >