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.beans.PropertyValue;
29 import com.sun.star.lang.Locale;
30 import com.sun.star.linguistic2.XSpellAlternatives;
31 import com.sun.star.linguistic2.XSpellChecker;
32 import lib.Status;
33 import lib.StatusException;
34 
35 /**
36 * Testing <code>com.sun.star.linguistic2.XSpellChecker</code>
37 * interface methods:
38 * <ul>
39 *   <li><code>isValid()</code></li>
40 *   <li><code>spell()</code></li>
41 * </ul><p>
42 * @see com.sun.star.linguistic2.XSpellChecker
43 */
44 public class _XSpellChecker extends MultiMethodTest {
45 
46     public XSpellChecker oObj = null;
47     XSpellChecker alternative = null;
48 
before()49     public void before() {
50         alternative = (XSpellChecker) tEnv.getObjRelation("AlternativeChecker");
51         if  (alternative == null) throw new StatusException(Status.failed
52             ("Relation AlternativeChecker not found")) ;
53     }
54 
55     /**
56     * Test calls the method for a correctly spelled word and
57     * for a uncorrectly spelled word and checks returned values. <p>
58     * Has <b> OK </b> status if returned value is equal to true in first case,
59     * if returned value is equal to false in second case and no exceptions
60     * were thrown. <p>
61     */
_isValid()62     public void _isValid() {
63         boolean res = true;
64         try {
65             log.println("Checking 'original' Spellchecker");
66             PropertyValue[] empty = new PropertyValue[0] ;
67             res &= oObj.isValid("Sun", new Locale("en","US",""), empty);
68             res &= !oObj.isValid("Summersun", new Locale("en","US","") ,empty);
69             log.println("Result so far is - "+ (res ? "OK" : "failed"));
70             log.println("Checking alternative Spellchecker");
71             res &= alternative.isValid("Sun", new Locale("en","US",""), empty);
72             res &= !alternative.isValid("Summersun", new Locale("en","US","") ,empty);
73         } catch (com.sun.star.lang.IllegalArgumentException ex) {
74             log.println("Exception while checking 'isValid'");
75             res = false;
76             ex.printStackTrace(log);
77         }
78         tRes.tested("isValid()",res);
79     }
80 
81     /**
82     * Test calls the method for a uncorrectly spelled word
83     * and checks returned values. <p>
84     * Has <b> OK </b> status if at least one spell alternative exists
85     * and no exceptions were thrown. <p>
86     */
_spell()87     public void _spell() {
88         boolean res = true;
89         try {
90             log.println("Checking 'original' Spellchecker");
91             PropertyValue[] empty = new PropertyValue[0] ;
92             XSpellAlternatives alt = oObj.spell(
93                             "Summersun",new Locale("en","US",""),empty);
94             String alternatives = alt.getAlternatives()[0];
95             res = (alternatives != null);
96             log.println("Result so far is - "+ (res ? "OK" : "failed"));
97             log.println("Checking alternative Spellchecker");
98             alt =alternative.spell(
99                             "Summersun",new Locale("en","US",""),empty);
100             alternatives = alt.getAlternatives()[0];
101             res &= (alternatives != null);
102         } catch (com.sun.star.lang.IllegalArgumentException ex) {
103             log.println("Exception while checking 'spell'");
104             res = false;
105             ex.printStackTrace(log);
106         }
107         tRes.tested("spell()",res);
108     }
109 
110 }  // finish class MTest
111 
112 
113