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 
24 package ifc.awt;
25 
26 import lib.MultiPropertyTest;
27 import util.utils;
28 
29 /*
30 * Testing <code>com.sun.star.awt.UnoControlDateFieldModel</code>
31 * service properties :
32 * <ul>
33 *  <li><code> BackgroundColor</code></li>
34 *  <li><code> Border</code></li>
35 *  <li><code> Date</code></li>
36 *  <li><code> DateMax</code></li>
37 *  <li><code> DateMin</code></li>
38 *  <li><code> DefaultControl</code></li>
39 *  <li><code> Enabled</code></li>
40 *  <li><code> DateFormat</code></li>
41 *  <li><code> FontDescriptor</code></li>
42 *  <li><code> Printable</code></li>
43 *  <li><code> ReadOnly</code></li>
44 *  <li><code> Spin</code></li>
45 *  <li><code> StrictFormat</code></li>
46 *  <li><code> Tabstop</code></li>
47 *  <li><code> TextColor</code></li>
48 * </ul>
49 * Almost all properties testing is automated by
50 * <code>lib.MultiPropertyTest</code>.
51 * @see com.sun.star.awt.UnoControlDateFieldModel
52 */
53 public class _UnoControlDateFieldModel extends MultiPropertyTest {
54 
55     /**
56     * This property can be void, so if old value is <code> null </code>
57     * new value must be specified.
58     */
_BackgroundColor()59     public void _BackgroundColor() {
60         testProperty("BackgroundColor", new PropertyTester() {
61             protected Object getNewValue(String prop, Object old) {
62                 return utils.isVoid(old) ? new Integer(6543) : null ;
63             }
64         }) ;
65     }
66 
67     /**
68     * This property can be VOID, and in case if it is so new
69     * value must defined.
70     */
_BorderColor()71     public void _BorderColor() {
72         testProperty("BorderColor", new PropertyTester() {
73             protected Object getNewValue(String p, Object old) {
74                 return utils.isVoid(old) ? new Integer(1234) : null ;
75             }
76         }) ;
77     }
78 
79 
80     /**
81     * This property can be void, so if old value is <code> null </code>
82     * new value must be specified.
83     */
_Date()84     public void _Date() {
85         testProperty("Date", new PropertyTester() {
86             protected Object getNewValue(String prop, Object old) {
87                 return utils.isVoid(old) ? new Integer(6543) :
88                     super.getNewValue(prop, old) ;
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     */
_Tabstop()97     public void _Tabstop() {
98         testProperty("Tabstop", new PropertyTester() {
99             protected Object getNewValue(String prop, Object old) {
100                 return utils.isVoid(old) ? new Boolean(true) : null ;
101             }
102         }) ;
103     }
104 
105     /**
106     * This property can be void, so if old value is <code> null </code>
107     * new value must be specified.
108     */
_TextColor()109     public void _TextColor() {
110         testProperty("TextColor", new PropertyTester() {
111             protected Object getNewValue(String prop, Object old) {
112                 return utils.isVoid(old) ? new Integer(123) : null ;
113             }
114         }) ;
115     }
116 
117     /**
118     * Redefined method returns value, that differs from property value.
119     */
120     protected PropertyTester ColorTester = new PropertyTester() {
121         protected Object getNewValue(String propName, Object oldValue) {
122             if (util.ValueComparer.equalValue(oldValue, new Integer(17)))
123                 return new Integer(25);
124             else
125                 return new Integer(17);
126         }
127     };
128 
129     /**
130     * This property can be void, so if old value is <code> null </code>
131     * new value must be specified.
132     */
_TextLineColor()133     public void _TextLineColor() {
134         log.println("Testing with custom Property tester") ;
135         testProperty("TextLineColor", ColorTester) ;
136     }
137 
_DateShowCentury()138     public void _DateShowCentury() {
139         boolean res = false;
140         try {
141             util.dbg.printPropertyInfo(oObj,"DateShowCentury",log);
142             Object oDsc = oObj.getPropertyValue("DateShowCentury");
143             Boolean dsc = null;
144             if (util.utils.isVoid(oDsc)) {
145                 log.println("Property is void, set it to true");
146                 dsc = new Boolean(true);
147             } else {
148                 dsc = (Boolean) oDsc;
149                 dsc = new Boolean(!dsc.booleanValue());
150                 log.println("Setting property to "+dsc);
151             }
152             oObj.setPropertyValue("DateShowCentury",dsc);
153             Boolean getdsc = (Boolean) oObj.getPropertyValue("DateShowCentury");
154             log.println("Getting value "+getdsc);
155             res = dsc.equals(getdsc);
156         } catch (com.sun.star.beans.UnknownPropertyException upe) {
157             log.println("Don't know the Property 'DateShowCentury'");
158         } catch (com.sun.star.lang.WrappedTargetException wte) {
159             log.println("WrappedTargetException while getting Property 'DateShowCentury'");
160         } catch (com.sun.star.lang.IllegalArgumentException iae) {
161             log.println("IllegalArgumentException while getting Property 'DateShowCentury'");
162         } catch (com.sun.star.beans.PropertyVetoException pve) {
163             log.println("PropertyVetoException while getting Property 'DateShowCentury'");
164         }
165         tRes.tested("DateShowCentury",res);
166 
167     }
168 }
169 
170