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;
45 public void before() {
46 alternative
= (XSpellChecker
) tEnv
.getObjRelation("AlternativeChecker");
47 if (alternative
== null) throw new StatusException(Status
.failed
48 ("Relation AlternativeChecker not found")) ;
52 * Test calls the method for a correctly spelled word and
53 * for a uncorrectly spelled word and checks returned values. <p>
54 * Has <b> OK </b> status if returned value is equal to true in first case,
55 * if returned value is equal to false in second case and no exceptions
58 public void _isValid() {
61 log
.println("Checking 'original' Spellchecker");
62 PropertyValue
[] empty
= new PropertyValue
[0] ;
63 res
&= oObj
.isValid("Sun", new Locale("en","US",""), empty
);
64 res
&= !oObj
.isValid("Summersun", new Locale("en","US","") ,empty
);
65 log
.println("Result so far is - "+ (res ?
"OK" : "failed"));
66 log
.println("Checking alternative Spellchecker");
67 res
&= alternative
.isValid("Sun", new Locale("en","US",""), empty
);
68 res
&= !alternative
.isValid("Summersun", new Locale("en","US","") ,empty
);
69 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
70 log
.println("Exception while checking 'isValid'");
72 ex
.printStackTrace(log
);
74 tRes
.tested("isValid()",res
);
78 * Test calls the method for a uncorrectly spelled word
79 * and checks returned values. <p>
80 * Has <b> OK </b> status if at least one spell alternative exists
81 * and no exceptions were thrown. <p>
83 public void _spell() {
86 log
.println("Checking 'original' Spellchecker");
87 PropertyValue
[] empty
= new PropertyValue
[0] ;
88 XSpellAlternatives alt
= oObj
.spell(
89 "Summersun",new Locale("en","US",""),empty
);
90 String alternatives
= alt
.getAlternatives()[0];
91 res
= (alternatives
!= null);
92 log
.println("Result so far is - "+ (res ?
"OK" : "failed"));
93 log
.println("Checking alternative Spellchecker");
94 alt
=alternative
.spell(
95 "Summersun",new Locale("en","US",""),empty
);
96 alternatives
= alt
.getAlternatives()[0];
97 res
&= (alternatives
!= null);
98 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
99 log
.println("Exception while checking 'spell'");
101 ex
.printStackTrace(log
);
103 tRes
.tested("spell()",res
);
106 } // finish class MTest