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