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.drawing;
24 
25 import com.sun.star.beans.XPropertySetInfo;
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.awt.XBitmap;
29 import com.sun.star.uno.AnyConverter;
30 import com.sun.star.uno.Type;
31 
32 /**
33  * Testing <code>com.sun.star.drawing.FillProperties</code>
34  * service properties :
35  * <ul>
36  *  <li><code> FillStyle</code></li>
37  *  <li><code> FillColor</code></li>
38  *  <li><code> FillTransparence</code></li>
39  *  <li><code> FillTransparenceGradientName</code></li>
40  *  <li><code> FillTransparenceGradient</code></li>
41  *  <li><code> FillGradientName</code></li>
42  *  <li><code> FillGradient</code></li>
43  *  <li><code> FillHatchName</code></li>
44  *  <li><code> FillHatch</code></li>
45  *  <li><code> FillBitmapName</code></li>
46  *  <li><code> FillBitmap</code></li>
47  *  <li><code> FillBitmapURL</code></li>
48  *  <li><code> FillBitmapOffsetX</code></li>
49  *  <li><code> FillBitmapOffsetY</code></li>
50  *  <li><code> FillBitmapPositionOffsetX</code></li>
51  *  <li><code> FillBitmapPositionOffsetY</code></li>
52  *  <li><code> FillBitmapRectanglePoint</code></li>
53  *  <li><code> FillBitmapLogicalSize</code></li>
54  *  <li><code> FillBitmapSizeX</code></li>
55  *  <li><code> FillBitmapSizeY</code></li>
56  *  <li><code> FillBitmapMode</code></li>
57  *  <li><code> FillBackground</code></li>
58  * </ul> <p>
59  * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
60  * @see com.sun.star.drawing.FillProperties
61  */
62 public class _FillProperties extends MultiPropertyTest {
63 
64     XBitmap the_bitmap = null;
65     XBitmap the_secondBitmap = null;
66     /**
67      * Property tester which changes URL.
68      */
69     protected PropertyTester URLTester = new PropertyTester() {
70 
71         protected Object getNewValue(String propName, Object oldValue)
72                 throws java.lang.IllegalArgumentException {
73             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) {
74                 return util.utils.getFullTestURL("crazy-blue.jpg");
75             } else {
76                 return util.utils.getFullTestURL("space-metal.jpg");
77             }
78         }
79     };
80     /**
81      * Property tester which switches two strings.
82      */
83     protected PropertyTester StringTester = new PropertyTester() {
84 
85         protected Object getNewValue(String propName, Object oldValue)
86                 throws java.lang.IllegalArgumentException {
87             if (oldValue.equals(str1)) {
88                 return str2;
89             } else {
90                 return str1;
91             }
92         }
93     };
94     /**
95      * Property tester which switches two XBitmap objects.
96      */
97     protected PropertyTester BitmapTester = new PropertyTester() {
98 
99         protected Object getNewValue(String propName, Object oldValue)
100                 throws java.lang.IllegalArgumentException {
101             if (util.ValueComparer.equalValue(oldValue, the_bitmap)) {
102                 return the_secondBitmap;
103             } else {
104                 return the_bitmap;
105             }
106         }
107     };
108 
109     /**
110      * This property must have an URL format
111      */
_FillBitmapURL()112     public void _FillBitmapURL() {
113         log.println("Testing with custom Property tester");
114         testProperty("FillBitmapURL", URLTester);
115     }
116     public String str1 = "";
117     public String str2 = "";
118 
119     /**
120      * This property must have predefined values
121      */
_FillGradientName()122     public void _FillGradientName() {
123         log.println("Testing with custom Property tester");
124         str1 = "Gradient 1";
125         str2 = "Gradient 3";
126         testProperty("FillGradientName", StringTester);
127     }
128 
129     /**
130      * This property must have predefined values
131      */
_FillBitmapName()132     public void _FillBitmapName() {
133         log.println("Testing with custom Property tester");
134         str1 = "Sky";
135         str2 = "Blank";
136         testProperty("FillBitmapName", StringTester);
137     }
138 
139     /**
140      * This property must have predefined values
141      */
_FillTransparenceGradientName()142     public void _FillTransparenceGradientName() {
143         log.println("Testing with custom Property tester");
144         str1 = "Transparency 2";
145         str2 = "Transparency 1";
146         testProperty("FillTransparenceGradientName", StringTester);
147     }
148 
149     /**
150      * This property must have predefined values
151      */
_FillHatchName()152     public void _FillHatchName() {
153         log.println("Testing with custom Property tester");
154         str1 = "Black 0 degrees";
155         str2 = "Black 45 degrees";
156         testProperty("FillHatchName", StringTester);
157     }
158 
159     /**
160      * This property is very interesting. After setting URL of bitmap you get
161      * <code>XBitmap</code> interface of the image file specified.
162      * The method first gets two different bitmaps and then tests the property.
163      */
_FillBitmap()164     public void _FillBitmap() {
165 
166         String propName = "FillBitmap";
167 
168         XPropertySetInfo info = oObj.getPropertySetInfo();
169 
170         if (!info.hasPropertyByName(propName)) {
171             if (isOptional(propName)) {
172                 // skipping optional property test
173                 log.println("Property '" + propName + "' is optional and not supported");
174                 tRes.tested(propName, true);
175                 return;
176             }
177         } else {
178 
179             try {
180 
181                 oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("crazy-blue.jpg"));
182 
183                 the_bitmap = (XBitmap) AnyConverter.toObject(
184                         new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap"));
185 
186                 oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("space-metal.jpg"));
187 
188                 the_secondBitmap = (XBitmap) AnyConverter.toObject(
189                         new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap"));
190 
191                 testProperty("FillBitmap", BitmapTester);
192 
193             } catch (com.sun.star.beans.PropertyVetoException e) {
194                 log.println("Couldn't change Bitmap");
195                 e.printStackTrace(log);
196                 tRes.tested("FillBitmap", false);
197 
198             } catch (com.sun.star.beans.UnknownPropertyException e) {
199                 log.println("Couldn't change Bitmap");
200                 e.printStackTrace(log);
201                 tRes.tested("FillBitmap", false);
202 
203             } catch (com.sun.star.lang.WrappedTargetException e) {
204                 log.println("Couldn't change Bitmap");
205                 e.printStackTrace(log);
206                 tRes.tested("FillBitmap", false);
207 
208             } catch (com.sun.star.lang.IllegalArgumentException e) {
209                 log.println("Couldn't change Bitmap");
210                 e.printStackTrace(log);
211                 tRes.tested("FillBitmap", false);
212             }
213         }
214     }
215     }
216