Path: blob/master/test/jdk/java/lang/String/CompactString/GetChars.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 java.util.Arrays;2425import org.testng.annotations.DataProvider;26import org.testng.annotations.Test;2728import static org.testng.Assert.assertTrue;2930/*31* @test32* @bug 807755933* @summary Tests Compact String. This one is for String.getChars.34* @run testng/othervm -XX:+CompactStrings GetChars35* @run testng/othervm -XX:-CompactStrings GetChars36*/3738public class GetChars extends CompactString {3940@DataProvider41public Object[][] provider() {42return new Object[][] {4344new Object[] { STRING_EMPTY, 0, STRING_EMPTY.length(),45new char[STRING_EMPTY.length()], 0, CHAR_ARRAY_EMPTY },46new Object[] { STRING_L1, 0, STRING_L1.length(),47new char[STRING_L1.length()], 0, CHAR_ARRAY_L1 },48new Object[] { STRING_L2, 0, STRING_L2.length(),49new char[STRING_L2.length()], 0, CHAR_ARRAY_L2 },50new Object[] { STRING_L4, 0, STRING_L4.length(),51new char[STRING_L4.length()], 0, CHAR_ARRAY_L4 },52new Object[] { STRING_LLONG, 0, STRING_LLONG.length(),53new char[STRING_LLONG.length()], 0, CHAR_ARRAY_LLONG },54new Object[] { STRING_U1, 0, STRING_U1.length(),55new char[STRING_U1.length()], 0, CHAR_ARRAY_U1 },56new Object[] { STRING_U2, 0, STRING_U2.length(),57new char[STRING_U2.length()], 0, CHAR_ARRAY_U2 },58new Object[] { STRING_M12, 0, STRING_M12.length(),59new char[STRING_M12.length()], 0, CHAR_ARRAY_M12 },60new Object[] { STRING_M11, 0, STRING_M11.length(),61new char[STRING_M11.length()], 0, CHAR_ARRAY_M11 },62new Object[] { STRING_UDUPLICATE, 0,63STRING_UDUPLICATE.length(),64new char[STRING_UDUPLICATE.length()], 0,65CHAR_ARRAY_UDUPLICATE },66new Object[] { STRING_MDUPLICATE1, 0,67STRING_MDUPLICATE1.length(),68new char[STRING_MDUPLICATE1.length()], 0,69CHAR_ARRAY_MDUPLICATE1 }, };70}7172@Test(dataProvider = "provider")73public void testGetChars(String str, int srcBegin, int srcEnd, char[] dst,74int dstBegin, char[] expected) {75map.get(str)76.forEach(77(source, data) -> {78data.getChars(srcBegin, srcEnd, dst, dstBegin);79assertTrue(80Arrays.equals(dst, expected),81String.format(82"testing String(%s).getChars(%d, %d, %s, %d), source : %s, ",83escapeNonASCIIs(data), srcBegin,84srcEnd, escapeNonASCIIs(Arrays85.toString(dst)), dstBegin,86source));87});88}8990}919293