1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
30 import lib
.MultiPropertyTest
;
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
;
38 * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
39 * service properties :
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>
54 * This test needs the following object relations :
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>
62 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
63 * @see com.sun.star.drawing.GraphicObjectShape
65 public class _GraphicObjectShape
extends MultiPropertyTest
{
68 * Property tester which changes URL.
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");
79 * Property tester which switches two XBitmap objects.
80 * It also uses two object relations with bitmaps.
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
;
91 public Any set
= null;
94 * Property tester which returns new <code>XIndexAccess</code> object.
96 protected PropertyTester ImapTester
= new PropertyTester() {
97 protected Object
getNewValue(String propName
, Object oldValue
) {
104 * This property must have URL format
106 public void _GraphicURL() {
107 log
.println("Testing with custom Property tester") ;
108 testProperty("GraphicURL", URLTester
) ;
111 public void _GraphicStreamURL() {
112 log
.println("Testing with custom Property tester") ;
113 testProperty("GraphicStreamURL", URLTester
) ;
116 public void _GraphicObjectFillBitmap() {
117 log
.println("Testing with custom Property tester") ;
118 testProperty("GraphicObjectFillBitmap", BitmapTester
) ;
122 * The test first retrieves ImageMap relation, then inserts it
123 * to the current container.
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);
132 boolean result
= true;
133 Object imapObject
= tEnv
.getObjRelation("ImapObject");
135 if ( imapObject
== null){
136 System
.out
.println("ERROR: object relation 'ImapObject' isn't available");
137 tRes
.tested("ImageMap", false);
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
);
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
);
154 int elementCountSecond
= xIndexContainer
.getCount();
155 result
= (elementCountFirst
+ 1 == elementCountSecond
);
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);
172 e
.printStackTrace(log
);