test/jdk/java/lang/String/CompactString/CodePointCount.java
changeset 47216 71c04702a3d5
parent 33663 2cd62a4bd471
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import org.testng.annotations.DataProvider;
       
    25 import org.testng.annotations.Test;
       
    26 
       
    27 import static org.testng.Assert.assertEquals;
       
    28 
       
    29 /*
       
    30  * @test
       
    31  * @bug 8077559
       
    32  * @summary Tests Compact String. This one is for String.codePointCount.
       
    33  * @run testng/othervm -XX:+CompactStrings CodePointCount
       
    34  * @run testng/othervm -XX:-CompactStrings CodePointCount
       
    35  */
       
    36 
       
    37 public class CodePointCount extends CompactString {
       
    38 
       
    39     @DataProvider
       
    40     public Object[][] provider() {
       
    41         return new Object[][] { new Object[] { STRING_EMPTY, 0, 0, 0 },
       
    42                 new Object[] { STRING_L1, 0, 1, 1 },
       
    43                 new Object[] { STRING_L1, 1, 1, 0 },
       
    44                 new Object[] { STRING_L2, 0, 2, 2 },
       
    45                 new Object[] { STRING_L2, 0, 1, 1 },
       
    46                 new Object[] { STRING_L2, 1, 2, 1 },
       
    47                 new Object[] { STRING_L4, 0, 4, 4 },
       
    48                 new Object[] { STRING_L4, 0, 1, 1 },
       
    49                 new Object[] { STRING_L4, 2, 4, 2 },
       
    50                 new Object[] { STRING_LLONG, 0, 8, 8 },
       
    51                 new Object[] { STRING_LLONG, 0, 5, 5 },
       
    52                 new Object[] { STRING_LLONG, 4, 8, 4 },
       
    53                 new Object[] { STRING_LLONG, 0, 7, 7 },
       
    54                 new Object[] { STRING_U1, 0, 1, 1 },
       
    55                 new Object[] { STRING_U2, 0, 2, 2 },
       
    56                 new Object[] { STRING_U2, 0, 1, 1 },
       
    57                 new Object[] { STRING_U2, 1, 2, 1 },
       
    58                 new Object[] { STRING_M12, 0, 2, 2 },
       
    59                 new Object[] { STRING_M12, 0, 1, 1 },
       
    60                 new Object[] { STRING_M12, 1, 2, 1 },
       
    61                 new Object[] { STRING_M11, 0, 2, 2 },
       
    62                 new Object[] { STRING_M11, 0, 1, 1 },
       
    63                 new Object[] { STRING_M11, 1, 2, 1 },
       
    64                 new Object[] { STRING_SUPPLEMENTARY, 0, 1, 1 },
       
    65                 new Object[] { STRING_SUPPLEMENTARY, 0, 2, 1 },
       
    66                 new Object[] { STRING_SUPPLEMENTARY, 0, 3, 2 },
       
    67                 new Object[] { STRING_SUPPLEMENTARY, 0, 5, 3 },
       
    68                 new Object[] { STRING_SUPPLEMENTARY, 0, 6, 4 },
       
    69                 new Object[] { STRING_SUPPLEMENTARY, 1, 4, 2 },
       
    70                 new Object[] { STRING_SUPPLEMENTARY, 1, 6, 4 },
       
    71                 new Object[] { STRING_SUPPLEMENTARY, 2, 4, 1 },};
       
    72     }
       
    73 
       
    74     @Test(dataProvider = "provider")
       
    75     public void testCodePointCount(String str, int beginIndex, int endIndex,
       
    76             int expected) {
       
    77         map.get(str)
       
    78                 .forEach(
       
    79                         (source, data) -> {
       
    80                             assertEquals(
       
    81                                     data.codePointCount(beginIndex, endIndex),
       
    82                                     expected,
       
    83                                     String.format(
       
    84                                             "testing String(%s).codePointCount(%d, %d), source : %s, ",
       
    85                                             escapeNonASCIIs(data), beginIndex,
       
    86                                             endIndex, source));
       
    87                         });
       
    88     }
       
    89 }