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