2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiPropertyTest
;
23 import com
.sun
.star
.awt
.XBitmap
;
24 import com
.sun
.star
.container
.XIndexContainer
;
25 import com
.sun
.star
.uno
.Any
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
29 * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
30 * service properties :
32 * <li><code> GraphicURL</code></li>
33 * <li><code> GraphicStreamURL</code></li>
34 * <li><code> GraphicObjectFillBitmap</code></li>
35 * <li><code> AdjustLuminance</code></li>
36 * <li><code> AdjustContrast</code></li>
37 * <li><code> AdjustRed</code></li>
38 * <li><code> AdjustGreen</code></li>
39 * <li><code> AdjustBlue</code></li>
40 * <li><code> Gamma</code></li>
41 * <li><code> Transparency</code></li>
42 * <li><code> GraphicColorMode</code></li>
43 * <li><code> ImageMap</code></li>
45 * This test needs the following object relations :
47 * <li> <code>'Bitmap1', 'Bitmap2'</code> (of type <code>XBitmap</code>):
48 * values to be set for property GraphicObjectFillBitmap </li>
49 * <li> <code>'IMAP'</code>
50 * (<code>com.sun.star.image.ImageMapRectangleObject</code> service instance):
51 * is used to be added to ImageMap container.</li>
53 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
54 * @see com.sun.star.drawing.GraphicObjectShape
56 public class _GraphicObjectShape
extends MultiPropertyTest
{
59 * Property tester which changes URL.
61 protected PropertyTester URLTester
= new PropertyTester() {
62 protected Object
getNewValue(String propName
, Object oldValue
) {
63 if (oldValue
.equals(util
.utils
.getFullTestURL("space-metal.jpg")))
64 return util
.utils
.getFullTestURL("crazy-blue.jpg"); else
65 return util
.utils
.getFullTestURL("space-metal.jpg");
70 * Property tester which switches two XBitmap objects.
71 * It also uses two object relations with bitmaps.
73 protected PropertyTester BitmapTester
= new PropertyTester() {
74 protected Object
getNewValue(String propName
, Object oldValue
){
75 XBitmap aBitmap1
=(XBitmap
) tEnv
.getObjRelation("Bitmap1");
76 XBitmap aBitmap2
=(XBitmap
) tEnv
.getObjRelation("Bitmap2");
77 if (oldValue
.equals(aBitmap1
)) return aBitmap2
;
82 public Any set
= null;
85 * Property tester which returns new <code>XIndexAccess</code> object.
87 protected PropertyTester ImapTester
= new PropertyTester() {
88 protected Object
getNewValue(String propName
, Object oldValue
) {
95 * This property must have URL format
97 public void _GraphicURL() {
98 log
.println("Testing with custom Property tester") ;
99 testProperty("GraphicURL", URLTester
) ;
102 public void _GraphicStreamURL() {
103 log
.println("Testing with custom Property tester") ;
104 testProperty("GraphicStreamURL", URLTester
) ;
107 public void _GraphicObjectFillBitmap() {
108 log
.println("Testing with custom Property tester") ;
109 testProperty("GraphicObjectFillBitmap", BitmapTester
) ;
113 * The test first retrieves ImageMap relation, then inserts it
114 * to the current container.
116 public void _ImageMap() {
117 if (! util
.utils
.hasPropertyByName(oObj
,"ImageMap")) {
118 log
.println("optional property 'ImageMap' isn't available");
119 tRes
.tested("ImageMap",true);
123 boolean result
= true;
124 Object imapObject
= tEnv
.getObjRelation("ImapObject");
126 if ( imapObject
== null){
127 System
.out
.println("ERROR: object relation 'ImapObject' isn't available");
128 tRes
.tested("ImageMap", false);
132 Object o
= oObj
.getPropertyValue("ImageMap");
133 XIndexContainer xIndexContainer
= UnoRuntime
.queryInterface(XIndexContainer
.class, o
);
134 util
.dbg
.printInterfaces(xIndexContainer
);
135 int elementCountFirst
= xIndexContainer
.getCount();
136 xIndexContainer
.insertByIndex(elementCountFirst
, imapObject
);
138 // this does not really change the property: the implementation
139 // behind "ImageMap" stays the same, but for a real change a C++
140 // implementation is needed. See css.lang.XUnoTunnel
141 oObj
.setPropertyValue("ImageMap", xIndexContainer
);
142 Object newObject
= oObj
.getPropertyValue("ImageMap");
143 xIndexContainer
= UnoRuntime
.queryInterface(XIndexContainer
.class, newObject
);
145 int elementCountSecond
= xIndexContainer
.getCount();
146 result
= (elementCountFirst
+ 1 == elementCountSecond
);
148 tRes
.tested("ImageMap", result
);
149 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
150 log
.println("Exception while checking 'ImageMap'");
151 e
.printStackTrace(log
);
152 tRes
.tested("ImageMap",false);
153 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
154 log
.println("Exception while checking 'ImageMap'");
155 e
.printStackTrace(log
);
156 tRes
.tested("ImageMap",false);
157 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
158 log
.println("Exception while checking 'ImageMap'");
159 e
.printStackTrace(log
);
160 tRes
.tested("ImageMap",false);
163 e
.printStackTrace(log
);