Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / drawing / _GraphicObjectShape.java
blob3d49bcb05f11edd606672471fa01048da21590ee
1 /*
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 .
19 package ifc.drawing;
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;
28 /**
29 * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
30 * service properties :
31 * <ul>
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>
44 * </ul> <p>
45 * This test needs the following object relations :
46 * <ul>
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>
52 * <ul> <p>
53 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
54 * @see com.sun.star.drawing.GraphicObjectShape
56 public class _GraphicObjectShape extends MultiPropertyTest {
58 /**
59 * Property tester which changes URL.
61 protected PropertyTester URLTester = new PropertyTester() {
62 @Override
63 protected Object getNewValue(String propName, Object oldValue) {
64 if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg")))
65 return util.utils.getFullTestURL("crazy-blue.jpg"); else
66 return util.utils.getFullTestURL("space-metal.jpg");
68 } ;
70 /**
71 * Property tester which switches two XBitmap objects.
72 * It also uses two object relations with bitmaps.
74 protected PropertyTester BitmapTester = new PropertyTester() {
75 @Override
76 protected Object getNewValue(String propName, Object oldValue){
77 XBitmap aBitmap1=(XBitmap) tEnv.getObjRelation("Bitmap1");
78 XBitmap aBitmap2=(XBitmap) tEnv.getObjRelation("Bitmap2");
79 if (oldValue.equals(aBitmap1)) return aBitmap2;
80 else return aBitmap1;
82 } ;
84 public Any set = null;
86 /**
87 * Property tester which returns new <code>XIndexAccess</code> object.
89 protected PropertyTester ImapTester = new PropertyTester() {
90 @Override
91 protected Object getNewValue(String propName, Object oldValue) {
92 return set;
94 } ;
97 /**
98 * This property must have URL format
100 public void _GraphicURL() {
101 log.println("Testing with custom Property tester") ;
102 testProperty("GraphicURL", URLTester) ;
105 public void _GraphicStreamURL() {
106 log.println("Testing with custom Property tester") ;
107 testProperty("GraphicStreamURL", URLTester) ;
110 public void _GraphicObjectFillBitmap() {
111 log.println("Testing with custom Property tester") ;
112 testProperty("GraphicObjectFillBitmap", BitmapTester) ;
116 * The test first retrieves ImageMap relation, then inserts it
117 * to the current container.
119 public void _ImageMap() {
120 if (! util.utils.hasPropertyByName(oObj,"ImageMap")) {
121 log.println("optional property 'ImageMap' isn't available");
122 tRes.tested("ImageMap",true);
123 return;
125 try {
126 boolean result = true;
127 Object imapObject = tEnv.getObjRelation("ImapObject");
129 if ( imapObject == null){
130 System.out.println("ERROR: object relation 'ImapObject' isn't available");
131 tRes.tested("ImageMap", false);
132 return;
135 Object o = oObj.getPropertyValue("ImageMap");
136 XIndexContainer xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, o);
137 util.dbg.printInterfaces(xIndexContainer);
138 int elementCountFirst = xIndexContainer.getCount();
139 xIndexContainer.insertByIndex(elementCountFirst, imapObject);
141 // this does not really change the property: the implementation
142 // behind "ImageMap" stays the same, but for a real change a C++
143 // implementation is needed. See css.lang.XUnoTunnel
144 oObj.setPropertyValue("ImageMap", xIndexContainer);
145 Object newObject = oObj.getPropertyValue("ImageMap");
146 xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, newObject);
148 int elementCountSecond = xIndexContainer.getCount();
149 result = (elementCountFirst + 1 == elementCountSecond);
151 tRes.tested("ImageMap", result);
152 } catch (com.sun.star.beans.UnknownPropertyException e) {
153 log.println("Exception while checking 'ImageMap'");
154 e.printStackTrace(log);
155 tRes.tested("ImageMap",false);
156 } catch (com.sun.star.lang.WrappedTargetException e) {
157 log.println("Exception while checking 'ImageMap'");
158 e.printStackTrace(log);
159 tRes.tested("ImageMap",false);
160 } catch (com.sun.star.lang.IllegalArgumentException e) {
161 log.println("Exception while checking 'ImageMap'");
162 e.printStackTrace(log);
163 tRes.tested("ImageMap",false);
165 catch(Exception e) {
166 e.printStackTrace(log);