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.linguistic2; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.lang.EventObject; 33 import com.sun.star.lang.Locale; 34 import com.sun.star.linguistic2.LinguServiceEvent; 35 import com.sun.star.linguistic2.XHyphenator; 36 import com.sun.star.linguistic2.XLinguServiceEventListener; 37 import com.sun.star.linguistic2.XLinguServiceManager; 38 import com.sun.star.linguistic2.XSpellChecker; 39 import com.sun.star.linguistic2.XThesaurus; 40 41 /** 42 *Testing <code>com.sun.star.linguistic2.XLinguServiceManager</code> 43 * interface methods: 44 * <ul> 45 * <li><code>getSpellChecker()</code></li> 46 * <li><code>getHyphenator()</code></li> 47 * <li><code>getThesaurus()</code></li> 48 * <li><code>addLinguServiceManagerListener()</code></li> 49 * <li><code>removeLinguServiceManagerListener()</code></li> 50 * <li><code>getAvailableServices()</code></li> 51 * <li><code>setConfiguredServices()</code></li> 52 * <li><code>getConfiguredServices()</code></li> 53 * </ul> <p> 54 *@see com.sun.star.linguistic2.XLinguServiceManager 55 */ 56 public class _XLinguServiceManager extends MultiMethodTest { 57 58 public XLinguServiceManager oObj = null; 59 boolean listenerCalled = false; 60 61 /** 62 * Class implements interface <code>XLinguServiceEventListener</code> 63 * for test method <code>addLinguServiceManagerListener</code>. 64 * @see com.sun.star.linguistic2.XLinguServiceEventListener 65 */ 66 public class MyLinguServiceEventListener implements 67 XLinguServiceEventListener { 68 public void disposing ( EventObject oEvent ) { 69 log.println("Listener has been disposed"); 70 } 71 public void processLinguServiceEvent(LinguServiceEvent aServiceEvent) { 72 listenerCalled = true; 73 log.println("Listener called"); 74 } 75 }; 76 77 XLinguServiceEventListener listener = new MyLinguServiceEventListener(); 78 79 /** 80 * Test calls the method and checks returned value. <p> 81 * Has <b> OK </b> status if returned value isn't null. <p> 82 */ 83 public void _getSpellChecker() { 84 XSpellChecker SC = oObj.getSpellChecker(); 85 tRes.tested("getSpellChecker()", SC != null); 86 } 87 88 /** 89 * Test calls the method and checks returned value. <p> 90 * Has <b> OK </b> status if returned value isn't null. <p> 91 */ 92 public void _getHyphenator() { 93 XHyphenator HN = oObj.getHyphenator(); 94 tRes.tested("getHyphenator()", HN != null); 95 } 96 97 /** 98 * Test calls the method and checks returned value. <p> 99 * Has <b> OK </b> status if returned value isn't null. <p> 100 */ 101 public void _getThesaurus() { 102 XThesaurus TS = oObj.getThesaurus(); 103 tRes.tested("getThesaurus()", TS != null); 104 } 105 106 /** 107 * Test calls the method and checks returned value. <p> 108 * Has <b> OK </b> status if returned value is equal to true. <p> 109 */ 110 public void _addLinguServiceManagerListener() { 111 boolean res = oObj.addLinguServiceManagerListener(listener); 112 tRes.tested("addLinguServiceManagerListener()", res); 113 } 114 115 /** 116 * Test calls the method and checks returned value. <p> 117 * Has <b> OK </b> status if returned value is equal to true. <p> 118 */ 119 public void _removeLinguServiceManagerListener() { 120 boolean res = oObj.removeLinguServiceManagerListener(listener); 121 tRes.tested("removeLinguServiceManagerListener()",res); 122 } 123 124 /** 125 * Test calls the method and checks returned value. <p> 126 * Has <b> OK </b> status if length of returned array is 127 * greater than zero.<p> 128 */ 129 public void _getAvailableServices() { 130 String[] services = oObj.getAvailableServices( 131 "com.sun.star.linguistic2.Hyphenator", 132 new Locale("en", "US", "") ); 133 tRes.tested("getAvailableServices()", services.length > 0); 134 } 135 136 /** 137 * Test calls the method and checks returned value. <p> 138 * Has <b> OK </b> status if length of returned array is 139 * greater than zero.<p> 140 */ 141 public void _getConfiguredServices() { 142 String[] services = oObj.getConfiguredServices( 143 "com.sun.star.linguistic2.Hyphenator", 144 new Locale("en", "US", "") ); 145 tRes.tested("getConfiguredServices()", services.length > 0); 146 } 147 148 /** 149 * Test sets empty list of service, checks value returned 150 * by method <code>getConfiguredServices()</code> and all services 151 * restored finally. <p> 152 * Has <b> OK </b> status if length of obtained service list equal to zero. 153 * <p>The following method tests are to be completed successfully before : 154 * <ul> 155 * <li> <code> getConfiguredServices() </code></li> 156 * </ul> 157 */ 158 public void _setConfiguredServices() { 159 requiredMethod("getConfiguredServices()"); 160 161 String[] services = oObj.getConfiguredServices( 162 "com.sun.star.linguistic2.Hyphenator",new Locale("en","US","")); 163 164 String[] empty = new String[0]; 165 oObj.setConfiguredServices( 166 "com.sun.star.linguistic2.Hyphenator", 167 new Locale("en", "US", ""), 168 empty ); 169 170 String[] get = oObj.getConfiguredServices( 171 "com.sun.star.linguistic2.Hyphenator", new Locale("en","US","")); 172 173 boolean res = (get.length == 0); 174 175 oObj.setConfiguredServices( 176 "com.sun.star.linguistic2.Hyphenator", 177 new Locale("en", "US", ""), 178 services ); 179 180 tRes.tested("setConfiguredServices()", res); 181 } 182 183 } // finish class _XLinguServiceManager 184 185 186