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