/*
* 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 4985217 5017280 6937112
* @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 reverse()
test4(); // Test for appendCodePoint(int codePoint)
test5(); // Test for codePointCount(int beginIndex, int endIndex)
test6(); // Test for offsetByCodePoints(int index, int offset)
}
/* 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",
};
/* 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}, // codePointAt(0)
{0xD800, 0x10000, 'g', 0xDC00, 0xE0202}, // codePointAt(9)
{'f', 0xDC00, 0xD800, 0xDC00, 0xDE02}, // codePointAt(length-1)
};
/*
* 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}, // codePointBefore(1)
{0xD800, 'l', 0x10000, 0xDC00, 0xDB40}, // codePointBefore(13)
{'f', 0xDC00, 0xD800, 0x10000, 0xE0202}, // codePointBefore(length)
};
/*
* Test for codePointBefore(int index) method
*/
static void test2() {
/*
* Normal case
*/
/*
* Abnormal case - verify that an exception is thrown.
*/
}
}
/* Expected results for:
* test3(): for reverse()
*
* Unlike golden1 and golden2, each array is the golden data for each text
* string in the above input data. For example, the first array is for
* the first input string.
*/
"fedcb\uDC00afedc\uD800\uDC00ba\uD800\uD800fed\uD800\uDC00cba",
"\uDC00tr\uD800\uDC00pon\uDC00mlk\uD800\uDC00jih\uD800gfed\uD800",
"\uD800on\uDC00ml\uDC00\uDC00ki9\uD800\uDC00hgfe\uDBFF\uDFFFdcba\uDC00",
"\uD800\uDC00@\\\uDC00^=;><\uDC00+;\uD800\uDC00&%\uD800$#!\uD800\uDC00",
// includes an undefined supplementary character in Unicode 4.0.0
"\uDB40\uDE02ihg\uDB40\uDE03f\uDB40\uDE02ed\uDB40\uDE01cba\uDB40\uDE00",
};
// Additional input data & expected result for test3()
{"a\uD800\uDC00", "\uD800\uDC00a"},
{"a\uDC00\uD800", "\uD800\uDC00a"},
{"\uD800\uDC00a", "a\uD800\uDC00"},
{"\uDC00\uD800a", "a\uD800\uDC00"},
{"\uDC00\uD800\uD801", "\uD801\uD800\uDC00"},
{"\uDC00\uD800\uDC01", "\uD800\uDC01\uDC00"},
{"\uD801\uD800\uDC00", "\uD800\uDC00\uD801"},
{"\uD800\uDC01\uDC00", "\uDC00\uD800\uDC01"},
{"\uD800\uDC00\uDC01\uD801", "\uD801\uDC01\uD800\uDC00"},
};
/*
* Test for reverse() method
*/
static void test3() {
}
}
}
/**
* Test for appendCodePoint() method
*/
static void test4() {
int c;
c = s.codePointAt(j);
}
"appendCodePoint() produced a wrong result with input["+i+"]");
}
// test exception
}
/**
* Test codePointCount(int, int)
*
* This test case assumes that
* Character.codePointCount(CharSequence, int, int) works
* correctly.
*/
static void test5() {
for (int j = 0; j <= length; j++) {
}
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 test6() {
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
}
}
}
boolean exceptionOccurred = false;
try {
}
catch (StringIndexOutOfBoundsException e) {
exceptionOccurred = true;
}
+ sb + "> should throw StringIndexOutOfBoundsPointerException.");
}
try {
} catch (Exception e) {
if (expectedException.isInstance(e)) {
return;
}
throw new RuntimeException("Error: Unexpected exception", e);
}
+ expectedException.getName());
}
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));
}
}
if (err) {
throw new RuntimeException("Error: " + s
+ " returned an unexpected value. got <"
+ ">, expected <"
+ ">");
}
}
}
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
}
}
}