Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / drawing / _GraphicObjectShape.java
blobdfbde7de198bc2c53e76daef7eb10704bfe0c5b2
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.UnoRuntime;
27 /**
28 * Testing <code>com.sun.star.drawing.GraphicObjectShape</code>
29 * service properties :
30 * <ul>
31 * <li><code> GraphicURL</code></li>
32 * <li><code> GraphicStreamURL</code></li>
33 * <li><code> GraphicObjectFillBitmap</code></li>
34 * <li><code> AdjustLuminance</code></li>
35 * <li><code> AdjustContrast</code></li>
36 * <li><code> AdjustRed</code></li>
37 * <li><code> AdjustGreen</code></li>
38 * <li><code> AdjustBlue</code></li>
39 * <li><code> Gamma</code></li>
40 * <li><code> Transparency</code></li>
41 * <li><code> GraphicColorMode</code></li>
42 * <li><code> ImageMap</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 * <li> <code>'Bitmap1', 'Bitmap2'</code> (of type <code>XBitmap</code>):
47 * values to be set for property GraphicObjectFillBitmap </li>
48 * <li> <code>'IMAP'</code>
49 * (<code>com.sun.star.image.ImageMapRectangleObject</code> service instance):
50 * is used to be added to ImageMap container.</li>
51 * <ul> <p>
52 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
53 * @see com.sun.star.drawing.GraphicObjectShape
55 public class _GraphicObjectShape extends MultiPropertyTest {
57 /**
58 * Property tester which changes URL.
60 protected PropertyTester URLTester = new PropertyTester() {
61 @Override
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");
67 } ;
69 /**
70 * Property tester which switches two XBitmap objects.
71 * It also uses two object relations with bitmaps.
73 protected PropertyTester BitmapTester = new PropertyTester() {
74 @Override
75 protected Object getNewValue(String propName, Object oldValue){
76 XBitmap aBitmap1=(XBitmap) tEnv.getObjRelation("Bitmap1");
77 XBitmap aBitmap2=(XBitmap) tEnv.getObjRelation("Bitmap2");
78 if (oldValue.equals(aBitmap1)) return aBitmap2;
79 else return aBitmap1;
81 } ;
83 /**
84 * This property must have URL format
86 public void _GraphicURL() {
87 log.println("Testing with custom Property tester") ;
88 testProperty("GraphicURL", URLTester) ;
91 public void _GraphicStreamURL() {
92 log.println("Testing with custom Property tester") ;
93 testProperty("GraphicStreamURL", URLTester) ;
96 public void _GraphicObjectFillBitmap() {
97 log.println("Testing with custom Property tester") ;
98 testProperty("GraphicObjectFillBitmap", BitmapTester) ;
102 * The test first retrieves ImageMap relation, then inserts it
103 * to the current container.
105 public void _ImageMap() {
106 if (! util.utils.hasPropertyByName(oObj,"ImageMap")) {
107 log.println("optional property 'ImageMap' isn't available");
108 tRes.tested("ImageMap",true);
109 return;
111 try {
112 boolean result = true;
113 Object imapObject = tEnv.getObjRelation("ImapObject");
115 if ( imapObject == null){
116 System.out.println("ERROR: object relation 'ImapObject' isn't available");
117 tRes.tested("ImageMap", false);
118 return;
121 Object o = oObj.getPropertyValue("ImageMap");
122 XIndexContainer xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, o);
123 util.dbg.printInterfaces(xIndexContainer);
124 int elementCountFirst = xIndexContainer.getCount();
125 xIndexContainer.insertByIndex(elementCountFirst, imapObject);
127 // this does not really change the property: the implementation
128 // behind "ImageMap" stays the same, but for a real change a C++
129 // implementation is needed. See css.lang.XUnoTunnel
130 oObj.setPropertyValue("ImageMap", xIndexContainer);
131 Object newObject = oObj.getPropertyValue("ImageMap");
132 xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, newObject);
134 int elementCountSecond = xIndexContainer.getCount();
135 result = (elementCountFirst + 1 == elementCountSecond);
137 tRes.tested("ImageMap", result);
138 } catch (com.sun.star.beans.UnknownPropertyException e) {
139 log.println("Exception while checking 'ImageMap'");
140 e.printStackTrace(log);
141 tRes.tested("ImageMap",false);
142 } catch (com.sun.star.lang.WrappedTargetException e) {
143 log.println("Exception while checking 'ImageMap'");
144 e.printStackTrace(log);
145 tRes.tested("ImageMap",false);
146 } catch (com.sun.star.lang.IllegalArgumentException e) {
147 log.println("Exception while checking 'ImageMap'");
148 e.printStackTrace(log);
149 tRes.tested("ImageMap",false);
151 catch(Exception e) {
152 e.printStackTrace(log);