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