/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/*
*
* @test
* @bug 4533872 4915683 4922962 4985217 5017280 6242664 6588260
* @summary Unit tests for supplementary character support (JSR-204)
*/
public class Supplementary {
test1(); // Test for codePointAt(int index)
test2(); // Test for codePointBefore(int index)
test3(); // Test for indexOf(int ch)
test4(); // Test for indexOf(int ch, int fromIndex)
test5(); // Test for lastIndexOf(int ch)
test6(); // Test for lastIndexOf(int ch, int fromIndex)
test7(); // Test for String(int[] codePoint, int offset, int count)
test8(); // Test for codePointCount(int beginIndex, int endIndex)
test9(); // Test for offsetByCodePoints(int index, int offset)
test10(); // Test for offsetByCodePoints(int index, int offset)
// To verify the fix for 6242664
}
/* Text strings which are used as input data.
* The comment above each text string means the index of each 16-bit char
* for convenience.
*/
/* 111 1 111111 22222
0123 4 5678 9 012 3 456789 01234 */
"abc\uD800\uDC00def\uD800\uD800ab\uD800\uDC00cdefa\uDC00bcdef",
/* 1 1111 1111 1 222
0 12345 6789 0 1234 5678 9 012 */
"\uD800defg\uD800hij\uD800\uDC00klm\uDC00nop\uDC00\uD800rt\uDC00",
/* 11 1 1111 1 112 222
0 12345 6 78901 2 3456 7 890 123 */
"\uDC00abcd\uDBFF\uDFFFefgh\uD800\uDC009ik\uDC00\uDC00lm\uDC00no\uD800",
/* 111 111111 1 22 2
0 1 2345 678 9 012 345678 9 01 2 */
"\uD800\uDC00!#$\uD800%&\uD800\uDC00;+\uDC00<>;=^\uDC00\\@\uD800\uDC00",
// includes an undefined supplementary character in Unicode 4.0.0
/* 1 11 1 1111 1
0 1 2345 6 789 0 12 3 4567 8 */
"\uDB40\uDE00abc\uDE01\uDB40de\uDB40\uDE02f\uDB40\uDE03ghi\uDB40\uDE02",
// all supplementary characters
/* 1 1
0 1 2 3 4 5 6 7 8 9 0 1 */
"\uD800\uDC00\uD800\uDC01\uD800\uDC02\uD800\uDC03\uD800\uDC04\uD800\uDC05"+
/* 1 1 1 1 1 1 1 1 2 2 2 2
2 3 4 5 6 7 8 9 0 1 2 3 */
"\uD800\uDC06\uD800\uDC07\uD800\uDC08\uD800\uDC08\uD800\uDC09\uD800\uDC0A"+
/* 2 2 2 2 2 2 3 3 3 3 3 3
4 5 6 7 8 9 0 1 2 3 4 5 */
"\uD800\uDC0B\uD800\uDC0C\uD800\uDC0D\uD800\uDC0A\uD800\uDC0F\uD800\uDC10"
};
/* Expected results for:
* test1(): for codePointAt()
*
* Each character in each array is the golden data for each text string
* in the above input data. For example, the first data in each array is
* for the first input string.
*/
static final int[][] golden1 = {
{'a', 0xD800, 0xDC00, 0x10000, 0xE0200, 0x10000},// codePointAt(0)
{0xD800, 0x10000, 'g', 0xDC00, 0xE0202, 0xDC04}, // codePointAt(9)
{'f', 0xDC00, 0xD800, 0xDC00, 0xDE02, 0xDC10}, // codePointAt(length-1)
{'f', 'p', 0xDC00, '^', 0xE0202, 0xDC08}, // codePointAt() for a substring
};
/*
* Test for codePointAt(int index) method
*/
static void test1() {
/*
* Normal case
*/
/*
* Abnormal case - verify that an exception is thrown.
*/
}
}
/* Expected results for:
* test2(): for codePointBefore()
*
* Each character in each array is the golden data for each text string
* in the above input data. For example, the first data in each array is
* for the first input string.
*/
static final int[][] golden2 = {
{'a', 0xD800, 0xDC00, 0xD800, 0xDB40, 0xD800}, // codePointBefore(1)
{0xD800, 'l', 0x10000, 0xDC00, 0xDB40, 0xD800}, // codePointBefore(13)
{'f', 0xDC00, 0xD800, 0x10000, 0xE0202, 0x10010},// codePointBefore(length)
{'b', 'd', 'a', 0xDC00, 0xDE00, 0xDC00}, // codePointBefore() for a substring
};
/*
* Test for codePointBefore(int index) method
*/
static void test2() {
/*
* Normal case
*/
/*
* Abnormal case - verify that an exception is thrown.
*/
}
}
/* Expected results for:
* test3(): for indexOf(int ch)
* test4(): for indexOf(int ch, int fromIndex)
* test5(): for lastIndexOf(int ch)
* test6(): for lastIndexOf(int ch, int fromIndex)
*
* Unlike golden1 and golden2, golden3[m][] is the golden data for text
* string in input[m].
*
* The meaning of each element in golden3[][n]
* golden3[][0]: character which is searched.
* golden3[][2]: the golden data for indexOf(int ch)
* From golden3[][2] to golden3[][n-1]:
* the golden data for indexOf(int ch, int fromIndex)
* The golden3[][n-2]: the golden data for lastIndexOf(int ch)
* From golden3[][1] to golden3[][n-2]:
* the golden data for lastIndexOf(int ch, int fromIndex)
*
* In other words, the data format is
* { ch, -1, index1, index2, ..., -1}
* where index1, index2, ... are all indices of the ch occurrences.
*/
static final int[][] golden3 = {
/* ch indices */
{'b', -1, 1, 11, 20, -1},
{0xD800, -1, 0, 5, 9, 19, -1},
{0xDC00, -1, 0, 12, 16, 17, 20, -1},
{0x10000, -1, 0, 8, 21, -1},
{0xE0202, -1, 9, 17, -1},
{0x1000A, -1, 22, 30, -1}
};
/*
* Test for indexOf(int ch) method
*/
static void test3() {
/*
* Normal case
*/
/*
* Abnormal case - char which isn't included in the string.
*/
}
}
/*
* Test for indexOf(int ch, int fromIndex) method
*/
static void test4() {
/*
* Normal case
*/
int fromIndex = 0;
golden3[i][j]) + 1;
}
/*
* Abnormal case1 - char is included in the string but fromIndex
* is incorrect.
*/
/*
* Abnormal case2 - char which isn't included in the string.
*/
}
}
/*
* Test for lastIndexOf(int ch) method
*/
static void test5() {
/*
* Normal case
*/
/*
* Abnormal case - char which isn't included in the string.
*/
}
}
/*
* Test for lastIndexOf(int ch, int fromIndex) method
*/
static void test6() {
/*
* Normal case
*/
golden3[i][j]) - 1;
}
/*
* Abnormal case1 - char is included in the string but fromIndex
* is incorrect.
*/
/*
* Abnormal case2 - char which isn't included in the string.
*/
}
}
/**
* Test for String(int[] codePoint, int offset, int count).
*/
static void test7() {
int nCodePoints = 0;
int c;
c = s.codePointAt(j);
nCodePoints++;
}
int[] codePoints = new int[nCodePoints];
mid = j;
}
c = s.codePointAt(j);
codePoints[count++] = c;
}
"first half: new String(int[]...) with input[" + i + "]");
"second half: new String(int[]...) with input[" + i + "]");
// test exceptions
}
{
// 6588260: (str) ArrayIndexOutOfBoundsException when trying
// to create a String from codePoints
//int[] x = new int[Character.MAX_CODE_POINT+1];
int[] x = new int[Character.MAX_CODE_POINT];
for (int i = 0; i < x.length; i++)
if (i != 0xdbff) // For round-trip safety
x[i] = i;
"s.codePointCount(0, s.length()) != x.length");
"s.length() <= x.length");
int c = s.codePointAt(j);
check(c != x[i], "c != x[i]");
}
}
}
/**
* Test codePointCount(int, int)
*
* This test case assumes that
* Character.codePointCount(CharSequence, int, int) works
* correctly.
*/
static void test8() {
for (int j = 0; j <= length; j++) {
// Create a substring of the text range. It shares the
// underlying char[] of the String str.
}
for (int j = length; j >= 0; j--) {
}
// test exceptions
}
}
/**
* Test offsetByCodePoints(int, int)
*
* This test case assumes that
* Character.codePointCount(CharSequence, int, int) works
* correctly.
*/
static void test9() {
for (int j = 0; j <= length; j++) {
int expected = j;
if (j > 0 && j < length) {
expected--;
}
}
}
for (int j = length; j >= 0; j--) {
int expected = j;
if (j > 0 && j < length) {
expected++;
}
}
result, 0);
}
// test exceptions
}
}
/**
* Test offsetByCodePoints(int, int) - to verify the fix for 6242664
*
* This test case assumes that
* Character.codePointCount(CharSequence, int, int) works
* correctly.
*/
static void test10() {
for (int j = 0; j <= length; j++) {
int expected = j;
if (j > 0 && j < length) {
expected--;
}
}
}
for (int j = length; j >= 0; j--) {
int expected = j;
if (j > 0 && j < length) {
expected++;
}
}
result, 0);
}
}
}
+ s + ">", c, expected);
}
boolean exceptionOccurred = false;
try {
}
catch (StringIndexOutOfBoundsException e) {
exceptionOccurred = true;
}
+ s + "> should throw StringIndexOutOfBoundsPointerException.");
}
testIndexOf2(s, c, expected);
if (s.indexOf(c) != -1) {
testIndexOf2(s + (char) c, c, expected);
if (Character.isSupplementaryCodePoint(c)) {
}
}
}
}
testLastIndexOf2(s, c, expected);
if (s.lastIndexOf(c) != -1) {
if (Character.isSupplementaryCodePoint(c)) {
}
}
}
int index = s.lastIndexOf(c);
}
return index;
}
return index;
}
try {
} catch (Exception e) {
if (expectedException.isInstance(e)) {
return;
}
throw new RuntimeException("Error: Unexpected exception", e);
}
}
try {
} catch (Exception e) {
if (expectedException.isInstance(e)) {
return;
}
throw new RuntimeException("Error: Unexpected exception", e);
}
}
try {
} catch (Exception e) {
if (expectedException.isInstance(e)) {
return;
}
throw new RuntimeException("Error: Unexpected exception", e);
}
}
if (err) {
}
}
if (err) {
throw new RuntimeException("Error: " + s
+ " returned an unexpected value. got "
+ toHexString(got)
+ ", expected "
+ toHexString(expected));
}
}
}
}