use of java.util.IllegalFormatFlagsException in project robovm by robovm.
the class OldFormatterTest method test_formatLjava_util_LocaleLjava_lang_StringLjava_lang_Object.
public void test_formatLjava_util_LocaleLjava_lang_StringLjava_lang_Object() {
Double val = new Double(3.14);
Calendar cal = Calendar.getInstance();
Formatter fLoc = null;
Formatter fNoL = null;
cal.set(2008, Calendar.SEPTEMBER, 23, 18, 30);
fLoc = new Formatter(Locale.GERMAN);
fNoL = new Formatter(Locale.GERMAN);
fLoc.format(Locale.US, "%f", val);
fNoL.format("%f", val);
assertFalse(fLoc.toString().equals(fNoL.toString()));
fLoc = new Formatter(Locale.FRANCE);
fNoL = new Formatter(Locale.FRANCE);
fLoc.format(Locale.US, "%f", val);
fNoL.format("%f", val);
assertFalse(fLoc.toString().equals(fNoL.toString()));
fLoc = new Formatter(Locale.US);
fNoL = new Formatter(Locale.US);
fLoc.format(Locale.US, "%f", val);
fNoL.format("%f", val);
assertTrue(fLoc.toString().equals(fNoL.toString()));
fLoc = new Formatter(Locale.GERMAN);
fNoL = new Formatter(Locale.GERMAN);
fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
assertFalse(fLoc.toString().equals(fNoL.toString()));
fLoc = new Formatter(Locale.FRANCE);
fNoL = new Formatter(Locale.FRANCE);
fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
assertFalse(fLoc.toString().equals(fNoL.toString()));
fLoc = new Formatter(Locale.US);
fNoL = new Formatter(Locale.US);
fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
assertTrue(fLoc.toString().equals(fNoL.toString()));
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 {
fLoc = new Formatter(Locale.US);
fLoc.format(Locale.FRANCE, illFlags[i], 1.23d);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException expected) {
}
try {
fLoc = new Formatter(Locale.CANADA);
fLoc.format(Locale.GERMAN, illFlags[i], (Double) null);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException expected) {
}
}
fLoc.close();
try {
fLoc.format(Locale.GERMAN, "%f", val);
fail();
} catch (FormatterClosedException expected) {
}
}
use of java.util.IllegalFormatFlagsException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_LineSeparator.
/**
* java.util.Formatter#format(String, Object...) for line sperator
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_LineSeparator() {
Formatter f = null;
/* J2ObjC: Setting line.separator has no effect, see System.lineSeparator().
String oldSeparator = System.getProperty("line.separator");
try {
System.setProperty("line.separator", "!\n");
f = new Formatter(Locale.US);
f.format("%1$n", 1);
assertEquals("!\n", f.toString());
f = new Formatter(Locale.KOREAN);
f.format("head%1$n%2$n", 1, new Date());
assertEquals("head!\n!\n", f.toString());
f = new Formatter(Locale.US);
f.format("%n%s", "hello");
assertEquals("!\nhello", f.toString());
} finally {
System.setProperty("line.separator", oldSeparator);
}*/
f = new Formatter(Locale.US);
try {
f.format("%-n");
fail("should throw IllegalFormatFlagsException: %-n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%+n");
fail("should throw IllegalFormatFlagsException: %+n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%#n");
fail("should throw IllegalFormatFlagsException: %#n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("% n");
fail("should throw IllegalFormatFlagsException: % n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%0n");
fail("should throw IllegalFormatFlagsException: %0n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%,n");
fail("should throw IllegalFormatFlagsException: %,n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%(n");
fail("should throw IllegalFormatFlagsException: %(n");
} catch (IllegalFormatFlagsException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%4n");
fail("should throw IllegalFormatWidthException");
} catch (IllegalFormatWidthException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%-4n");
fail("should throw IllegalFormatWidthException");
} catch (IllegalFormatWidthException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%.9n");
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%5.9n");
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
//System.setProperty("line.separator", oldSeparator);
}
use of java.util.IllegalFormatFlagsException 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.IllegalFormatFlagsException 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.IllegalFormatFlagsException 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
}
}
Aggregations