use of java.util.FormatFlagsConversionMismatchException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException.
/**
* java.util.Formatter#format(String, Object...) for exceptions in
* Float/Double/BigDecimal conversion type 'e', 'E', 'g', 'G', 'f', 'a', 'A'
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException() {
Formatter f = null;
final char[] conversions = { 'e', 'E', 'g', 'G', 'f', 'a', 'A' };
final Object[] illArgs = { false, (byte) 1, (short) 2, 3, (long) 4, new BigInteger("5"), new Character('c'), new Object(), new Date() };
for (int i = 0; i < illArgs.length; i++) {
for (int j = 0; j < conversions.length; j++) {
try {
f = new Formatter(Locale.UK);
f.format("%" + conversions[j], illArgs[i]);
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
}
}
try {
f = new Formatter(Locale.UK);
f.format("%a", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
try {
f = new Formatter(Locale.UK);
f.format("%A", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
final String[] flagsConversionMismatches = { "%,e", "%,E", "%#g", "%#G", "%,a", "%,A", "%(a", "%(A" };
for (int i = 0; i < flagsConversionMismatches.length; i++) {
try {
f = new Formatter(Locale.CHINA);
f.format(flagsConversionMismatches[i], new BigDecimal(1));
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
f = new Formatter(Locale.JAPAN);
f.format(flagsConversionMismatches[i], (BigDecimal) null);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingFormatWidths = { "%-0e", "%0e", "%-e", "%-0E", "%0E", "%-E", "%-0g", "%0g", "%-g", "%-0G", "%0G", "%-G", "%-0f", "%0f", "%-f", "%-0a", "%0a", "%-a", "%-0A", "%0A", "%-A" };
for (int i = 0; i < missingFormatWidths.length; i++) {
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], 1f);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], (Float) null);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
final String[] illFlags = { "%+ e", "%+ E", "%+ g", "%+ G", "%+ f", "%+ a", "%+ A", "%-03e", "%-03E", "%-03g", "%-03G", "%-03f", "%-03a", "%-03A" };
for (int i = 0; i < illFlags.length; i++) {
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], 1.23d);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], (Double) null);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
}
f = new Formatter(Locale.US);
try {
f.format("%F", 1);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.util.FormatFlagsConversionMismatchException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigDecimalExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for BigDecimal
* exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigDecimalExceptionOrder() {
Formatter f = null;
BigDecimal bd = new BigDecimal("1.0");
/*
* Summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* FormatFlagsConversionMismatchException >
* IllegalFormatConversionException
*
*/
try {
// compare FormatFlagsConversionMismatchException and
// IllegalFormatConversionException
f = new Formatter(Locale.US);
f.format("%,e", (byte) 1);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
// compare IllegalFormatFlagsException and
// FormatFlagsConversionMismatchException
f = new Formatter(Locale.US);
f.format("%+ ,e", bd);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
// compare MissingFormatWidthException and
// IllegalFormatFlagsException
f = new Formatter(Locale.US);
f.format("%+ -e", bd);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
// MissingFormatWidthException
try {
f = new Formatter(Locale.US);
f.format("%-F", bd);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.util.FormatFlagsConversionMismatchException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionOther.
/**
* java.util.Formatter#format(String, Object...) for general
* conversion other cases
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionOther() {
/*
* In Turkish locale, the upper case of 'i' is 'İ'. The
* following test indicate that 'i' is coverted to upper case
* without using the turkish locale.
*/
Formatter f = new Formatter(new Locale("tr"));
f.format("%S", "i");
//assertEquals("I", f.toString()); J2ObjC changed.
assertEquals("İ", f.toString());
final Object[] input = { Boolean.FALSE, Boolean.TRUE, new Character('c'), new Byte((byte) 0x01), new Short((short) 0x0001), new Integer(1), new Float(1.1f), new Double(1.1d), "", "string content", new MockFormattable(), (Object) null };
f = new Formatter(Locale.GERMAN);
for (int i = 0; i < input.length; i++) {
if (!(input[i] instanceof Formattable)) {
try {
f.format("%#s", input[i]);
/*
* fail on RI, spec says if the '#' flag is present and the
* argument is not a Formattable , then a
* FormatFlagsConversionMismatchException will be thrown.
*/
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
} else {
f.format("%#s%<-#8s", input[i]);
assertEquals("customized format function width: -1 precision: -1customized format function width: 8 precision: -1", f.toString());
}
}
}
use of java.util.FormatFlagsConversionMismatchException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerConversionException.
/**
* java.util.Formatter#format(String, Object...) for BigInteger
* conversion exception
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerConversionException() {
Formatter f = null;
final String[] flagsConversionMismatches = { "%#d", "%,o", "%,x", "%,X" };
for (int i = 0; i < flagsConversionMismatches.length; i++) {
try {
f = new Formatter(Locale.CHINA);
f.format(flagsConversionMismatches[i], new BigInteger("1"));
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingFormatWidths = { "%-0d", "%0d", "%-d", "%-0o", "%0o", "%-o", "%-0x", "%0x", "%-x", "%-0X", "%0X", "%-X" };
for (int i = 0; i < missingFormatWidths.length; i++) {
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], new BigInteger("1"));
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
final String[] illFlags = { "%+ d", "%-08d", "%+ o", "%-08o", "%+ x", "%-08x", "%+ X", "%-08X" };
for (int i = 0; i < illFlags.length; i++) {
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], new BigInteger("1"));
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
}
final String[] precisionExceptions = { "%.4d", "%2.5o", "%8.6x", "%11.17X" };
for (int i = 0; i < precisionExceptions.length; i++) {
try {
f = new Formatter(Locale.US);
f.format(precisionExceptions[i], new BigInteger("1"));
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
}
f = new Formatter(Locale.US);
try {
f.format("%D", new BigInteger("1"));
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%O", new BigInteger("1"));
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
try {
f = new Formatter();
f.format("%010000000000000000000000000000000001d", new BigInteger("1"));
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
use of java.util.FormatFlagsConversionMismatchException 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());
}
Aggregations