2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc
.linguistic2
;
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.beans
.PropertyValue
;
24 import com
.sun
.star
.lang
.Locale
;
25 import com
.sun
.star
.linguistic2
.XSpellAlternatives
;
26 import com
.sun
.star
.linguistic2
.XSpellChecker
;
28 import lib
.StatusException
;
31 * Testing <code>com.sun.star.linguistic2.XSpellChecker</code>
34 * <li><code>isValid()</code></li>
35 * <li><code>spell()</code></li>
37 * @see com.sun.star.linguistic2.XSpellChecker
39 public class _XSpellChecker
extends MultiMethodTest
{
41 public XSpellChecker oObj
= null;
42 XSpellChecker alternative
= null;
44 public void before() {
45 alternative
= (XSpellChecker
) tEnv
.getObjRelation("AlternativeChecker");
46 if (alternative
== null) throw new StatusException(Status
.failed
47 ("Relation AlternativeChecker not found")) ;
51 * Test calls the method for a correctly spelled word and
52 * for a uncorrectly spelled word and checks returned values. <p>
53 * Has <b> OK </b> status if returned value is equal to true in first case,
54 * if returned value is equal to false in second case and no exceptions
57 public void _isValid() {
60 log
.println("Checking 'original' Spellchecker");
61 PropertyValue
[] empty
= new PropertyValue
[0] ;
62 res
&= oObj
.isValid("Sun", new Locale("en","US",""), empty
);
63 res
&= !oObj
.isValid("Summersun", new Locale("en","US","") ,empty
);
64 log
.println("Result so far is - "+ (res ?
"OK" : "failed"));
65 log
.println("Checking alternative Spellchecker");
66 res
&= alternative
.isValid("Sun", new Locale("en","US",""), empty
);
67 res
&= !alternative
.isValid("Summersun", new Locale("en","US","") ,empty
);
68 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
69 log
.println("Exception while checking 'isValid'");
71 ex
.printStackTrace(log
);
73 tRes
.tested("isValid()",res
);
77 * Test calls the method for a uncorrectly spelled word
78 * and checks returned values. <p>
79 * Has <b> OK </b> status if at least one spell alternative exists
80 * and no exceptions were thrown. <p>
82 public void _spell() {
85 log
.println("Checking 'original' Spellchecker");
86 PropertyValue
[] empty
= new PropertyValue
[0] ;
87 XSpellAlternatives alt
= oObj
.spell(
88 "Summersun",new Locale("en","US",""),empty
);
89 String alternatives
= alt
.getAlternatives()[0];
90 res
= (alternatives
!= null);
91 log
.println("Result so far is - "+ (res ?
"OK" : "failed"));
92 log
.println("Checking alternative Spellchecker");
93 alt
=alternative
.spell(
94 "Summersun",new Locale("en","US",""),empty
);
95 alternatives
= alt
.getAlternatives()[0];
96 res
&= (alternatives
!= null);
97 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
98 log
.println("Exception while checking 'spell'");
100 ex
.printStackTrace(log
);
102 tRes
.tested("spell()",res
);
105 } // finish class MTest