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.drawing;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.awt.XBitmap;
29 import com.sun.star.container.XIndexContainer;
30 import com.sun.star.uno.Any;
31 import com.sun.star.uno.UnoRuntime;
32 
33 /**
34 * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
35 * service properties :
36 * <ul>
37 *  <li><code> GraphicURL</code></li>
38 *  <li><code> GraphicStreamURL</code></li>
39 *  <li><code> GraphicObjectFillBitmap</code></li>
40 *  <li><code> AdjustLuminance</code></li>
41 *  <li><code> AdjustContrast</code></li>
42 *  <li><code> AdjustRed</code></li>
43 *  <li><code> AdjustGreen</code></li>
44 *  <li><code> AdjustBlue</code></li>
45 *  <li><code> Gamma</code></li>
46 *  <li><code> Transparency</code></li>
47 *  <li><code> GraphicColorMode</code></li>
48 *  <li><code> ImageMap</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 *  <li> <code>'Bitmap1', 'Bitmap2'</code> (of type <code>XBitmap</code>):
53 *   values to be set for property GraphicObjectFillBitmap </li>
54 *  <li> <code>'IMAP'</code>
55 *   (<code>com.sun.star.image.ImageMapRectangleObject</code> service instance):
56 *   is used to be added to ImageMap container.</li>
57 * <ul> <p>
58 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
59 * @see com.sun.star.drawing.GraphicObjectShape
60 */
61 public class _GraphicObjectShape extends MultiPropertyTest {
62 
63     /**
64      * Property tester which changes URL.
65      */
66     protected PropertyTester URLTester = new PropertyTester() {
67         protected Object getNewValue(String propName, Object oldValue) {
68             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg")))
69                 return util.utils.getFullTestURL("crazy-blue.jpg"); else
70                 return util.utils.getFullTestURL("space-metal.jpg");
71         }
72     } ;
73 
74     /**
75      * Property tester which switches two XBitmap objects.
76      * It also uses two object relations with bitmaps.
77      */
78     protected PropertyTester BitmapTester = new PropertyTester() {
79         protected Object getNewValue(String propName, Object oldValue){
80             XBitmap aBitmap1=(XBitmap) tEnv.getObjRelation("Bitmap1");
81             XBitmap aBitmap2=(XBitmap) tEnv.getObjRelation("Bitmap2");
82             if (oldValue.equals(aBitmap1)) return aBitmap2;
83             else return aBitmap1;
84         }
85     } ;
86 
87     public Any set = null;
88 
89     /**
90      * Property tester which returns new <code>XIndexAccess</code> object.
91      */
92     protected PropertyTester ImapTester = new PropertyTester() {
93         protected Object getNewValue(String propName, Object oldValue) {
94             return set;
95         }
96     } ;
97 
98 
99     /**
100      * This property must have URL format
101      */
_GraphicURL()102     public void _GraphicURL() {
103         log.println("Testing with custom Property tester") ;
104         testProperty("GraphicURL", URLTester) ;
105     }
106 
_GraphicStreamURL()107     public void _GraphicStreamURL() {
108         log.println("Testing with custom Property tester") ;
109         testProperty("GraphicStreamURL", URLTester) ;
110     }
111 
_GraphicObjectFillBitmap()112     public void _GraphicObjectFillBitmap() {
113         log.println("Testing with custom Property tester") ;
114         testProperty("GraphicObjectFillBitmap", BitmapTester) ;
115     }
116 
117     /**
118      * The test first retrieves ImageMap relation, then inserts it
119      * to the current container.
120      */
_ImageMap()121     public void _ImageMap() {
122         if (! util.utils.hasPropertyByName(oObj,"ImageMap")) {
123             log.println("optional property 'ImageMap' isn't available");
124             tRes.tested("ImageMap",true);
125             return;
126         }
127         try {
128             boolean result = true;
129             Object imapObject = tEnv.getObjRelation("ImapObject");
130 
131             if ( imapObject == null){
132                 System.out.println("ERROR: object relation 'ImapObject' isn't available");
133                 tRes.tested("ImageMap", false);
134                 return;
135             }
136 
137             Object o = oObj.getPropertyValue("ImageMap");
138             XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, o);
139             util.dbg.printInterfaces(xIndexContainer);
140             int elementCountFirst = xIndexContainer.getCount();
141             xIndexContainer.insertByIndex(elementCountFirst, imapObject);
142 
143             // this does not really change the property: the implementation
144             // behind "ImageMap" stays the same, but for a real change a C++
145             // implementation is needed. See css.lang.XUnoTunnel
146             oObj.setPropertyValue("ImageMap", xIndexContainer);
147             Object newObject = oObj.getPropertyValue("ImageMap");
148             xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, newObject);
149 
150             int elementCountSecond = xIndexContainer.getCount();
151             result = (elementCountFirst + 1 == elementCountSecond);
152 
153             tRes.tested("ImageMap", result);
154         } catch (com.sun.star.beans.UnknownPropertyException e) {
155             log.println("Exception while checking 'ImageMap'");
156             e.printStackTrace(log);
157             tRes.tested("ImageMap",false);
158         } catch (com.sun.star.lang.WrappedTargetException e) {
159             log.println("Exception while checking 'ImageMap'");
160             e.printStackTrace(log);
161             tRes.tested("ImageMap",false);
162         } catch (com.sun.star.lang.IllegalArgumentException e) {
163             log.println("Exception while checking 'ImageMap'");
164             e.printStackTrace(log);
165             tRes.tested("ImageMap",false);
166         }
167         catch(Exception e) {
168             e.printStackTrace(log);
169         }
170     }
171 
172 }
173 
174