1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 package ifc.text; 28 29 import com.sun.star.awt.Point; 30 import com.sun.star.container.XIndexContainer; 31 import com.sun.star.uno.UnoRuntime; 32 33 import java.util.Random; 34 35 import lib.MultiPropertyTest; 36 37 import util.utils; 38 39 40 /** 41 * Testing <code>com.sun.star.text.TextGraphicObject</code> 42 * service properties : 43 * <ul> 44 * <li><code> ImageMap</code></li> 45 * <li><code> ContentProtected</code></li> 46 * <li><code> SurroundContour</code></li> 47 * <li><code> ContourOutside</code></li> 48 * <li><code> ContourPolyPolygon</code></li> 49 * <li><code> GraphicCrop</code></li> 50 * <li><code> HoriMirroredOnEvenPages</code></li> 51 * <li><code> HoriMirroredOnOddPages</code></li> 52 * <li><code> VertMirrored</code></li> 53 * <li><code> GraphicURL</code></li> 54 * <li><code> GraphicFilter</code></li> 55 * <li><code> ActualSize</code></li> 56 * <li><code> AdjustLuminance</code></li> 57 * <li><code> AdjustContrast</code></li> 58 * <li><code> AdjustRed</code></li> 59 * <li><code> AdjustGreen</code></li> 60 * <li><code> AdjustBlue</code></li> 61 * <li><code> Gamma</code></li> 62 * <li><code> GraphicIsInverted</code></li> 63 * <li><code> Transparency</code></li> 64 * <li><code> GraphicColorMode</code></li> 65 * </ul> <p> 66 * This test needs the following object relations : 67 * <ul> 68 * <li> <code>'ImageMap'</code> (an inmplementation of 69 * <code>com.sun.star.image.ImageMapObject</code>): 70 * is used to insert a new Map into collection 71 * from 'ImageMap' property. </li> 72 * <ul> <p> 73 * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 74 * @see com.sun.star.text.TextGraphicObject 75 */ 76 public class _TextGraphicObject extends MultiPropertyTest { 77 public Random rdm = new Random(); 78 79 /** 80 * The tester which can change a sequence of <code>Point</code>'s 81 * or create a new one if necessary. 82 */ 83 protected PropertyTester PointTester = new PropertyTester() { 84 protected Object getNewValue(String propName, Object oldValue) 85 throws java.lang.IllegalArgumentException { 86 if (utils.isVoid(oldValue)) { 87 return newPoint(); 88 } else { 89 return changePoint((Point[][]) oldValue); 90 } 91 } 92 }; 93 94 /** 95 * Tested with custom <code>PointTester</code>. 96 */ 97 public void _ContourPolyPolygon() { 98 log.println("Testing with custom Property tester"); 99 testProperty("ContourPolyPolygon", PointTester); 100 } 101 102 /** 103 * Retrieves an ImageMap from relation and inserts it to the collection 104 * obtained as property value. Then this collection is set back. 105 * After that property value is get again. The number of elements 106 * in the old collection and in just gotten collection is checked. 107 * 108 * Has <b>OK</b> status if the number of elements in the new obtained 109 * collection is greater than in old one. 110 */ 111 public void _ImageMap() { 112 boolean result = true; 113 114 try { 115 XIndexContainer imgMap = (XIndexContainer) UnoRuntime.queryInterface( 116 XIndexContainer.class, 117 oObj.getPropertyValue("ImageMap")); 118 int previous = imgMap.getCount(); 119 log.println("Count (previous) " + previous); 120 121 Object im = tEnv.getObjRelation("IMGMAP"); 122 imgMap.insertByIndex(0, im); 123 oObj.setPropertyValue("ImageMap", imgMap); 124 imgMap = (XIndexContainer) UnoRuntime.queryInterface( 125 XIndexContainer.class, 126 oObj.getPropertyValue("ImageMap")); 127 128 int after = imgMap.getCount(); 129 log.println("Count (after) " + after); 130 result = previous < after; 131 } catch (Exception ex) { 132 result = false; 133 } 134 135 tRes.tested("ImageMap", result); 136 } 137 138 /** 139 * Creates a new random points sequence. 140 */ 141 public Point[][] newPoint() { 142 Point[][] res = new Point[1][185]; 143 144 for (int i = 0; i < res[0].length; i++) { 145 res[0][i] = new Point(); 146 res[0][i].X = rd() * rd() * rd(); 147 res[0][i].Y = rd() * rd() * rd(); 148 ; 149 } 150 151 return res; 152 } 153 154 public int rd() { 155 return rdm.nextInt(6); 156 } 157 158 /** 159 * Changes the existing point sequence. 160 */ 161 public Point[][] changePoint(Point[][] oldPoint) { 162 Point[][] res = oldPoint; 163 164 for (int i = 0; i < res[0].length; i++) { 165 res[0][i].X += 1; 166 res[0][i].Y += 1; 167 } 168 169 return res; 170 } 171 } // finish class _TextGraphicObject 172