xref: /AOO41X/main/qadevOOo/tests/java/ifc/style/_CharacterProperties.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 
28*cdf0e10cSrcweir package ifc.style;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
31*cdf0e10cSrcweir import com.sun.star.container.XNameContainer;
32*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
33*cdf0e10cSrcweir import com.sun.star.uno.Type;
34*cdf0e10cSrcweir import com.sun.star.xml.AttributeData;
35*cdf0e10cSrcweir import java.util.Enumeration;
36*cdf0e10cSrcweir import java.util.Hashtable;
37*cdf0e10cSrcweir import lib.MultiPropertyTest;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir import util.ValueChanger;
40*cdf0e10cSrcweir import util.utils;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /**
44*cdf0e10cSrcweir * Testing <code>com.sun.star.style.CharacterProperties</code>
45*cdf0e10cSrcweir * service properties :
46*cdf0e10cSrcweir * <ul>
47*cdf0e10cSrcweir *  <li><code> CharFontName</code></li>
48*cdf0e10cSrcweir *  <li><code> CharFontStyleName</code></li>
49*cdf0e10cSrcweir *  <li><code> CharFontFamily</code></li>
50*cdf0e10cSrcweir *  <li><code> CharFontCharSet</code></li>
51*cdf0e10cSrcweir *  <li><code> CharFontPitch</code></li>
52*cdf0e10cSrcweir *  <li><code> CharColor</code></li>
53*cdf0e10cSrcweir *  <li><code> CharEscapement</code></li>
54*cdf0e10cSrcweir *  <li><code> CharHeight</code></li>
55*cdf0e10cSrcweir *  <li><code> CharUnderline</code></li>
56*cdf0e10cSrcweir *  <li><code> CharWeight</code></li>
57*cdf0e10cSrcweir *  <li><code> CharPosture</code></li>
58*cdf0e10cSrcweir *  <li><code> CharAutoKerning</code></li>
59*cdf0e10cSrcweir *  <li><code> CharBackColor</code></li>
60*cdf0e10cSrcweir *  <li><code> CharBackTransparent</code></li>
61*cdf0e10cSrcweir *  <li><code> CharCaseMap</code></li>
62*cdf0e10cSrcweir *  <li><code> CharCrossedOut</code></li>
63*cdf0e10cSrcweir *  <li><code> CharFlash</code></li>
64*cdf0e10cSrcweir *  <li><code> CharStrikeout</code></li>
65*cdf0e10cSrcweir *  <li><code> CharWordMode</code></li>
66*cdf0e10cSrcweir *  <li><code> CharKerning</code></li>
67*cdf0e10cSrcweir *  <li><code> CharLocale</code></li>
68*cdf0e10cSrcweir *  <li><code> CharKeepTogether</code></li>
69*cdf0e10cSrcweir *  <li><code> CharNoLineBreak</code></li>
70*cdf0e10cSrcweir *  <li><code> CharShadowed</code></li>
71*cdf0e10cSrcweir *  <li><code> CharFontType</code></li>
72*cdf0e10cSrcweir *  <li><code> CharStyleName</code></li>
73*cdf0e10cSrcweir *  <li><code> CharContoured</code></li>
74*cdf0e10cSrcweir *  <li><code> CharCombineIsOn</code></li>
75*cdf0e10cSrcweir *  <li><code> CharCombinePrefix</code></li>
76*cdf0e10cSrcweir *  <li><code> CharCombineSuffix</code></li>
77*cdf0e10cSrcweir *  <li><code> CharEmphasize</code></li>
78*cdf0e10cSrcweir *  <li><code> CharRelief</code></li>
79*cdf0e10cSrcweir *  <li><code> RubyText</code></li>
80*cdf0e10cSrcweir *  <li><code> RubyAdjust</code></li>
81*cdf0e10cSrcweir *  <li><code> RubyCharStyleName</code></li>
82*cdf0e10cSrcweir *  <li><code> RubyIsAbove</code></li>
83*cdf0e10cSrcweir *  <li><code> CharRotation</code></li>
84*cdf0e10cSrcweir *  <li><code> CharRotationIsFitToLine</code></li>
85*cdf0e10cSrcweir *  <li><code> CharScaleWidth</code></li>
86*cdf0e10cSrcweir *  <li><code> HyperLinkURL</code></li>
87*cdf0e10cSrcweir *  <li><code> HyperLinkTarget</code></li>
88*cdf0e10cSrcweir *  <li><code> HyperLinkName</code></li>
89*cdf0e10cSrcweir *  <li><code> TextUserDefinedAttributes</code></li>
90*cdf0e10cSrcweir * </ul> <p>
91*cdf0e10cSrcweir * This test needs the following object relations :
92*cdf0e10cSrcweir * <ul>
93*cdf0e10cSrcweir *  <li> <code>'PARA'</code>: <b>optional</b>
94*cdf0e10cSrcweir *   (must implement <code>XPropertySet</code>):
95*cdf0e10cSrcweir *   if this relation is specified then some properties
96*cdf0e10cSrcweir *   testing is performed in a special manner. (e.g. this used in
97*cdf0e10cSrcweir *   <code>sw.SwXParagraph</code> component) For details
98*cdf0e10cSrcweir *   see {@link #changeProp} method description. </li>
99*cdf0e10cSrcweir *  <li> <code>'PORTION'</code>: <b>optional</b>
100*cdf0e10cSrcweir *   (must implement <code>XPropertySet</code>):
101*cdf0e10cSrcweir *   if this relation is specified then some properties
102*cdf0e10cSrcweir *   testing is performed in a special manner. (e.g. this used in
103*cdf0e10cSrcweir *   <code>sw.SwXParagraph</code> component) For details
104*cdf0e10cSrcweir *   see {@link #changeProp} method description. </li>
105*cdf0e10cSrcweir * <ul> <p>
106*cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
107*cdf0e10cSrcweir * @see com.sun.star.style.CharacterProperties
108*cdf0e10cSrcweir */
109*cdf0e10cSrcweir public class _CharacterProperties extends MultiPropertyTest {
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     public void _CharFontName() {
112*cdf0e10cSrcweir         testProperty("CharFontName", "Times New Roman", "Arial") ;
113*cdf0e10cSrcweir     }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     public void _CharHeight() {
116*cdf0e10cSrcweir         testProperty("CharHeight", new PropertyTester() {
117*cdf0e10cSrcweir             protected Object getNewValue(String propName, Object old) {
118*cdf0e10cSrcweir                 if (utils.isVoid(old)) {
119*cdf0e10cSrcweir                     return new Float(10) ;
120*cdf0e10cSrcweir                 } else {
121*cdf0e10cSrcweir                     return new Float(((Float) old).floatValue() + 10) ;
122*cdf0e10cSrcweir                 }
123*cdf0e10cSrcweir             }
124*cdf0e10cSrcweir         }) ;
125*cdf0e10cSrcweir     }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     /**
128*cdf0e10cSrcweir      * Custom tester for properties which contains image URLs.
129*cdf0e10cSrcweir      * Switches between two JPG images' URLs.
130*cdf0e10cSrcweir      */
131*cdf0e10cSrcweir     protected PropertyTester URLTester = new PropertyTester() {
132*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
133*cdf0e10cSrcweir             if (oldValue.equals("http://www.sun.com"))
134*cdf0e10cSrcweir                 return "http://www.openoffice.org"; else
135*cdf0e10cSrcweir                 return "http://www.sun.com";
136*cdf0e10cSrcweir         }
137*cdf0e10cSrcweir     } ;
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     public void _HyperLinkURL() {
140*cdf0e10cSrcweir         testProperty("HyperLinkURL", URLTester) ;
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     public void _HyperLinkName() {
144*cdf0e10cSrcweir         testProperty("HyperLinkName", URLTester) ;
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     public void _HyperLinkTarget() {
148*cdf0e10cSrcweir         testProperty("HyperLinkTarget", URLTester) ;
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     public void _CharWeight() {
152*cdf0e10cSrcweir         testProperty("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD),
153*cdf0e10cSrcweir             new Float(com.sun.star.awt.FontWeight.THIN)) ;
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     public void _CharPosture() {
157*cdf0e10cSrcweir         testProperty("CharPosture", com.sun.star.awt.FontSlant.ITALIC,
158*cdf0e10cSrcweir             com.sun.star.awt.FontSlant.NONE) ;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     /**
162*cdf0e10cSrcweir      * Custom tester for style name properties. If object relations "STYLENAME1"
163*cdf0e10cSrcweir      * and "STYLENAME2" exists, then testing with these strings, else switches
164*cdf0e10cSrcweir      * between 'Citation' and 'Emphasis' names.
165*cdf0e10cSrcweir      */
166*cdf0e10cSrcweir     protected PropertyTester StyleTester = new PropertyTester() {
167*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
168*cdf0e10cSrcweir             String oStyleName1 = (String) tEnv.getObjRelation("STYLENAME1");
169*cdf0e10cSrcweir             String oStyleName2 = (String) tEnv.getObjRelation("STYLENAME2");
170*cdf0e10cSrcweir             if ((oStyleName1 != null) && (oStyleName2 != null)){
171*cdf0e10cSrcweir                 log.println("use strings given by object relation: '"
172*cdf0e10cSrcweir                             + oStyleName1 + "' '" + oStyleName2 +"'");
173*cdf0e10cSrcweir                 if (oldValue.equals( oStyleName1))
174*cdf0e10cSrcweir                     return oStyleName2;
175*cdf0e10cSrcweir                 else
176*cdf0e10cSrcweir                     return oStyleName1;
177*cdf0e10cSrcweir             }
178*cdf0e10cSrcweir             if (utils.isVoid(oldValue) || (oldValue.equals("Standard")))
179*cdf0e10cSrcweir                 return "Example"; else
180*cdf0e10cSrcweir                 return "Emphasis";
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir     } ;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     /**
185*cdf0e10cSrcweir      * Custom tester for style names properties. Switches between
186*cdf0e10cSrcweir      * 'Citation' and 'Emphasis' names.
187*cdf0e10cSrcweir      */
188*cdf0e10cSrcweir     protected PropertyTester StylesTester = new PropertyTester() {
189*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
190*cdf0e10cSrcweir             if (utils.isVoid(oldValue) || (oldValue.equals("Standard")))
191*cdf0e10cSrcweir                 return new String[] {"Citation"}; else
192*cdf0e10cSrcweir                 return new String[] {"Emphasis"};
193*cdf0e10cSrcweir         }
194*cdf0e10cSrcweir     } ;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     /**
197*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
198*cdf0e10cSrcweir      * of this property performed using these objects, else
199*cdf0e10cSrcweir      * testing is performed in common way.
200*cdf0e10cSrcweir      */
201*cdf0e10cSrcweir     public void _CharStyleName() {
202*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
203*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
204*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
205*cdf0e10cSrcweir         if (oPara == null) {
206*cdf0e10cSrcweir             testProperty("CharStyleName", StyleTester) ;
207*cdf0e10cSrcweir         } else {
208*cdf0e10cSrcweir             changeProp((XPropertySet) oPara,
209*cdf0e10cSrcweir                 (XPropertySet) oPort,"CharStyleName","Standard");
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     /**
214*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
215*cdf0e10cSrcweir      * of this property performed using these objects, else
216*cdf0e10cSrcweir      * testing is performed in common way.
217*cdf0e10cSrcweir      */
218*cdf0e10cSrcweir     public void _CharStyleNames() {
219*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
220*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
221*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
222*cdf0e10cSrcweir         if (oPara == null) {
223*cdf0e10cSrcweir             testProperty("CharStyleNames", StylesTester) ;
224*cdf0e10cSrcweir         } else {
225*cdf0e10cSrcweir             String[] newNames = {"Standard"};
226*cdf0e10cSrcweir             changeProp((XPropertySet) oPara,
227*cdf0e10cSrcweir                (XPropertySet) oPort,"CharStyleNames",new String[] {"Standard"});
228*cdf0e10cSrcweir         }
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     /**
232*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
233*cdf0e10cSrcweir      * of this property performed using these objects, else
234*cdf0e10cSrcweir      * testing is performed in common way.
235*cdf0e10cSrcweir      */
236*cdf0e10cSrcweir     public void _RubyCharStyleName() {
237*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
238*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
239*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
240*cdf0e10cSrcweir         if (oPara == null) {
241*cdf0e10cSrcweir             testProperty("RubyCharStyleName", StyleTester) ;
242*cdf0e10cSrcweir         } else {
243*cdf0e10cSrcweir             changeProp((XPropertySet) oPara, (XPropertySet)
244*cdf0e10cSrcweir                 oPort,"RubyCharStyleName","Standard");
245*cdf0e10cSrcweir         }
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     /**
249*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
250*cdf0e10cSrcweir      * of this property performed using these objects, else
251*cdf0e10cSrcweir      * testing is performed in common way.
252*cdf0e10cSrcweir      */
253*cdf0e10cSrcweir     public void _RubyAdjust() {
254*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
255*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
256*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
257*cdf0e10cSrcweir         if (oPara == null) {
258*cdf0e10cSrcweir             testProperty("RubyAdjust",new Short((short)0),new Short((short)1));
259*cdf0e10cSrcweir         } else {
260*cdf0e10cSrcweir             Short aShort = new Short((short) 1);
261*cdf0e10cSrcweir             changeProp((XPropertySet) oPara,
262*cdf0e10cSrcweir                 (XPropertySet) oPort,"RubyAdjust", aShort);
263*cdf0e10cSrcweir         }
264*cdf0e10cSrcweir         Short aShort = new Short((short) 1);
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     /**
268*cdf0e10cSrcweir      * Custom tester for the ruby text property.
269*cdf0e10cSrcweir      */
270*cdf0e10cSrcweir     protected PropertyTester RubyTextTester = new PropertyTester() {
271*cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue)
272*cdf0e10cSrcweir                 throws java.lang.IllegalArgumentException {
273*cdf0e10cSrcweir             if (utils.isVoid(oldValue)) {
274*cdf0e10cSrcweir                 return new String("RubyText");
275*cdf0e10cSrcweir             } else {
276*cdf0e10cSrcweir                 return ValueChanger.changePValue(oldValue);
277*cdf0e10cSrcweir             }
278*cdf0e10cSrcweir         }
279*cdf0e10cSrcweir     } ;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     /**
282*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
283*cdf0e10cSrcweir      * of this property performed using these objects, else
284*cdf0e10cSrcweir      * testing is performed in common way.
285*cdf0e10cSrcweir      */
286*cdf0e10cSrcweir     public void _RubyText() {
287*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
288*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
289*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
290*cdf0e10cSrcweir         if (oPara == null) {
291*cdf0e10cSrcweir             testProperty("RubyText", RubyTextTester) ;
292*cdf0e10cSrcweir         } else {
293*cdf0e10cSrcweir             changeProp((XPropertySet) oPara, (XPropertySet) oPort,
294*cdf0e10cSrcweir                 "RubyText","");
295*cdf0e10cSrcweir         }
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir     /**
299*cdf0e10cSrcweir      * If relations for paragraph and portion exist, then testing
300*cdf0e10cSrcweir      * of this property performed using these objects, else
301*cdf0e10cSrcweir      * testing is performed in common way.
302*cdf0e10cSrcweir      */
303*cdf0e10cSrcweir     public void _RubyIsAbove() {
304*cdf0e10cSrcweir         log.println("Testing with custom Property tester") ;
305*cdf0e10cSrcweir         Object oPara = tEnv.getObjRelation("PARA");
306*cdf0e10cSrcweir         Object oPort = tEnv.getObjRelation("PORTION");
307*cdf0e10cSrcweir         if (oPara == null) {
308*cdf0e10cSrcweir             testProperty("RubyIsAbove") ;
309*cdf0e10cSrcweir         } else {
310*cdf0e10cSrcweir             changeProp((XPropertySet) oPara, (XPropertySet) oPort,
311*cdf0e10cSrcweir                 "RubyIsAbove",new Boolean(true));
312*cdf0e10cSrcweir         }
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     /**
316*cdf0e10cSrcweir     * This property only takes values between 0..100
317*cdf0e10cSrcweir     * so ist must be treated special
318*cdf0e10cSrcweir     */
319*cdf0e10cSrcweir     public void _CharEscapementHeight() {
320*cdf0e10cSrcweir         Byte aByte = new Byte((byte)75);
321*cdf0e10cSrcweir         Byte max = new Byte((byte)100);
322*cdf0e10cSrcweir         testProperty("CharEscapementHeight", aByte, max) ;
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     /**
327*cdf0e10cSrcweir     * This property can be void, so if old value is <code> null </code>
328*cdf0e10cSrcweir     * new value must be specified.
329*cdf0e10cSrcweir     */
330*cdf0e10cSrcweir     public void _CharRotation() {
331*cdf0e10cSrcweir         Short aShort = new Short((short) 10);
332*cdf0e10cSrcweir         changeProp(oObj,oObj, "CharRotation", aShort);
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     /**
336*cdf0e10cSrcweir      * Tests the property specified by <code>name</code> using
337*cdf0e10cSrcweir      * property set <code>oProps</code>, but value after setting
338*cdf0e10cSrcweir      * this property to a new value is checked using another
339*cdf0e10cSrcweir      * PropertySet <code>get</code>. Special cases used for
340*cdf0e10cSrcweir      * <code>CharRotation</code> property (it can have only certain values
341*cdf0e10cSrcweir      * 0, 900, ...), and for  <code>*StyleName</code> properties
342*cdf0e10cSrcweir      * (only existing style names are accepted)
343*cdf0e10cSrcweir      * @param oProps PropertySet from which property value is get
344*cdf0e10cSrcweir      * changed and set.
345*cdf0e10cSrcweir      * @param get PropertySet where property value is checked after
346*cdf0e10cSrcweir      * setting.
347*cdf0e10cSrcweir      * @param name Propety name to test.
348*cdf0e10cSrcweir      * @param newVal Value used to set as new property value if
349*cdf0e10cSrcweir      * the value get is null.
350*cdf0e10cSrcweir      */
351*cdf0e10cSrcweir     public void changeProp(XPropertySet oProps,
352*cdf0e10cSrcweir             XPropertySet get,String name, Object newVal) {
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         Object gValue = null;
355*cdf0e10cSrcweir         Object sValue = null;
356*cdf0e10cSrcweir         Object ValueToSet = null;
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir         try {
359*cdf0e10cSrcweir             //waitForAllThreads();
360*cdf0e10cSrcweir             gValue = oProps.getPropertyValue(name);
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir             if ( (gValue == null) || (utils.isVoid(gValue)) ) {
363*cdf0e10cSrcweir                 log.println("Value for "+name+" is NULL");
364*cdf0e10cSrcweir                 gValue = newVal;
365*cdf0e10cSrcweir             }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir             //waitForAllThreads();
368*cdf0e10cSrcweir             if (name.equals("CharRotation")) {
369*cdf0e10cSrcweir                 Short s1 = new Short((short) 0);
370*cdf0e10cSrcweir                 Short s2 = new Short((short) 900);
371*cdf0e10cSrcweir                 if (gValue.equals(s1)) {
372*cdf0e10cSrcweir                     ValueToSet = s2;
373*cdf0e10cSrcweir                 } else {
374*cdf0e10cSrcweir                     ValueToSet = s1;
375*cdf0e10cSrcweir                 }
376*cdf0e10cSrcweir             } else {
377*cdf0e10cSrcweir                 ValueToSet = ValueChanger.changePValue(gValue);
378*cdf0e10cSrcweir             }
379*cdf0e10cSrcweir             if (name.endsWith("StyleName")) {
380*cdf0e10cSrcweir                 if ( ((String) gValue).equals("Standard") ) {
381*cdf0e10cSrcweir                     ValueToSet="Main index entry";
382*cdf0e10cSrcweir                 }
383*cdf0e10cSrcweir                 else {
384*cdf0e10cSrcweir                     ValueToSet="Emphasis";
385*cdf0e10cSrcweir                 }
386*cdf0e10cSrcweir             }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir             //waitForAllThreads();
389*cdf0e10cSrcweir             oProps.setPropertyValue(name,ValueToSet);
390*cdf0e10cSrcweir             sValue = get.getPropertyValue(name);
391*cdf0e10cSrcweir             if (sValue == null) {
392*cdf0e10cSrcweir                 log.println("Value for "+name+" is NULL after setting");
393*cdf0e10cSrcweir                 sValue = gValue;
394*cdf0e10cSrcweir             }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir             //check get-set methods
397*cdf0e10cSrcweir             if (gValue.equals(sValue)) {
398*cdf0e10cSrcweir                 log.println("Value for '"+name+"' hasn't changed");
399*cdf0e10cSrcweir                 tRes.tested(name, false);
400*cdf0e10cSrcweir             } else {
401*cdf0e10cSrcweir                 log.println("Property '"+name+"' OK");
402*cdf0e10cSrcweir                 log.println("old: "+gValue.toString());
403*cdf0e10cSrcweir                 log.println("new: "+ValueToSet.toString());
404*cdf0e10cSrcweir                 log.println("result: "+sValue.toString());
405*cdf0e10cSrcweir                 tRes.tested(name, true);
406*cdf0e10cSrcweir             }
407*cdf0e10cSrcweir         }
408*cdf0e10cSrcweir         catch (com.sun.star.beans.UnknownPropertyException ex) {
409*cdf0e10cSrcweir             if (isOptional(name)) {
410*cdf0e10cSrcweir                 log.println("Property '"+name+
411*cdf0e10cSrcweir                     "' is optional and not supported");
412*cdf0e10cSrcweir                 tRes.tested(name,true);
413*cdf0e10cSrcweir             }
414*cdf0e10cSrcweir             else {
415*cdf0e10cSrcweir                 log.println("Exception occured while testing property '" +
416*cdf0e10cSrcweir                      name + "'");
417*cdf0e10cSrcweir                 ex.printStackTrace(log);
418*cdf0e10cSrcweir                 tRes.tested(name, false);
419*cdf0e10cSrcweir             }
420*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
421*cdf0e10cSrcweir             log.println("Exception occured while testing property '" +
422*cdf0e10cSrcweir                 name + "'");
423*cdf0e10cSrcweir             e.printStackTrace(log);
424*cdf0e10cSrcweir             tRes.tested(name, false);
425*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
426*cdf0e10cSrcweir             log.println("Exception occured while testing property '" +
427*cdf0e10cSrcweir                  name + "'");
428*cdf0e10cSrcweir             e.printStackTrace(log);
429*cdf0e10cSrcweir             tRes.tested(name, false);
430*cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
431*cdf0e10cSrcweir             log.println("Exception occured while testing property '" +
432*cdf0e10cSrcweir                  name + "'");
433*cdf0e10cSrcweir             e.printStackTrace(log);
434*cdf0e10cSrcweir             tRes.tested(name, false);
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir     }// end of changeProp
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     public void _TextUserDefinedAttributes() {
439*cdf0e10cSrcweir         XNameContainer uda = null;
440*cdf0e10cSrcweir         boolean res = false;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         try {
443*cdf0e10cSrcweir             try{
444*cdf0e10cSrcweir                 uda = (XNameContainer) AnyConverter.toObject(
445*cdf0e10cSrcweir                           new Type(XNameContainer.class),
446*cdf0e10cSrcweir                           oObj.getPropertyValue("TextUserDefinedAttributes"));
447*cdf0e10cSrcweir             } catch (com.sun.star.lang.IllegalArgumentException e){
448*cdf0e10cSrcweir                 log.println("TextUserDefinedAttributes is empty.");
449*cdf0e10cSrcweir                 uda = new _CharacterProperties.OwnUserDefinedAttributes();
450*cdf0e10cSrcweir             }
451*cdf0e10cSrcweir             AttributeData attr = new AttributeData();
452*cdf0e10cSrcweir             attr.Namespace = "http://www.sun.com/staroffice/apitest/Cellprop";
453*cdf0e10cSrcweir             attr.Type = "CDATA";
454*cdf0e10cSrcweir             attr.Value = "true";
455*cdf0e10cSrcweir             uda.insertByName("Cellprop:has-first-alien-attribute", attr);
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir             String[] els = uda.getElementNames();
458*cdf0e10cSrcweir             oObj.setPropertyValue("TextUserDefinedAttributes", uda);
459*cdf0e10cSrcweir             uda = (XNameContainer) AnyConverter.toObject(
460*cdf0e10cSrcweir                           new Type(XNameContainer.class),
461*cdf0e10cSrcweir                           oObj.getPropertyValue("TextUserDefinedAttributes"));
462*cdf0e10cSrcweir             els = uda.getElementNames();
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir             Object obj = uda.getByName("Cellprop:has-first-alien-attribute");
465*cdf0e10cSrcweir             res = true;
466*cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException upe) {
467*cdf0e10cSrcweir             if (isOptional("TextUserDefinedAttributes")) {
468*cdf0e10cSrcweir                 log.println("Property is optional and not supported");
469*cdf0e10cSrcweir                 res = true;
470*cdf0e10cSrcweir             } else {
471*cdf0e10cSrcweir                 log.println("Don't know the Property 'TextUserDefinedAttributes'");
472*cdf0e10cSrcweir             }
473*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException wte) {
474*cdf0e10cSrcweir             log.println(
475*cdf0e10cSrcweir                     "WrappedTargetException while getting Property 'TextUserDefinedAttributes'");
476*cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException nee) {
477*cdf0e10cSrcweir             log.println("added Element isn't part of the NameContainer");
478*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException iae) {
479*cdf0e10cSrcweir             log.println(
480*cdf0e10cSrcweir                     "IllegalArgumentException while getting Property 'TextUserDefinedAttributes'");
481*cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException pve) {
482*cdf0e10cSrcweir             log.println(
483*cdf0e10cSrcweir                     "PropertyVetoException while getting Property 'TextUserDefinedAttributes'");
484*cdf0e10cSrcweir         } catch (com.sun.star.container.ElementExistException eee) {
485*cdf0e10cSrcweir             log.println(
486*cdf0e10cSrcweir                     "ElementExistException while getting Property 'TextUserDefinedAttributes'");
487*cdf0e10cSrcweir         }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir         tRes.tested("TextUserDefinedAttributes", res);
490*cdf0e10cSrcweir     }
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir     private class OwnUserDefinedAttributes implements XNameContainer{
493*cdf0e10cSrcweir         Hashtable members = null;
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir         public OwnUserDefinedAttributes() {
497*cdf0e10cSrcweir             members = new Hashtable();
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir         public Object getByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
501*cdf0e10cSrcweir             return members.get(str);
502*cdf0e10cSrcweir         }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir         public String[] getElementNames() {
505*cdf0e10cSrcweir             Enumeration oEnum = members.keys();
506*cdf0e10cSrcweir             int count = members.size();
507*cdf0e10cSrcweir             String[] res = new String[count];
508*cdf0e10cSrcweir             int i=0;
509*cdf0e10cSrcweir             while(oEnum.hasMoreElements())
510*cdf0e10cSrcweir                 res[i] = (String)oEnum.nextElement();
511*cdf0e10cSrcweir             return res;
512*cdf0e10cSrcweir         }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir         public com.sun.star.uno.Type getElementType() {
515*cdf0e10cSrcweir             Enumeration oEnum = members.keys();
516*cdf0e10cSrcweir             String key = (String)oEnum.nextElement();
517*cdf0e10cSrcweir             Object o = members.get(key);
518*cdf0e10cSrcweir             return new Type(o.getClass());
519*cdf0e10cSrcweir         }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir         public boolean hasByName(String str) {
522*cdf0e10cSrcweir             return members.get(str) != null;
523*cdf0e10cSrcweir         }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir         public boolean hasElements() {
526*cdf0e10cSrcweir             return members.size() > 0;
527*cdf0e10cSrcweir         }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir         public void insertByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.ElementExistException, com.sun.star.lang.WrappedTargetException {
530*cdf0e10cSrcweir             members.put(str, obj);
531*cdf0e10cSrcweir         }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir         public void removeByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
534*cdf0e10cSrcweir             members.remove(str);
535*cdf0e10cSrcweir         }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir         public void replaceByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
538*cdf0e10cSrcweir             members.put(str, obj);
539*cdf0e10cSrcweir         }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     }
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir } //finish class _CharacterProperties
544*cdf0e10cSrcweir 
545