jdk/test/sun/awt/datatransfer/DataFlavorComparatorTest1.java
author yan
Tue, 23 Jun 2015 11:59:27 +0300
changeset 31448 1066345d2a8a
parent 27057 2202074399cf
child 31887 a0b91dedca5c
permissions -rw-r--r--
8076468: Add @modules to tests in jdk_desktop test group Reviewed-by: yan, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27057
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     1
/*
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 27057
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27057
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     4
 *
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     8
 *
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    13
 * accompanied this code).
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    14
 *
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    18
 *
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    21
 * questions.
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    22
 */
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    23
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    24
/* @test
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    25
   @bug 8058473
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    26
   @summary "Comparison method violates its general contract" when using Clipboard
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    27
            Ensure that DataFlavorComparator conforms to Comparator contract
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    28
   @author Anton Nashatyrev
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 27057
diff changeset
    29
   @modules java.datatransfer/sun.datatransfer
27057
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    30
   @run main DataFlavorComparatorTest1
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    31
*/
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    32
import sun.datatransfer.DataFlavorUtil;
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    33
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    34
import java.awt.datatransfer.DataFlavor;
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    35
import java.util.Comparator;
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    36
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    37
public class DataFlavorComparatorTest1 {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    38
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    40
        String[] mimes = new String[] {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    41
                "text/plain",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    42
                "text/plain; charset=unicode",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    43
                "text/plain; charset=cp1251",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    44
                "text/plain; charset=unicode; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    45
                "text/plain; charset=unicode; class=java.io.Serializable",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    46
                "text/plain; charset=unicode; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    47
                "text/plain; class=java.lang.String",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    48
                "text/plain; class=java.io.Reader",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    49
                "text/plain; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    50
                "text/html",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    51
                "text/html; charset=unicode",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    52
                "text/html; charset=cp1251",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    53
                "text/html; charset=unicode; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    54
                "text/html; charset=unicode; class=java.io.Serializable",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    55
                "text/html; charset=unicode; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    56
                "text/html; class=java.lang.String",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    57
                "text/html; class=java.io.Reader",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    58
                "text/html; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    59
                "text/unknown",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    60
                "text/unknown; charset=unicode",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    61
                "text/unknown; charset=cp1251",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    62
                "text/unknown; charset=unicode; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    63
                "text/unknown; charset=unicode; class=java.io.Serializable",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    64
                "text/unknown; charset=unicode; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    65
                "text/unknown; class=java.lang.String",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    66
                "text/unknown; class=java.io.Reader",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    67
                "text/unknown; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    68
                "application/unknown; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    69
                "application/unknown; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    70
                "application/unknown",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    71
                "application/x-java-jvm-local-objectref; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    72
                "application/x-java-jvm-local-objectref; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    73
                "application/x-java-jvm-local-objectref",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    74
                "unknown/flavor",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    75
                "unknown/flavor; class=java.io.InputStream",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    76
                "unknown/flavor; class=java.lang.Object",
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    77
        };
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    78
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    79
        DataFlavor[] flavors = new DataFlavor[mimes.length];
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    80
        for (int i = 0; i < flavors.length; i++) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    81
            flavors[i] = new DataFlavor(mimes[i]);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    82
        }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    83
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    84
        testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    85
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    86
        System.out.println("Passed.");
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    87
    }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    88
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    89
    private static void testComparator(Comparator cmp, DataFlavor[] flavs)
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    90
            throws ClassNotFoundException {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    91
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    92
        for (DataFlavor x: flavs) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    93
            for (DataFlavor y: flavs) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    94
                if (Math.signum(cmp.compare(x,y)) != -Math.signum(cmp.compare(y,x))) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    95
                    throw new RuntimeException("Antisymmetry violated: " + x + ", " + y);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    96
                }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    97
                if (cmp.compare(x,y) == 0 && !x.equals(y)) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    98
                    throw new RuntimeException("Equals rule violated: " + x + ", " + y);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
    99
                }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   100
                for (DataFlavor z: flavs) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   101
                    if (cmp.compare(x,y) == 0) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   102
                        if (Math.signum(cmp.compare(x, z)) != Math.signum(cmp.compare(y, z))) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   103
                            throw new RuntimeException("Transitivity (1) violated: " + x + ", " + y + ", " + z);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   104
                        }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   105
                    } else {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   106
                        if (Math.signum(cmp.compare(x, y)) == Math.signum(cmp.compare(y, z))) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   107
                            if (Math.signum(cmp.compare(x, y)) != Math.signum(cmp.compare(x, z))) {
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   108
                                throw new RuntimeException("Transitivity (2) violated: " + x + ", " + y + ", " + z);
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   109
                            }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   110
                        }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   111
                    }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   112
                }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   113
            }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   114
        }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   115
    }
2202074399cf 8058473: "Comparison method violates its general contract" when using Clipboard
anashaty
parents:
diff changeset
   116
}