/*
* 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.
*/
/* Type-specific source code for unit test
*
* Regenerate the BasicX classes via genBasic.sh whenever this file changes.
* We check in the generated source files so that the test tree can be used
* independently of the rest of the source tree.
*/
#if[double]
#end[double]
#if[datetime]
}
{
}
}
}
try {
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
} finally {
try {
} catch (IOException ex) {
}
}
}
boolean caught = false;
try {
} catch (Throwable x) {
caught = true;
}
if (!caught)
else
pass();
}
boolean caught = false;
try {
} catch (Throwable x) {
caught = true;
}
if (!caught)
else
pass();
}
#if[datetime]
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Calendar
// the default timezone.
: exp);
// Date (implemented via conversion to Calendar)
// long (implemented via conversion to Calendar)
long l = c.getTimeInMillis();
if (upper)
// repeat all tests for upper case variant (%T)
exp.toUpperCase(), c, false);
}
private static void testHours() {
for (int i = 0; i < 24; i++) {
// GregorianCalendar(int year, int month, int dayOfMonth,
// int hourOfDay, int minute, int second);
//-----------------------------------------------------------------
// DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// DateTime.HOUR - 'l' (1 - 12) -- like I
//-----------------------------------------------------------------
int v = i % 12;
v = (v == 0 ? 12 : v);
//-----------------------------------------------------------------
// DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded]
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// DateTime.HOUR_0 - 'I' (01 - 12)
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// DateTime.AM_PM - (am or pm)
//-----------------------------------------------------------------
}
}
#if[dec]
#if[prim]
return ($type$) -v;
}
#if[Byte]
}
#if[Short]
return new $type$((short) -v.shortValue());
}
#if[Integer]
}
#if[Long]
}
#if[BigDecimal]
return new $type$(v);
}
return v.negate();
}
}
}
#if[float]
return ($type$) v;
}
return ($type$) -v;
}
}
return 1.0f / v;
}
#end[float]
#if[Float]
return new $type$(v);
}
return new $type$(-v.floatValue());
}
}
}
#if[double]
return ($type$) v;
}
return -v;
}
return v * mul;
}
return 1.0 / v;
}
#end[double]
#if[Double]
return new $type$(v);
}
return new $type$(-v.doubleValue());
}
}
}
public static void test() {
// conversion suffixes, or flags are illegal and are reserved for
// future extensions. Use of such a character in a format string will
// cause an UnknownFormatConversionException or
// UnknownFormatFlagsException to be thrown.
//---------------------------------------------------------------------
// Formatter.java class javadoc examples
//---------------------------------------------------------------------
test("Amount gained or lost since last statement: $ %,(.2f",
"Amount gained or lost since last statement: $ (6,217.58)",
(new BigDecimal("-6217.58")));
test("Unable to open file '%1$s': %2$s",
"Unable to open file 'food': No such file or directory",
"food", "No such file or directory");
test("Duke's Birthday: %1$tB %1$te, %1$tY",
"Duke's Birthday: May 23, 1995",
duke);
test("Duke's Birthday: %1$tB %1$te, %1$tY",
"Duke's Birthday: May 23, 1995",
test("Duke's Birthday: %1$tB %1$te, %1$tY",
"Duke's Birthday: May 23, 1995",
duke.getTimeInMillis());
test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
"d c b a d c b a", "a", "b", "c", "d");
//---------------------------------------------------------------------
// %b
//
// General conversion applicable to any argument.
//---------------------------------------------------------------------
// Boolean.java hardcodes the Strings for "true" and "false", so no
// localization is possible.
// If you pass in a single array to a varargs method, the compiler
// uses it as the array of arguments rather than treating it as a
// single array-type argument.
//---------------------------------------------------------------------
// %b - errors
//---------------------------------------------------------------------
// correct or side-effect of implementation?
//---------------------------------------------------------------------
// %c
//
// General conversion applicable to any argument.
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %c - errors
//---------------------------------------------------------------------
(float) 0.1);
new Object());
//---------------------------------------------------------------------
// %s
//
// General conversion applicable to any argument.
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %s - errors
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %h
//
// General conversion applicable to any argument.
//---------------------------------------------------------------------
"Hello, Duke");
//---------------------------------------------------------------------
// %h - errors
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// flag/conversion errors
//---------------------------------------------------------------------
#if[dec]
#if[prim]
#else[prim]
//---------------------------------------------------------------------
// %d
//
// Numeric conversion applicable to byte, short, int, long, and
// BigInteger.
//---------------------------------------------------------------------
#if[byte]
#if[prim]
//---------------------------------------------------------------------
// %d - byte
//---------------------------------------------------------------------
#else[byte]
#if[short]
//---------------------------------------------------------------------
// %d - short
//---------------------------------------------------------------------
#else[short]
#if[prim]
//---------------------------------------------------------------------
// %d - int and long
//---------------------------------------------------------------------
#end[short]
#end[byte]
//---------------------------------------------------------------------
// %d - errors
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %o
//
// Numeric conversion applicable to byte, short, int, long, and
// BigInteger.
//---------------------------------------------------------------------
#if[byte]
//---------------------------------------------------------------------
// %o - byte
//---------------------------------------------------------------------
#end[byte]
#if[short]
//---------------------------------------------------------------------
// %o - short
//---------------------------------------------------------------------
#end[short]
#if[int]
//---------------------------------------------------------------------
// %o - int
//---------------------------------------------------------------------
#end[int]
#if[long]
//---------------------------------------------------------------------
// %o - long
//---------------------------------------------------------------------
#end[long]
//---------------------------------------------------------------------
// %o - errors
//---------------------------------------------------------------------
minByte);
minByte);
minByte);
//---------------------------------------------------------------------
// %x
//
// Numeric conversion applicable to byte, short, int, long, and
// BigInteger.
//---------------------------------------------------------------------
#if[byte]
//---------------------------------------------------------------------
// %x - byte
//---------------------------------------------------------------------
#end[byte]
#if[short]
//---------------------------------------------------------------------
// %x - short
//---------------------------------------------------------------------
#end[short]
#if[int]
//---------------------------------------------------------------------
// %x - int
//---------------------------------------------------------------------
#end[int]
#if[long]
//---------------------------------------------------------------------
// %x - long
//---------------------------------------------------------------------
#end[long]
//---------------------------------------------------------------------
// %x - errors
//---------------------------------------------------------------------
#if[BigInteger]
//---------------------------------------------------------------------
// BigInteger - errors
//---------------------------------------------------------------------
new BigInteger("1"));
//---------------------------------------------------------------------
// %d - BigInteger
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %o - BigInteger
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %x - BigInteger
//---------------------------------------------------------------------
#if[fp]
#if[BigDecimal]
//---------------------------------------------------------------------
// %s - BigDecimal
//---------------------------------------------------------------------
#if[float]
//---------------------------------------------------------------------
// %s - float
//---------------------------------------------------------------------
#end[float]
#if[Float]
//---------------------------------------------------------------------
// %s - Float
//---------------------------------------------------------------------
#if[double]
//---------------------------------------------------------------------
// %s - double
//---------------------------------------------------------------------
#end[double]
#if[Double]
//---------------------------------------------------------------------
// %s - Double
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// flag/conversion errors
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %e
//
// Floating-point conversions applicable to float, double, and
// BigDecimal.
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %e - float and double
//---------------------------------------------------------------------
// double PI = 3.141 592 653 589 793 238 46;
// double PI^300
// = 13962455701329742638131355433930076081862072808 ... e+149
#if[BigDecimal]
//---------------------------------------------------------------------
// %e - BigDecimal
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %e - boundary problems
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %f
//
// Floating-point conversions applicable to float, double, and
// BigDecimal.
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %f - boundary problems
//---------------------------------------------------------------------
#if[BigDecimal]
//---------------------------------------------------------------------
// %f - BigDecimal
//---------------------------------------------------------------------
// #6476425
#if[float]
//---------------------------------------------------------------------
// %f - float
//---------------------------------------------------------------------
// Float can not accurately store 1e6 * PI.
#else[float]
#if[!Float]
//---------------------------------------------------------------------
// %f - float, double, Double, BigDecimal
//---------------------------------------------------------------------
#end[float]
//---------------------------------------------------------------------
// %g
//
// Floating-point conversions applicable to float, double, and
// BigDecimal.
//---------------------------------------------------------------------
// double PI^300
// = 13962455701329742638131355433930076081862072808 ... e+149
#if[BigDecimal]
//---------------------------------------------------------------------
// %g - BigDecimal
//---------------------------------------------------------------------
#if[float]
// Float can not accurately store 1e6 * PI.
#else[float]
#if[!Float]
#end[float]
#if[double]
//---------------------------------------------------------------------
// %a
//
// Floating-point conversions applicable to float, double, and
// BigDecimal.
//---------------------------------------------------------------------
#end[double]
//---------------------------------------------------------------------
// %f, %e, %g, %a - Boundaries
//---------------------------------------------------------------------
#if[float]
//---------------------------------------------------------------------
// %f, %e, %g, %a - NaN
//---------------------------------------------------------------------
// s
// test("%F", "NAN", Float.NaN);
//---------------------------------------------------------------------
// %f, %e, %g, %a - +0.0
//---------------------------------------------------------------------
// test("%F", "0.000000", +0.0);
//---------------------------------------------------------------------
// %f, %e, %g, %a - -0.0
//---------------------------------------------------------------------
// test("%F", "-0.000000", -0.0);
//---------------------------------------------------------------------
// %f, %e, %g, %a - +Infinity
//---------------------------------------------------------------------
// test("%F", "INFINITY", Float.POSITIVE_INFINITY);
//---------------------------------------------------------------------
// %f, %e, %g, %a - -Infinity
//---------------------------------------------------------------------
// test("%F", "-INFINITY", Float.NEGATIVE_INFINITY);
//---------------------------------------------------------------------
// %f, %e, %g, %a - Float.MIN_VALUE
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %f, %e, %g, %a - Float.MAX_VALUE
//---------------------------------------------------------------------
#end[float]
#if[double]
//---------------------------------------------------------------------
// %f, %e, %g, %a - Double.MIN_VALUE
//---------------------------------------------------------------------
test("%30.350f","0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000490000000000000000000000000",
//---------------------------------------------------------------------
// %f, %e, %g, %a - Double.MAX_VALUE
//---------------------------------------------------------------------
test("%f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000",
test("%,f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000",
test("%,(f", "(179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000)",
test("%,30.5f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.00000",
test("%30.13f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000",
test("%30.20f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000",
#end[double]
//---------------------------------------------------------------------
// %t
//
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %t - errors
//---------------------------------------------------------------------
#if[datetime]
//---------------------------------------------------------------------
// %t - create test Calendar
//---------------------------------------------------------------------
// Get the supported ids for GMT-08:00 (Pacific Standard Time)
// Create a Pacific Standard Time time zone
// public GregorianCalendar(TimeZone zone, Locale aLocale);
// public final void set(int year, int month, int date,
// int hourOfDay, int minute, int second);
//---------------------------------------------------------------------
// %t - Minutes, {nano,milli}*seconds
//
// testDateTime() verifies the expected output for all applicable types
// (Calendar, Date, and long). It also verifies output for "%t" and
// "%T". Thus it is sufficient to invoke that method once per
// conversion/expected output.
//---------------------------------------------------------------------
// testDateTime("%tQ", "801283714584", c0);
//---------------------------------------------------------------------
//
// testHours() iterates through all twenty-four hours to verify
//---------------------------------------------------------------------
testHours();
//---------------------------------------------------------------------
// %t - Portions of date [ day, month, dates, weeks ]
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %t - TimeZone
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %tz should always adjust for DST
//---------------------------------------------------------------------
// Artificial TimeZone based on PST with 3:15 DST always in effect
// 24hrs - 1m = 60 * 60 * 1000 * 24 - 1
(int)(60 * 60 * 1000 * 3.25));
// Restore the TimeZone and verify
throw new RuntimeException("Default TimeZone not restored");
//---------------------------------------------------------------------
// %t - Composites
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %n
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// %%
//---------------------------------------------------------------------
// perhaps an IllegalFormatArgumentIndexException should be defined?
}
}