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