undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
72
test/jdk/java/lang/String/CompactString/CharAt.java
Normal file
72
test/jdk/java/lang/String/CompactString/CharAt.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.charAt.
|
||||
* @run testng/othervm -XX:+CompactStrings CharAt
|
||||
* @run testng/othervm -XX:-CompactStrings CharAt
|
||||
*/
|
||||
|
||||
public class CharAt extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_L1, new char[] { 'A' } },
|
||||
new Object[] { STRING_L2, new char[] { 'A', 'B' } },
|
||||
new Object[] { STRING_L4, new char[] { 'A', 'B', 'C', 'D' } },
|
||||
new Object[] { STRING_LLONG,
|
||||
new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' } },
|
||||
new Object[] { STRING_U1, new char[] { '\uFF21' } },
|
||||
new Object[] { STRING_U2, new char[] { '\uFF21', '\uFF22' } },
|
||||
new Object[] { STRING_M12, new char[] { '\uFF21', 'A' } },
|
||||
new Object[] { STRING_M11, new char[] { 'A', '\uFF21' } }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCharAt(String str, char[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
IntStream
|
||||
.range(0, str.length())
|
||||
.forEach(
|
||||
i -> assertEquals(
|
||||
str.charAt(i),
|
||||
expected[i],
|
||||
String.format(
|
||||
"testing String(%s).charAt(%d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
i, source)));
|
||||
});
|
||||
}
|
||||
}
|
||||
79
test/jdk/java/lang/String/CompactString/CodePointAt.java
Normal file
79
test/jdk/java/lang/String/CompactString/CodePointAt.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.codePointAt.
|
||||
* @run testng/othervm -XX:+CompactStrings CodePointAt
|
||||
* @run testng/othervm -XX:-CompactStrings CodePointAt
|
||||
*/
|
||||
|
||||
public class CodePointAt extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_L1, new int[] { 'A' } },
|
||||
new Object[] { STRING_L2, new int[] { 'A', 'B' } },
|
||||
new Object[] { STRING_L4, new int[] { 'A', 'B', 'C', 'D' } },
|
||||
new Object[] { STRING_LLONG,
|
||||
new int[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' } },
|
||||
new Object[] { STRING_U1, new int[] { '\uFF21' } },
|
||||
new Object[] { STRING_U2, new int[] { '\uFF21', '\uFF22' } },
|
||||
new Object[] { STRING_M12, new int[] { '\uFF21', 'A' } },
|
||||
new Object[] { STRING_M11, new int[] { 'A', '\uFF21' } },
|
||||
new Object[] {
|
||||
STRING_SUPPLEMENTARY,
|
||||
new int[] { Character.toCodePoint('\uD801', '\uDC00'),
|
||||
'\uDC00',
|
||||
Character.toCodePoint('\uD801', '\uDC01'),
|
||||
'\uDC01', '\uFF21', 'A' }, } };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCodePointAt(String str, int[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
IntStream
|
||||
.range(0, str.length())
|
||||
.forEach(
|
||||
i -> assertEquals(
|
||||
str.codePointAt(i),
|
||||
expected[i],
|
||||
String.format(
|
||||
"testing String(%s).codePointAt(%d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
i, source)));
|
||||
});
|
||||
}
|
||||
}
|
||||
79
test/jdk/java/lang/String/CompactString/CodePointBefore.java
Normal file
79
test/jdk/java/lang/String/CompactString/CodePointBefore.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.codePointBefore.
|
||||
* @run testng/othervm -XX:+CompactStrings CodePointBefore
|
||||
* @run testng/othervm -XX:-CompactStrings CodePointBefore
|
||||
*/
|
||||
|
||||
public class CodePointBefore extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_L1, new int[] { 'A' } },
|
||||
new Object[] { STRING_L2, new int[] { 'A', 'B' } },
|
||||
new Object[] { STRING_L4, new int[] { 'A', 'B', 'C', 'D' } },
|
||||
new Object[] { STRING_LLONG,
|
||||
new int[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' } },
|
||||
new Object[] { STRING_U1, new int[] { '\uFF21' } },
|
||||
new Object[] { STRING_U2, new int[] { '\uFF21', '\uFF22' } },
|
||||
new Object[] { STRING_M12, new int[] { '\uFF21', 'A' } },
|
||||
new Object[] { STRING_M11, new int[] { 'A', '\uFF21' } },
|
||||
new Object[] {
|
||||
STRING_SUPPLEMENTARY,
|
||||
new int[] { '\uD801', Character.toCodePoint('\uD801', '\uDC00'),
|
||||
'\uD801', Character.toCodePoint('\uD801', '\uDC01'),
|
||||
'\uFF21', 'A' }, } };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCodePointBefore(String str, int[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
IntStream
|
||||
.range(0, str.length())
|
||||
.forEach(
|
||||
i -> assertEquals(
|
||||
str.codePointBefore(i + 1),
|
||||
expected[i],
|
||||
String.format(
|
||||
"testing String(%s).codePointBefore(%d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
i + 1, source)));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
89
test/jdk/java/lang/String/CompactString/CodePointCount.java
Normal file
89
test/jdk/java/lang/String/CompactString/CodePointCount.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.codePointCount.
|
||||
* @run testng/othervm -XX:+CompactStrings CodePointCount
|
||||
* @run testng/othervm -XX:-CompactStrings CodePointCount
|
||||
*/
|
||||
|
||||
public class CodePointCount extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] { new Object[] { STRING_EMPTY, 0, 0, 0 },
|
||||
new Object[] { STRING_L1, 0, 1, 1 },
|
||||
new Object[] { STRING_L1, 1, 1, 0 },
|
||||
new Object[] { STRING_L2, 0, 2, 2 },
|
||||
new Object[] { STRING_L2, 0, 1, 1 },
|
||||
new Object[] { STRING_L2, 1, 2, 1 },
|
||||
new Object[] { STRING_L4, 0, 4, 4 },
|
||||
new Object[] { STRING_L4, 0, 1, 1 },
|
||||
new Object[] { STRING_L4, 2, 4, 2 },
|
||||
new Object[] { STRING_LLONG, 0, 8, 8 },
|
||||
new Object[] { STRING_LLONG, 0, 5, 5 },
|
||||
new Object[] { STRING_LLONG, 4, 8, 4 },
|
||||
new Object[] { STRING_LLONG, 0, 7, 7 },
|
||||
new Object[] { STRING_U1, 0, 1, 1 },
|
||||
new Object[] { STRING_U2, 0, 2, 2 },
|
||||
new Object[] { STRING_U2, 0, 1, 1 },
|
||||
new Object[] { STRING_U2, 1, 2, 1 },
|
||||
new Object[] { STRING_M12, 0, 2, 2 },
|
||||
new Object[] { STRING_M12, 0, 1, 1 },
|
||||
new Object[] { STRING_M12, 1, 2, 1 },
|
||||
new Object[] { STRING_M11, 0, 2, 2 },
|
||||
new Object[] { STRING_M11, 0, 1, 1 },
|
||||
new Object[] { STRING_M11, 1, 2, 1 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 1, 1 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 2, 1 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 3, 2 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 5, 3 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 6, 4 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 1, 4, 2 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 1, 6, 4 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 2, 4, 1 },};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCodePointCount(String str, int beginIndex, int endIndex,
|
||||
int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.codePointCount(beginIndex, endIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).codePointCount(%d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), beginIndex,
|
||||
endIndex, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
305
test/jdk/java/lang/String/CompactString/CompactString.java
Normal file
305
test/jdk/java/lang/String/CompactString/CompactString.java
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
/*
|
||||
* Base class of tests for Compact String.
|
||||
*
|
||||
*/
|
||||
public class CompactString {
|
||||
|
||||
final Map<String, Map<String, String>> map = new HashMap<>();
|
||||
|
||||
enum StringSources {
|
||||
EMPTY(STRING_EMPTY, BYTE_ARRAY_EMTPY, CHAR_ARRAY_EMPTY,
|
||||
POINT_ARRAY_EMTPY), LDUPLICATE(STRING_LDUPLICATE,
|
||||
BYTE_ARRAY_LDUPLICATE, CHAR_ARRAY_LDUPLICATE,
|
||||
POINT_ARRAY_LDUPLICATE), LLONG(STRING_LLONG, BYTE_ARRAY_LLONG,
|
||||
CHAR_ARRAY_LLONG, POINT_ARRAY_LLONG), L1(STRING_L1,
|
||||
BYTE_ARRAY_L1, CHAR_ARRAY_L1, POINT_ARRAY_L1), L2(STRING_L2,
|
||||
BYTE_ARRAY_L2, CHAR_ARRAY_L2, POINT_ARRAY_L2), L4(STRING_L4,
|
||||
BYTE_ARRAY_L4, CHAR_ARRAY_L4, POINT_ARRAY_L4), UDUPLICATE(
|
||||
STRING_UDUPLICATE, BYTE_ARRAY_UDUPLICATE,
|
||||
CHAR_ARRAY_UDUPLICATE, POINT_ARRAY_UDUPLICATE), U1(STRING_U1,
|
||||
BYTE_ARRAY_U1, CHAR_ARRAY_U1, POINT_ARRAY_U1), U2(STRING_U2,
|
||||
BYTE_ARRAY_U2, CHAR_ARRAY_U2, POINT_ARRAY_U2), MDUPLICATE1(
|
||||
STRING_MDUPLICATE1, BYTE_ARRAY_MDUPLICATE1,
|
||||
CHAR_ARRAY_MDUPLICATE1, POINT_ARRAY_MDUPLICATE1), MDUPLICATE2(
|
||||
STRING_MDUPLICATE2, BYTE_ARRAY_MDUPLICATE2,
|
||||
CHAR_ARRAY_MDUPLICATE2, POINT_ARRAY_MDUPLICATE2), MLONG1(
|
||||
STRING_MLONG1, BYTE_ARRAY_MLONG1, CHAR_ARRAY_MLONG1,
|
||||
POINT_ARRAY_MLONG1), MLONG2(STRING_MLONG2, BYTE_ARRAY_MLONG2,
|
||||
CHAR_ARRAY_MLONG2, POINT_ARRAY_MLONG2), M11(STRING_M11,
|
||||
BYTE_ARRAY_M11, CHAR_ARRAY_M11, POINT_ARRAY_M11), M12(
|
||||
STRING_M12, BYTE_ARRAY_M12, CHAR_ARRAY_M12, POINT_ARRAY_M12), SUPPLEMENTARY(
|
||||
STRING_SUPPLEMENTARY, BYTE_ARRAY_SUPPLEMENTARY,
|
||||
CHAR_ARRAY_SUPPLEMENTARY, POINT_ARRAY_SUPPLEMENTARY), SUPPLEMENTARY_LOWERCASE(
|
||||
STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
BYTE_ARRAY_SUPPLEMENTARY_LOWERCASE,
|
||||
CHAR_ARRAY_SUPPLEMENTARY_LOWERCASE,
|
||||
POINT_ARRAY_SUPPLEMENTARY_LOWERCASE);
|
||||
|
||||
private StringSources(String s, byte[] b, char[] c, int[] i) {
|
||||
str = s;
|
||||
ba = b;
|
||||
ca = c;
|
||||
ia = i;
|
||||
}
|
||||
|
||||
String getString() {
|
||||
return str;
|
||||
}
|
||||
|
||||
byte[] getByteArray() {
|
||||
return ba;
|
||||
}
|
||||
|
||||
char[] getCharArray() {
|
||||
return ca;
|
||||
}
|
||||
|
||||
int[] getIntArray() {
|
||||
return ia;
|
||||
}
|
||||
|
||||
private final String str;
|
||||
private final byte[] ba;
|
||||
private final char[] ca;
|
||||
private final int[] ia;
|
||||
}
|
||||
|
||||
protected static final String DEFAULT_CHARSET_NAME = "UTF-8";
|
||||
protected static final Charset DEFAULT_CHARSET = Charset
|
||||
.forName(DEFAULT_CHARSET_NAME);
|
||||
|
||||
protected static final String STRING_EMPTY = "";
|
||||
protected static final byte[] BYTE_ARRAY_EMTPY = new byte[0];
|
||||
protected static final char[] CHAR_ARRAY_EMPTY = new char[0];
|
||||
protected static final int[] POINT_ARRAY_EMTPY = new int[0];
|
||||
|
||||
protected static final String STRING_LDUPLICATE = "ABABABABAB";
|
||||
protected static final byte[] BYTE_ARRAY_LDUPLICATE = new byte[] { 'A', 'B',
|
||||
'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B' };
|
||||
protected static final char[] CHAR_ARRAY_LDUPLICATE = new char[] { 'A', 'B',
|
||||
'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B' };
|
||||
protected static final int[] POINT_ARRAY_LDUPLICATE = new int[] { 'A', 'B',
|
||||
'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B' };
|
||||
|
||||
protected static final String STRING_LLONG = "ABCDEFGH";
|
||||
protected static final byte[] BYTE_ARRAY_LLONG = new byte[] { 'A', 'B', 'C',
|
||||
'D', 'E', 'F', 'G', 'H' };
|
||||
protected static final char[] CHAR_ARRAY_LLONG = new char[] { 'A', 'B', 'C',
|
||||
'D', 'E', 'F', 'G', 'H' };
|
||||
protected static final int[] POINT_ARRAY_LLONG = new int[] { 'A', 'B', 'C',
|
||||
'D', 'E', 'F', 'G', 'H' };
|
||||
|
||||
protected static final String STRING_L1 = "A";
|
||||
protected static final byte[] BYTE_ARRAY_L1 = new byte[] { 'A' };
|
||||
protected static final char[] CHAR_ARRAY_L1 = new char[] { 'A' };
|
||||
protected static final int[] POINT_ARRAY_L1 = new int[] { 'A' };
|
||||
|
||||
protected static final String STRING_L2 = "AB";
|
||||
protected static final byte[] BYTE_ARRAY_L2 = new byte[] { 'A', 'B' };
|
||||
protected static final char[] CHAR_ARRAY_L2 = new char[] { 'A', 'B' };
|
||||
protected static final int[] POINT_ARRAY_L2 = new int[] { 'A', 'B' };
|
||||
|
||||
protected static final String STRING_L4 = "ABCD";
|
||||
protected static final byte[] BYTE_ARRAY_L4 = new byte[] { 'A', 'B', 'C', 'D' };
|
||||
protected static final char[] CHAR_ARRAY_L4 = new char[] { 'A', 'B', 'C', 'D' };
|
||||
protected static final int[] POINT_ARRAY_L4 = new int[] { 'A', 'B', 'C', 'D' };
|
||||
|
||||
/*
|
||||
* Because right now ASCII is the default encoding parameter for source code
|
||||
* in JDK build environment, so we escape them. same as below.
|
||||
*/
|
||||
protected static final String STRING_UDUPLICATE = "\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22";
|
||||
protected static final byte[] BYTE_ARRAY_UDUPLICATE = getBytes(STRING_UDUPLICATE);
|
||||
protected static final char[] CHAR_ARRAY_UDUPLICATE = new char[] { '\uFF21',
|
||||
'\uFF22', '\uFF21', '\uFF22', '\uFF21', '\uFF22', '\uFF21',
|
||||
'\uFF22', '\uFF21', '\uFF22' };
|
||||
protected static final int[] POINT_ARRAY_UDUPLICATE = new int[] { '\uFF21',
|
||||
'\uFF22', '\uFF21', '\uFF22', '\uFF21', '\uFF22', '\uFF21',
|
||||
'\uFF22', '\uFF21', '\uFF22' };
|
||||
|
||||
protected static final String STRING_U1 = "\uFF21";
|
||||
protected static final byte[] BYTE_ARRAY_U1 = getBytes(STRING_U1);
|
||||
protected static final char[] CHAR_ARRAY_U1 = new char[] { '\uFF21' };
|
||||
protected static final int[] POINT_ARRAY_U1 = new int[] { '\uFF21' };
|
||||
|
||||
protected static final String STRING_U2 = "\uFF21\uFF22";
|
||||
protected static final byte[] BYTE_ARRAY_U2 = getBytes(STRING_U2);
|
||||
protected static final char[] CHAR_ARRAY_U2 = new char[] { '\uFF21', '\uFF22' };
|
||||
protected static final int[] POINT_ARRAY_U2 = new int[] { '\uFF21', '\uFF22' };
|
||||
|
||||
protected static final String STRING_MDUPLICATE1 = "\uFF21A\uFF21A\uFF21A\uFF21A\uFF21A";
|
||||
protected static final byte[] BYTE_ARRAY_MDUPLICATE1 = getBytes(STRING_MDUPLICATE1);
|
||||
protected static final char[] CHAR_ARRAY_MDUPLICATE1 = new char[] { '\uFF21',
|
||||
'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A' };
|
||||
protected static final int[] POINT_ARRAY_MDUPLICATE1 = new int[] { '\uFF21',
|
||||
'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A' };
|
||||
|
||||
protected static final String STRING_MDUPLICATE2 = "A\uFF21A\uFF21A\uFF21A\uFF21A\uFF21";
|
||||
protected static final byte[] BYTE_ARRAY_MDUPLICATE2 = getBytes(STRING_MDUPLICATE2);
|
||||
protected static final char[] CHAR_ARRAY_MDUPLICATE2 = new char[] { 'A',
|
||||
'\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A',
|
||||
'\uFF21' };
|
||||
protected static final int[] POINT_ARRAY_MDUPLICATE2 = new int[] { 'A',
|
||||
'\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A', '\uFF21', 'A',
|
||||
'\uFF21' };
|
||||
|
||||
protected static final String STRING_MLONG1 = "A\uFF21B\uFF22C\uFF23D\uFF24E\uFF25F\uFF26G\uFF27H\uFF28";
|
||||
protected static final byte[] BYTE_ARRAY_MLONG1 = getBytes(STRING_MLONG1);
|
||||
protected static final char[] CHAR_ARRAY_MLONG1 = new char[] { 'A', '\uFF21',
|
||||
'B', '\uFF22', 'C', '\uFF23', 'D', '\uFF24', 'E', '\uFF25', 'F',
|
||||
'\uFF26', 'G', '\uFF27', 'H', '\uFF28' };
|
||||
protected static final int[] POINT_ARRAY_MLONG1 = new int[] { 'A', '\uFF21',
|
||||
'B', '\uFF22', 'C', '\uFF23', 'D', '\uFF24', 'E', '\uFF25', 'F',
|
||||
'\uFF26', 'G', '\uFF27', 'H', '\uFF28' };
|
||||
|
||||
protected static final String STRING_MLONG2 = "\uFF21A\uFF22B\uFF23C\uFF24D\uFF25E\uFF26F\uFF27G\uFF28H";
|
||||
protected static final byte[] BYTE_ARRAY_MLONG2 = getBytes(STRING_MLONG2);
|
||||
protected static final char[] CHAR_ARRAY_MLONG2 = new char[] { '\uFF21', 'A',
|
||||
'\uFF22', 'B', '\uFF23', 'C', '\uFF24', 'D', '\uFF25', 'E',
|
||||
'\uFF26', 'F', '\uFF27', 'G', '\uFF28', 'H' };
|
||||
protected static final int[] POINT_ARRAY_MLONG2 = new int[] { '\uFF21', 'A',
|
||||
'\uFF22', 'B', '\uFF23', 'C', '\uFF24', 'D', '\uFF25', 'E',
|
||||
'\uFF26', 'F', '\uFF27', 'G', '\uFF28', 'H' };
|
||||
|
||||
protected static final String STRING_M11 = "A\uFF21";
|
||||
protected static final byte[] BYTE_ARRAY_M11 = getBytes(STRING_M11);
|
||||
protected static final char[] CHAR_ARRAY_M11 = new char[] { 'A', '\uFF21' };
|
||||
protected static final int[] POINT_ARRAY_M11 = new int[] { 'A', '\uFF21' };
|
||||
|
||||
protected static final String STRING_M12 = "\uFF21A";
|
||||
protected static final byte[] BYTE_ARRAY_M12 = getBytes(STRING_M12);
|
||||
protected static final char[] CHAR_ARRAY_M12 = new char[] { '\uFF21', 'A' };
|
||||
protected static final int[] POINT_ARRAY_M12 = new int[] { '\uFF21', 'A' };
|
||||
|
||||
protected static final String STRING_SUPPLEMENTARY = "\uD801\uDC00\uD801\uDC01\uFF21A";
|
||||
protected static final byte[] BYTE_ARRAY_SUPPLEMENTARY = getBytes(STRING_SUPPLEMENTARY);
|
||||
protected static final char[] CHAR_ARRAY_SUPPLEMENTARY = new char[] {
|
||||
'\uD801', '\uDC00', '\uD801', '\uDC01', '\uFF21', 'A' };
|
||||
protected static final int[] POINT_ARRAY_SUPPLEMENTARY = new int[] {
|
||||
'\uD801', '\uDC00', '\uD801', '\uDC01', '\uFF21', 'A' };
|
||||
|
||||
protected static final String STRING_SUPPLEMENTARY_LOWERCASE = "\uD801\uDC28\uD801\uDC29\uFF41a";
|
||||
protected static final byte[] BYTE_ARRAY_SUPPLEMENTARY_LOWERCASE = getBytes(STRING_SUPPLEMENTARY_LOWERCASE);
|
||||
protected static final char[] CHAR_ARRAY_SUPPLEMENTARY_LOWERCASE = new char[] {
|
||||
'\uD801', '\uDC28', '\uD801', '\uDC29', '\uFF41', 'a' };
|
||||
protected static final int[] POINT_ARRAY_SUPPLEMENTARY_LOWERCASE = new int[] {
|
||||
'\uD801', '\uDC28', '\uD801', '\uDC29', '\uFF41', 'a' };
|
||||
|
||||
protected static final String SRC_BYTE_ARRAY_WITH_CHARSETNAME = "source from byte array with charset name";
|
||||
protected static final String SRC_BYTE_ARRAY_WITH_CHARSET = "source from byte array with charset";
|
||||
protected static final String SRC_CHAR_ARRAY = "source from char array";
|
||||
protected static final String SRC_POINT_ARRAY = "source from code point array";
|
||||
protected static final String SRC_STRING = "source from String";
|
||||
protected static final String SRC_STRINGBUFFER = "source from StringBuffer";
|
||||
protected static final String SRC_STRINGBUILDER = "source from StringBuilder";
|
||||
protected static final String SRC_COPYVALUEOF = "source from copyValueOf from char array";
|
||||
protected static final String SRC_VALUEOF = "source from valueOf from char array";
|
||||
|
||||
static {
|
||||
System.out
|
||||
.println(String
|
||||
.format("====== The platform's default charset is \"%s\", we're using \"%s\" for testing.",
|
||||
Charset.defaultCharset().name(),
|
||||
DEFAULT_CHARSET_NAME));
|
||||
}
|
||||
|
||||
private static byte[] getBytes(String str) {
|
||||
byte[] res = null;
|
||||
try {
|
||||
res = str.getBytes(DEFAULT_CHARSET_NAME);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("caught UnsupportedEncodingException!!!", e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private void setUpOneString(String content, byte[] ba, char[] ca, int[] cpa)
|
||||
throws UnsupportedEncodingException {
|
||||
final Map<String, String> m = new HashMap<>();
|
||||
m.put(SRC_BYTE_ARRAY_WITH_CHARSETNAME, new String(ba,
|
||||
DEFAULT_CHARSET_NAME));
|
||||
m.put(SRC_BYTE_ARRAY_WITH_CHARSET, new String(ba, DEFAULT_CHARSET));
|
||||
m.put(SRC_CHAR_ARRAY, new String(ca));
|
||||
m.put(SRC_POINT_ARRAY, new String(cpa, 0, cpa.length));
|
||||
m.put(SRC_STRING, new String(content));
|
||||
m.put(SRC_STRINGBUFFER, new String(new StringBuffer(content)));
|
||||
m.put(SRC_STRINGBUILDER, new String(new StringBuilder(content)));
|
||||
m.put(SRC_COPYVALUEOF, String.copyValueOf(ca));
|
||||
m.put(SRC_VALUEOF, String.valueOf(ca));
|
||||
map.put(content, m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the test data, use 9 ways to construct one String.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* If the named charset is not supported in setUpOneString(xxx).
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setUp() throws UnsupportedEncodingException {
|
||||
for (StringSources src : StringSources.values()) {
|
||||
setUpOneString(src.getString(), src.getByteArray(),
|
||||
src.getCharArray(), src.getIntArray());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Escape non-ASCII characters since not all systems support them.
|
||||
*/
|
||||
protected String escapeNonASCIIs(String str) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c > 0x7F) {
|
||||
sb.append("\\u").append(Integer.toHexString((int) c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Escape non-ASCII characters since not all systems support them.
|
||||
*/
|
||||
protected String escapeNonASCII(char c) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (c > 0x7F) {
|
||||
sb.append("\\u").append(Integer.toHexString((int) c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
137
test/jdk/java/lang/String/CompactString/CompareTo.java
Normal file
137
test/jdk/java/lang/String/CompactString/CompareTo.java
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559 8137326
|
||||
* @summary Tests Compact String. Verifies the compareTo method for String,
|
||||
* StringBuilder and StringBuffer.
|
||||
* @run testng/othervm -XX:+CompactStrings CompareTo
|
||||
* @run testng/othervm -XX:-CompactStrings CompareTo
|
||||
*/
|
||||
|
||||
public class CompareTo extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "A", -1 },
|
||||
new Object[] { STRING_EMPTY, "\uFF21", -1 },
|
||||
new Object[] { STRING_L1, "AB", -1 },
|
||||
new Object[] { STRING_L1, "A", 0 },
|
||||
new Object[] { STRING_L1, "a", -32 },
|
||||
new Object[] { STRING_L1, "\uFF21", -65248 },
|
||||
new Object[] { STRING_L2, "AB", 0 },
|
||||
new Object[] { STRING_L2, "Ab", -32 },
|
||||
new Object[] { STRING_L2, "AA", 1 },
|
||||
new Object[] { STRING_L2, "\uFF21", -65248 },
|
||||
new Object[] { STRING_L2, "A\uFF21", -65247 },
|
||||
new Object[] { STRING_L4, "ABC", 1 },
|
||||
new Object[] { STRING_L4, "AB", 2 },
|
||||
new Object[] { STRING_L4, "ABcD", -32 },
|
||||
new Object[] { STRING_L4, "ABCD\uFF21\uFF21", -2 },
|
||||
new Object[] { STRING_L4, "ABCD\uFF21", -1 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFG\uFF21", -65241 },
|
||||
new Object[] { STRING_LLONG, "AB", 6 },
|
||||
new Object[] { STRING_LLONG, "ABCD", 4 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH\uFF21\uFF21", -2 },
|
||||
new Object[] { STRING_U1, "\uFF21", 0 },
|
||||
new Object[] { STRING_U1, "\uFF22", -1 },
|
||||
new Object[] { STRING_U1, "\uFF21\uFF22", -1 },
|
||||
new Object[] { STRING_U1, "A", 65248 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 0 },
|
||||
new Object[] { STRING_U2, "\uFF22", -1 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF21", 1 },
|
||||
new Object[] { STRING_U2, "A", 65248 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 0 },
|
||||
new Object[] { STRING_M12, "A\uFF21", 65248 },
|
||||
new Object[] { STRING_M12, "\uFF21\uFF21", -65248 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 0 },
|
||||
new Object[] { STRING_M11, "\uFF21A", -65248 },
|
||||
new Object[] { STRING_M11, "AA", 65248 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCompareTo(String str, String anotherString, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.compareTo(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).compareTo(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs the same test with StringBuilder
|
||||
*/
|
||||
@Test(dataProvider = "provider")
|
||||
public void testStringBuilder(String str, String anotherString, int expected) {
|
||||
StringBuilder another = new StringBuilder(anotherString);
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
StringBuilder sb = new StringBuilder(data);
|
||||
assertEquals(
|
||||
sb.compareTo(another),
|
||||
expected,
|
||||
String.format(
|
||||
"testing StringBuilder(%s).compareTo(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs the same test with StringBuffer
|
||||
*/
|
||||
@Test(dataProvider = "provider")
|
||||
public void testStringBuffer(String str, String anotherString, int expected) {
|
||||
StringBuffer another = new StringBuffer(anotherString);
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
StringBuffer sb = new StringBuffer(data);
|
||||
assertEquals(
|
||||
sb.compareTo(another),
|
||||
expected,
|
||||
String.format(
|
||||
"testing StringBuffer(%s).compareTo(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559 8248655 8264544
|
||||
* @summary Tests Compact String. This one is for String.compareToIgnoreCase.
|
||||
* @run testng/othervm -XX:+CompactStrings CompareToIgnoreCase
|
||||
* @run testng/othervm -XX:-CompactStrings CompareToIgnoreCase
|
||||
*/
|
||||
|
||||
public class CompareToIgnoreCase extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_EMPTY, "A", -1 },
|
||||
new Object[] { STRING_L1, "a", 0 },
|
||||
new Object[] { STRING_L1, "A", 0 },
|
||||
new Object[] { STRING_L1, "\uFF21", -65248 },
|
||||
new Object[] { STRING_L1, "B", -1 },
|
||||
new Object[] { STRING_L2, "AB", 0 },
|
||||
new Object[] { STRING_L2, "aB", 0 },
|
||||
new Object[] { STRING_L2, "\uFF21", -65248 },
|
||||
new Object[] { STRING_L2, "A\uFF21", -65247 },
|
||||
new Object[] { STRING_L4, "ABCD", 0 },
|
||||
new Object[] { STRING_L4, "abcd", 0 },
|
||||
new Object[] { STRING_L4, "ABc\uFF21", -65245 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", 0 },
|
||||
new Object[] { STRING_LLONG, "abcdefgh", 0 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFG\uFF21", -65241 },
|
||||
new Object[] { STRING_LLONG, "abcdefg\uFF21", -65241 },
|
||||
new Object[] { STRING_U1, "\uFF41", 0 },
|
||||
new Object[] { STRING_U1,
|
||||
"\uFF41\uFF42\uFF43\uFF44\uFF45\uFF46\uFF47\uFF48", -7 },
|
||||
new Object[] { STRING_U1, "A", 65248 },
|
||||
new Object[] { STRING_U2, "\uFF41", 1 },
|
||||
new Object[] { STRING_U2, "\uFF41\uFF42", 0 },
|
||||
new Object[] { STRING_U2,
|
||||
"\uFF41\uFF42\uFF43\uFF44\uFF45\uFF46\uFF47\uFF48", -6 },
|
||||
new Object[] { STRING_M12, "\uFF41a", 0 },
|
||||
new Object[] { STRING_M12, "\uFF41\uFF42", -65249 },
|
||||
new Object[] { STRING_M11, "a\uFF41", 0 },
|
||||
new Object[] { STRING_M11, "a\uFF42", -1 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, STRING_SUPPLEMENTARY_LOWERCASE, 0 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "\uD801\uDC28\uD801\uDC27\uFF41a", -38 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "\uD802\uDC00\uD801\uDC01\uFF21A", -984 },
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCompareToIgnoreCase(String str, String anotherString,
|
||||
int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.compareToIgnoreCase(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).compareToIgnoreCase(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
132
test/jdk/java/lang/String/CompactString/Concat.java
Normal file
132
test/jdk/java/lang/String/CompactString/Concat.java
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.concat.
|
||||
* @run testng/othervm -XX:+CompactStrings Concat
|
||||
* @run testng/othervm -XX:-CompactStrings Concat
|
||||
*/
|
||||
|
||||
public class Concat extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_EMPTY, "ABC", "ABC" },
|
||||
new Object[] { STRING_EMPTY,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"ABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_EMPTY,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_L1,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"AABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_L1,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"A\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_L2,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"ABABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_L2,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"AB\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_L4,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"ABCDABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_L4,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"ABCD\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_LLONG,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"ABCDEFGHABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_LLONG,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"ABCDEFGH\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_U1,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"\uFF21ABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_U1,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"\uFF21\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_U2,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"\uFF21\uFF22ABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_U2,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_M12,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"\uFF21AABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_M12,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"\uFF21A\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },
|
||||
new Object[] { STRING_M11,
|
||||
"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),
|
||||
"A\uFF21ABC\uFF21\uFF22\uFF23DEF" },
|
||||
new Object[] {
|
||||
STRING_M11,
|
||||
"\uFF21\uFF22\uFF23".concat("ABC").concat(
|
||||
"\uFF24\uFF25\uFF26"),
|
||||
"A\uFF21\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testConcat(String str, String anotherString, String expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.concat(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).concat(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
91
test/jdk/java/lang/String/CompactString/Contains.java
Normal file
91
test/jdk/java/lang/String/CompactString/Contains.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.contains.
|
||||
* @run testng/othervm -XX:+CompactStrings Contains
|
||||
* @run testng/othervm -XX:-CompactStrings Contains
|
||||
*/
|
||||
|
||||
public class Contains extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "", true },
|
||||
new Object[] { STRING_EMPTY, "A", false },
|
||||
new Object[] { STRING_EMPTY, "\uFF21", false },
|
||||
new Object[] { STRING_L1, "", true },
|
||||
new Object[] { STRING_L1, "A", true },
|
||||
new Object[] { STRING_L1, "\uFF21", false },
|
||||
new Object[] { STRING_L2, "", true },
|
||||
new Object[] { STRING_L2, "A", true },
|
||||
new Object[] { STRING_L2, "AB", true },
|
||||
new Object[] { STRING_L2, "B", true },
|
||||
new Object[] { STRING_L2, "ABC", false },
|
||||
new Object[] { STRING_L2, "ab", false },
|
||||
new Object[] { STRING_L4, "ABCD", true },
|
||||
new Object[] { STRING_L4, "BC", true },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", true },
|
||||
new Object[] { STRING_LLONG, "BCDEFGH", true },
|
||||
new Object[] { STRING_LLONG, "EF", true },
|
||||
new Object[] { STRING_U1, "", true },
|
||||
new Object[] { STRING_U1, "\uFF21", true },
|
||||
new Object[] { STRING_U1, "a", false },
|
||||
new Object[] { STRING_U1, "\uFF21B", false },
|
||||
new Object[] { STRING_U2, "", true },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", true },
|
||||
new Object[] { STRING_U2, "a", false },
|
||||
new Object[] { STRING_U2, "\uFF21B", false },
|
||||
new Object[] { STRING_M12, "\uFF21A", true },
|
||||
new Object[] { STRING_M12, "\uFF21", true },
|
||||
new Object[] { STRING_M12, "A", true },
|
||||
new Object[] { STRING_M12, "A\uFF21", false },
|
||||
new Object[] { STRING_M11, "A\uFF21", true },
|
||||
new Object[] { STRING_M11, "Ab", false }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testContains(String str, String anotherString, boolean expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.contains(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).contains(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
92
test/jdk/java/lang/String/CompactString/EndsWith.java
Normal file
92
test/jdk/java/lang/String/CompactString/EndsWith.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.endsWith.
|
||||
* @run testng/othervm -XX:+CompactStrings EndsWith
|
||||
* @run testng/othervm -XX:-CompactStrings EndsWith
|
||||
*/
|
||||
|
||||
public class EndsWith extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] { new Object[] { STRING_EMPTY, "", true },
|
||||
new Object[] { STRING_EMPTY, "A", false },
|
||||
new Object[] { STRING_L1, "A", true },
|
||||
new Object[] { STRING_L1, "", true },
|
||||
new Object[] { STRING_L1, " ", false },
|
||||
new Object[] { STRING_L2, "AB", true },
|
||||
new Object[] { STRING_L2, "B", true },
|
||||
new Object[] { STRING_L2, "", true },
|
||||
new Object[] { STRING_L2, "A", false },
|
||||
new Object[] { STRING_L4, "ABCD", true },
|
||||
new Object[] { STRING_L4, "CD", true },
|
||||
new Object[] { STRING_L4, "D", true },
|
||||
new Object[] { STRING_L4, "", true },
|
||||
new Object[] { STRING_L4, "BC", false },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", true },
|
||||
new Object[] { STRING_LLONG, "EFGH", true },
|
||||
new Object[] { STRING_LLONG, "", true },
|
||||
new Object[] { STRING_LLONG, "CDEF", false },
|
||||
new Object[] { STRING_LLONG, "\uFF28", false },
|
||||
new Object[] { STRING_U1, "\uFF21", true },
|
||||
new Object[] { STRING_U1, "", true },
|
||||
new Object[] { STRING_U1, "\uFF22", false },
|
||||
new Object[] { STRING_U1, "B", false },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", true },
|
||||
new Object[] { STRING_U2, "\uFF22", true },
|
||||
new Object[] { STRING_U2, "", true },
|
||||
new Object[] { STRING_U2, "\uFF21", false },
|
||||
new Object[] { STRING_M12, "\uFF21A", true },
|
||||
new Object[] { STRING_M12, "A", true },
|
||||
new Object[] { STRING_M12, "", true },
|
||||
new Object[] { STRING_M12, "AA", false },
|
||||
new Object[] { STRING_M11, "A\uFF21", true },
|
||||
new Object[] { STRING_M11, "\uFF21", true },
|
||||
new Object[] { STRING_M11, "", true },
|
||||
new Object[] { STRING_M11, "\uFF21\uFF21", false }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testEndsWith(String str, String suffix, boolean expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.endsWith(suffix),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).endsWith(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(suffix), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
81
test/jdk/java/lang/String/CompactString/Equals.java
Normal file
81
test/jdk/java/lang/String/CompactString/Equals.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.equals.
|
||||
* @run testng/othervm -XX:+CompactStrings Equals
|
||||
* @run testng/othervm -XX:-CompactStrings Equals
|
||||
*/
|
||||
|
||||
public class Equals extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_EMPTY, "", true },
|
||||
new Object[] { STRING_EMPTY, "A", false },
|
||||
new Object[] { STRING_EMPTY, new StringBuffer(""), false },
|
||||
new Object[] { STRING_L1, "A", true },
|
||||
new Object[] { STRING_L1, "", false },
|
||||
new Object[] { STRING_L1, new StringBuffer("A"), false },
|
||||
new Object[] { STRING_L2, "AB", true },
|
||||
new Object[] { STRING_L2, "", false },
|
||||
new Object[] { STRING_L2, new StringBuilder("AB"), false },
|
||||
new Object[] { STRING_L4, "ABCD", true },
|
||||
new Object[] { STRING_L4, "abc", false },
|
||||
new Object[] { STRING_L4, "", false },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", true },
|
||||
new Object[] { STRING_LLONG, "ABCDEFG", false },
|
||||
new Object[] { STRING_LLONG, new StringBuilder("ABCDEFGH"),
|
||||
false },
|
||||
new Object[] { STRING_U1, "\uFF21", true },
|
||||
new Object[] { STRING_U1, "", false },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", true },
|
||||
new Object[] { STRING_U2, "\uFF21", false },
|
||||
new Object[] { STRING_U2, "", false },
|
||||
new Object[] { STRING_U2, new StringBuilder("\uFF21\uFF22"),
|
||||
false },
|
||||
new Object[] { STRING_M12, "\uFF21A", true },
|
||||
new Object[] { STRING_M12, "A\uFF21", false },
|
||||
new Object[] { STRING_M11, "A\uFF21", true },
|
||||
new Object[] { STRING_M11, new StringBuilder("\uFF21A"), false }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testEquals(String str, Object obj, boolean expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(data.equals(obj), expected, String.format(
|
||||
"testing String(%s).equals(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(obj.toString()), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
107
test/jdk/java/lang/String/CompactString/EqualsIgnoreCase.java
Normal file
107
test/jdk/java/lang/String/CompactString/EqualsIgnoreCase.java
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559 8248655 8302871
|
||||
* @summary Tests Compact String. This one is for String.equalsIgnoreCase.
|
||||
* @run testng/othervm -XX:+CompactStrings EqualsIgnoreCase
|
||||
* @run testng/othervm -XX:-CompactStrings EqualsIgnoreCase
|
||||
*/
|
||||
|
||||
public class EqualsIgnoreCase extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "", true },
|
||||
new Object[] { STRING_L1, "a", true },
|
||||
new Object[] { STRING_L2, "aB", true },
|
||||
new Object[] { STRING_L4, "AbCd", true },
|
||||
new Object[] { STRING_LLONG, "aBcDeFgH", true },
|
||||
new Object[] { STRING_U1, "\uFF41", true },
|
||||
new Object[] { STRING_U1, "\uFF21", true },
|
||||
new Object[] { STRING_U2, "\uFF41\uFF42", true },
|
||||
new Object[] { STRING_U2, "\uFF41\uFF22", true },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF42", true },
|
||||
new Object[] { STRING_M12, "\uFF41a", true },
|
||||
new Object[] { STRING_M12, "\uFF21A", true },
|
||||
new Object[] { STRING_M11, "a\uFF41", true },
|
||||
new Object[] { STRING_M11, "A\uFF21", true },
|
||||
new Object[] { STRING_SUPPLEMENTARY, STRING_SUPPLEMENTARY_LOWERCASE, true },
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testEqualsIgnoreCase(String str, String anotherString,
|
||||
boolean expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.equalsIgnoreCase(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).equalsIgnoreCase(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Exhaustively check that all 256x256 latin1 code point pairs are equalsIgnoreCased
|
||||
* in a manner consistent with Character.toLowerCase(Character.toUpperCase(c));
|
||||
*/
|
||||
@Test
|
||||
public void checkConsistencyWithCharacterUppercaseLowerCase() {
|
||||
for (char a = 0; a < 256; a++) {
|
||||
for (char b = 0; b < 256; b++) {
|
||||
|
||||
int caseFoldA = Character.toLowerCase(Character.toUpperCase(a));
|
||||
int caseFoldB = Character.toLowerCase(Character.toUpperCase(b));
|
||||
|
||||
String astr = Character.toString(a);
|
||||
String bstr = Character.toString(b);
|
||||
|
||||
// If characters fold to the same lowercase, their strings should equalsIgnoreCase:
|
||||
if (caseFoldA == caseFoldB) {
|
||||
assertTrue(astr.equalsIgnoreCase(bstr),
|
||||
"Expected %s to equalsIgnoreCase %s".formatted(astr, bstr));
|
||||
} else {
|
||||
assertFalse(astr.equalsIgnoreCase(bstr),
|
||||
"Expected %s to not equalsIgnoreCase %s".formatted(astr, bstr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
test/jdk/java/lang/String/CompactString/GetChars.java
Normal file
91
test/jdk/java/lang/String/CompactString/GetChars.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.getChars.
|
||||
* @run testng/othervm -XX:+CompactStrings GetChars
|
||||
* @run testng/othervm -XX:-CompactStrings GetChars
|
||||
*/
|
||||
|
||||
public class GetChars extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, 0, STRING_EMPTY.length(),
|
||||
new char[STRING_EMPTY.length()], 0, CHAR_ARRAY_EMPTY },
|
||||
new Object[] { STRING_L1, 0, STRING_L1.length(),
|
||||
new char[STRING_L1.length()], 0, CHAR_ARRAY_L1 },
|
||||
new Object[] { STRING_L2, 0, STRING_L2.length(),
|
||||
new char[STRING_L2.length()], 0, CHAR_ARRAY_L2 },
|
||||
new Object[] { STRING_L4, 0, STRING_L4.length(),
|
||||
new char[STRING_L4.length()], 0, CHAR_ARRAY_L4 },
|
||||
new Object[] { STRING_LLONG, 0, STRING_LLONG.length(),
|
||||
new char[STRING_LLONG.length()], 0, CHAR_ARRAY_LLONG },
|
||||
new Object[] { STRING_U1, 0, STRING_U1.length(),
|
||||
new char[STRING_U1.length()], 0, CHAR_ARRAY_U1 },
|
||||
new Object[] { STRING_U2, 0, STRING_U2.length(),
|
||||
new char[STRING_U2.length()], 0, CHAR_ARRAY_U2 },
|
||||
new Object[] { STRING_M12, 0, STRING_M12.length(),
|
||||
new char[STRING_M12.length()], 0, CHAR_ARRAY_M12 },
|
||||
new Object[] { STRING_M11, 0, STRING_M11.length(),
|
||||
new char[STRING_M11.length()], 0, CHAR_ARRAY_M11 },
|
||||
new Object[] { STRING_UDUPLICATE, 0,
|
||||
STRING_UDUPLICATE.length(),
|
||||
new char[STRING_UDUPLICATE.length()], 0,
|
||||
CHAR_ARRAY_UDUPLICATE },
|
||||
new Object[] { STRING_MDUPLICATE1, 0,
|
||||
STRING_MDUPLICATE1.length(),
|
||||
new char[STRING_MDUPLICATE1.length()], 0,
|
||||
CHAR_ARRAY_MDUPLICATE1 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testGetChars(String str, int srcBegin, int srcEnd, char[] dst,
|
||||
int dstBegin, char[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
data.getChars(srcBegin, srcEnd, dst, dstBegin);
|
||||
assertTrue(
|
||||
Arrays.equals(dst, expected),
|
||||
String.format(
|
||||
"testing String(%s).getChars(%d, %d, %s, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), srcBegin,
|
||||
srcEnd, escapeNonASCIIs(Arrays
|
||||
.toString(dst)), dstBegin,
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
249
test/jdk/java/lang/String/CompactString/IndexOf.java
Normal file
249
test/jdk/java/lang/String/CompactString/IndexOf.java
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.indexOf.
|
||||
* @run testng/othervm -XX:+CompactStrings IndexOf
|
||||
* @run testng/othervm -XX:-CompactStrings IndexOf
|
||||
*/
|
||||
|
||||
public class IndexOf extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, (int) 'A', -1 },
|
||||
new Object[] { STRING_L1, (int) 'A', 0 },
|
||||
new Object[] { STRING_L2, (int) 'A', 0 },
|
||||
new Object[] { STRING_L2, (int) 'B', 1 },
|
||||
new Object[] { STRING_L4, (int) 'A', 0 },
|
||||
new Object[] { STRING_L4, (int) 'D', 3 },
|
||||
new Object[] { STRING_L4, (int) 'E', -1 },
|
||||
new Object[] { STRING_LLONG, (int) 'A', 0 },
|
||||
new Object[] { STRING_LLONG, (int) 'H', 7 },
|
||||
new Object[] { STRING_U1, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_U1, (int) 'A', -1 },
|
||||
new Object[] { STRING_U2, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_U2, (int) '\uFF22', 1 },
|
||||
new Object[] { STRING_M12, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_M12, (int) 'A', 1 },
|
||||
new Object[] { STRING_M11, (int) 'A', 0 },
|
||||
new Object[] { STRING_M11, (int) '\uFF21', 1 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF22', 1 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 'A', 5 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, '\uFF21', 4 },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
Character.toCodePoint('\uD801', '\uDC00'), 0 },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
Character.toCodePoint('\uD801', '\uDC01'), 2 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testIndexOf(String str, int ch, int expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(data.indexOf(ch), expected, String.format(
|
||||
"testing String(%s).indexOf(%d), source : %s, ",
|
||||
escapeNonASCIIs(data), ch, source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider2() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, (int) 'A', 0, -1 },
|
||||
new Object[] { STRING_L1, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L1, (int) 'A', 1, -1 },
|
||||
new Object[] { STRING_L1, (int) 'B', 0, -1 },
|
||||
new Object[] { STRING_L2, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L2, (int) 'A', 1, -1 },
|
||||
new Object[] { STRING_L2, (int) 'B', 0, 1 },
|
||||
new Object[] { STRING_L2, (int) 'B', 1, 1 },
|
||||
new Object[] { STRING_L4, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L4, (int) 'D', 2, 3 },
|
||||
new Object[] { STRING_L4, (int) 'B', 2, -1 },
|
||||
new Object[] { STRING_LLONG, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_LLONG, (int) 'H', 5, 7 },
|
||||
new Object[] { STRING_U1, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_U1, (int) 'A', 0, -1 },
|
||||
new Object[] { STRING_U2, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_U2, (int) '\uFF22', 0, 1 },
|
||||
new Object[] { STRING_M12, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_M12, (int) 'A', 1, 1 },
|
||||
new Object[] { STRING_M11, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_M11, (int) '\uFF21', 1, 1 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF21', 1, 2 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF22', 1, 1 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider2")
|
||||
public void testIndexOf(String str, int ch, int fromIndex, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.indexOf(ch, fromIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).indexOf(%d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), ch,
|
||||
fromIndex, source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider3() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "A", -1 },
|
||||
new Object[] { STRING_L1, "A", 0 },
|
||||
new Object[] { STRING_L1, "AB", -1 },
|
||||
new Object[] { STRING_L2, "A", 0 },
|
||||
new Object[] { STRING_L2, "B", 1 },
|
||||
new Object[] { STRING_L2, "AB", 0 },
|
||||
new Object[] { STRING_L2, "AC", -1 },
|
||||
new Object[] { STRING_L2, "ABC", -1 },
|
||||
new Object[] { STRING_L4, "ABCD", 0 },
|
||||
new Object[] { STRING_L4, "D", 3 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", 0 },
|
||||
new Object[] { STRING_LLONG, "EFGH", 4 },
|
||||
new Object[] { STRING_LLONG, "EFGHI", -1 },
|
||||
new Object[] { STRING_U1, "\uFF21", 0 },
|
||||
new Object[] { STRING_U1, "\uFF21A", -1 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 0 },
|
||||
new Object[] { STRING_U2, "\uFF22", 1 },
|
||||
new Object[] { STRING_U2, "A\uFF22", -1 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 0 },
|
||||
new Object[] { STRING_M12, "A", 1 },
|
||||
new Object[] { STRING_M12, "\uFF21\uFF21", -1 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 0 },
|
||||
new Object[] { STRING_M11, "\uFF21", 1 },
|
||||
new Object[] { STRING_M11, "A", 0 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
0 },
|
||||
new Object[] { STRING_UDUPLICATE,
|
||||
"\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21", 1 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21",
|
||||
-1 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider3")
|
||||
public void testIndexOf(String str, String anotherString, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.indexOf(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).indexOf(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider4() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "A", 0, -1 },
|
||||
new Object[] { STRING_L1, "A", 0, 0 },
|
||||
new Object[] { STRING_L1, "A", 1, -1 },
|
||||
new Object[] { STRING_L1, "AB", 0, -1 },
|
||||
new Object[] { STRING_L2, "A", 0, 0 },
|
||||
new Object[] { STRING_L2, "B", 0, 1 },
|
||||
new Object[] { STRING_L2, "AB", 0, 0 },
|
||||
new Object[] { STRING_L2, "AB", 1, -1 },
|
||||
new Object[] { STRING_L4, "ABCD", 0, 0 },
|
||||
new Object[] { STRING_L4, "BC", 0, 1 },
|
||||
new Object[] { STRING_L4, "A", 0, 0 },
|
||||
new Object[] { STRING_L4, "CD", 0, 2 },
|
||||
new Object[] { STRING_L4, "A", 2, -1 },
|
||||
new Object[] { STRING_L4, "ABCDE", 0, -1 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", 0, 0 },
|
||||
new Object[] { STRING_LLONG, "DEFGH", 0, 3 },
|
||||
new Object[] { STRING_LLONG, "A", 0, 0 },
|
||||
new Object[] { STRING_LLONG, "GHI", 0, -1 },
|
||||
new Object[] { STRING_U1, "\uFF21", 0, 0 },
|
||||
new Object[] { STRING_U1, "\uFF21A", 0, -1 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 0, 0 },
|
||||
new Object[] { STRING_U2, "\uFF22", 0, 1 },
|
||||
new Object[] { STRING_U2, "\uFF21", 1, -1 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 0, 0 },
|
||||
new Object[] { STRING_M12, "A", 1, 1 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 1, -1 },
|
||||
new Object[] { STRING_M12, "\uFF21", 0, 0 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 0, 0 },
|
||||
new Object[] { STRING_M11, "\uFF21", 1, 1 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 1, -1 },
|
||||
new Object[] { STRING_M11, "A\uFF21A", 0, -1 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
0, 0 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
1, -1 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
1, 1 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22\uFF21\uFF22",
|
||||
4, 4 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22\uFF21\uFF22",
|
||||
7, -1 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider4")
|
||||
public void testIndexOf(String str, String anotherString, int fromIndex,
|
||||
int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.indexOf(anotherString, fromIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).indexOf(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
fromIndex, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
64
test/jdk/java/lang/String/CompactString/Intern.java
Normal file
64
test/jdk/java/lang/String/CompactString/Intern.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.intern.
|
||||
* @run testng/othervm -XX:+CompactStrings Intern
|
||||
* @run testng/othervm -XX:-CompactStrings Intern
|
||||
*/
|
||||
|
||||
public class Intern extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "" },
|
||||
new Object[] { STRING_L1, "A" },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH" },
|
||||
new Object[] { STRING_U1, "\uFF21" },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22" },
|
||||
new Object[] { STRING_M12, "\uFF21A" },
|
||||
new Object[] { STRING_M11, "A\uFF21" },
|
||||
new Object[] { STRING_MDUPLICATE1,
|
||||
"\uFF21A\uFF21A\uFF21A\uFF21A\uFF21A" }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testIntern(String str, String expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertTrue(data.intern() == expected, String.format(
|
||||
"testing String(%s).intern(), source : %s, ",
|
||||
escapeNonASCIIs(data), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
225
test/jdk/java/lang/String/CompactString/LastIndexOf.java
Normal file
225
test/jdk/java/lang/String/CompactString/LastIndexOf.java
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.lastIndexOf.
|
||||
* @run testng/othervm -XX:+CompactStrings LastIndexOf
|
||||
* @run testng/othervm -XX:-CompactStrings LastIndexOf
|
||||
*/
|
||||
|
||||
public class LastIndexOf extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, (int) 'A', -1 },
|
||||
new Object[] { STRING_L1, (int) 'A', 0 },
|
||||
new Object[] { STRING_L2, (int) 'A', 0 },
|
||||
new Object[] { STRING_L2, (int) 'B', 1 },
|
||||
new Object[] { STRING_L4, (int) 'A', 0 },
|
||||
new Object[] { STRING_L4, (int) 'D', 3 },
|
||||
new Object[] { STRING_LLONG, (int) 'A', 0 },
|
||||
new Object[] { STRING_LLONG, (int) 'H', 7 },
|
||||
new Object[] { STRING_U1, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_U1, (int) 'B', -1 },
|
||||
new Object[] { STRING_U2, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_U2, (int) '\uFF22', 1 },
|
||||
new Object[] { STRING_M12, (int) '\uFF21', 0 },
|
||||
new Object[] { STRING_M12, (int) 'A', 1 },
|
||||
new Object[] { STRING_M11, (int) 'A', 0 },
|
||||
new Object[] { STRING_M11, (int) '\uFF21', 1 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF22', 9 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF21', 8 },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
Character.toCodePoint('\uD801', '\uDC01'), 2 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testLastIndexOf(String str, int ch, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.lastIndexOf(ch),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).lastIndexOf(%d), source : %s, ",
|
||||
escapeNonASCIIs(data), ch, source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider2() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, (int) 'A', 0, -1 },
|
||||
new Object[] { STRING_L1, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L1, (int) 'A', 1, 0 },
|
||||
new Object[] { STRING_L2, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L2, (int) 'B', 1, 1 },
|
||||
new Object[] { STRING_L2, (int) 'B', 2, 1 },
|
||||
new Object[] { STRING_L4, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_L4, (int) 'C', 2, 2 },
|
||||
new Object[] { STRING_L4, (int) 'C', 1, -1 },
|
||||
new Object[] { STRING_LLONG, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_LLONG, (int) 'H', 7, 7 },
|
||||
new Object[] { STRING_LLONG, (int) 'H', 6, -1 },
|
||||
new Object[] { STRING_U1, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_U1, (int) '\uFF21', 7, 0 },
|
||||
new Object[] { STRING_U2, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_U2, (int) '\uFF22', 0, -1 },
|
||||
new Object[] { STRING_M12, (int) '\uFF21', 0, 0 },
|
||||
new Object[] { STRING_M12, (int) 'A', 1, 1 },
|
||||
new Object[] { STRING_M12, (int) 'A', 0, -1 },
|
||||
new Object[] { STRING_M11, (int) 'A', 0, 0 },
|
||||
new Object[] { STRING_M11, (int) '\uFF21', 1, 1 },
|
||||
new Object[] { STRING_M11, (int) '\uFF21', 0, -1 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF21', 5, 4 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF21', 6, 6 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF22', 5, 5 },
|
||||
new Object[] { STRING_UDUPLICATE, (int) '\uFF22', 6, 5 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider2")
|
||||
public void testLastIndexOf(String str, int ch, int fromIndex, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.lastIndexOf(ch, fromIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).lastIndexOf(%d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), ch,
|
||||
fromIndex, source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider3() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "A", -1 },
|
||||
new Object[] { STRING_L1, "A", 0 },
|
||||
new Object[] { STRING_L1, "AB", -1 },
|
||||
|
||||
new Object[] { STRING_L2, "AB", 0 },
|
||||
new Object[] { STRING_L2, "B", 1 },
|
||||
new Object[] { STRING_L4, "ABCD", 0 },
|
||||
new Object[] { STRING_L4, "B", 1 },
|
||||
new Object[] { STRING_LLONG, "ABCD", 0 },
|
||||
new Object[] { STRING_LLONG, "GH", 6 },
|
||||
new Object[] { STRING_U1, "\uFF21", 0 },
|
||||
new Object[] { STRING_U1, "\uFF22", -1 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 0 },
|
||||
new Object[] { STRING_U2, "\uFF22", 1 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 0 },
|
||||
new Object[] { STRING_M12, "A", 1 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 0 },
|
||||
new Object[] { STRING_M11, "\uFF21", 1 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22\uFF21\uFF22", 6 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22", 8 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider3")
|
||||
public void testLastIndexOf(String str, String anotherString, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.lastIndexOf(anotherString),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).lastIndexOf(%s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider4() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "A", 0, -1 },
|
||||
new Object[] { STRING_L2, "AB", 0, 0 },
|
||||
|
||||
new Object[] { STRING_L1, "AB", -1, -1 },
|
||||
|
||||
new Object[] { STRING_L2, "B", 1, 1 },
|
||||
new Object[] { STRING_L2, "B", 0, -1 },
|
||||
new Object[] { STRING_L4, "ABC", 3, 0 },
|
||||
new Object[] { STRING_L4, "ABC", 0, 0 },
|
||||
new Object[] { STRING_L4, "ABC", 1, 0 },
|
||||
new Object[] { STRING_L4, "BC", 1, 1 },
|
||||
new Object[] { STRING_L4, "BC", 0, -1 },
|
||||
new Object[] { STRING_LLONG, "ABCDEFGH", 0, 0 },
|
||||
new Object[] { STRING_LLONG, "EFGH", 7, 4 },
|
||||
new Object[] { STRING_LLONG, "EFGH", 3, -1 },
|
||||
new Object[] { STRING_U1, "\uFF21", 0, 0 },
|
||||
new Object[] { STRING_U1, "\uFF21", 7, 0 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 0, 0 },
|
||||
new Object[] { STRING_U2, "\uFF21\uFF22", 1, 0 },
|
||||
new Object[] { STRING_M12, "\uFF21A", 0, 0 },
|
||||
new Object[] { STRING_M12, "A", 1, 1 },
|
||||
new Object[] { STRING_M12, "A", 0, -1 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 0, 0 },
|
||||
new Object[] { STRING_M11, "A\uFF21", 1, 0 },
|
||||
new Object[] { STRING_M11, "\uFF21", 0, -1 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
9, 0 },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
0, 0 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22", 6, 6 },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22\uFF21", 6, 6 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider4")
|
||||
public void testLastIndexOf(String str, String anotherString,
|
||||
int fromIndex, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.lastIndexOf(anotherString, fromIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).lastIndexOf(%s, %d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(anotherString),
|
||||
fromIndex, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
61
test/jdk/java/lang/String/CompactString/Length.java
Normal file
61
test/jdk/java/lang/String/CompactString/Length.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.length.
|
||||
* @run testng/othervm -XX:+CompactStrings Length
|
||||
* @run testng/othervm -XX:-CompactStrings Length
|
||||
*/
|
||||
|
||||
public class Length extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, 0 }, new Object[] { STRING_L1, 1 },
|
||||
new Object[] { STRING_L2, 2 },
|
||||
new Object[] { STRING_LLONG, 8 },
|
||||
new Object[] { STRING_U1, 1 }, new Object[] { STRING_U2, 2 },
|
||||
new Object[] { STRING_M12, 2 }, new Object[] { STRING_M11, 2 },
|
||||
new Object[] { STRING_UDUPLICATE, 10 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 6 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testLength(String str, int expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(data.length(), expected, String.format(
|
||||
"testing String(%s).length(), source : %s, ",
|
||||
escapeNonASCIIs(data), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
150
test/jdk/java/lang/String/CompactString/MaxSizeUTF16String.java
Normal file
150
test/jdk/java/lang/String/CompactString/MaxSizeUTF16String.java
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559 8321180
|
||||
* @summary Tests Compact String for maximum size strings
|
||||
* @requires os.maxMemory >= 8g & vm.bits == 64
|
||||
* @requires vm.flagless
|
||||
* @run junit/othervm/timeout=480 -XX:+CompactStrings -Xmx8g MaxSizeUTF16String
|
||||
* @run junit/othervm/timeout=480 -XX:-CompactStrings -Xmx8g MaxSizeUTF16String
|
||||
* @run junit/othervm/timeout=480 -Xcomp -Xmx8g MaxSizeUTF16String
|
||||
*/
|
||||
|
||||
public class MaxSizeUTF16String {
|
||||
|
||||
private final static int MAX_UTF16_STRING_LENGTH = Integer.MAX_VALUE / 2;
|
||||
|
||||
private final static String EXPECTED_OOME_MESSAGE = "UTF16 String size is";
|
||||
private final static String EXPECTED_VM_LIMIT_MESSAGE = "Requested array size exceeds VM limit";
|
||||
private final static String UNEXPECTED_JAVA_HEAP_SPACE = "Java heap space";
|
||||
|
||||
// Create a large UTF-8 byte array with a single non-latin1 character
|
||||
private static byte[] generateUTF8Data(int byteSize) {
|
||||
byte[] nonAscii = "\u0100".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] arr = new byte[byteSize];
|
||||
System.arraycopy(nonAscii, 0, arr, 0, nonAscii.length); // non-latin1 at start
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Create a large char array with a single non-latin1 character
|
||||
private static char[] generateCharData(int size) {
|
||||
char[] nonAscii = "\u0100".toCharArray();
|
||||
char[] arr = new char[size];
|
||||
System.arraycopy(nonAscii, 0, arr, 0, nonAscii.length); // non-latin1 at start
|
||||
return arr;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxUTF8() {
|
||||
// Overly large UTF-8 data with 1 non-latin1 char
|
||||
final byte[] large_utf8_bytes = generateUTF8Data(MAX_UTF16_STRING_LENGTH + 1);
|
||||
int[] sizes = new int[] {
|
||||
MAX_UTF16_STRING_LENGTH + 1,
|
||||
MAX_UTF16_STRING_LENGTH,
|
||||
MAX_UTF16_STRING_LENGTH - 1};
|
||||
for (int size : sizes) {
|
||||
System.err.println("Checking max UTF16 string len: " + size);
|
||||
try {
|
||||
// Use only part of the UTF-8 byte array
|
||||
new String(large_utf8_bytes, 0, size, StandardCharsets.UTF_8);
|
||||
if (size >= MAX_UTF16_STRING_LENGTH) {
|
||||
fail("Expected OutOfMemoryError with message prefix: " + EXPECTED_OOME_MESSAGE);
|
||||
}
|
||||
} catch (OutOfMemoryError ex) {
|
||||
if (ex.getMessage().equals(UNEXPECTED_JAVA_HEAP_SPACE)) {
|
||||
// Insufficient heap size
|
||||
throw ex;
|
||||
}
|
||||
if (!ex.getMessage().startsWith(EXPECTED_OOME_MESSAGE) &&
|
||||
!ex.getMessage().startsWith(EXPECTED_VM_LIMIT_MESSAGE)) {
|
||||
fail("Failed: Not the OutOfMemoryError expected", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxCharArray() {
|
||||
// Overly large UTF-8 data with 1 non-latin1 char
|
||||
final char[] large_char_array = generateCharData(MAX_UTF16_STRING_LENGTH + 1);
|
||||
int[] sizes = new int[]{
|
||||
MAX_UTF16_STRING_LENGTH + 1,
|
||||
MAX_UTF16_STRING_LENGTH,
|
||||
MAX_UTF16_STRING_LENGTH - 1};
|
||||
for (int size : sizes) {
|
||||
System.err.println("Checking max UTF16 string len: " + size);
|
||||
try {
|
||||
// Large char array with 1 non-latin1 char
|
||||
new String(large_char_array, 0, size);
|
||||
if (size >= MAX_UTF16_STRING_LENGTH) {
|
||||
fail("Expected OutOfMemoryError with message prefix: " + EXPECTED_OOME_MESSAGE);
|
||||
}
|
||||
} catch (OutOfMemoryError ex) {
|
||||
if (ex.getMessage().equals(UNEXPECTED_JAVA_HEAP_SPACE)) {
|
||||
// Insufficient heap size
|
||||
throw ex;
|
||||
}
|
||||
if (!ex.getMessage().startsWith(EXPECTED_OOME_MESSAGE) &&
|
||||
!ex.getMessage().startsWith(EXPECTED_VM_LIMIT_MESSAGE)) {
|
||||
throw new RuntimeException("Wrong exception message: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test that UTF-8 of too large strings throws OOME, (not NegativeArraySizeException).
|
||||
*/
|
||||
@Test
|
||||
public void testMaxUTF8_UTF16Encode() {
|
||||
String s = "\uFFFF";
|
||||
final byte[] bytes1 = s.getBytes(StandardCharsets.UTF_8);
|
||||
assertEquals(3, bytes1.length, "UTF_8 encoded length of 0xffff");
|
||||
|
||||
int min = Integer.MAX_VALUE / bytes1.length - 1;
|
||||
int max = min + 3;
|
||||
|
||||
// String of size min can be UTF_8 encoded.
|
||||
System.out.println("testing size: " + min);
|
||||
String s1 = s.repeat(min);
|
||||
byte[] bytes = s1.getBytes(StandardCharsets.UTF_8);
|
||||
int remaining = Integer.MAX_VALUE - bytes.length;
|
||||
assertTrue(remaining >= bytes1.length, "remainder too large: " + remaining);
|
||||
|
||||
// Strings of size min+1...min+2, throw OOME
|
||||
// The resulting byte array would exceed implementation limits
|
||||
for (int count = min + 1; count < max; count++) {
|
||||
System.out.println("testing size: " + count);
|
||||
final String s2 = s.repeat(count);
|
||||
OutOfMemoryError ex = assertThrows(OutOfMemoryError.class, () -> s2.getBytes(StandardCharsets.UTF_8));
|
||||
ex.printStackTrace();
|
||||
};
|
||||
}
|
||||
}
|
||||
75
test/jdk/java/lang/String/CompactString/NegativeSize.java
Normal file
75
test/jdk/java/lang/String/CompactString/NegativeSize.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String for negative size.
|
||||
* @requires vm.bits == 64 & os.maxMemory >= 4G
|
||||
* @run main/othervm -XX:+CompactStrings -Xmx4g NegativeSize
|
||||
* @run main/othervm -XX:-CompactStrings -Xmx4g NegativeSize
|
||||
*/
|
||||
|
||||
// In Java8: java.lang.OutOfMemoryError: Java heap space
|
||||
// In Java9+: was java.lang.NegativeArraySizeException: -1894967266
|
||||
public class NegativeSize {
|
||||
|
||||
static byte[] generateData() {
|
||||
int asciisize = 1_200_000_000;
|
||||
byte[] nonAscii = "非アスキー".getBytes();
|
||||
int nonAsciiSize = nonAscii.length;
|
||||
// 1 GB
|
||||
byte[] arr = new byte[asciisize + nonAsciiSize];
|
||||
for (int i=0; i<asciisize; ++i) {
|
||||
arr[i] = (byte)('0' + (i % 40));
|
||||
}
|
||||
for(int i=0; i<nonAsciiSize; ++i) {
|
||||
arr[i + asciisize] = nonAscii[i];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
try {
|
||||
byte[] largeBytes = generateData();
|
||||
String inStr = new String(largeBytes, StandardCharsets.UTF_8);
|
||||
System.out.println(inStr.length());
|
||||
System.out.println(inStr.substring(1_200_000_000));
|
||||
} catch (OutOfMemoryError ex) {
|
||||
if (ex.getMessage().startsWith("UTF16 String size is")) {
|
||||
System.out.println("Succeeded with OutOfMemoryError");
|
||||
} else {
|
||||
throw new RuntimeException("Failed: Not the OutOfMemoryError expected", ex);
|
||||
}
|
||||
} catch (NegativeArraySizeException ex) {
|
||||
throw new RuntimeException("Failed: Expected OutOfMemoryError", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
test/jdk/java/lang/String/CompactString/Numbers.java
Normal file
106
test/jdk/java/lang/String/CompactString/Numbers.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is testing
|
||||
* Integer/Long's methods related to String.
|
||||
* @run testng/othervm -XX:+CompactStrings Numbers
|
||||
* @run testng/othervm -XX:-CompactStrings Numbers
|
||||
*/
|
||||
|
||||
public class Numbers {
|
||||
|
||||
/*
|
||||
* Data provider for testIntegerLong
|
||||
*
|
||||
* @return input parameter for testIntegerLong
|
||||
*/
|
||||
@DataProvider
|
||||
public Object[][] numbers() {
|
||||
return new Object[][] {
|
||||
{ Integer.toBinaryString(Integer.MAX_VALUE),
|
||||
"1111111111111111111111111111111" },
|
||||
{ Integer.toBinaryString(Integer.MIN_VALUE),
|
||||
"10000000000000000000000000000000" },
|
||||
{ Integer.toBinaryString(7), "111" },
|
||||
{ Integer.toBinaryString(0), "0" },
|
||||
{ Integer.toOctalString(Integer.MAX_VALUE), "17777777777" },
|
||||
{ Integer.toOctalString(Integer.MIN_VALUE), "20000000000" },
|
||||
{ Integer.toOctalString(9), "11" },
|
||||
{ Integer.toOctalString(0), "0" },
|
||||
{ Integer.toHexString(Integer.MAX_VALUE), "7fffffff" },
|
||||
{ Integer.toHexString(Integer.MIN_VALUE), "80000000" },
|
||||
{ Integer.toHexString(17), "11" },
|
||||
{ Integer.toHexString(0), "0" },
|
||||
{ Integer.toString(Integer.MAX_VALUE, 2),
|
||||
"1111111111111111111111111111111" },
|
||||
{ Integer.toString(Integer.MIN_VALUE, 2),
|
||||
"-10000000000000000000000000000000" },
|
||||
{ Integer.toString(7, 2), "111" },
|
||||
{ Integer.toString(0, 2), "0" },
|
||||
{ Integer.toString(Integer.MAX_VALUE, 8), "17777777777" },
|
||||
{ Integer.toString(Integer.MIN_VALUE, 8), "-20000000000" },
|
||||
{ Integer.toString(9, 8), "11" },
|
||||
{ Integer.toString(Integer.MAX_VALUE, 16), "7fffffff" },
|
||||
{ Integer.toString(Integer.MIN_VALUE, 16), "-80000000" },
|
||||
{ Integer.toString(17, 16), "11" },
|
||||
{ Long.toBinaryString(Long.MAX_VALUE),
|
||||
"111111111111111111111111111111111111111111111111111111111111111" },
|
||||
{ Long.toBinaryString(Long.MIN_VALUE),
|
||||
"1000000000000000000000000000000000000000000000000000000000000000" },
|
||||
{ Long.toOctalString(Long.MAX_VALUE), "777777777777777777777" },
|
||||
{ Long.toOctalString(Long.MIN_VALUE), "1000000000000000000000" },
|
||||
{ Long.toHexString(Long.MAX_VALUE), "7fffffffffffffff" },
|
||||
{ Long.toHexString(Long.MIN_VALUE), "8000000000000000" },
|
||||
{ Long.toString(Long.MAX_VALUE, 2),
|
||||
"111111111111111111111111111111111111111111111111111111111111111" },
|
||||
{ Long.toString(Long.MIN_VALUE, 2),
|
||||
"-1000000000000000000000000000000000000000000000000000000000000000" },
|
||||
{ Long.toString(Long.MAX_VALUE, 8), "777777777777777777777" },
|
||||
{ Long.toString(Long.MIN_VALUE, 8), "-1000000000000000000000" },
|
||||
{ Long.toString(Long.MAX_VALUE, 16), "7fffffffffffffff" },
|
||||
{ Long.toString(Long.MIN_VALUE, 16), "-8000000000000000" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test Integer/Long's methods related to String.
|
||||
*
|
||||
* @param res
|
||||
* real result
|
||||
* @param expected
|
||||
* expected result
|
||||
*/
|
||||
@Test(dataProvider = "numbers")
|
||||
public void testIntegerLong(String res, String expected) {
|
||||
assertEquals(res, expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.offsetByCodePoints.
|
||||
* @run testng/othervm -XX:+CompactStrings OffsetByCodePoints
|
||||
* @run testng/othervm -XX:-CompactStrings OffsetByCodePoints
|
||||
*/
|
||||
|
||||
public class OffsetByCodePoints extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 1, 2 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 0, 3, 5 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 1, 1, 2 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 1, 3, 5 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 2, 1, 4 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 2, 2, 5 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 2, 3, 6 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 3, 1, 4 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 3, 2, 5 },
|
||||
new Object[] { STRING_SUPPLEMENTARY, 3, 3, 6 }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testOffsetByCodePoints(String str, int index,
|
||||
int codePointOffset, int expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.offsetByCodePoints(index,
|
||||
codePointOffset),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).offsetByCodePoints(%d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), index,
|
||||
codePointOffset, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
192
test/jdk/java/lang/String/CompactString/RegionMatches.java
Normal file
192
test/jdk/java/lang/String/CompactString/RegionMatches.java
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559 8248655 8264544
|
||||
* @summary Tests Compact String. This one is for String.regionMatches.
|
||||
* @run testng/othervm -XX:+CompactStrings RegionMatches
|
||||
* @run testng/othervm -XX:-CompactStrings RegionMatches
|
||||
*/
|
||||
|
||||
public class RegionMatches extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },
|
||||
new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },
|
||||
new Object[] { STRING_EMPTY, true, 0, "A", 0, 0, true },
|
||||
new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },
|
||||
new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },
|
||||
new Object[] { STRING_L1, false, 0, "a", 0, 1, false },
|
||||
new Object[] { STRING_L1, false, 0, "BA", 1, 1, true },
|
||||
new Object[] { STRING_L1, false, 0, "Ba", 1, 1, false },
|
||||
new Object[] { STRING_L1, true, 0, "a", 0, 1, true },
|
||||
new Object[] { STRING_L1, true, 0, "BA", 1, 1, true },
|
||||
new Object[] { STRING_L1, true, 0, "Ba", 1, 1, true },
|
||||
new Object[] { STRING_L2, true, 1, "b", 0, 1, true },
|
||||
new Object[] { STRING_L2, true, 1, "B", 0, 1, true },
|
||||
new Object[] { STRING_L2, true, 0, "xaBc", 1, 2, true },
|
||||
new Object[] { STRING_L2, false, 0, "AB", 0, 2, true },
|
||||
new Object[] { STRING_L2, false, 0, "Ab", 0, 2, false },
|
||||
new Object[] { STRING_L2, false, 1, "BAB", 2, 1, true },
|
||||
new Object[] { STRING_LLONG, true, 1, "bCdEF", 0, 5, true },
|
||||
new Object[] { STRING_LLONG, false, 2, "CDEFG", 0, 5, true },
|
||||
new Object[] { STRING_LLONG, true, 2, "CDEFg", 0, 5, true },
|
||||
new Object[] { STRING_U1, true, 0, "\uFF41", 0, 1, true },
|
||||
new Object[] { STRING_U1, false, 0, "\uFF41", 0, 1, false },
|
||||
new Object[] { STRING_MDUPLICATE1, true, 0, "\uFF41a\uFF41", 0,
|
||||
3, true },
|
||||
new Object[] { STRING_MDUPLICATE1, false, 0, "\uFF21a\uFF21",
|
||||
0, 3, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 0, "\uD801\uDC28\uD801\uDC29",
|
||||
0, 4, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 1, "\uDC00\uD801",
|
||||
0, 2, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 1, "\uDC28",
|
||||
0, 1, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 4, "\uFF21", 0, 1,
|
||||
true },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 5, "A", 0, 1, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY, true, 0, "\uD802\uDC00\uD801\uDC01\uFF21A", 0, 2, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 0,
|
||||
"\uD801\uDC28\uD801\uDC29", 0, 4, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 0,
|
||||
"\uD801\uDC00\uD801\uDC01", 0, 4, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,
|
||||
"\uDC28\uD801", 0, 2, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,
|
||||
"\uDC00", 0, 1, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,
|
||||
"\uDC00\uD801", 0, 2, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 4,
|
||||
"\uFF21", 0, 1, true },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,
|
||||
"\uFF21", 0, 1, false },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,
|
||||
"\uFF41", 0, 1, true },
|
||||
// Turkish I with dot
|
||||
new Object[] { "\u0130", false, 0, "i", 0, 1, false },
|
||||
new Object[] { "\u0130", true, 0, "i", 0, 1, true },
|
||||
new Object[] { "\u0130", false, 0, "I", 0, 1, false },
|
||||
new Object[] { "\u0130", true, 0, "I", 0, 1, true },
|
||||
// i without dot
|
||||
new Object[] { "\u0131", false, 0, "i", 0, 1, false },
|
||||
new Object[] { "\u0131", true, 0, "i", 0, 1, true },
|
||||
new Object[] { "\u0131", false, 0, "I", 0, 1, false },
|
||||
new Object[] { "\u0131", true, 0, "I", 0, 1, true },
|
||||
// Exhaustive list of 1-char latin1 strings that match
|
||||
// case-insensitively:
|
||||
// for (char c1 = 0; c1 < 255; c1++) {
|
||||
// for (char c2 = c; c2 < 255; c2++) {
|
||||
// if (c1 == c2) continue;
|
||||
// if (String.valueOf(c1).regionMatches(true, 0, String.valueOf(c2), 0, 1)) {
|
||||
// System.out.println(" new Object[] { \"\\u00"
|
||||
// + Integer.toHexString((int)c) + "\", true, 0, \"\\u00"
|
||||
// + Integer.toHexString((int)c2) + "\", 0, 1, true },");
|
||||
// }}}
|
||||
new Object[] { "\u0041", true, 0, "\u0061", 0, 1, true },
|
||||
new Object[] { "\u0042", true, 0, "\u0062", 0, 1, true },
|
||||
new Object[] { "\u0043", true, 0, "\u0063", 0, 1, true },
|
||||
new Object[] { "\u0044", true, 0, "\u0064", 0, 1, true },
|
||||
new Object[] { "\u0045", true, 0, "\u0065", 0, 1, true },
|
||||
new Object[] { "\u0046", true, 0, "\u0066", 0, 1, true },
|
||||
new Object[] { "\u0047", true, 0, "\u0067", 0, 1, true },
|
||||
new Object[] { "\u0048", true, 0, "\u0068", 0, 1, true },
|
||||
new Object[] { "\u0049", true, 0, "\u0069", 0, 1, true },
|
||||
new Object[] { "\u004a", true, 0, "\u006a", 0, 1, true },
|
||||
new Object[] { "\u004b", true, 0, "\u006b", 0, 1, true },
|
||||
new Object[] { "\u004c", true, 0, "\u006c", 0, 1, true },
|
||||
new Object[] { "\u004d", true, 0, "\u006d", 0, 1, true },
|
||||
new Object[] { "\u004e", true, 0, "\u006e", 0, 1, true },
|
||||
new Object[] { "\u004f", true, 0, "\u006f", 0, 1, true },
|
||||
new Object[] { "\u0050", true, 0, "\u0070", 0, 1, true },
|
||||
new Object[] { "\u0051", true, 0, "\u0071", 0, 1, true },
|
||||
new Object[] { "\u0052", true, 0, "\u0072", 0, 1, true },
|
||||
new Object[] { "\u0053", true, 0, "\u0073", 0, 1, true },
|
||||
new Object[] { "\u0054", true, 0, "\u0074", 0, 1, true },
|
||||
new Object[] { "\u0055", true, 0, "\u0075", 0, 1, true },
|
||||
new Object[] { "\u0056", true, 0, "\u0076", 0, 1, true },
|
||||
new Object[] { "\u0057", true, 0, "\u0077", 0, 1, true },
|
||||
new Object[] { "\u0058", true, 0, "\u0078", 0, 1, true },
|
||||
new Object[] { "\u0059", true, 0, "\u0079", 0, 1, true },
|
||||
new Object[] { "\u005a", true, 0, "\u007a", 0, 1, true },
|
||||
new Object[] { "\u00c0", true, 0, "\u00e0", 0, 1, true },
|
||||
new Object[] { "\u00c1", true, 0, "\u00e1", 0, 1, true },
|
||||
new Object[] { "\u00c2", true, 0, "\u00e2", 0, 1, true },
|
||||
new Object[] { "\u00c3", true, 0, "\u00e3", 0, 1, true },
|
||||
new Object[] { "\u00c4", true, 0, "\u00e4", 0, 1, true },
|
||||
new Object[] { "\u00c5", true, 0, "\u00e5", 0, 1, true },
|
||||
new Object[] { "\u00c6", true, 0, "\u00e6", 0, 1, true },
|
||||
new Object[] { "\u00c7", true, 0, "\u00e7", 0, 1, true },
|
||||
new Object[] { "\u00c8", true, 0, "\u00e8", 0, 1, true },
|
||||
new Object[] { "\u00c9", true, 0, "\u00e9", 0, 1, true },
|
||||
new Object[] { "\u00ca", true, 0, "\u00ea", 0, 1, true },
|
||||
new Object[] { "\u00cb", true, 0, "\u00eb", 0, 1, true },
|
||||
new Object[] { "\u00cc", true, 0, "\u00ec", 0, 1, true },
|
||||
new Object[] { "\u00cd", true, 0, "\u00ed", 0, 1, true },
|
||||
new Object[] { "\u00ce", true, 0, "\u00ee", 0, 1, true },
|
||||
new Object[] { "\u00cf", true, 0, "\u00ef", 0, 1, true },
|
||||
new Object[] { "\u00d0", true, 0, "\u00f0", 0, 1, true },
|
||||
new Object[] { "\u00d1", true, 0, "\u00f1", 0, 1, true },
|
||||
new Object[] { "\u00d2", true, 0, "\u00f2", 0, 1, true },
|
||||
new Object[] { "\u00d3", true, 0, "\u00f3", 0, 1, true },
|
||||
new Object[] { "\u00d4", true, 0, "\u00f4", 0, 1, true },
|
||||
new Object[] { "\u00d5", true, 0, "\u00f5", 0, 1, true },
|
||||
new Object[] { "\u00d6", true, 0, "\u00f6", 0, 1, true },
|
||||
new Object[] { "\u00d8", true, 0, "\u00f8", 0, 1, true },
|
||||
new Object[] { "\u00d9", true, 0, "\u00f9", 0, 1, true },
|
||||
new Object[] { "\u00da", true, 0, "\u00fa", 0, 1, true },
|
||||
new Object[] { "\u00db", true, 0, "\u00fb", 0, 1, true },
|
||||
new Object[] { "\u00dc", true, 0, "\u00fc", 0, 1, true },
|
||||
new Object[] { "\u00dd", true, 0, "\u00fd", 0, 1, true },
|
||||
new Object[] { "\u00de", true, 0, "\u00fe", 0, 1, true },
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testRegionMatches(String str, boolean ignoreCase, int toffset,
|
||||
String other, int ooffset, int len, boolean expected) {
|
||||
map.getOrDefault(str, Map.of(str, str)) // Allow data provider to test adhoc strings
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.regionMatches(ignoreCase, toffset,
|
||||
other, ooffset, len),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).regionMatches(%b, %d, %s, %d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), ignoreCase,
|
||||
toffset, escapeNonASCIIs(other),
|
||||
ooffset, len, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
117
test/jdk/java/lang/String/CompactString/Replace.java
Normal file
117
test/jdk/java/lang/String/CompactString/Replace.java
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.replace.
|
||||
* @run testng/othervm -XX:+CompactStrings Replace
|
||||
* @run testng/othervm -XX:-CompactStrings Replace
|
||||
*/
|
||||
|
||||
public class Replace extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_L1, 'A', 'B', "B" },
|
||||
new Object[] { STRING_L1, 'A', 'A', "A" },
|
||||
new Object[] { STRING_L1, 'A', '\uFF21', "\uFF21" },
|
||||
new Object[] { STRING_L2, 'A', 'B', "BB" },
|
||||
new Object[] { STRING_L2, 'B', 'A', "AA" },
|
||||
new Object[] { STRING_L2, 'C', 'A', "AB" },
|
||||
new Object[] { STRING_L2, 'B', '\uFF21', "A\uFF21" },
|
||||
new Object[] { STRING_U1, '\uFF21', 'A', "A" },
|
||||
new Object[] { STRING_U1, '\uFF22', 'A', "\uFF21" },
|
||||
new Object[] { STRING_U2, '\uFF22', 'A', "\uFF21A" },
|
||||
new Object[] { STRING_M12, 'A', '\uFF21', "\uFF21\uFF21" },
|
||||
new Object[] { STRING_M11, '\uFF21', 'A', "AA" },
|
||||
new Object[] { STRING_UDUPLICATE, '\uFF21', 'A',
|
||||
"A\uFF22A\uFF22A\uFF22A\uFF22A\uFF22" },
|
||||
new Object[] { STRING_MDUPLICATE1, '\uFF21', 'A', "AAAAAAAAAA" },
|
||||
new Object[] { STRING_MDUPLICATE1, 'A', '\uFF21',
|
||||
"\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21" }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testReplace(String str, char oldChar, char newChar,
|
||||
String expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.replace(oldChar, newChar),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).replace(%s, %s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCII(oldChar),
|
||||
escapeNonASCII(newChar), source));
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider2() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "", "ABC", "ABC" },
|
||||
new Object[] { STRING_EMPTY, "", "", "" },
|
||||
new Object[] { STRING_L1, "A", "B", "B" },
|
||||
new Object[] { STRING_L1, "A", "A", "A" },
|
||||
new Object[] { STRING_L2, "B", "\uFF21", "A\uFF21" },
|
||||
new Object[] { STRING_LLONG, "BCD", "\uFF21", "A\uFF21EFGH" },
|
||||
new Object[] { STRING_U1, "\uFF21", "A", "A" },
|
||||
new Object[] { STRING_U1, "\uFF21", "A\uFF21", "A\uFF21" },
|
||||
new Object[] { STRING_U2, "\uFF21", "A", "A\uFF22" },
|
||||
new Object[] { STRING_U2, "\uFF22", "A", "\uFF21A" },
|
||||
new Object[] { STRING_UDUPLICATE, "\uFF21\uFF22", "AB",
|
||||
"ABABABABAB" },
|
||||
new Object[] { STRING_MDUPLICATE1, "\uFF21", "A", "AAAAAAAAAA" },
|
||||
new Object[] { STRING_MDUPLICATE1, "A", "\uFF21",
|
||||
"\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21\uFF21" }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider2")
|
||||
public void testReplace(String str, CharSequence target,
|
||||
CharSequence replacement, String expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.replace(target, replacement),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).replace(%s, %s), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(target.toString()),
|
||||
escapeNonASCIIs(replacement
|
||||
.toString()), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static jdk.test.lib.util.SerializationUtils.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.SerializationUtils
|
||||
* @summary Tests Compact String. This one is testing String serialization
|
||||
* among -XX:+CompactStrings/-XX:-CompactStrings/LegacyString
|
||||
* @run testng/othervm -XX:+CompactStrings SerializationTest
|
||||
* @run testng/othervm -XX:-CompactStrings SerializationTest
|
||||
*/
|
||||
|
||||
public class SerializationTest {
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
// every byte array is serialized from corresponding String object
|
||||
// by previous JDK(build 1.8.0_45-b14).
|
||||
new Object[] { "", new byte[] { -84, -19, 0, 5, 116, 0, 0 } },
|
||||
new Object[] { "A", new byte[] { -84, -19, 0, 5, 116, 0, 1, 65 } },
|
||||
new Object[] { "AB", new byte[] { -84, -19, 0, 5, 116, 0, 2, 65, 66 } },
|
||||
new Object[] { "abcdefghijk",
|
||||
new byte[] {-84, -19, 0, 5, 116, 0, 11, 97, 98, 99, 100, 101,
|
||||
102, 103, 104, 105, 106, 107 } },
|
||||
new Object[] { "\uff21", new byte[] { -84, -19, 0, 5, 116, 0, 3, -17, -68, -95 } },
|
||||
new Object[] { "\uff21\uff22", new byte[] { -84, -19, 0, 5, 116, 0, 6, -17, -68,
|
||||
-95, -17, -68, -94 } },
|
||||
new Object[] { "\uff21A\uff21A\uff21A\uff21A\uff21A",
|
||||
new byte[] { -84, -19, 0, 5, 116, 0, 20, -17, -68, -95, 65, -17, -68,
|
||||
-95, 65, -17, -68, -95, 65, -17, -68, -95, 65, -17, -68, -95, 65 } },
|
||||
new Object[] { "A\uff21B\uff22C\uff23D\uff24E\uff25F\uff26G\uff27H\uff28",
|
||||
new byte[] { -84, -19, 0, 5, 116, 0, 32, 65, -17, -68, -95, 66, -17, -68,
|
||||
-94, 67, -17, -68, -93, 68, -17, -68, -92, 69, -17, -68, -91, 70, -17,
|
||||
-68, -90, 71, -17, -68, -89, 72, -17, -68, -88 } },
|
||||
new Object[] { "\uff21A\uff22B\uff23C\uff24D\uff25E\uff26F\uff27G\uff28H",
|
||||
new byte[] { -84, -19, 0, 5, 116, 0, 32, -17, -68, -95, 65, -17, -68,
|
||||
-94, 66, -17, -68, -93, 67, -17, -68, -92, 68, -17, -68, -91, 69, -17,
|
||||
-68, -90, 70, -17, -68, -89, 71, -17, -68, -88, 72 } },
|
||||
new Object[] { "\ud801\udc00\ud801\udc01\uff21A",
|
||||
new byte[] { -84, -19, 0, 5, 116, 0, 16, -19, -96, -127, -19, -80, -128,
|
||||
-19, -96, -127, -19, -80, -127, -17, -68, -95, 65 } },
|
||||
new Object[] { "\uff21\uff22\uff21\uff22\uff21\uff22\uff21\uff22\uff21\uff22",
|
||||
new byte[] { -84, -19, 0, 5, 116, 0, 30, -17, -68, -95, -17, -68, -94, -17,
|
||||
-68, -95, -17, -68, -94, -17, -68, -95, -17, -68, -94, -17, -68, -95, -17,
|
||||
-68, -94, -17, -68, -95, -17, -68, -94 } } };
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify serialization works between Compact String/Legacy String
|
||||
*/
|
||||
@Test(dataProvider = "provider")
|
||||
public void test(String strContent, byte[] baInJDK8) throws Exception {
|
||||
// Serialize a String object into byte array.
|
||||
byte[] ba = serialize(strContent);
|
||||
assertEquals(ba, baInJDK8);
|
||||
// Deserialize a String object from byte array which is generated by previous JDK(build 1.8.0_45-b14).
|
||||
Object obj = deserialize(ba);
|
||||
assertEquals(obj.getClass(), String.class);
|
||||
assertEquals((String)obj, strContent);
|
||||
}
|
||||
}
|
||||
181
test/jdk/java/lang/String/CompactString/Split.java
Normal file
181
test/jdk/java/lang/String/CompactString/Split.java
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.split.
|
||||
* @run testng/othervm -XX:+CompactStrings Split
|
||||
* @run testng/othervm -XX:-CompactStrings Split
|
||||
*/
|
||||
|
||||
public class Split extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_L1, "", 0, new String[] { "A" } },
|
||||
new Object[] { STRING_L1, "", 1, new String[] { "A" } },
|
||||
new Object[] { STRING_L1, "", 2, new String[] { "A", "" } },
|
||||
new Object[] { STRING_L1, "A", 0, new String[] {} },
|
||||
new Object[] { STRING_L2, "A", 0, new String[] { "", "B" } },
|
||||
new Object[] { STRING_L2, "B", 0, new String[] { "A" } },
|
||||
new Object[] { STRING_LLONG, "D", 0,
|
||||
new String[] { "ABC", "EFGH" } },
|
||||
new Object[] { STRING_LLONG, "[D]", 0,
|
||||
new String[] { "ABC", "EFGH" } },
|
||||
new Object[] { STRING_LLONG, "CD", 0,
|
||||
new String[] { "AB", "EFGH" } },
|
||||
new Object[] { STRING_LLONG, "DC", 0,
|
||||
new String[] { "ABCDEFGH" } },
|
||||
new Object[] { STRING_LLONG, "[CF]", 0,
|
||||
new String[] { "AB", "DE", "GH" } },
|
||||
new Object[] { STRING_LLONG, "[CF]", 1,
|
||||
new String[] { "ABCDEFGH" } },
|
||||
new Object[] { STRING_LLONG, "[CF]", 2,
|
||||
new String[] { "AB", "DEFGH" } },
|
||||
new Object[] { STRING_LLONG, "[FC]", 0,
|
||||
new String[] { "AB", "DE", "GH" } },
|
||||
new Object[] { STRING_LLONG, "[FC]", 1,
|
||||
new String[] { "ABCDEFGH" } },
|
||||
new Object[] { STRING_LLONG, "[FC]", 2,
|
||||
new String[] { "AB", "DEFGH" } },
|
||||
new Object[] { STRING_U1, "", 0, new String[] { "\uFF21" } },
|
||||
new Object[] { STRING_U1, "", 1, new String[] { "\uFF21" } },
|
||||
new Object[] { STRING_U1, "", 2, new String[] { "\uFF21", "" } },
|
||||
new Object[] { STRING_U1, "\uFF21", 0, new String[] {} },
|
||||
new Object[] { STRING_M12, "\uFF21", 0,
|
||||
new String[] { "", "A" } },
|
||||
new Object[] { STRING_M12, "A", 0, new String[] { "\uFF21" } },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21",
|
||||
0,
|
||||
new String[] { "", "\uFF22", "\uFF22", "\uFF22",
|
||||
"\uFF22", "\uFF22" } },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21",
|
||||
2,
|
||||
new String[] { "",
|
||||
"\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22" } },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF21",
|
||||
4,
|
||||
new String[] { "", "\uFF22", "\uFF22",
|
||||
"\uFF22\uFF21\uFF22\uFF21\uFF22" } },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF22",
|
||||
0,
|
||||
new String[] { "\uFF21", "\uFF21", "\uFF21", "\uFF21",
|
||||
"\uFF21" } },
|
||||
new Object[] {
|
||||
STRING_UDUPLICATE,
|
||||
"\uFF22",
|
||||
3,
|
||||
new String[] { "\uFF21", "\uFF21",
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22" } },
|
||||
|
||||
new Object[] { STRING_MDUPLICATE1, "\uFF21", 0,
|
||||
new String[] { "", "A", "A", "A", "A", "A" } },
|
||||
new Object[] { STRING_MDUPLICATE1, "\uFF21", 3,
|
||||
new String[] { "", "A", "A\uFF21A\uFF21A\uFF21A" } },
|
||||
new Object[] {
|
||||
STRING_MDUPLICATE1,
|
||||
"A",
|
||||
0,
|
||||
new String[] { "\uFF21", "\uFF21", "\uFF21", "\uFF21",
|
||||
"\uFF21" } },
|
||||
new Object[] {
|
||||
STRING_MDUPLICATE1,
|
||||
"A",
|
||||
4,
|
||||
new String[] { "\uFF21", "\uFF21", "\uFF21",
|
||||
"\uFF21A\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "\uD801\uDC01", 0,
|
||||
new String[] { "\uD801\uDC00", "\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "\uDC01", 0,
|
||||
new String[] { "\uD801\uDC00\uD801\uDC01\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "\uD801\uDC01", 0,
|
||||
new String[] { "\uD801\uDC00", "\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uD801\uDC01\uFF21]", 0,
|
||||
new String[] { "\uD801\uDC00", "", "A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uD801\uDC01\uFF21]", 1,
|
||||
new String[] { "\uD801\uDC00\uD801\uDC01\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uD801\uDC01\uFF21]", 2,
|
||||
new String[] { "\uD801\uDC00", "\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uFF21\uD801\uDC01]", 0,
|
||||
new String[] { "\uD801\uDC00", "", "A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uFF21\uD801\uDC01]", 1,
|
||||
new String[] { "\uD801\uDC00\uD801\uDC01\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY, "[\uFF21\uD801\uDC01]", 2,
|
||||
new String[] { "\uD801\uDC00", "\uFF21A" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, "\uDC01", 0,
|
||||
new String[] { "\uD801\uDC28\uD801\uDC29\uFF41a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, "\uD801\uDC29",
|
||||
0, new String[] { "\uD801\uDC28", "\uFF41a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uD801\uDC29\uFF41]", 0,
|
||||
new String[] { "\uD801\uDC28", "", "a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uD801\uDC29\uFF41]", 1,
|
||||
new String[] { "\uD801\uDC28\uD801\uDC29\uFF41a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uD801\uDC29\uFF41]", 2,
|
||||
new String[] { "\uD801\uDC28", "\uFF41a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uFF41\uD801\uDC29]", 0,
|
||||
new String[] { "\uD801\uDC28", "", "a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uFF41\uD801\uDC29]", 1,
|
||||
new String[] { "\uD801\uDC28\uD801\uDC29\uFF41a" } },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"[\uFF41\uD801\uDC29]", 2,
|
||||
new String[] { "\uD801\uDC28", "\uFF41a" } }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testSplit(String str, String regex, int limit, String[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertTrue(
|
||||
Arrays.equals(data.split(regex, limit),
|
||||
expected),
|
||||
String.format(
|
||||
"testing String(%s).split(%s, %d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(regex), limit,
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
109
test/jdk/java/lang/String/CompactString/StartsWith.java
Normal file
109
test/jdk/java/lang/String/CompactString/StartsWith.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.startsWith.
|
||||
* @run testng/othervm -XX:+CompactStrings StartsWith
|
||||
* @run testng/othervm -XX:-CompactStrings StartsWith
|
||||
*/
|
||||
|
||||
public class StartsWith extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] {STRING_EMPTY, "", 0, true},
|
||||
new Object[] {STRING_EMPTY, "A", 0, false},
|
||||
new Object[] {STRING_EMPTY, "", 0, true},
|
||||
new Object[] {STRING_EMPTY, "", -1, false},
|
||||
new Object[] {STRING_L1, "A", 0, true},
|
||||
new Object[] {STRING_L1, "A", -1, false},
|
||||
new Object[] {STRING_L1, "A", 1, false},
|
||||
new Object[] {STRING_L2, "B", 1, true},
|
||||
new Object[] {STRING_L2, "B", 0, false},
|
||||
new Object[] {STRING_L2, "A", 0, true},
|
||||
new Object[] {STRING_L2, "AB", 1, false},
|
||||
new Object[] {STRING_L4, "ABC", 0, true},
|
||||
new Object[] {STRING_LLONG, "ABCDEFGH", 0, true},
|
||||
new Object[] {STRING_LLONG, "ABCDE", 0, true},
|
||||
new Object[] {STRING_LLONG, "CDE", 0, false},
|
||||
new Object[] {STRING_LLONG, "FG", 5, true},
|
||||
new Object[] {STRING_U1, "\uFF21", 0, true},
|
||||
new Object[] {STRING_U1, "", 1, true},
|
||||
new Object[] {STRING_U1, "\uFF21", 0, true},
|
||||
new Object[] {STRING_U1, "A", 0, false},
|
||||
new Object[] {STRING_U2, "\uFF21\uFF22", 0, true},
|
||||
new Object[] {STRING_U2, "\uFF21", 0, true},
|
||||
new Object[] {STRING_U2, "\uFF22", 0, false},
|
||||
new Object[] {STRING_U2, "", 0, true},
|
||||
new Object[] {STRING_M12, "\uFF21", 0, true},
|
||||
new Object[] {STRING_M12, "\uFF21A", 0, true},
|
||||
new Object[] {STRING_M12, "A", 0, false},
|
||||
new Object[] {STRING_M12, "\uFF21A", 0, true},
|
||||
new Object[] {STRING_M12, "A", 1, true},
|
||||
new Object[] {STRING_M11, "A", 0, true},
|
||||
new Object[] {STRING_M11, "A\uFF21", 0, true},
|
||||
new Object[] {STRING_M11, "A\uFF21", 0, true},
|
||||
new Object[] {STRING_M11, "\uFF21", 1, true},
|
||||
new Object[] {STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
|
||||
0, true},
|
||||
new Object[] {STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 0, true},
|
||||
new Object[] {STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 2, true},
|
||||
new Object[] {STRING_UDUPLICATE,
|
||||
"\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 5, false},
|
||||
new Object[] {STRING_MDUPLICATE1,
|
||||
"\uFF21A\uFF21A\uFF21A\uFF21A\uFF21A", 0, true},
|
||||
new Object[] {STRING_MDUPLICATE1,
|
||||
"\uFF21A\uFF21A\uFF21A\uFF21A\uFF21", 0, true},
|
||||
new Object[] {STRING_MDUPLICATE1, "A\uFF21A\uFF21A\uFF21A", 1, true},
|
||||
new Object[] {STRING_SUPPLEMENTARY, "\uDC01\uFF21", 3, true},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testStartsWith(String str, String prefix, int toffset,
|
||||
boolean expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.startsWith(prefix, toffset),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).startsWith(%s, %d), source : %s, ",
|
||||
escapeNonASCIIs(data),
|
||||
escapeNonASCIIs(prefix), toffset,
|
||||
source));
|
||||
});
|
||||
}
|
||||
}
|
||||
84
test/jdk/java/lang/String/CompactString/SubString.java
Normal file
84
test/jdk/java/lang/String/CompactString/SubString.java
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.subString.
|
||||
* @run testng/othervm -XX:+CompactStrings SubString
|
||||
* @run testng/othervm -XX:-CompactStrings SubString
|
||||
*/
|
||||
|
||||
public class SubString extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, 0, 0, "" },
|
||||
new Object[] { STRING_L1, 0, 1, "A" },
|
||||
new Object[] { STRING_L1, 1, 1, "" },
|
||||
new Object[] { STRING_L2, 0, 2, "AB" },
|
||||
new Object[] { STRING_L2, 1, 2, "B" },
|
||||
new Object[] { STRING_LLONG, 0, 8, "ABCDEFGH" },
|
||||
new Object[] { STRING_LLONG, 7, 8, "H" },
|
||||
new Object[] { STRING_LLONG, 8, 8, "" },
|
||||
new Object[] { STRING_LLONG, 3, 7, "DEFG" },
|
||||
new Object[] { STRING_U1, 0, 1, "\uFF21" },
|
||||
new Object[] { STRING_U1, 1, 1, "" },
|
||||
new Object[] { STRING_U1, 0, 0, "" },
|
||||
new Object[] { STRING_U2, 0, 2, "\uFF21\uFF22" },
|
||||
new Object[] { STRING_U2, 1, 2, "\uFF22" },
|
||||
new Object[] { STRING_U2, 2, 2, "" },
|
||||
new Object[] { STRING_U2, 0, 2, "\uFF21\uFF22" },
|
||||
new Object[] { STRING_U2, 1, 2, "\uFF22" },
|
||||
new Object[] { STRING_M12, 1, 2, "A" },
|
||||
new Object[] { STRING_M11, 0, 1, "A" },
|
||||
new Object[] { STRING_M11, 1, 2, "\uFF21" },
|
||||
new Object[] { STRING_UDUPLICATE, 1, 5,
|
||||
"\uFF22\uFF21\uFF22\uFF21" },
|
||||
new Object[] { STRING_MDUPLICATE1, 9, 10, "A" },
|
||||
new Object[] { STRING_MDUPLICATE1, 7, 8, "A" }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testSubstring(String str, int beginIndex, int endIndex,
|
||||
String expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(
|
||||
data.substring(beginIndex, endIndex),
|
||||
expected,
|
||||
String.format(
|
||||
"testing String(%s).substring(%d, %d), source : %s, ",
|
||||
escapeNonASCIIs(data), beginIndex,
|
||||
endIndex, source));
|
||||
});
|
||||
}
|
||||
}
|
||||
67
test/jdk/java/lang/String/CompactString/ToCharArray.java
Normal file
67
test/jdk/java/lang/String/CompactString/ToCharArray.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.toCharArray.
|
||||
* @run testng/othervm -XX:+CompactStrings ToCharArray
|
||||
* @run testng/othervm -XX:-CompactStrings ToCharArray
|
||||
*/
|
||||
|
||||
public class ToCharArray extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_EMPTY, new char[] {} },
|
||||
new Object[] { STRING_L1, new char[] { 'A' } },
|
||||
new Object[] { STRING_L2, new char[] { 'A', 'B' } },
|
||||
new Object[] { STRING_LLONG,
|
||||
new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' } },
|
||||
new Object[] { STRING_U1, new char[] { '\uFF21' } },
|
||||
new Object[] { STRING_U2, new char[] { '\uFF21', '\uFF22' } },
|
||||
new Object[] { STRING_M12, new char[] { '\uFF21', 'A' } },
|
||||
new Object[] { STRING_M11, new char[] { 'A', '\uFF21' } }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testToCharArray(String str, char[] expected) {
|
||||
map.get(str)
|
||||
.forEach(
|
||||
(source, data) -> {
|
||||
assertTrue(
|
||||
Arrays.equals(data.toCharArray(), expected),
|
||||
String.format(
|
||||
"testing String(%s).toCharArray(), source : %s, ",
|
||||
escapeNonASCIIs(data), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
66
test/jdk/java/lang/String/CompactString/ToLowerCase.java
Normal file
66
test/jdk/java/lang/String/CompactString/ToLowerCase.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.toLowerCase.
|
||||
* @run testng/othervm -XX:+CompactStrings ToLowerCase
|
||||
* @run testng/othervm -XX:-CompactStrings ToLowerCase
|
||||
*/
|
||||
|
||||
public class ToLowerCase extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] { STRING_EMPTY, "" },
|
||||
new Object[] { STRING_L1, "a" },
|
||||
new Object[] { STRING_L2, "ab" },
|
||||
new Object[] { STRING_U1, "\uFF41" },
|
||||
new Object[] { STRING_MDUPLICATE1,
|
||||
"\uFF41a\uFF41a\uFF41a\uFF41a\uFF41a" },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
"\uD801\uDC28\uD801\uDC29\uFF41a" },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"\uD801\uDC28\uD801\uDC29\uFF41a" },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
STRING_SUPPLEMENTARY_LOWERCASE } };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testToLowerCase(String str, String expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(data.toLowerCase(), expected, String.format(
|
||||
"testing String(%s).toLowerCase(), source : %s, ",
|
||||
escapeNonASCIIs(data), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
67
test/jdk/java/lang/String/CompactString/ToUpperCase.java
Normal file
67
test/jdk/java/lang/String/CompactString/ToUpperCase.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.toUpperCase.
|
||||
* @run testng/othervm -XX:+CompactStrings ToUpperCase
|
||||
* @run testng/othervm -XX:-CompactStrings ToUpperCase
|
||||
*/
|
||||
|
||||
public class ToUpperCase extends CompactString {
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
|
||||
new Object[] { STRING_EMPTY, "" },
|
||||
new Object[] { STRING_L1, "A" },
|
||||
new Object[] { STRING_L2, "AB" },
|
||||
new Object[] { STRING_U1, "\uFF21" },
|
||||
new Object[] { STRING_MDUPLICATE1,
|
||||
"\uFF21A\uFF21A\uFF21A\uFF21A\uFF21A" },
|
||||
new Object[] { STRING_SUPPLEMENTARY,
|
||||
"\uD801\uDC00\uD801\uDC01\uFF21A" },
|
||||
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
"\uD801\uDC00\uD801\uDC01\uFF21A" },
|
||||
new Object[] { STRING_SUPPLEMENTARY_LOWERCASE,
|
||||
STRING_SUPPLEMENTARY }, };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "provider")
|
||||
public void testToUpperCase(String str, String expected) {
|
||||
map.get(str).forEach(
|
||||
(source, data) -> {
|
||||
assertEquals(data.toUpperCase(), expected, String.format(
|
||||
"testing String(%s).toUpperCase(), source : %s, ",
|
||||
escapeNonASCIIs(data), source));
|
||||
});
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/lang/String/CompactString/Trim.java
Normal file
71
test/jdk/java/lang/String/CompactString/Trim.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.trim.
|
||||
* @run testng/othervm -XX:+CompactStrings Trim
|
||||
* @run testng/othervm -XX:-CompactStrings Trim
|
||||
*/
|
||||
|
||||
public class Trim {
|
||||
|
||||
/*
|
||||
* Data provider for testTrim
|
||||
*
|
||||
* @return input parameter for testTrim
|
||||
*/
|
||||
@DataProvider
|
||||
public Object[][] trims() {
|
||||
return new Object[][] {
|
||||
{ " \t \t".trim(), "" },
|
||||
{ "\t \t ".trim(), "" },
|
||||
{ "\t A B C\t ".trim(), "A B C" },
|
||||
{ " \t A B C \t".trim(), "A B C" },
|
||||
{ "\t \uFF21 \uFF22 \uFF23\t ".trim(), "\uFF21 \uFF22 \uFF23" },
|
||||
{ " \t \uFF21 \uFF22 \uFF23 \t".trim(), "\uFF21 \uFF22 \uFF23" },
|
||||
{ " \t \uFF41 \uFF42 \uFF43 \t".trim(), "\uFF41 \uFF42 \uFF43" },
|
||||
{ " \t A\uFF21 B\uFF22 C\uFF23 \t".trim(),
|
||||
"A\uFF21 B\uFF22 C\uFF23" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test trim().
|
||||
*
|
||||
* @param res
|
||||
* real result
|
||||
* @param expected
|
||||
* expected result
|
||||
*/
|
||||
@Test(dataProvider = "trims")
|
||||
public void testTrim(String res, String expected) {
|
||||
assertEquals(res, expected);
|
||||
}
|
||||
|
||||
}
|
||||
92
test/jdk/java/lang/String/CompactString/VMOptionsTest.java
Normal file
92
test/jdk/java/lang/String/CompactString/VMOptionsTest.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is testing
|
||||
* if Compact String enable/disable VM Options is indeed working in String class,
|
||||
* it's verified by testing if the VM option affect coder and
|
||||
* COMPACT_STRINGS field in String class.
|
||||
* @modules java.base/java.lang:open
|
||||
* @run testng/othervm -XX:+CompactStrings -DCompactStringEnabled=true VMOptionsTest
|
||||
* @run testng/othervm -XX:-CompactStrings -DCompactStringEnabled=false VMOptionsTest
|
||||
*/
|
||||
|
||||
public class VMOptionsTest {
|
||||
boolean compactStringEnabled;
|
||||
// corresponding "COMPACT_STRINGS" field in String class.
|
||||
Field COMPACT_STRINGS;
|
||||
// corresponding "coder" field in String class.
|
||||
Field coder;
|
||||
|
||||
// corresponding coder type in String class.
|
||||
final byte LATIN1 = 0;
|
||||
final byte UTF16 = 1;
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() throws Exception {
|
||||
compactStringEnabled = Boolean.valueOf(System.getProperty("CompactStringEnabled", null));
|
||||
COMPACT_STRINGS = String.class.getDeclaredField("COMPACT_STRINGS");
|
||||
COMPACT_STRINGS.setAccessible(true);
|
||||
coder = String.class.getDeclaredField("coder");
|
||||
coder.setAccessible(true);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] provider() {
|
||||
return new Object[][] {
|
||||
new Object[] {"", LATIN1},
|
||||
new Object[] {"abc", LATIN1},
|
||||
new Object[] {"A\uff21", UTF16},
|
||||
new Object[] {"\uff21\uff22", UTF16}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* verify the coder field in String objects.
|
||||
*/
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCoder(String str, byte expected) throws Exception {
|
||||
byte c = (byte) coder.get(str);
|
||||
expected = compactStringEnabled ? expected : UTF16;
|
||||
assertEquals(c, expected);
|
||||
}
|
||||
|
||||
/*
|
||||
* verify the COMPACT_STRINGS flag in String objects.
|
||||
*/
|
||||
@Test(dataProvider = "provider")
|
||||
public void testCompactStringFlag(String str, byte ignore) throws Exception {
|
||||
assertTrue(COMPACT_STRINGS.get(str).equals(compactStringEnabled));
|
||||
}
|
||||
}
|
||||
78
test/jdk/java/lang/String/CompactString/ValueOf.java
Normal file
78
test/jdk/java/lang/String/CompactString/ValueOf.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8077559
|
||||
* @summary Tests Compact String. This one is for String.valueOf.
|
||||
* valueOf(char[] data) is not tested here.
|
||||
* @run testng/othervm -XX:+CompactStrings ValueOf
|
||||
* @run testng/othervm -XX:-CompactStrings ValueOf
|
||||
*/
|
||||
|
||||
public class ValueOf {
|
||||
|
||||
/*
|
||||
* Data provider for testValueOf
|
||||
*
|
||||
* @return input parameter for testValueOf
|
||||
*/
|
||||
@DataProvider
|
||||
public Object[][] valueOfs() {
|
||||
return new Object[][] { { String.valueOf(true), "true" },
|
||||
{ String.valueOf(false), "false" },
|
||||
{ String.valueOf(1.0f), "1.0" },
|
||||
{ String.valueOf(0.0f), "0.0" },
|
||||
{ String.valueOf(Float.MAX_VALUE), "3.4028235E38" },
|
||||
{ String.valueOf(Float.MIN_VALUE), "1.4E-45" },
|
||||
{ String.valueOf(1.0d), "1.0" },
|
||||
{ String.valueOf(0.0d), "0.0" },
|
||||
{ String.valueOf(Double.MAX_VALUE), "1.7976931348623157E308" },
|
||||
{ String.valueOf(Double.MIN_VALUE), "4.9E-324" },
|
||||
{ String.valueOf(1), "1" }, { String.valueOf(0), "0" },
|
||||
{ String.valueOf(Integer.MAX_VALUE), "2147483647" },
|
||||
{ String.valueOf(Integer.MIN_VALUE), "-2147483648" },
|
||||
{ String.valueOf(1L), "1" }, { String.valueOf(0L), "0" },
|
||||
{ String.valueOf(Long.MAX_VALUE), "9223372036854775807" },
|
||||
{ String.valueOf(Long.MIN_VALUE), "-9223372036854775808" } };
|
||||
}
|
||||
|
||||
/*
|
||||
* test String.valueOf(xxx).
|
||||
*
|
||||
* @param res
|
||||
* real result
|
||||
* @param expected
|
||||
* expected result
|
||||
*/
|
||||
@Test(dataProvider = "valueOfs")
|
||||
public void testValueOf(String res, String expected) {
|
||||
assertEquals(res, expected);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue