use of java.util.IllegalFormatCodePointException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_CharacterConversion.
/**
* java.util.Formatter#format(String, Object...) for Character
* conversion
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_CharacterConversion() {
Formatter f = new Formatter(Locale.US);
final Object[] illArgs = { Boolean.TRUE, new Float(1.1f), new Double(1.1d), "string content", new Float(1.1f), new Date() };
for (int i = 0; i < illArgs.length; i++) {
try {
f.format("%c", illArgs[i]);
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
}
try {
f.format("%c", Integer.MAX_VALUE);
fail("should throw IllegalFormatCodePointException");
} catch (IllegalFormatCodePointException e) {
// expected
}
try {
f.format("%#c", 'c');
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
final Object[][] triple = { { 'c', "%c", "c" }, { 'c', "%-2c", "c " }, { 'ģ', "%c", "ģ" }, { 'ģ', "%-2c", "ģ " }, { (byte) 0x11, "%c", "" }, { (byte) 0x11, "%-2c", " " }, { (short) 0x1111, "%c", "ᄑ" }, { (short) 0x1111, "%-2c", "ᄑ " }, { 0x11, "%c", "" }, { 0x11, "%-2c", " " } };
final int input = 0;
final int pattern = 1;
final int output = 2;
for (int i = 0; i < triple.length; i++) {
f = new Formatter(Locale.US);
f.format((String) triple[i][pattern], triple[i][input]);
assertEquals(triple[i][output], f.toString());
}
f = new Formatter(Locale.US);
f.format("%c", 0x10000);
assertEquals(0x10000, f.toString().codePointAt(0));
try {
f.format("%2.2c", 'c');
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
f = new Formatter(Locale.US);
f.format("%C", 'w');
// error on RI, throw UnknownFormatConversionException
// RI do not support converter 'C'
assertEquals("W", f.toString());
f = new Formatter(Locale.JAPAN);
f.format("%Ced", 0x1111);
// error on RI, throw UnknownFormatConversionException
// RI do not support converter 'C'
assertEquals("ᄑed", f.toString());
}
use of java.util.IllegalFormatCodePointException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionException.
/**
* java.util.Formatter#format(String, Object...) for general
* conversion exception
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionException() {
final String[] flagMismatch = { "%#b", "%+b", "% b", "%0b", "%,b", "%(b", "%#B", "%+B", "% B", "%0B", "%,B", "%(B", "%#h", "%+h", "% h", "%0h", "%,h", "%(h", "%#H", "%+H", "% H", "%0H", "%,H", "%(H", "%+s", "% s", "%0s", "%,s", "%(s", "%+S", "% S", "%0S", "%,S", "%(S" };
Formatter f = new Formatter(Locale.US);
for (int i = 0; i < flagMismatch.length; i++) {
try {
f.format(flagMismatch[i], "something");
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingWidth = { "%-b", "%-B", "%-h", "%-H", "%-s", "%-S" };
for (int i = 0; i < missingWidth.length; i++) {
try {
f.format(missingWidth[i], "something");
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
// Regression test
f = new Formatter();
try {
f.format("%c", (byte) -0x0001);
fail("Should throw IllegalFormatCodePointException");
} catch (IllegalFormatCodePointException e) {
// expected
}
f = new Formatter();
try {
f.format("%c", (short) -0x0001);
fail("Should throw IllegalFormatCodePointException");
} catch (IllegalFormatCodePointException e) {
// expected
}
f = new Formatter();
try {
f.format("%c", -0x0001);
fail("Should throw IllegalFormatCodePointException");
} catch (IllegalFormatCodePointException e) {
// expected
}
}
Aggregations