test/jdk/java/lang/String/CompactString/RegionMatches.java
author herrick
Mon, 14 Oct 2019 14:36:45 -0400
branchJDK-8200758-branch
changeset 58584 910b14f4fe3a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232042: [macos] Installation fails if application name contains spaces Submitted-by: almatvee Reviewed-by: aherrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     1
/*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     4
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     8
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    13
 * accompanied this code).
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    14
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    18
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    21
 * questions.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    22
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    23
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    24
import org.testng.annotations.DataProvider;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    25
import org.testng.annotations.Test;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    26
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    27
import static org.testng.Assert.assertEquals;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    28
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    29
/*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    30
 * @test
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    31
 * @bug 8077559
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    32
 * @summary Tests Compact String. This one is for String.regionMatches.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    33
 * @run testng/othervm -XX:+CompactStrings RegionMatches
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    34
 * @run testng/othervm -XX:-CompactStrings RegionMatches
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    35
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    36
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    37
public class RegionMatches extends CompactString {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    38
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    39
    @DataProvider
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    40
    public Object[][] provider() {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    41
        return new Object[][] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    42
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    43
                new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    44
                new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    45
                new Object[] { STRING_EMPTY, true, 0, "A", 0, 0, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    46
                new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    47
                new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    48
                new Object[] { STRING_L1, false, 0, "a", 0, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    49
                new Object[] { STRING_L1, false, 0, "BA", 1, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    50
                new Object[] { STRING_L1, false, 0, "Ba", 1, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    51
                new Object[] { STRING_L1, true, 0, "a", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    52
                new Object[] { STRING_L1, true, 0, "BA", 1, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    53
                new Object[] { STRING_L1, true, 0, "Ba", 1, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    54
                new Object[] { STRING_L2, true, 1, "b", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    55
                new Object[] { STRING_L2, true, 1, "B", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    56
                new Object[] { STRING_L2, true, 0, "xaBc", 1, 2, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    57
                new Object[] { STRING_L2, false, 0, "AB", 0, 2, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    58
                new Object[] { STRING_L2, false, 0, "Ab", 0, 2, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    59
                new Object[] { STRING_L2, false, 1, "BAB", 2, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    60
                new Object[] { STRING_LLONG, true, 1, "bCdEF", 0, 5, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    61
                new Object[] { STRING_LLONG, false, 2, "CDEFG", 0, 5, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    62
                new Object[] { STRING_LLONG, true, 2, "CDEFg", 0, 5, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    63
                new Object[] { STRING_U1, true, 0, "\uFF41", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    64
                new Object[] { STRING_U1, false, 0, "\uFF41", 0, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    65
                new Object[] { STRING_MDUPLICATE1, true, 0, "\uFF41a\uFF41", 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    66
                        3, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    67
                new Object[] { STRING_MDUPLICATE1, false, 0, "\uFF21a\uFF21",
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    68
                        0, 3, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    69
                new Object[] { STRING_SUPPLEMENTARY, true, 1, "\uDC00\uD801",
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    70
                        0, 2, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    71
                new Object[] { STRING_SUPPLEMENTARY, true, 4, "\uFF21", 0, 1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    72
                        true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    73
                new Object[] { STRING_SUPPLEMENTARY, true, 5, "A", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    74
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 0,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    75
                        "\uD801\uDC28\uD801\uDC29", 0, 4, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    76
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    77
                        "\uDC28\uD801", 0, 2, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    78
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    79
                        "\uDC00\uD801", 0, 2, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    80
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 4,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    81
                        "\uFF21", 0, 1, true },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    82
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    83
                        "\uFF21", 0, 1, false },
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    84
                new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    85
                        "\uFF41", 0, 1, true }, };
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    86
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    87
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    88
    @Test(dataProvider = "provider")
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    89
    public void testRegionMatches(String str, boolean ignoreCase, int toffset,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    90
            String other, int ooffset, int len, boolean expected) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    91
        map.get(str)
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    92
                .forEach(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    93
                        (source, data) -> {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    94
                            assertEquals(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    95
                                    data.regionMatches(ignoreCase, toffset,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    96
                                            other, ooffset, len),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    97
                                    expected,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    98
                                    String.format(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    99
                                            "testing String(%s).regionMatches(%b, %d, %s, %d, %d), source : %s, ",
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   100
                                            escapeNonASCIIs(data), ignoreCase,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   101
                                            toffset, escapeNonASCIIs(other),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   102
                                            ooffset, len, source));
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   103
                        });
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   104
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   105
}