1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.text; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.Point; 26cdf0e10cSrcweir import com.sun.star.container.XIndexContainer; 27cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import java.util.Random; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import lib.MultiPropertyTest; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import util.utils; 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** 37cdf0e10cSrcweir * Testing <code>com.sun.star.text.TextGraphicObject</code> 38cdf0e10cSrcweir * service properties : 39cdf0e10cSrcweir * <ul> 40cdf0e10cSrcweir * <li><code> ImageMap</code></li> 41cdf0e10cSrcweir * <li><code> ContentProtected</code></li> 42cdf0e10cSrcweir * <li><code> SurroundContour</code></li> 43cdf0e10cSrcweir * <li><code> ContourOutside</code></li> 44cdf0e10cSrcweir * <li><code> ContourPolyPolygon</code></li> 45cdf0e10cSrcweir * <li><code> GraphicCrop</code></li> 46cdf0e10cSrcweir * <li><code> HoriMirroredOnEvenPages</code></li> 47cdf0e10cSrcweir * <li><code> HoriMirroredOnOddPages</code></li> 48cdf0e10cSrcweir * <li><code> VertMirrored</code></li> 49cdf0e10cSrcweir * <li><code> GraphicURL</code></li> 50cdf0e10cSrcweir * <li><code> GraphicFilter</code></li> 51cdf0e10cSrcweir * <li><code> ActualSize</code></li> 52cdf0e10cSrcweir * <li><code> AdjustLuminance</code></li> 53cdf0e10cSrcweir * <li><code> AdjustContrast</code></li> 54cdf0e10cSrcweir * <li><code> AdjustRed</code></li> 55cdf0e10cSrcweir * <li><code> AdjustGreen</code></li> 56cdf0e10cSrcweir * <li><code> AdjustBlue</code></li> 57cdf0e10cSrcweir * <li><code> Gamma</code></li> 58cdf0e10cSrcweir * <li><code> GraphicIsInverted</code></li> 59cdf0e10cSrcweir * <li><code> Transparency</code></li> 60cdf0e10cSrcweir * <li><code> GraphicColorMode</code></li> 61cdf0e10cSrcweir * </ul> <p> 62cdf0e10cSrcweir * This test needs the following object relations : 63cdf0e10cSrcweir * <ul> 64cdf0e10cSrcweir * <li> <code>'ImageMap'</code> (an inmplementation of 65cdf0e10cSrcweir * <code>com.sun.star.image.ImageMapObject</code>): 66cdf0e10cSrcweir * is used to insert a new Map into collection 67cdf0e10cSrcweir * from 'ImageMap' property. </li> 68cdf0e10cSrcweir * <ul> <p> 69cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 70cdf0e10cSrcweir * @see com.sun.star.text.TextGraphicObject 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir public class _TextGraphicObject extends MultiPropertyTest { 73cdf0e10cSrcweir public Random rdm = new Random(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir /** 76cdf0e10cSrcweir * The tester which can change a sequence of <code>Point</code>'s 77cdf0e10cSrcweir * or create a new one if necessary. 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir protected PropertyTester PointTester = new PropertyTester() { 80cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 81cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 82cdf0e10cSrcweir if (utils.isVoid(oldValue)) { 83cdf0e10cSrcweir return newPoint(); 84cdf0e10cSrcweir } else { 85cdf0e10cSrcweir return changePoint((Point[][]) oldValue); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir } 88cdf0e10cSrcweir }; 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** 91cdf0e10cSrcweir * Tested with custom <code>PointTester</code>. 92cdf0e10cSrcweir */ _ContourPolyPolygon()93cdf0e10cSrcweir public void _ContourPolyPolygon() { 94cdf0e10cSrcweir log.println("Testing with custom Property tester"); 95cdf0e10cSrcweir testProperty("ContourPolyPolygon", PointTester); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** 99cdf0e10cSrcweir * Retrieves an ImageMap from relation and inserts it to the collection 100cdf0e10cSrcweir * obtained as property value. Then this collection is set back. 101cdf0e10cSrcweir * After that property value is get again. The number of elements 102cdf0e10cSrcweir * in the old collection and in just gotten collection is checked. 103cdf0e10cSrcweir * 104cdf0e10cSrcweir * Has <b>OK</b> status if the number of elements in the new obtained 105cdf0e10cSrcweir * collection is greater than in old one. 106cdf0e10cSrcweir */ _ImageMap()107cdf0e10cSrcweir public void _ImageMap() { 108cdf0e10cSrcweir boolean result = true; 109cdf0e10cSrcweir 110cdf0e10cSrcweir try { 111cdf0e10cSrcweir XIndexContainer imgMap = (XIndexContainer) UnoRuntime.queryInterface( 112cdf0e10cSrcweir XIndexContainer.class, 113cdf0e10cSrcweir oObj.getPropertyValue("ImageMap")); 114cdf0e10cSrcweir int previous = imgMap.getCount(); 115cdf0e10cSrcweir log.println("Count (previous) " + previous); 116cdf0e10cSrcweir 117cdf0e10cSrcweir Object im = tEnv.getObjRelation("IMGMAP"); 118cdf0e10cSrcweir imgMap.insertByIndex(0, im); 119cdf0e10cSrcweir oObj.setPropertyValue("ImageMap", imgMap); 120cdf0e10cSrcweir imgMap = (XIndexContainer) UnoRuntime.queryInterface( 121cdf0e10cSrcweir XIndexContainer.class, 122cdf0e10cSrcweir oObj.getPropertyValue("ImageMap")); 123cdf0e10cSrcweir 124cdf0e10cSrcweir int after = imgMap.getCount(); 125cdf0e10cSrcweir log.println("Count (after) " + after); 126cdf0e10cSrcweir result = previous < after; 127cdf0e10cSrcweir } catch (Exception ex) { 128cdf0e10cSrcweir result = false; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir tRes.tested("ImageMap", result); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** 135cdf0e10cSrcweir * Creates a new random points sequence. 136cdf0e10cSrcweir */ 137cdf0e10cSrcweir public Point[][] newPoint() { 138cdf0e10cSrcweir Point[][] res = new Point[1][185]; 139cdf0e10cSrcweir 140cdf0e10cSrcweir for (int i = 0; i < res[0].length; i++) { 141cdf0e10cSrcweir res[0][i] = new Point(); 142cdf0e10cSrcweir res[0][i].X = rd() * rd() * rd(); 143cdf0e10cSrcweir res[0][i].Y = rd() * rd() * rd(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir return res; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir public int rd() { 150cdf0e10cSrcweir return rdm.nextInt(6); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir /** 154cdf0e10cSrcweir * Changes the existing point sequence. 155cdf0e10cSrcweir */ 156cdf0e10cSrcweir public Point[][] changePoint(Point[][] oldPoint) { 157cdf0e10cSrcweir Point[][] res = oldPoint; 158cdf0e10cSrcweir 159cdf0e10cSrcweir for (int i = 0; i < res[0].length; i++) { 160cdf0e10cSrcweir res[0][i].X += 1; 161cdf0e10cSrcweir res[0][i].Y += 1; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir return res; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir } // finish class _TextGraphicObject 167