1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.i18n;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.i18n.KNumberFormatType;
33 import com.sun.star.i18n.KNumberFormatUsage;
34 import com.sun.star.i18n.NumberFormatCode;
35 import com.sun.star.i18n.NumberFormatIndex;
36 import com.sun.star.i18n.XNumberFormatCode;
37 import com.sun.star.lang.Locale;
38 
39 /**
40 * Testing <code>com.sun.star.i18n.XNumberFormatCode</code>
41 * interface methods:
42 * <ul>
43 *  <li><code> getDefault() </code></li>
44 *  <li><code> getFormatCode() </code></li>
45 *  <li><code> getAllFormatCode() </code></li>
46 *  <li><code> getAllFormatCodes() </code></li>
47 * </ul><p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.i18n.XNumberFormatCode
50 */
51 public class _XNumberFormatCode extends MultiMethodTest {
52     public XNumberFormatCode oObj = null;
53     public String[] languages = new String[]
54         {"de","en","es","fr","ko","ko","zh"};
55     public String[] countries = new String[]
56         {"DE","US","ES","FR","KR","KR","CN"};
57 
58     /**
59     * Test calls the method twice with two different format types as
60     * parameters for each locale. Result is checked after every call.<p>
61     * Has <b> OK </b> status if both times returned structure's field 'Code'
62     * does not equal to empty string.
63     */
64     public void _getDefault() {
65         boolean res = true;
66         NumberFormatCode nfc = null;
67 
68         for (int i=0;i<7;i++) {
69             nfc = oObj.getDefault(KNumberFormatType.SHORT,
70                 KNumberFormatUsage.DATE, getLocale(i));
71             String str = nfc.Code;
72             if (str.equals("")) {
73                 log.println("'NumberFormat.code.equals(\"\") = true' for"
74                     + " language: " + languages[i]);
75                 log.println("Usage: oObj.getDefault(KNumberFormatType.SHORT,"
76                     + " KNumberFormatUsage.DATE,new Locale(" + languages[i]
77                     + "," + countries[i] + ",\"\");");
78             }
79             res &= !str.equals("");
80 
81             nfc = oObj.getDefault(KNumberFormatType.LONG,
82                 KNumberFormatUsage.DATE,getLocale(i));
83             str = nfc.Code;
84             if (str.equals("")) {
85                 log.println("'NumberFormat.code.equals(\"\") = true' for "
86                     + "language: " + languages[i]);
87                 log.println("Usage: oObj.getDefault(KNumberFormatType.LONG,"
88                     + " KNumberFormatUsage.DATE,new Locale(" + languages[i]
89                     + "," + countries[i] + ",\"\");");
90             }
91             res &= ( ! str.equals("") );
92         }
93         tRes.tested("getDefault()", res);
94     }
95 
96     /**
97     * Test calls the method twice for each locale with two different arguments.
98     * After every call result is checked.<p>
99     * Has <b> OK </b> status if both times returned structure's field 'Code'
100     * does not equal to a empty string.
101     */
102     public void _getFormatCode() {
103         boolean res = true;
104         NumberFormatCode nfc = null;
105 
106         for (int i=0;i<7;i++) {
107             nfc = oObj.getFormatCode
108                 (NumberFormatIndex.DATE_SYSTEM_SHORT,getLocale(i));
109             res &= ( ! nfc.Code.equals("") );
110             nfc = oObj.getFormatCode
111                 (NumberFormatIndex.DATE_SYSTEM_LONG,getLocale(i));
112             res &= ( ! nfc.Code.equals("") );
113         }
114         tRes.tested("getFormatCode()", res);
115     }
116 
117     /**
118     * Test calls the method twice with two different arguments for each locale.
119     * After every call result is checked.<p>
120     * Has <b> OK </b> status if both times returned array's length does not
121     * equal to zero.
122     */
123     public void _getAllFormatCode() {
124         boolean res = true;
125         NumberFormatCode[] nfc = null;
126 
127         for (int i=0;i<7;i++) {
128             nfc = oObj.getAllFormatCode(KNumberFormatUsage.DATE, getLocale(i));
129             res &= ( nfc.length != 0 );
130             nfc = oObj.getAllFormatCode(KNumberFormatUsage.TIME, getLocale(i));
131             res &= ( nfc.length != 0 );
132         }
133         tRes.tested("getAllFormatCode()", res);
134     }
135 
136     /**
137     * Test calls the method for each locale. <p>
138     * Has <b> OK </b> status if returned array's length does not equal to zero.
139     */
140     public void _getAllFormatCodes() {
141         boolean res = true;
142         NumberFormatCode[] nfc = null;
143 
144         for (int i=0;i<7;i++) {
145             nfc = oObj.getAllFormatCodes(getLocale(i));
146             res &= ( nfc.length != 0 );
147         }
148         tRes.tested("getAllFormatCodes()", res);
149     }
150 
151     /**
152     * Method returns locale for a given language and country.
153     * @param localeIndex index of needed locale.
154     * @return Locale by the index from arrays defined above
155     */
156     public Locale getLocale(int k) {
157         return new Locale(languages[k], countries[k], "");
158     }
159 
160 
161 
162 } // end XNumberFormatCode
163 
164