1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package ifc.awt;
20 
21 import lib.MultiPropertyTest;
22 import util.utils;
23 
24 /**
25 * Testing <code>com.sun.star.awt.UnoControlFormattedFieldModel</code>
26 * service properties :
27 * <ul>
28 *  <li><code> Align</code></li>
29 *  <li><code> BackgroundColor</code></li>
30 *  <li><code> Border</code></li>
31 *  <li><code> DefaultControl</code></li>
32 *  <li><code> EffectiveDefault</code></li>
33 *  <li><code> EffectiveMax</code></li>
34 *  <li><code> EffectiveMin</code></li>
35 *  <li><code> EffectiveValue</code></li>
36 *  <li><code> Enabled</code></li>
37 *  <li><code> FontDescriptor</code></li>
38 *  <li><code> FormatKey</code></li>
39 *  <li><code> FormatsSupplier</code></li>
40 *  <li><code> MaxTextLen</code></li>
41 *  <li><code> Printable</code></li>
42 *  <li><code> ReadOnly</code></li>
43 *  <li><code> Spin</code></li>
44 *  <li><code> StrictFormat</code></li>
45 *  <li><code> Tabstop</code></li>
46 *  <li><code> Text</code></li>
47 *  <li><code> TextColor</code></li>
48 *  <li><code> HelpText</code></li>
49 *  <li><code> HelpURL</code></li>
50 * </ul> <p>
51 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
52 * @see com.sun.star.awt.UnoControlFormattedFieldModel
53 */
54 public class _UnoControlFormattedFieldModel extends MultiPropertyTest {
55 
56     /**
57     * Redefined method must return a valid service name, that differs from
58     * name exists.
59     *
60     */
61     protected PropertyTester ControlTester = new PropertyTester() {
62         @Override
63         protected Object getNewValue(String propName, Object oldValue) {
64             if (util.ValueComparer.equalValue(oldValue,
65                         "com.sun.star.form.control.FormattedField"))
66                 return "com.sun.star.awt.UnoControlFormattedField";
67             else
68                 return "com.sun.star.form.control.FormattedField";
69         }
70     };
71 
72     /**
73     * This property must contain a valid service name.
74     */
_DefaultControl()75     public void _DefaultControl() {
76         log.println("Testing with custom Property tester") ;
77         testProperty("DefaultControl", ControlTester) ;
78     }
79 
80     /**
81     * This property can be VOID, and in case if it is so new
82     * value must defined.
83     */
_BorderColor()84     public void _BorderColor() {
85         testProperty("BorderColor", new PropertyTester() {
86             @Override
87             protected Object getNewValue(String p, Object old) {
88                 return utils.isVoid(old) ? Integer.valueOf(1234) : null ;
89             }
90         }) ;
91     }
92 
93     /**
94     * This property can be void, so if old value is <code> null </code>
95     * new value must be specified.
96     */
_TextColor()97     public void _TextColor() {
98         testProperty("TextColor", new PropertyTester() {
99             @Override
100             protected Object getNewValue(String p, Object v) {
101                 return utils.isVoid(v) ? Integer.valueOf(123) :
102                     super.getNewValue(p,v) ;
103             }
104         }) ;
105     }
106 
107     /**
108     * This property can be void, so if old value is <code> null </code>
109     * new value must be specified.
110     */
_TextLineColor()111     public void _TextLineColor() {
112         testProperty("TextLineColor", new PropertyTester() {
113             @Override
114             protected Object getNewValue(String p, Object v) {
115                 return utils.isVoid(v) ? Integer.valueOf(123) :
116                     super.getNewValue(p,v) ;
117             }
118         }) ;
119     }
120 
121     /**
122     * This property can be void, so if old value is <code> null </code>
123     * new value must be specified.
124     */
_BackgroundColor()125     public void _BackgroundColor() {
126         testProperty("BackgroundColor", new PropertyTester() {
127             @Override
128             protected Object getNewValue(String p, Object v) {
129                 return utils.isVoid(v) ? Integer.valueOf(123) :
130                     super.getNewValue(p,v) ;
131             }
132         }) ;
133     }
134 
135     /**
136     * This property can be void, so if old value is <code> null </code>
137     * new value must be specified.
138     */
_EffectiveDefault()139     public void _EffectiveDefault() {
140         testProperty("EffectiveDefault", new Double(5.8),new Double(2.3)) ;
141     }
142 
143     /**
144     * This property can be void, so if old value is <code> null </code>
145     * new value must be specified.
146     */
_EffectiveValue()147     public void _EffectiveValue() {
148         testProperty("EffectiveValue", new Double(5.8),new Double(2.3)) ;
149     }
150 
151     /**
152     * This property can be void, so if old value is <code> null </code>
153     * new value must be specified.
154     */
_EffectiveMax()155     public void _EffectiveMax() {
156         testProperty("EffectiveMax", new PropertyTester() {
157             @Override
158             protected Object getNewValue(String p, Object v) {
159                 return utils.isVoid(v) ? new Double(123.8) :
160                     super.getNewValue(p,v) ;
161             }
162         }) ;
163     }
164 
165     /**
166     * This property can be void, so if old value is <code> null </code>
167     * new value must be specified.
168     */
_FormatsSupplier()169     public void _FormatsSupplier() {
170         testProperty("FormatsSupplier", new PropertyTester() {
171             @Override
172             protected Object getNewValue(String p, Object v) {
173                 Object newValue = null;
174                 try {
175                     newValue = tParam.getMSF().createInstance(
176                                     "com.sun.star.util.NumberFormatsSupplier");
177                 } catch (com.sun.star.uno.Exception e) {
178                     System.out.println("caught exception: " + e);
179                 }
180                 return newValue;
181             }
182         }) ;
183     }
184 
185     /**
186     * This property can be void, so if old value is <code> null </code>
187     * new value must be specified.
188     */
_EffectiveMin()189     public void _EffectiveMin() {
190         testProperty("EffectiveMin", new PropertyTester() {
191             @Override
192             protected Object getNewValue(String p, Object v) {
193                 return utils.isVoid(v) ? new Double(0.1) :
194                     super.getNewValue(p,v) ;
195             }
196         }) ;
197     }
198 
199     /**
200     * This property can be void, so if old value is <code> null </code>
201     * new value must be specified.
202     */
_FormatKey()203     public void _FormatKey() {
204         testProperty("FormatKey", new PropertyTester() {
205             @Override
206             protected Object getNewValue(String p, Object v) {
207                 return utils.isVoid(v) ? Integer.valueOf(0) :
208                     super.getNewValue(p,v) ;
209             }
210         }) ;
211     }
212 
213     /**
214     * This property can be void, so if old value is <code> null </code>
215     * new value must be specified.
216     */
_StrictFromat()217     public void _StrictFromat() {
218         testProperty("StrictFromat", new PropertyTester() {
219             @Override
220             protected Object getNewValue(String p, Object v) {
221                 return utils.isVoid(v) ? Boolean.TRUE :
222                     super.getNewValue(p,v) ;
223             }
224         }) ;
225     }
226 
227     /**
228     * This property can be void, so if old value is <code> null </code>
229     * new value must be specified.
230     */
_Tabstop()231     public void _Tabstop() {
232         testProperty("Tabstop", new PropertyTester() {
233             @Override
234             protected Object getNewValue(String p, Object v) {
235                 return utils.isVoid(v) ? Boolean.TRUE :
236                     null ;
237             }
238         }) ;
239     }
240 
241     /**
242     * This property can be void, so if old value is <code> null </code>
243     * new value must be specified.
244     */
_Text()245     public void _Text() {
246         testProperty("Text", new PropertyTester() {
247             @Override
248             protected Object getNewValue(String p, Object v) {
249                 return utils.isVoid(v) ? "UnoControlFormattedFieldModel" :
250                     super.getNewValue(p,v) ;
251             }
252         }) ;
253     }
254 }
255