Path: blob/master/test/jdk/java/lang/String/CompactString/CodePointCount.java
41152 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import org.testng.annotations.DataProvider;24import org.testng.annotations.Test;2526import static org.testng.Assert.assertEquals;2728/*29* @test30* @bug 807755931* @summary Tests Compact String. This one is for String.codePointCount.32* @run testng/othervm -XX:+CompactStrings CodePointCount33* @run testng/othervm -XX:-CompactStrings CodePointCount34*/3536public class CodePointCount extends CompactString {3738@DataProvider39public Object[][] provider() {40return new Object[][] { new Object[] { STRING_EMPTY, 0, 0, 0 },41new Object[] { STRING_L1, 0, 1, 1 },42new Object[] { STRING_L1, 1, 1, 0 },43new Object[] { STRING_L2, 0, 2, 2 },44new Object[] { STRING_L2, 0, 1, 1 },45new Object[] { STRING_L2, 1, 2, 1 },46new Object[] { STRING_L4, 0, 4, 4 },47new Object[] { STRING_L4, 0, 1, 1 },48new Object[] { STRING_L4, 2, 4, 2 },49new Object[] { STRING_LLONG, 0, 8, 8 },50new Object[] { STRING_LLONG, 0, 5, 5 },51new Object[] { STRING_LLONG, 4, 8, 4 },52new Object[] { STRING_LLONG, 0, 7, 7 },53new Object[] { STRING_U1, 0, 1, 1 },54new Object[] { STRING_U2, 0, 2, 2 },55new Object[] { STRING_U2, 0, 1, 1 },56new Object[] { STRING_U2, 1, 2, 1 },57new Object[] { STRING_M12, 0, 2, 2 },58new Object[] { STRING_M12, 0, 1, 1 },59new Object[] { STRING_M12, 1, 2, 1 },60new Object[] { STRING_M11, 0, 2, 2 },61new Object[] { STRING_M11, 0, 1, 1 },62new Object[] { STRING_M11, 1, 2, 1 },63new Object[] { STRING_SUPPLEMENTARY, 0, 1, 1 },64new Object[] { STRING_SUPPLEMENTARY, 0, 2, 1 },65new Object[] { STRING_SUPPLEMENTARY, 0, 3, 2 },66new Object[] { STRING_SUPPLEMENTARY, 0, 5, 3 },67new Object[] { STRING_SUPPLEMENTARY, 0, 6, 4 },68new Object[] { STRING_SUPPLEMENTARY, 1, 4, 2 },69new Object[] { STRING_SUPPLEMENTARY, 1, 6, 4 },70new Object[] { STRING_SUPPLEMENTARY, 2, 4, 1 },};71}7273@Test(dataProvider = "provider")74public void testCodePointCount(String str, int beginIndex, int endIndex,75int expected) {76map.get(str)77.forEach(78(source, data) -> {79assertEquals(80data.codePointCount(beginIndex, endIndex),81expected,82String.format(83"testing String(%s).codePointCount(%d, %d), source : %s, ",84escapeNonASCIIs(data), beginIndex,85endIndex, source));86});87}88}899091