1472N/A * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1472N/A * or visit www.oracle.com if you need additional information or have any 0N/A/* Type-specific source code for unit test 0N/A * Regenerate the BasicX classes via genBasic.sh whenever this file changes. 0N/A * We check in the generated source files so that the test tree can be used 0N/A * independently of the rest of the source tree. 0N/A// -- This file was mechanically generated: Do not edit! -- // 0N/A //--------------------------------------------------------------------- 0N/A // Date/Time conversions applicable to Calendar, Date, and long. 0N/A //--------------------------------------------------------------------- 0N/A // Date/long do not have timezone information so they will always use 0N/A // the default timezone. 0N/A // Date (implemented via conversion to Calendar) 0N/A // long (implemented via conversion to Calendar) 0N/A // repeat all tests for upper case variant (%T) 0N/A for (
int i =
0; i <
24; i++) {
0N/A // GregorianCalendar(int year, int month, int dayOfMonth, 0N/A // int hourOfDay, int minute, int second); 0N/A //----------------------------------------------------------------- 0N/A // DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H 0N/A //----------------------------------------------------------------- 0N/A //----------------------------------------------------------------- 0N/A // DateTime.HOUR - 'l' (1 - 12) -- like I 0N/A //----------------------------------------------------------------- 0N/A v = (v ==
0 ?
12 : v);
0N/A //----------------------------------------------------------------- 0N/A // DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded] 0N/A //----------------------------------------------------------------- 0N/A //----------------------------------------------------------------- 0N/A // DateTime.HOUR_0 - 'I' (01 - 12) 0N/A //----------------------------------------------------------------- //----------------------------------------------------------------- // DateTime.AM_PM - (am or pm) //----------------------------------------------------------------- public static void test() {
// Any characters not explicitly defined as conversions, date/time // 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. //--------------------------------------------------------------------- //--------------------------------------------------------------------- test(
"%4$2s %3$2s %2$2s %1$2s",
" d c b a",
"a",
"b",
"c",
"d");
test(
"Amount gained or lost since last statement: $ %,(.2f",
"Amount gained or lost since last statement: $ (6,217.58)",
testSysOut(
"Local time: %tT",
"Local time: 16:17:00", c);
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",
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",
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");
test(
"%s %s %<s %<s",
"a b b b",
"a",
"b",
"c",
"d");
test(
"%s %s %s %s",
"a b c d",
"a",
"b",
"c",
"d");
test(
"%2$s %s %<s %s",
"b a a b",
"a",
"b",
"c",
"d");
//--------------------------------------------------------------------- // General conversion applicable to any argument. //--------------------------------------------------------------------- test(
"%b",
"true",
true);
test(
"%b",
"false",
false);
test(
"%B",
"TRUE",
true);
test(
"%B",
"FALSE",
false);
test(
"%14b",
" true",
true);
test(
"%-14b",
"true ",
true);
test(
"%5.1b",
" f",
false);
test(
"%-5.1b",
"f ",
false);
test(
"%b",
"true",
"foo");
// 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. //--------------------------------------------------------------------- //--------------------------------------------------------------------- // correct or side-effect of implementation? //--------------------------------------------------------------------- // General conversion applicable to any argument. //--------------------------------------------------------------------- test(
"%c",
"H", (
byte)
72);
test(
"%c",
"i", (
short)
105);
test(
"%c",
"!", (
int)
33);
//--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // General conversion applicable to any argument. //--------------------------------------------------------------------- test(
"%s",
"Hello, Duke",
"Hello, Duke");
test(
"%S",
"HELLO, DUKE",
"Hello, Duke");
test(
"%20S",
" HELLO, DUKE",
"Hello, Duke");
test(
"%20s",
" Hello, Duke",
"Hello, Duke");
test(
"%-20s",
"Hello, Duke ",
"Hello, Duke");
test(
"%-20.5s",
"Hello ",
"Hello, Duke");
//--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // General conversion applicable to any argument. //--------------------------------------------------------------------- test(
"%10h",
" ddf63471",
"Hello, Duke");
test(
"%-10h",
"ddf63471 ",
"Hello, Duke");
test(
"%-10H",
"DDF63471 ",
"Hello, Duke");
test(
"%10h",
" 402e0000",
15.0);
test(
"%10H",
" 402E0000",
15.0);
//--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // Date/Time conversions applicable to Calendar, Date, and long. //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // %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 //--------------------------------------------------------------------- // testDateTime("%tQ", "801283714584", c0); //--------------------------------------------------------------------- // testHours() iterates through all twenty-four hours to verify //--------------------------------------------------------------------- //--------------------------------------------------------------------- // %t - Portions of date [ day, month, dates, weeks ] //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // %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 //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- // perhaps an IllegalFormatArgumentIndexException should be defined?