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