452 checkNewIndex(a, 0, index, length); |
455 checkNewIndex(a, 0, index, length); |
453 index = Character.offsetByCodePoints(a, length, 0, length, 0); |
456 index = Character.offsetByCodePoints(a, length, 0, length, 0); |
454 checkNewIndex(a, 0, index, length); |
457 checkNewIndex(a, 0, index, length); |
455 } |
458 } |
456 |
459 |
|
460 /** |
|
461 * Test toString(int) |
|
462 * |
|
463 * This test case assumes that Character.toChars()/String(char[]) work |
|
464 * correctly. |
|
465 */ |
|
466 static void test06() { |
|
467 for (int cp = Character.MIN_CODE_POINT; cp <= Character.MAX_CODE_POINT; cp++) { |
|
468 String result = Character.toString(cp); |
|
469 String expected = new String(Character.toChars(cp)); |
|
470 if (!result.equals(expected)) { |
|
471 throw new RuntimeException("Wrong string is created. code point: " + |
|
472 cp + ", result: " + result + ", expected: " + expected); |
|
473 } |
|
474 } |
|
475 } |
|
476 |
457 private static void checkNewIndex(Object data, int offset, int result, int expected) { |
477 private static void checkNewIndex(Object data, int offset, int result, int expected) { |
458 String type = getType(data); |
478 String type = getType(data); |
459 String offsetType = (offset > 0) ? "positive" : (offset < 0) ? "negative" : "0"; |
479 String offsetType = (offset > 0) ? "positive" : (offset < 0) ? "negative" : "0"; |
460 if (result != expected) { |
480 if (result != expected) { |
461 throw new RuntimeException("offsetByCodePoints(" + type + ", ...) [" |
481 throw new RuntimeException("offsetByCodePoints(" + type + ", ...) [" |
578 } |
598 } |
579 } |
599 } |
580 |
600 |
581 // Test toChar(int) |
601 // Test toChar(int) |
582 // toChar(int, char[], int) |
602 // toChar(int, char[], int) |
|
603 // toString(int) |
583 // for exceptions |
604 // for exceptions |
584 static void testExceptions00() { |
605 static void testExceptions00() { |
585 callToChars1(-1, IllegalArgumentException.class); |
606 callToChars1(-1, IllegalArgumentException.class); |
586 callToChars1(MAX_SUPPLEMENTARY + 1, IllegalArgumentException.class); |
607 callToChars1(MAX_SUPPLEMENTARY + 1, IllegalArgumentException.class); |
587 |
608 |
593 callToChars3('A', new char[1], 1, IndexOutOfBoundsException.class); |
614 callToChars3('A', new char[1], 1, IndexOutOfBoundsException.class); |
594 callToChars3(MIN_SUPPLEMENTARY, new char[0], 0, IndexOutOfBoundsException.class); |
615 callToChars3(MIN_SUPPLEMENTARY, new char[0], 0, IndexOutOfBoundsException.class); |
595 callToChars3(MIN_SUPPLEMENTARY, new char[1], 0, IndexOutOfBoundsException.class); |
616 callToChars3(MIN_SUPPLEMENTARY, new char[1], 0, IndexOutOfBoundsException.class); |
596 callToChars3(MIN_SUPPLEMENTARY, new char[2], -1, IndexOutOfBoundsException.class); |
617 callToChars3(MIN_SUPPLEMENTARY, new char[2], -1, IndexOutOfBoundsException.class); |
597 callToChars3(MIN_SUPPLEMENTARY, new char[2], 1, IndexOutOfBoundsException.class); |
618 callToChars3(MIN_SUPPLEMENTARY, new char[2], 1, IndexOutOfBoundsException.class); |
|
619 |
|
620 callToString(Character.MIN_CODE_POINT - 1, IllegalArgumentException.class); |
|
621 callToString(Character.MAX_CODE_POINT + 1, IllegalArgumentException.class); |
598 } |
622 } |
599 |
623 |
600 static final boolean At = true, Before = false; |
624 static final boolean At = true, Before = false; |
601 |
625 |
602 /** |
626 /** |
832 } |
856 } |
833 throw new RuntimeException("offsetCodePointCounts(char[]...) didn't throw " |
857 throw new RuntimeException("offsetCodePointCounts(char[]...) didn't throw " |
834 + expectedException.getName()); |
858 + expectedException.getName()); |
835 } |
859 } |
836 |
860 |
|
861 private static void callToString(int codePoint, Class expectedException) { |
|
862 try { |
|
863 String s = Character.toString(codePoint); |
|
864 } catch (Exception e) { |
|
865 if (expectedException.isInstance(e)) { |
|
866 return; |
|
867 } |
|
868 throw new RuntimeException("Unspecified exception", e); |
|
869 } |
|
870 throw new RuntimeException("toString(int) didn't throw " |
|
871 + expectedException.getName()); |
|
872 } |
|
873 |
837 private static String getType(Object data) { |
874 private static String getType(Object data) { |
838 return (data instanceof CharSequence) ? "CharSequence" : "char[]"; |
875 return (data instanceof CharSequence) ? "CharSequence" : "char[]"; |
839 } |
876 } |
840 |
877 |
841 private static String toHexString(int c) { |
878 private static String toHexString(int c) { |