test/jdk/java/util/EnumSet/RetainAll.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 5506 jdk/test/java/util/EnumSet/RetainAll.java@202f599c92aa
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6377356
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test EnumSet.retainAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Josh Bloch, Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class RetainAll {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    enum RegularA { A0, A2 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    enum RegularB { B0, B1 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    enum JumboA {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        A00, A01, A02, A03, A04, A05, A06, A07, A08, A09,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        A10, A11, A12, A13, A14, A15, A16, A17, A18, A19,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        A20, A21, A22, A23, A24, A25, A26, A27, A28, A29,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        A30, A31, A32, A33, A34, A35, A36, A37, A38, A39,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        A40, A41, A42, A43, A44, A45, A46, A47, A48, A49,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        A50, A51, A52, A53, A54, A55, A56, A57, A58, A59,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        A60, A61, A62, A63, A64, A65, A66, A67, A68, A69,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    enum JumboB {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        B00, B01, B02, B03, B04, B05, B06, B07, B08, B09,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        B10, B11, B12, B13, B14, B15, B16, B17, B18, B19,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        B20, B21, B22, B23, B24, B25, B26, B27, B28, B29,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        B30, B31, B32, B33, B34, B35, B36, B37, B38, B39,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        B40, B41, B42, B43, B44, B45, B46, B47, B48, B49,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        B50, B51, B52, B53, B54, B55, B56, B57, B58, B59,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        B60, B61, B62, B63, B64, B65, B66, B67, B68, B69,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static void realMain(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        Set<RegularA> ras = EnumSet.noneOf(RegularA.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        Set<RegularB> rbs = EnumSet.noneOf(RegularB.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        Set<JumboA>   jas = EnumSet.noneOf(JumboA.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        Set<JumboB>   jbs = EnumSet.noneOf(JumboB.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        check(ras.getClass().getName().matches(".*Regular.*"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        check(jas.getClass().getName().matches(".*Jumbo.*"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        check(! ras.retainAll(ras));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        check(! ras.retainAll(rbs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        check(! jas.retainAll(jas));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        check(! jas.retainAll(jbs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        check(! ras.retainAll(jas));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        check(! jas.retainAll(ras));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (failed > 0) throw new AssertionError("Some tests failed");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}