1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.drawing;
28 
29 import com.sun.star.beans.XPropertySetInfo;
30 import lib.MultiPropertyTest;
31 
32 import com.sun.star.awt.XBitmap;
33 import com.sun.star.uno.AnyConverter;
34 import com.sun.star.uno.Type;
35 
36 /**
37  * Testing <code>com.sun.star.drawing.FillProperties</code>
38  * service properties :
39  * <ul>
40  *  <li><code> FillStyle</code></li>
41  *  <li><code> FillColor</code></li>
42  *  <li><code> FillTransparence</code></li>
43  *  <li><code> FillTransparenceGradientName</code></li>
44  *  <li><code> FillTransparenceGradient</code></li>
45  *  <li><code> FillGradientName</code></li>
46  *  <li><code> FillGradient</code></li>
47  *  <li><code> FillHatchName</code></li>
48  *  <li><code> FillHatch</code></li>
49  *  <li><code> FillBitmapName</code></li>
50  *  <li><code> FillBitmap</code></li>
51  *  <li><code> FillBitmapURL</code></li>
52  *  <li><code> FillBitmapOffsetX</code></li>
53  *  <li><code> FillBitmapOffsetY</code></li>
54  *  <li><code> FillBitmapPositionOffsetX</code></li>
55  *  <li><code> FillBitmapPositionOffsetY</code></li>
56  *  <li><code> FillBitmapRectanglePoint</code></li>
57  *  <li><code> FillBitmapLogicalSize</code></li>
58  *  <li><code> FillBitmapSizeX</code></li>
59  *  <li><code> FillBitmapSizeY</code></li>
60  *  <li><code> FillBitmapMode</code></li>
61  *  <li><code> FillBackground</code></li>
62  * </ul> <p>
63  * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
64  * @see com.sun.star.drawing.FillProperties
65  */
66 public class _FillProperties extends MultiPropertyTest {
67 
68     XBitmap the_bitmap = null;
69     XBitmap the_secondBitmap = null;
70     /**
71      * Property tester which changes URL.
72      */
73     protected PropertyTester URLTester = new PropertyTester() {
74 
75         protected Object getNewValue(String propName, Object oldValue)
76                 throws java.lang.IllegalArgumentException {
77             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) {
78                 return util.utils.getFullTestURL("crazy-blue.jpg");
79             } else {
80                 return util.utils.getFullTestURL("space-metal.jpg");
81             }
82         }
83     };
84     /**
85      * Property tester which switches two strings.
86      */
87     protected PropertyTester StringTester = new PropertyTester() {
88 
89         protected Object getNewValue(String propName, Object oldValue)
90                 throws java.lang.IllegalArgumentException {
91             if (oldValue.equals(str1)) {
92                 return str2;
93             } else {
94                 return str1;
95             }
96         }
97     };
98     /**
99      * Property tester which switches two XBitmap objects.
100      */
101     protected PropertyTester BitmapTester = new PropertyTester() {
102 
103         protected Object getNewValue(String propName, Object oldValue)
104                 throws java.lang.IllegalArgumentException {
105             if (util.ValueComparer.equalValue(oldValue, the_bitmap)) {
106                 return the_secondBitmap;
107             } else {
108                 return the_bitmap;
109             }
110         }
111     };
112 
113     /**
114      * This property must have an URL format
115      */
116     public void _FillBitmapURL() {
117         log.println("Testing with custom Property tester");
118         testProperty("FillBitmapURL", URLTester);
119     }
120     public String str1 = "";
121     public String str2 = "";
122 
123     /**
124      * This property must have predefined values
125      */
126     public void _FillGradientName() {
127         log.println("Testing with custom Property tester");
128         str1 = "Gradient 1";
129         str2 = "Gradient 3";
130         testProperty("FillGradientName", StringTester);
131     }
132 
133     /**
134      * This property must have predefined values
135      */
136     public void _FillBitmapName() {
137         log.println("Testing with custom Property tester");
138         str1 = "Sky";
139         str2 = "Blank";
140         testProperty("FillBitmapName", StringTester);
141     }
142 
143     /**
144      * This property must have predefined values
145      */
146     public void _FillTransparenceGradientName() {
147         log.println("Testing with custom Property tester");
148         str1 = "Transparency 2";
149         str2 = "Transparency 1";
150         testProperty("FillTransparenceGradientName", StringTester);
151     }
152 
153     /**
154      * This property must have predefined values
155      */
156     public void _FillHatchName() {
157         log.println("Testing with custom Property tester");
158         str1 = "Black 0 degrees";
159         str2 = "Black 45 degrees";
160         testProperty("FillHatchName", StringTester);
161     }
162 
163     /**
164      * This property is very interesting. After setting URL of bitmap you get
165      * <code>XBitmap</code> interface of the image file specified.
166      * The method first gets two different bitmaps and then tests the property.
167      */
168     public void _FillBitmap() {
169 
170         String propName = "FillBitmap";
171 
172         XPropertySetInfo info = oObj.getPropertySetInfo();
173 
174         if (!info.hasPropertyByName(propName)) {
175             if (isOptional(propName)) {
176                 // skipping optional property test
177                 log.println("Property '" + propName + "' is optional and not supported");
178                 tRes.tested(propName, true);
179                 return;
180             }
181         } else {
182 
183             try {
184 
185                 oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("crazy-blue.jpg"));
186 
187                 the_bitmap = (XBitmap) AnyConverter.toObject(
188                         new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap"));
189 
190                 oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("space-metal.jpg"));
191 
192                 the_secondBitmap = (XBitmap) AnyConverter.toObject(
193                         new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap"));
194 
195                 testProperty("FillBitmap", BitmapTester);
196 
197             } catch (com.sun.star.beans.PropertyVetoException e) {
198                 log.println("Couldn't change Bitmap");
199                 e.printStackTrace(log);
200                 tRes.tested("FillBitmap", false);
201 
202             } catch (com.sun.star.beans.UnknownPropertyException e) {
203                 log.println("Couldn't change Bitmap");
204                 e.printStackTrace(log);
205                 tRes.tested("FillBitmap", false);
206 
207             } catch (com.sun.star.lang.WrappedTargetException e) {
208                 log.println("Couldn't change Bitmap");
209                 e.printStackTrace(log);
210                 tRes.tested("FillBitmap", false);
211 
212             } catch (com.sun.star.lang.IllegalArgumentException e) {
213                 log.println("Couldn't change Bitmap");
214                 e.printStackTrace(log);
215                 tRes.tested("FillBitmap", false);
216             }
217         }
218     }
219     }
220