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