1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.i18n;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.i18n.KNumberFormatType;
29 import com.sun.star.i18n.KNumberFormatUsage;
30 import com.sun.star.i18n.NumberFormatCode;
31 import com.sun.star.i18n.NumberFormatIndex;
32 import com.sun.star.i18n.XNumberFormatCode;
33 import com.sun.star.lang.Locale;
34 
35 /**
36 * Testing <code>com.sun.star.i18n.XNumberFormatCode</code>
37 * interface methods:
38 * <ul>
39 *  <li><code> getDefault() </code></li>
40 *  <li><code> getFormatCode() </code></li>
41 *  <li><code> getAllFormatCode() </code></li>
42 *  <li><code> getAllFormatCodes() </code></li>
43 * </ul><p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.i18n.XNumberFormatCode
46 */
47 public class _XNumberFormatCode extends MultiMethodTest {
48     public XNumberFormatCode oObj = null;
49     public String[] languages = new String[]
50         {"de","en","es","fr","ko","ko","zh"};
51     public String[] countries = new String[]
52         {"DE","US","ES","FR","KR","KR","CN"};
53 
54     /**
55     * Test calls the method twice with two different format types as
56     * parameters for each locale. Result is checked after every call.<p>
57     * Has <b> OK </b> status if both times returned structure's field 'Code'
58     * does not equal to empty string.
59     */
_getDefault()60     public void _getDefault() {
61         boolean res = true;
62         NumberFormatCode nfc = null;
63 
64         for (int i=0;i<7;i++) {
65             nfc = oObj.getDefault(KNumberFormatType.SHORT,
66                 KNumberFormatUsage.DATE, getLocale(i));
67             String str = nfc.Code;
68             if (str.equals("")) {
69                 log.println("'NumberFormat.code.equals(\"\") = true' for"
70                     + " language: " + languages[i]);
71                 log.println("Usage: oObj.getDefault(KNumberFormatType.SHORT,"
72                     + " KNumberFormatUsage.DATE,new Locale(" + languages[i]
73                     + "," + countries[i] + ",\"\");");
74             }
75             res &= !str.equals("");
76 
77             nfc = oObj.getDefault(KNumberFormatType.LONG,
78                 KNumberFormatUsage.DATE,getLocale(i));
79             str = nfc.Code;
80             if (str.equals("")) {
81                 log.println("'NumberFormat.code.equals(\"\") = true' for "
82                     + "language: " + languages[i]);
83                 log.println("Usage: oObj.getDefault(KNumberFormatType.LONG,"
84                     + " KNumberFormatUsage.DATE,new Locale(" + languages[i]
85                     + "," + countries[i] + ",\"\");");
86             }
87             res &= ( ! str.equals("") );
88         }
89         tRes.tested("getDefault()", res);
90     }
91 
92     /**
93     * Test calls the method twice for each locale with two different arguments.
94     * After every call result is checked.<p>
95     * Has <b> OK </b> status if both times returned structure's field 'Code'
96     * does not equal to a empty string.
97     */
_getFormatCode()98     public void _getFormatCode() {
99         boolean res = true;
100         NumberFormatCode nfc = null;
101 
102         for (int i=0;i<7;i++) {
103             nfc = oObj.getFormatCode
104                 (NumberFormatIndex.DATE_SYSTEM_SHORT,getLocale(i));
105             res &= ( ! nfc.Code.equals("") );
106             nfc = oObj.getFormatCode
107                 (NumberFormatIndex.DATE_SYSTEM_LONG,getLocale(i));
108             res &= ( ! nfc.Code.equals("") );
109         }
110         tRes.tested("getFormatCode()", res);
111     }
112 
113     /**
114     * Test calls the method twice with two different arguments for each locale.
115     * After every call result is checked.<p>
116     * Has <b> OK </b> status if both times returned array's length does not
117     * equal to zero.
118     */
_getAllFormatCode()119     public void _getAllFormatCode() {
120         boolean res = true;
121         NumberFormatCode[] nfc = null;
122 
123         for (int i=0;i<7;i++) {
124             nfc = oObj.getAllFormatCode(KNumberFormatUsage.DATE, getLocale(i));
125             res &= ( nfc.length != 0 );
126             nfc = oObj.getAllFormatCode(KNumberFormatUsage.TIME, getLocale(i));
127             res &= ( nfc.length != 0 );
128         }
129         tRes.tested("getAllFormatCode()", res);
130     }
131 
132     /**
133     * Test calls the method for each locale. <p>
134     * Has <b> OK </b> status if returned array's length does not equal to zero.
135     */
_getAllFormatCodes()136     public void _getAllFormatCodes() {
137         boolean res = true;
138         NumberFormatCode[] nfc = null;
139 
140         for (int i=0;i<7;i++) {
141             nfc = oObj.getAllFormatCodes(getLocale(i));
142             res &= ( nfc.length != 0 );
143         }
144         tRes.tested("getAllFormatCodes()", res);
145     }
146 
147     /**
148     * Method returns locale for a given language and country.
149     * @param k index of needed locale.
150     * @return Locale by the index from arrays defined above
151     */
getLocale(int k)152     public Locale getLocale(int k) {
153         return new Locale(languages[k], countries[k], "");
154     }
155 
156 
157 
158 } // end XNumberFormatCode
159 
160