/*************************************************************************
*
* $RCSfile: _XCollator.java,v $
*
* $Revision: 1.1 $
*
* last change:$Date: 2003-01-27 18:10:34 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package ifc.i18n;
import com.sun.star.i18n.CollatorOptions;
import com.sun.star.i18n.XCollator;
import com.sun.star.lang.Locale;
import java.text.Collator;
import lib.MultiMethodTest;
/**
* Testing com.sun.star.i18n.XCollator
* interface methods :
*
compareSubstring()
compareString()
loadDefaultCollator()
loadCollatorAlgorithm()
listCollatorAlgorithms()
loadCollatorAlgorithmWithEndUserOption()
listCollatorOptions()
* Test is NOT multithread compilant.
* @see com.sun.star.i18n.XCollator */ public class _XCollator extends MultiMethodTest { public XCollator oObj = null; private String[] alg = null ; private int[] opt = null ; Locale loc = new Locale("en", "EN", ""); /** * Just retrieves a list of algorithms.
* Has OK status if non-zero length array returned. */ public void _listCollatorAlgorithms() { alg = oObj.listCollatorAlgorithms(loc) ; log.println("Collator algorithms :"); if (alg != null) { for (int i = 0; i < alg.length; i++) { log.println(" '" + alg[i] + "'") ; } tRes.tested("listCollatorAlgorithms()", alg.length > 0) ; } else { tRes.tested("listCollatorAlgorithms()", false) ; } } /** * Just gets a list of options for some collator.
* Has OK status if not null value returned.
* The following method tests are to be completed successfully before : *
listCollatorAlgorithms
: to have some
* algorithm name. * Has OK status if compareString() returned correct values. */ public void _loadDefaultCollator() { oObj.loadDefaultCollator(loc, 0); boolean res = oObj.compareString("A", "a") != 0; oObj.loadDefaultCollator(loc, CollatorOptions.CollatorOptions_IGNORE_CASE); res &= oObj.compareString("a", "A") == 0; tRes.tested("loadDefaultCollator()", res) ; } /** * Calls the method with no options and with options(IGNORE_CASE), * compares strings.
* Has OK status if compareString() returned correct values. * The following method tests are to be completed successfully before : *
listCollatorAlgorithms
: to have some
* algorithm name. * Has OK status if compareString() returned correct values. * The following method tests are to be completed successfully before : *
listCollatorAlgorithms
: to have some
* algorithm name. * Has OK status if comparing of different strings * returns not 0 value, then comparing in the opposite * order returns value with opposite sign, and comparing * of two equal strings returns 0. The such comparing is performed * for one character strings. */ public void _compareSubstring() { boolean result = true ; char[] chars = new char[2] ; Collator col = null ; log.println(" #### Testing English locale ####") ; oObj.loadDefaultCollator(loc, 0) ; col = Collator.getInstance(new java.util.Locale("en", "EN")) ; for (char ch = 0x0020; ch < 0x007F; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareSubstring(chars, col) ; } log.println(" #### Testing Russian locale ####") ; oObj.loadDefaultCollator( new com.sun.star.lang.Locale("ru", "RU", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ru", "RU")) ; for (char ch = 0x0410; ch < 0x0450; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareSubstring(chars, col) ; } log.println(" #### Testing Japan locale ####") ; oObj.loadDefaultCollator( new com.sun.star.lang.Locale("ja", "JP", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ja", "JP")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareSubstring(chars, col) ; } log.println(" #### Testing China locale ####") ; oObj.loadDefaultCollator(new Locale("zh", "CN", ""), 0) ; col = Collator.getInstance(new java.util.Locale("zh", "CN")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareSubstring(chars, col) ; } log.println(" #### Testing Korean locale ####") ; oObj.loadDefaultCollator(new Locale("ko", "KR", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ko", "KR")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareSubstring(chars, col) ; } tRes.tested("compareSubstring()", result) ; } /** * Test is performed for locales : en, ru, ja, zh, ko. * Default collator is loaded for each locale. Then collation * is performed for different combination of symbols from range of * this locale.
* Has OK status if comparing of different strings * returns not 0 value, then comparing in the opposite * order returns value with opposite sign, and comparing * of two equal strings returns 0. The such comparing is performed * for one character strings. */ public void _compareString() { boolean result = true ; char[] chars = new char[2] ; Collator col = null ; log.println(" #### Testing English locale ####") ; oObj.loadDefaultCollator( new com.sun.star.lang.Locale("en", "EN", ""), 0) ; col = Collator.getInstance(new java.util.Locale("en", "EN")) ; for (char ch = 0x0020; ch < 0x007F; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareString(chars, col) ; } log.println(" #### Testing Russian locale ####") ; oObj.loadDefaultCollator( new com.sun.star.lang.Locale("ru", "RU", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ru", "RU")) ; for (char ch = 0x0410; ch < 0x0450; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareString(chars, col) ; } log.println(" #### Testing Japan locale ####") ; oObj.loadDefaultCollator( new com.sun.star.lang.Locale("ja", "JP", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ja", "JP")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareString(chars, col) ; } log.println(" #### Testing China locale ####") ; oObj.loadDefaultCollator(new Locale("zh", "CN", ""), 0) ; col = Collator.getInstance(new java.util.Locale("zh", "CN")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareString(chars, col) ; } log.println(" #### Testing Korean locale ####") ; oObj.loadDefaultCollator(new Locale("ko", "KR", ""), 0) ; col = Collator.getInstance(new java.util.Locale("ko", "KR")) ; for (char ch = 0x4E00; ch < 0x4EFD; ch ++) { chars[0] = ch ; chars[1] = (char) (ch + 1) ; result &= testCompareString(chars, col) ; } tRes.tested("compareString()", result) ; } /** * Testing compareString() method. At first method is testing single chars * comparing, then strings comparing. * @param locChar sequence of at list two characters of a given locale * to be used in comparing. * @param col Collator for a given locale * @return true if: *