1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package api.i18n; 25 26 import com.sun.star.i18n.XIndexEntrySupplier; 27 import com.sun.star.lang.Locale; 28 import com.sun.star.uno.UnoRuntime; 29 import com.sun.star.uno.XComponentContext; 30 import org.junit.After; 31 import org.junit.AfterClass; 32 import org.junit.Before; 33 import org.junit.BeforeClass; 34 import org.junit.Assert; 35 import org.junit.Test; 36 import org.openoffice.test.uno.UnoApp; 37 38 /** 39 * Testing <code>com.sun.star.i18n.XIndexEntrySupplier</code> 40 * interface methods: 41 * <ul> 42 * <li><code> getIndexCharacter() </code></li> 43 * <li><code> getIndexFollowPageWord() </code></li> 44 * </ul><p> 45 * Test is <b> NOT </b> multithread compliant. <p> 46 * @see com.sun.star.i18n.XIndexEntrySupplier 47 */ 48 public class XIndexEntrySupplierTest { 49 private static final UnoApp app = new UnoApp(); 50 51 private XComponentContext xContext = null; 52 public XIndexEntrySupplier oObj = null; 53 public String[] languages = new String[]{"de","en","es","fr","ja","ko","zh"}; 54 public String[] countries = new String[]{"DE","US","ES","FR","JP","KR","CN"}; 55 public String[] onePage = new String[]{"f.","p."," s."," sv","p.","",""}; 56 public String[] morePages = new String[]{"ff.","pp."," ss."," sv","pp.","",""}; 57 58 // setup and close connections 59 @BeforeClass setUpConnection()60 public static void setUpConnection() throws Exception 61 { 62 app.start(); 63 } 64 65 @AfterClass tearDownConnection()66 public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception 67 { 68 app.close(); 69 } 70 71 @Before before()72 public void before() throws Exception { 73 xContext = app.getComponentContext(); 74 oObj = UnoRuntime.queryInterface( 75 XIndexEntrySupplier.class, 76 xContext.getServiceManager().createInstanceWithContext("com.sun.star.i18n.IndexEntrySupplier", xContext) 77 ); 78 } 79 80 /** 81 * Test calls the method, then result is checked. <p> 82 * Has <b> OK </b> status if the method returns right index for several 83 * locales and word. 84 */ 85 @Test _getIndexCharacter()86 public void _getIndexCharacter() { 87 boolean res = true; 88 System.out.println("getIndexCharacter('chapter', getLocale(i), '')"); 89 for (int i=0; i<7; i++) { 90 System.out.print("getIndexCharacter('chapter', " + countries[i] + ") :"); 91 String get = oObj.getIndexCharacter("chapter", getLocale(i), ""); 92 System.out.println(get); 93 res &= get.equals("C"); 94 } 95 Assert.assertTrue("getIndexCharacter()", res); 96 } 97 98 /** 99 * Test calls the method with two different parameters: for one page and 100 * for several pages, after every call result is checked. <p> 101 * Has <b> OK </b> status if method returns right index for several locales. 102 */ 103 @Test _getIndexFollowPageWord()104 public void _getIndexFollowPageWord() { 105 boolean res = true; 106 107 for (int i=0; i<7; i++) { 108 String get = oObj.getIndexFollowPageWord(true, getLocale(i)); 109 if (! get.equals(morePages[i]) ) { 110 System.out.println("Language: " + languages[i]); 111 System.out.println("Getting: #" + get + "#"); 112 System.out.println("Expected: #" + morePages[i] + "#"); 113 } 114 res &= get.equals(morePages[i]); 115 get = oObj.getIndexFollowPageWord(false,getLocale(i)); 116 if (! get.equals(onePage[i]) ) { 117 System.out.println("Language: " + languages[i]); 118 System.out.println("Getting: #" + get + "#"); 119 System.out.println("Expected: #" + onePage[i] + "#"); 120 } 121 res &= get.equals(onePage[i]); 122 } 123 Assert.assertTrue("getIndexFollowPageWord()", res); 124 } 125 126 /** 127 * Method returns locale for a given language and country. 128 * @param k index of needed locale. 129 * @return Locale by the index from arrays defined above 130 */ getLocale(int k)131 public Locale getLocale(int k) { 132 return new Locale(languages[k], countries[k], ""); 133 } 134 135 136 } // end XIndexEntrySupplier 137