]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/format/IntlTestDateFormatAPIC.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / format / IntlTestDateFormatAPIC.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2001-2004, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 \r
8 /** \r
9  * Port From:   ICU4C v1.8.1 : format : IntlTestDateFormatAPI\r
10  * Source File: $ICU4CRoot/source/test/intltest/dtfmapts.cpp\r
11  **/\r
12 \r
13 package com.ibm.icu.dev.test.format;\r
14 \r
15 import com.ibm.icu.text.*;\r
16 import java.util.Date;\r
17 import java.text.FieldPosition;\r
18 import java.text.ParsePosition;\r
19 \r
20 /*\r
21  * This is an API test, not a unit test.  It doesn't test very many cases, and doesn't\r
22  * try to test the full functionality.  It just calls each function in the class and\r
23  * verifies that it works on a basic level.\r
24  */\r
25 public class IntlTestDateFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {\r
26     \r
27     public static void main(String[] args)  throws Exception {\r
28         new IntlTestDateFormatAPIC().run(args);\r
29     }\r
30     \r
31     /**\r
32      * Test hiding of parse() and format() APIs in the Format hierarchy.\r
33      * We test the entire hierarchy, even though this test is located in\r
34      * the DateFormat API test.\r
35      */\r
36     public void TestNameHiding() {\r
37     \r
38         // N.B.: This test passes if it COMPILES, since it's a test of\r
39         // compile-time name hiding.\r
40     \r
41         Date dateObj = new Date(0);\r
42         Number numObj = new Double(3.1415926535897932384626433832795);\r
43         StringBuffer strBuffer = new StringBuffer("");\r
44         String str;\r
45         FieldPosition fpos = new FieldPosition(0);\r
46         ParsePosition ppos = new ParsePosition(0);\r
47     \r
48         // DateFormat calling Format API\r
49         {\r
50             logln("DateFormat");\r
51             DateFormat dateFmt = DateFormat.getInstance();\r
52             if (dateFmt != null) {\r
53                 str = dateFmt.format(dateObj);\r
54                 strBuffer = dateFmt.format(dateObj, strBuffer, fpos);\r
55             } else {\r
56                 errln("FAIL: Can't create DateFormat");\r
57             }\r
58         }\r
59     \r
60         // SimpleDateFormat calling Format & DateFormat API\r
61         {\r
62             logln("SimpleDateFormat");\r
63             SimpleDateFormat sdf = new SimpleDateFormat();\r
64             // Format API\r
65             str = sdf.format(dateObj);\r
66             strBuffer = sdf.format(dateObj, strBuffer, fpos);\r
67             // DateFormat API\r
68             strBuffer = sdf.format(new Date(0), strBuffer, fpos);\r
69             str = sdf.format(new Date(0));\r
70             try {\r
71                 sdf.parse(str);\r
72                 sdf.parse(str, ppos);\r
73             } catch (java.text.ParseException pe) {\r
74                 System.out.println(pe);\r
75             }\r
76         }\r
77     \r
78         // NumberFormat calling Format API\r
79         {\r
80             logln("NumberFormat");\r
81             NumberFormat fmt = NumberFormat.getInstance();\r
82             if (fmt != null) {\r
83                 str = fmt.format(numObj);\r
84                 strBuffer = fmt.format(numObj, strBuffer, fpos);\r
85             } else {\r
86                 errln("FAIL: Can't create NumberFormat");\r
87             }\r
88         }\r
89     \r
90         // DecimalFormat calling Format & NumberFormat API\r
91         {\r
92             logln("DecimalFormat");\r
93             DecimalFormat fmt = new DecimalFormat();\r
94             // Format API\r
95             str = fmt.format(numObj);\r
96             strBuffer = fmt.format(numObj, strBuffer, fpos);\r
97             // NumberFormat API\r
98             str = fmt.format(2.71828);\r
99             str = fmt.format(1234567);\r
100             strBuffer = fmt.format(1.41421, strBuffer, fpos);\r
101             strBuffer = fmt.format(9876543, strBuffer, fpos);\r
102             Number obj = fmt.parse(str, ppos);\r
103             try {\r
104                 obj = fmt.parse(str);\r
105                 if(obj==null){\r
106                     errln("FAIL: The format object could not parse the string : "+str);\r
107                 }\r
108             } catch (java.text.ParseException pe) {\r
109                 System.out.println(pe);\r
110             }\r
111         }\r
112         \r
113         //ICU4J have not the classes ChoiceFormat and MessageFormat\r
114         /*\r
115         // ChoiceFormat calling Format & NumberFormat API\r
116         {\r
117             logln("ChoiceFormat");\r
118             ChoiceFormat fmt = new ChoiceFormat("0#foo|1#foos|2#foos");\r
119             // Format API\r
120             str = fmt.format(numObj);\r
121             strBuffer = fmt.format(numObj, strBuffer, fpos);\r
122             // NumberFormat API\r
123             str = fmt.format(2.71828);\r
124             str = fmt.format(1234567);\r
125             strBuffer = fmt.format(1.41421, strBuffer, fpos);\r
126             strBuffer = fmt.format(9876543, strBuffer, fpos);\r
127             Number obj = fmt.parse(str, ppos);\r
128             try {\r
129                 obj = fmt.parse(str);\r
130             } catch (java.text.ParseException pe) {\r
131                 System.out.println(pe);\r
132             }\r
133         }\r
134     \r
135         \r
136         // MessageFormat calling Format API\r
137         {\r
138             logln("MessageFormat");\r
139             MessageFormat fmt = new MessageFormat("");\r
140             // Format API\r
141             // We use dateObj, which MessageFormat should reject.\r
142             // We're testing name hiding, not the format method.\r
143             try {\r
144                 str = fmt.format(dateObj);\r
145             } catch (Exception e) {\r
146                 //e.printStackTrace();\r
147             }\r
148             try {\r
149                 strBuffer = fmt.format(dateObj, strBuffer, fpos);\r
150             } catch (Exception e) {\r
151                 //e.printStackTrace();\r
152             }\r
153         }\r
154         */\r
155     }\r
156 }