1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc
.linguistic2
;
30 import lib
.MultiMethodTest
;
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
;
37 import lib
.StatusException
;
40 * Testing <code>com.sun.star.linguistic2.XSpellChecker</code>
43 * <li><code>isValid()</code></li>
44 * <li><code>spell()</code></li>
46 * @see com.sun.star.linguistic2.XSpellChecker
48 public class _XSpellChecker
extends MultiMethodTest
{
50 public XSpellChecker oObj
= null;
51 XSpellChecker alternative
= null;
53 public void before() {
54 alternative
= (XSpellChecker
) tEnv
.getObjRelation("AlternativeChecker");
55 if (alternative
== null) throw new StatusException(Status
.failed
56 ("Relation AlternativeChecker not found")) ;
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
66 public void _isValid() {
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'");
80 ex
.printStackTrace(log
);
82 tRes
.tested("isValid()",res
);
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>
91 public void _spell() {
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'");
109 ex
.printStackTrace(log
);
111 tRes
.tested("spell()",res
);
114 } // finish class MTest