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