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