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