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 package test.java.lang.String.CompactString; 24 25 import java.util.stream.IntStream; 26 27 import org.testng.annotations.DataProvider; 28 import org.testng.annotations.Test; 29 30 import static org.testng.Assert.assertEquals; 31 32 /* 33 * @test 34 * @bug 8077559 35 * @summary Tests Compact String. This one is for String.charAt. 36 * @run testng/othervm -XX:+CompactStrings CharAt 37 * @run testng/othervm -XX:-CompactStrings CharAt 38 */ 39 40 public class CharAt extends CompactString { 41 42 @DataProvider provider()43 public Object[][] provider() { 44 return new Object[][] { 45 new Object[] { STRING_L1, new char[] { 'A' } }, 46 new Object[] { STRING_L2, new char[] { 'A', 'B' } }, 47 new Object[] { STRING_L4, new char[] { 'A', 'B', 'C', 'D' } }, 48 new Object[] { STRING_LLONG, 49 new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' } }, 50 new Object[] { STRING_U1, new char[] { '\uFF21' } }, 51 new Object[] { STRING_U2, new char[] { '\uFF21', '\uFF22' } }, 52 new Object[] { STRING_M12, new char[] { '\uFF21', 'A' } }, 53 new Object[] { STRING_M11, new char[] { 'A', '\uFF21' } }, }; 54 } 55 56 @Test(dataProvider = "provider") testCharAt(String str, char[] expected)57 public void testCharAt(String str, char[] expected) { 58 map.get(str) 59 .forEach( 60 (source, data) -> { 61 IntStream 62 .range(0, str.length()) 63 .forEach( 64 i -> assertEquals( 65 str.charAt(i), 66 expected[i], 67 String.format( 68 "testing String(%s).charAt(%d), source : %s, ", 69 escapeNonASCIIs(data), 70 i, source))); 71 }); 72 } 73 } 74