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.XIndexEntrySupplier;
33 import com.sun.star.lang.Locale;
34 
35 /**
36 * Testing <code>com.sun.star.i18n.XIndexEntrySupplier</code>
37 * interface methods:
38 * <ul>
39 *  <li><code> getIndexCharacter() </code></li>
40 *  <li><code> getIndexFollowPageWord() </code></li>
41 * </ul><p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.i18n.XIndexEntrySupplier
44 */
45 public class _XIndexEntrySupplier extends MultiMethodTest {
46     public XIndexEntrySupplier oObj = null;
47     public String[] languages = new String[]{"de","en","es","fr","ja","ko","zh"};
48     public String[] countries = new String[]{"DE","US","ES","FR","JP","KR","CN"};
49     public String[] onePage = new String[]{"f.","p."," s."," sv","p.","",""};
50     public String[] morePages = new String[]{"ff.","pp."," ss."," sv","pp.","",""};
51 
52     /**
53     * Test calls the method, then result is checked. <p>
54     * Has <b> OK </b> status if the method returns right index for several
55     * locales and word.
56     */
57     public void _getIndexCharacter() {
58         boolean res = true;
59         log.println("getIndexCharacter('chapter', getLocale(i), '')");
60         for (int i=0; i<7; i++) {
61             log.print("getIndexCharacter('chapter', " + countries[i] + ") :");
62             String get = oObj.getIndexCharacter("chapter", getLocale(i), "");
63             log.println(get);
64             res &= get.equals("C");
65         }
66         tRes.tested("getIndexCharacter()", res);
67     }
68 
69     /**
70     * Test calls the method with two different parameters: for one page and
71     * for several pages, after every call result is checked. <p>
72     * Has <b> OK </b> status if method returns right index for several locales.
73     */
74     public void _getIndexFollowPageWord() {
75         boolean res = true;
76 
77         for (int i=0; i<7; i++) {
78             String get = oObj.getIndexFollowPageWord(true, getLocale(i));
79             if (! get.equals(morePages[i]) ) {
80                 log.println("Language: " + languages[i]);
81                 log.println("Getting: #" + get + "#");
82                 log.println("Expected: #" + morePages[i] + "#");
83             }
84             res &= get.equals(morePages[i]);
85             get = oObj.getIndexFollowPageWord(false,getLocale(i));
86             if (! get.equals(onePage[i]) ) {
87                 log.println("Language: " + languages[i]);
88                 log.println("Getting: #" + get + "#");
89                 log.println("Expected: #" + onePage[i] + "#");
90             }
91             res &= get.equals(onePage[i]);
92         }
93         tRes.tested("getIndexFollowPageWord()", res);
94     }
95 
96     /**
97     * Method returns locale for a given language and country.
98     * @param localeIndex index of needed locale.
99     * @return Locale by the index from arrays defined above
100     */
101     public Locale getLocale(int k) {
102         return new Locale(languages[k], countries[k], "");
103     }
104 
105 
106 } // end XIndexEntrySupplier
107 
108