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 package ifc.sheet;
24 
25 import lib.MultiPropertyTest;
26 
27 import com.sun.star.i18n.ForbiddenCharacters;
28 import com.sun.star.i18n.XForbiddenCharacters;
29 import com.sun.star.lang.Locale;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.util.Date;
32 
33 
34 /**
35 * Testing <code>com.sun.star.sheet.SpreadsheetDocumentSettings</code>
36 * service properties :
37 * <ul>
38 *  <li><code> IsIterationEnabled</code></li>
39 *  <li><code> IterationCount</code></li>
40 *  <li><code> IterationEpsilon</code></li>
41 *  <li><code> StandardDecimals</code></li>
42 *  <li><code> NullDate</code></li>
43 *  <li><code> DefaultTabStop</code></li>
44 *  <li><code> IgnoreCase</code></li>
45 *  <li><code> CalcAsShown</code></li>
46 *  <li><code> MatchWholeCell</code></li>
47 *  <li><code> SpellOnline</code></li>
48 *  <li><code> LookUpLabels</code></li>
49 *  <li><code> RegularExpressions</code></li>
50 *  <li><code> ForbiddenCharacters</code></li>
51 *  <li><code> HasDrawPages</code></li>
52 * </ul> <p>
53 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
54 * @see com.sun.star.sheet.SpreadsheetDocumentSettings
55 */
56 public class _SpreadsheetDocumentSettings extends MultiPropertyTest {
57     /**
58      *This class is destined to custom test of property <code>NullDate</code>.
59      */
60     protected PropertyTester DateTester = new PropertyTester() {
61         protected Object getNewValue(String propName, Object oldValue) {
62             Date date = (Date) oldValue;
63             Date newDate = new Date((short) (date.Day - 1), date.Month,
64                                     date.Year);
65 
66             return newDate;
67         }
68     };
69 
70     /**
71      *This class is destined to custom test of property <code>ForbiddenCharacters</code>.
72      */
73     protected PropertyTester ChrTester = new PropertyTester() {
74         protected Object getNewValue(String propName, Object oldValue) {
75             return new ForbiddenChrTest();
76         }
77 
78         protected boolean compare(Object obj1, Object obj2) {
79             Locale loc = new Locale("ru", "RU", "");
80             XForbiddenCharacters fc1 = (XForbiddenCharacters) UnoRuntime.queryInterface(
81                                                XForbiddenCharacters.class,
82                                                obj1);
83             XForbiddenCharacters fc2 = (XForbiddenCharacters) UnoRuntime.queryInterface(
84                                                XForbiddenCharacters.class,
85                                                obj2);
86             boolean has1 = fc1.hasForbiddenCharacters(loc);
87             boolean has2 = fc2.hasForbiddenCharacters(loc);
88 
89             return has1 == has2;
90         }
91     };
92 
93     /**
94      * Test property <code>NullDate</code> using custom <code>PropertyTest</code>.
95      */
_NullDate()96     public void _NullDate() {
97         testProperty("NullDate", DateTester);
98     }
99 
100     /**
101      * Test property <code>ForbiddenCharacters</code> using custom <code>PropertyTest</code>.
102      */
_ForbiddenCharacters()103     public void _ForbiddenCharacters() {
104         testProperty("ForbiddenCharacters", ChrTester);
105     }
106 
107     /**
108      * Class implements interface <code>XForbiddenCharacters</code>.
109      * It's destined to custom test of property <code>ForbiddenCharacters</code>.
110      * Feature of the class that it supports forbidden characters
111      * for russian locale.
112      * @see com.sun.star.i18n.XForbiddenCharacters
113      */
114     protected class ForbiddenChrTest implements XForbiddenCharacters {
115         protected Locale locale = new Locale("ru", "RU", "");
116         protected ForbiddenCharacters chrs = new ForbiddenCharacters("q", "w");
117 
getForbiddenCharacters(Locale rLocale)118         public ForbiddenCharacters getForbiddenCharacters(Locale rLocale)
119             throws com.sun.star.container.NoSuchElementException {
120             if (rLocale.Country.equals(locale.Country) &&
121                     rLocale.Language.equals(locale.Language) &&
122                     rLocale.Variant.equals(locale.Variant)) {
123                 return chrs;
124             }
125 
126             throw new com.sun.star.container.NoSuchElementException();
127         }
128 
setForbiddenCharacters(Locale rLocale, ForbiddenCharacters rForbiddenCharacters)129         public void setForbiddenCharacters(Locale rLocale,
130                                            ForbiddenCharacters rForbiddenCharacters) {
131         }
132 
removeForbiddenCharacters(Locale rLocale)133         public void removeForbiddenCharacters(Locale rLocale) {
134         }
135 
hasForbiddenCharacters(Locale rLocale)136         public boolean hasForbiddenCharacters(Locale rLocale) {
137             if (rLocale.Country.equals(locale.Country) &&
138                     rLocale.Language.equals(locale.Language) &&
139                     rLocale.Variant.equals(locale.Variant)) {
140                 return true;
141             }
142 
143             return false;
144         }
145     }
146 }