• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Arrays;
26 
27 import org.testng.annotations.DataProvider;
28 import org.testng.annotations.Test;
29 
30 import static org.testng.Assert.assertTrue;
31 
32 /*
33  * @test
34  * @bug 8077559
35  * @summary Tests Compact String. This one is for String.getChars.
36  * @run testng/othervm -XX:+CompactStrings GetChars
37  * @run testng/othervm -XX:-CompactStrings GetChars
38  */
39 
40 public class GetChars extends CompactString {
41 
42     @DataProvider
provider()43     public Object[][] provider() {
44         return new Object[][] {
45 
46                 new Object[] { STRING_EMPTY, 0, STRING_EMPTY.length(),
47                         new char[STRING_EMPTY.length()], 0, CHAR_ARRAY_EMPTY },
48                 new Object[] { STRING_L1, 0, STRING_L1.length(),
49                         new char[STRING_L1.length()], 0, CHAR_ARRAY_L1 },
50                 new Object[] { STRING_L2, 0, STRING_L2.length(),
51                         new char[STRING_L2.length()], 0, CHAR_ARRAY_L2 },
52                 new Object[] { STRING_L4, 0, STRING_L4.length(),
53                         new char[STRING_L4.length()], 0, CHAR_ARRAY_L4 },
54                 new Object[] { STRING_LLONG, 0, STRING_LLONG.length(),
55                         new char[STRING_LLONG.length()], 0, CHAR_ARRAY_LLONG },
56                 new Object[] { STRING_U1, 0, STRING_U1.length(),
57                         new char[STRING_U1.length()], 0, CHAR_ARRAY_U1 },
58                 new Object[] { STRING_U2, 0, STRING_U2.length(),
59                         new char[STRING_U2.length()], 0, CHAR_ARRAY_U2 },
60                 new Object[] { STRING_M12, 0, STRING_M12.length(),
61                         new char[STRING_M12.length()], 0, CHAR_ARRAY_M12 },
62                 new Object[] { STRING_M11, 0, STRING_M11.length(),
63                         new char[STRING_M11.length()], 0, CHAR_ARRAY_M11 },
64                 new Object[] { STRING_UDUPLICATE, 0,
65                         STRING_UDUPLICATE.length(),
66                         new char[STRING_UDUPLICATE.length()], 0,
67                         CHAR_ARRAY_UDUPLICATE },
68                 new Object[] { STRING_MDUPLICATE1, 0,
69                         STRING_MDUPLICATE1.length(),
70                         new char[STRING_MDUPLICATE1.length()], 0,
71                         CHAR_ARRAY_MDUPLICATE1 }, };
72     }
73 
74     @Test(dataProvider = "provider")
testGetChars(String str, int srcBegin, int srcEnd, char[] dst, int dstBegin, char[] expected)75     public void testGetChars(String str, int srcBegin, int srcEnd, char[] dst,
76             int dstBegin, char[] expected) {
77         map.get(str)
78                 .forEach(
79                         (source, data) -> {
80                             data.getChars(srcBegin, srcEnd, dst, dstBegin);
81                             assertTrue(
82                                     Arrays.equals(dst, expected),
83                                     String.format(
84                                             "testing String(%s).getChars(%d, %d, %s, %d), source : %s, ",
85                                             escapeNonASCIIs(data), srcBegin,
86                                             srcEnd, escapeNonASCIIs(Arrays
87                                                     .toString(dst)), dstBegin,
88                                             source));
89                         });
90     }
91 
92 }
93