1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.drawing;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import lib.MultiPropertyTest;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import com.sun.star.awt.XBitmap;
33*cdf0e10cSrcweir import com.sun.star.container.XIndexContainer;
34*cdf0e10cSrcweir import com.sun.star.uno.Any;
35*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir /**
38*cdf0e10cSrcweir * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
39*cdf0e10cSrcweir * service properties :
40*cdf0e10cSrcweir * <ul>
41*cdf0e10cSrcweir *  <li><code> GraphicURL</code></li>
42*cdf0e10cSrcweir *  <li><code> GraphicStreamURL</code></li>
43*cdf0e10cSrcweir *  <li><code> GraphicObjectFillBitmap</code></li>
44*cdf0e10cSrcweir *  <li><code> AdjustLuminance</code></li>
45*cdf0e10cSrcweir *  <li><code> AdjustContrast</code></li>
46*cdf0e10cSrcweir *  <li><code> AdjustRed</code></li>
47*cdf0e10cSrcweir *  <li><code> AdjustGreen</code></li>
48*cdf0e10cSrcweir *  <li><code> AdjustBlue</code></li>
49*cdf0e10cSrcweir *  <li><code> Gamma</code></li>
50*cdf0e10cSrcweir *  <li><code> Transparency</code></li>
51*cdf0e10cSrcweir *  <li><code> GraphicColorMode</code></li>
52*cdf0e10cSrcweir *  <li><code> ImageMap</code></li>
53*cdf0e10cSrcweir * </ul> <p>
54*cdf0e10cSrcweir * This test needs the following object relations :
55*cdf0e10cSrcweir * <ul>
56*cdf0e10cSrcweir *  <li> <code>'Bitmap1', 'Bitmap2'</code> (of type <code>XBitmap</code>):
57*cdf0e10cSrcweir *   values to be set for property GraphicObjectFillBitmap </li>
58*cdf0e10cSrcweir *  <li> <code>'IMAP'</code>
59*cdf0e10cSrcweir *   (<code>com.sun.star.image.ImageMapRectangleObject</code> service instance):
60*cdf0e10cSrcweir *   is used to be added to ImageMap container.</li>
61*cdf0e10cSrcweir * <ul> <p>
62*cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
63*cdf0e10cSrcweir * @see com.sun.star.drawing.GraphicObjectShape
64*cdf0e10cSrcweir */
65*cdf0e10cSrcweir public class _GraphicObjectShape extends MultiPropertyTest {
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     /**
68*cdf0e10cSrcweir      * Property tester which changes URL.
69*cdf0e10cSrcweir      */
70*cdf0e10cSrcweir     protected PropertyTester URLTester = new PropertyTester() {
71*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
72*cdf0e10cSrcweir             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg")))
73*cdf0e10cSrcweir                 return util.utils.getFullTestURL("crazy-blue.jpg"); else
74*cdf0e10cSrcweir                 return util.utils.getFullTestURL("space-metal.jpg");
75*cdf0e10cSrcweir         }
76*cdf0e10cSrcweir     } ;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     /**
79*cdf0e10cSrcweir      * Property tester which switches two XBitmap objects.
80*cdf0e10cSrcweir      * It also uses two object relations with bitmaps.
81*cdf0e10cSrcweir      */
82*cdf0e10cSrcweir     protected PropertyTester BitmapTester = new PropertyTester() {
83*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue){
84*cdf0e10cSrcweir             XBitmap aBitmap1=(XBitmap) tEnv.getObjRelation("Bitmap1");
85*cdf0e10cSrcweir             XBitmap aBitmap2=(XBitmap) tEnv.getObjRelation("Bitmap2");
86*cdf0e10cSrcweir             if (oldValue.equals(aBitmap1)) return aBitmap2;
87*cdf0e10cSrcweir             else return aBitmap1;
88*cdf0e10cSrcweir         }
89*cdf0e10cSrcweir     } ;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     public Any set = null;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     /**
94*cdf0e10cSrcweir      * Property tester which returns new <code>XIndexAccess</code> object.
95*cdf0e10cSrcweir      */
96*cdf0e10cSrcweir     protected PropertyTester ImapTester = new PropertyTester() {
97*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
98*cdf0e10cSrcweir             return set;
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir     } ;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     /**
104*cdf0e10cSrcweir      * This property must have URL format
105*cdf0e10cSrcweir      */
106*cdf0e10cSrcweir     public void _GraphicURL() {
107*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
108*cdf0e10cSrcweir         testProperty("GraphicURL", URLTester) ;
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     public void _GraphicStreamURL() {
112*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
113*cdf0e10cSrcweir         testProperty("GraphicStreamURL", URLTester) ;
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     public void _GraphicObjectFillBitmap() {
117*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
118*cdf0e10cSrcweir         testProperty("GraphicObjectFillBitmap", BitmapTester) ;
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     /**
122*cdf0e10cSrcweir      * The test first retrieves ImageMap relation, then inserts it
123*cdf0e10cSrcweir      * to the current container.
124*cdf0e10cSrcweir      */
125*cdf0e10cSrcweir     public void _ImageMap() {
126*cdf0e10cSrcweir         if (! util.utils.hasPropertyByName(oObj,"ImageMap")) {
127*cdf0e10cSrcweir             log.println("optional property 'ImageMap' isn't available");
128*cdf0e10cSrcweir             tRes.tested("ImageMap",true);
129*cdf0e10cSrcweir             return;
130*cdf0e10cSrcweir         }
131*cdf0e10cSrcweir         try {
132*cdf0e10cSrcweir             boolean result = true;
133*cdf0e10cSrcweir             Object imapObject = tEnv.getObjRelation("ImapObject");
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir             if ( imapObject == null){
136*cdf0e10cSrcweir                 System.out.println("ERROR: object relation 'ImapObject' isn't available");
137*cdf0e10cSrcweir                 tRes.tested("ImageMap", false);
138*cdf0e10cSrcweir                 return;
139*cdf0e10cSrcweir             }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             Object o = oObj.getPropertyValue("ImageMap");
142*cdf0e10cSrcweir             XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, o);
143*cdf0e10cSrcweir             util.dbg.printInterfaces(xIndexContainer);
144*cdf0e10cSrcweir             int elementCountFirst = xIndexContainer.getCount();
145*cdf0e10cSrcweir             xIndexContainer.insertByIndex(elementCountFirst, imapObject);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir             // this does not really change the property: the implementation
148*cdf0e10cSrcweir             // behind "ImageMap" stays the same, but for a real change a C++
149*cdf0e10cSrcweir             // implementation is needed. See css.lang.XUnoTunnel
150*cdf0e10cSrcweir             oObj.setPropertyValue("ImageMap", xIndexContainer);
151*cdf0e10cSrcweir             Object newObject = oObj.getPropertyValue("ImageMap");
152*cdf0e10cSrcweir             xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, newObject);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir             int elementCountSecond = xIndexContainer.getCount();
155*cdf0e10cSrcweir             result = (elementCountFirst + 1 == elementCountSecond);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             tRes.tested("ImageMap", result);
158*cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
159*cdf0e10cSrcweir             log.println("Exception while checking 'ImageMap'");
160*cdf0e10cSrcweir             e.printStackTrace(log);
161*cdf0e10cSrcweir             tRes.tested("ImageMap",false);
162*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
163*cdf0e10cSrcweir             log.println("Exception while checking 'ImageMap'");
164*cdf0e10cSrcweir             e.printStackTrace(log);
165*cdf0e10cSrcweir             tRes.tested("ImageMap",false);
166*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
167*cdf0e10cSrcweir             log.println("Exception while checking 'ImageMap'");
168*cdf0e10cSrcweir             e.printStackTrace(log);
169*cdf0e10cSrcweir             tRes.tested("ImageMap",false);
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir         catch(Exception e) {
172*cdf0e10cSrcweir             e.printStackTrace(log);
173*cdf0e10cSrcweir         }
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178