Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / style / _CharacterProperties.java
blob91c1c4f23c0a3842f554f5a18bd07bf2a3a64970
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _CharacterProperties.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.style;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.container.XNameContainer;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.xml.AttributeData;
38 import java.util.Enumeration;
39 import java.util.Hashtable;
40 import lib.MultiPropertyTest;
42 import util.ValueChanger;
43 import util.utils;
46 /**
47 * Testing <code>com.sun.star.style.CharacterProperties</code>
48 * service properties :
49 * <ul>
50 * <li><code> CharFontName</code></li>
51 * <li><code> CharFontStyleName</code></li>
52 * <li><code> CharFontFamily</code></li>
53 * <li><code> CharFontCharSet</code></li>
54 * <li><code> CharFontPitch</code></li>
55 * <li><code> CharColor</code></li>
56 * <li><code> CharEscapement</code></li>
57 * <li><code> CharHeight</code></li>
58 * <li><code> CharUnderline</code></li>
59 * <li><code> CharWeight</code></li>
60 * <li><code> CharPosture</code></li>
61 * <li><code> CharAutoKerning</code></li>
62 * <li><code> CharBackColor</code></li>
63 * <li><code> CharBackTransparent</code></li>
64 * <li><code> CharCaseMap</code></li>
65 * <li><code> CharCrossedOut</code></li>
66 * <li><code> CharFlash</code></li>
67 * <li><code> CharStrikeout</code></li>
68 * <li><code> CharWordMode</code></li>
69 * <li><code> CharKerning</code></li>
70 * <li><code> CharLocale</code></li>
71 * <li><code> CharKeepTogether</code></li>
72 * <li><code> CharNoLineBreak</code></li>
73 * <li><code> CharShadowed</code></li>
74 * <li><code> CharFontType</code></li>
75 * <li><code> CharStyleName</code></li>
76 * <li><code> CharContoured</code></li>
77 * <li><code> CharCombineIsOn</code></li>
78 * <li><code> CharCombinePrefix</code></li>
79 * <li><code> CharCombineSuffix</code></li>
80 * <li><code> CharEmphasize</code></li>
81 * <li><code> CharRelief</code></li>
82 * <li><code> RubyText</code></li>
83 * <li><code> RubyAdjust</code></li>
84 * <li><code> RubyCharStyleName</code></li>
85 * <li><code> RubyIsAbove</code></li>
86 * <li><code> CharRotation</code></li>
87 * <li><code> CharRotationIsFitToLine</code></li>
88 * <li><code> CharScaleWidth</code></li>
89 * <li><code> HyperLinkURL</code></li>
90 * <li><code> HyperLinkTarget</code></li>
91 * <li><code> HyperLinkName</code></li>
92 * <li><code> TextUserDefinedAttributes</code></li>
93 * </ul> <p>
94 * This test needs the following object relations :
95 * <ul>
96 * <li> <code>'PARA'</code>: <b>optional</b>
97 * (must implement <code>XPropertySet</code>):
98 * if this relation is specified then some properties
99 * testing is performed in a special manner. (e.g. this used in
100 * <code>sw.SwXParagraph</code> component) For details
101 * see {@link #changeProp} method description. </li>
102 * <li> <code>'PORTION'</code>: <b>optional</b>
103 * (must implement <code>XPropertySet</code>):
104 * if this relation is specified then some properties
105 * testing is performed in a special manner. (e.g. this used in
106 * <code>sw.SwXParagraph</code> component) For details
107 * see {@link #changeProp} method description. </li>
108 * <ul> <p>
109 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
110 * @see com.sun.star.style.CharacterProperties
112 public class _CharacterProperties extends MultiPropertyTest {
114 public void _CharFontName() {
115 testProperty("CharFontName", "Times New Roman", "Arial") ;
118 public void _CharHeight() {
119 testProperty("CharHeight", new PropertyTester() {
120 protected Object getNewValue(String propName, Object old) {
121 if (utils.isVoid(old)) {
122 return new Float(10) ;
123 } else {
124 return new Float(((Float) old).floatValue() + 10) ;
127 }) ;
131 * Custom tester for properties which contains image URLs.
132 * Switches between two JPG images' URLs.
134 protected PropertyTester URLTester = new PropertyTester() {
135 protected Object getNewValue(String propName, Object oldValue) {
136 if (oldValue.equals("http://www.sun.com"))
137 return "http://www.openoffice.org"; else
138 return "http://www.sun.com";
142 public void _HyperLinkURL() {
143 testProperty("HyperLinkURL", URLTester) ;
146 public void _HyperLinkName() {
147 testProperty("HyperLinkName", URLTester) ;
150 public void _HyperLinkTarget() {
151 testProperty("HyperLinkTarget", URLTester) ;
154 public void _CharWeight() {
155 testProperty("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD),
156 new Float(com.sun.star.awt.FontWeight.THIN)) ;
159 public void _CharPosture() {
160 testProperty("CharPosture", com.sun.star.awt.FontSlant.ITALIC,
161 com.sun.star.awt.FontSlant.NONE) ;
165 * Custom tester for style name properties. If object relations "STYLENAME1"
166 * and "STYLENAME2" exists, then testing with these strings, else switches
167 * between 'Citation' and 'Emphasis' names.
169 protected PropertyTester StyleTester = new PropertyTester() {
170 protected Object getNewValue(String propName, Object oldValue) {
171 String oStyleName1 = (String) tEnv.getObjRelation("STYLENAME1");
172 String oStyleName2 = (String) tEnv.getObjRelation("STYLENAME2");
173 if ((oStyleName1 != null) && (oStyleName2 != null)){
174 log.println("use strings given by object relation: '"
175 + oStyleName1 + "' '" + oStyleName2 +"'");
176 if (oldValue.equals( oStyleName1))
177 return oStyleName2;
178 else
179 return oStyleName1;
181 if (utils.isVoid(oldValue) || (oldValue.equals("Standard")))
182 return "Example"; else
183 return "Emphasis";
188 * Custom tester for style names properties. Switches between
189 * 'Citation' and 'Emphasis' names.
191 protected PropertyTester StylesTester = new PropertyTester() {
192 protected Object getNewValue(String propName, Object oldValue) {
193 if (utils.isVoid(oldValue) || (oldValue.equals("Standard")))
194 return new String[] {"Citation"}; else
195 return new String[] {"Emphasis"};
200 * If relations for paragraph and portion exist, then testing
201 * of this property performed using these objects, else
202 * testing is performed in common way.
204 public void _CharStyleName() {
205 log.println("Testing with custom Property tester") ;
206 Object oPara = tEnv.getObjRelation("PARA");
207 Object oPort = tEnv.getObjRelation("PORTION");
208 if (oPara == null) {
209 testProperty("CharStyleName", StyleTester) ;
210 } else {
211 changeProp((XPropertySet) oPara,
212 (XPropertySet) oPort,"CharStyleName","Standard");
217 * If relations for paragraph and portion exist, then testing
218 * of this property performed using these objects, else
219 * testing is performed in common way.
221 public void _CharStyleNames() {
222 log.println("Testing with custom Property tester") ;
223 Object oPara = tEnv.getObjRelation("PARA");
224 Object oPort = tEnv.getObjRelation("PORTION");
225 if (oPara == null) {
226 testProperty("CharStyleNames", StylesTester) ;
227 } else {
228 String[] newNames = {"Standard"};
229 changeProp((XPropertySet) oPara,
230 (XPropertySet) oPort,"CharStyleNames",new String[] {"Standard"});
235 * If relations for paragraph and portion exist, then testing
236 * of this property performed using these objects, else
237 * testing is performed in common way.
239 public void _RubyCharStyleName() {
240 log.println("Testing with custom Property tester") ;
241 Object oPara = tEnv.getObjRelation("PARA");
242 Object oPort = tEnv.getObjRelation("PORTION");
243 if (oPara == null) {
244 testProperty("RubyCharStyleName", StyleTester) ;
245 } else {
246 changeProp((XPropertySet) oPara, (XPropertySet)
247 oPort,"RubyCharStyleName","Standard");
252 * If relations for paragraph and portion exist, then testing
253 * of this property performed using these objects, else
254 * testing is performed in common way.
256 public void _RubyAdjust() {
257 log.println("Testing with custom Property tester") ;
258 Object oPara = tEnv.getObjRelation("PARA");
259 Object oPort = tEnv.getObjRelation("PORTION");
260 if (oPara == null) {
261 testProperty("RubyAdjust",new Short((short)0),new Short((short)1));
262 } else {
263 Short aShort = new Short((short) 1);
264 changeProp((XPropertySet) oPara,
265 (XPropertySet) oPort,"RubyAdjust", aShort);
267 Short aShort = new Short((short) 1);
271 * Custom tester for the ruby text property.
273 protected PropertyTester RubyTextTester = new PropertyTester() {
274 protected Object getNewValue(String propName, Object oldValue)
275 throws java.lang.IllegalArgumentException {
276 if (utils.isVoid(oldValue)) {
277 return new String("RubyText");
278 } else {
279 return ValueChanger.changePValue(oldValue);
285 * If relations for paragraph and portion exist, then testing
286 * of this property performed using these objects, else
287 * testing is performed in common way.
289 public void _RubyText() {
290 log.println("Testing with custom Property tester") ;
291 Object oPara = tEnv.getObjRelation("PARA");
292 Object oPort = tEnv.getObjRelation("PORTION");
293 if (oPara == null) {
294 testProperty("RubyText", RubyTextTester) ;
295 } else {
296 changeProp((XPropertySet) oPara, (XPropertySet) oPort,
297 "RubyText","");
302 * If relations for paragraph and portion exist, then testing
303 * of this property performed using these objects, else
304 * testing is performed in common way.
306 public void _RubyIsAbove() {
307 log.println("Testing with custom Property tester") ;
308 Object oPara = tEnv.getObjRelation("PARA");
309 Object oPort = tEnv.getObjRelation("PORTION");
310 if (oPara == null) {
311 testProperty("RubyIsAbove") ;
312 } else {
313 changeProp((XPropertySet) oPara, (XPropertySet) oPort,
314 "RubyIsAbove",new Boolean(true));
319 * This property only takes values between 0..100
320 * so ist must be treated special
322 public void _CharEscapementHeight() {
323 Byte aByte = new Byte((byte)75);
324 Byte max = new Byte((byte)100);
325 testProperty("CharEscapementHeight", aByte, max) ;
330 * This property can be void, so if old value is <code> null </code>
331 * new value must be specified.
333 public void _CharRotation() {
334 Short aShort = new Short((short) 10);
335 changeProp(oObj,oObj, "CharRotation", aShort);
339 * Tests the property specified by <code>name</code> using
340 * property set <code>oProps</code>, but value after setting
341 * this property to a new value is checked using another
342 * PropertySet <code>get</code>. Special cases used for
343 * <code>CharRotation</code> property (it can have only certain values
344 * 0, 900, ...), and for <code>*StyleName</code> properties
345 * (only existing style names are accepted)
346 * @param oProps PropertySet from which property value is get
347 * changed and set.
348 * @param get PropertySet where property value is checked after
349 * setting.
350 * @param name Propety name to test.
351 * @param newVal Value used to set as new property value if
352 * the value get is null.
354 public void changeProp(XPropertySet oProps,
355 XPropertySet get,String name, Object newVal) {
357 Object gValue = null;
358 Object sValue = null;
359 Object ValueToSet = null;
361 try {
362 //waitForAllThreads();
363 gValue = oProps.getPropertyValue(name);
365 if ( (gValue == null) || (utils.isVoid(gValue)) ) {
366 log.println("Value for "+name+" is NULL");
367 gValue = newVal;
370 //waitForAllThreads();
371 if (name.equals("CharRotation")) {
372 Short s1 = new Short((short) 0);
373 Short s2 = new Short((short) 900);
374 if (gValue.equals(s1)) {
375 ValueToSet = s2;
376 } else {
377 ValueToSet = s1;
379 } else {
380 ValueToSet = ValueChanger.changePValue(gValue);
382 if (name.endsWith("StyleName")) {
383 if ( ((String) gValue).equals("Standard") ) {
384 ValueToSet="Main index entry";
386 else {
387 ValueToSet="Emphasis";
391 //waitForAllThreads();
392 oProps.setPropertyValue(name,ValueToSet);
393 sValue = get.getPropertyValue(name);
394 if (sValue == null) {
395 log.println("Value for "+name+" is NULL after setting");
396 sValue = gValue;
399 //check get-set methods
400 if (gValue.equals(sValue)) {
401 log.println("Value for '"+name+"' hasn't changed");
402 tRes.tested(name, false);
403 } else {
404 log.println("Property '"+name+"' OK");
405 log.println("old: "+gValue.toString());
406 log.println("new: "+ValueToSet.toString());
407 log.println("result: "+sValue.toString());
408 tRes.tested(name, true);
411 catch (com.sun.star.beans.UnknownPropertyException ex) {
412 if (isOptional(name)) {
413 log.println("Property '"+name+
414 "' is optional and not supported");
415 tRes.tested(name,true);
417 else {
418 log.println("Exception occured while testing property '" +
419 name + "'");
420 ex.printStackTrace(log);
421 tRes.tested(name, false);
423 } catch (com.sun.star.lang.WrappedTargetException e) {
424 log.println("Exception occured while testing property '" +
425 name + "'");
426 e.printStackTrace(log);
427 tRes.tested(name, false);
428 } catch (com.sun.star.lang.IllegalArgumentException e) {
429 log.println("Exception occured while testing property '" +
430 name + "'");
431 e.printStackTrace(log);
432 tRes.tested(name, false);
433 } catch (com.sun.star.beans.PropertyVetoException e) {
434 log.println("Exception occured while testing property '" +
435 name + "'");
436 e.printStackTrace(log);
437 tRes.tested(name, false);
439 }// end of changeProp
441 public void _TextUserDefinedAttributes() {
442 XNameContainer uda = null;
443 boolean res = false;
445 try {
446 try{
447 uda = (XNameContainer) AnyConverter.toObject(
448 new Type(XNameContainer.class),
449 oObj.getPropertyValue("TextUserDefinedAttributes"));
450 } catch (com.sun.star.lang.IllegalArgumentException e){
451 log.println("TextUserDefinedAttributes is empty.");
452 uda = new _CharacterProperties.OwnUserDefinedAttributes();
454 AttributeData attr = new AttributeData();
455 attr.Namespace = "http://www.sun.com/staroffice/apitest/Cellprop";
456 attr.Type = "CDATA";
457 attr.Value = "true";
458 uda.insertByName("Cellprop:has-first-alien-attribute", attr);
460 String[] els = uda.getElementNames();
461 oObj.setPropertyValue("TextUserDefinedAttributes", uda);
462 uda = (XNameContainer) AnyConverter.toObject(
463 new Type(XNameContainer.class),
464 oObj.getPropertyValue("TextUserDefinedAttributes"));
465 els = uda.getElementNames();
467 Object obj = uda.getByName("Cellprop:has-first-alien-attribute");
468 res = true;
469 } catch (com.sun.star.beans.UnknownPropertyException upe) {
470 if (isOptional("TextUserDefinedAttributes")) {
471 log.println("Property is optional and not supported");
472 res = true;
473 } else {
474 log.println("Don't know the Property 'TextUserDefinedAttributes'");
476 } catch (com.sun.star.lang.WrappedTargetException wte) {
477 log.println(
478 "WrappedTargetException while getting Property 'TextUserDefinedAttributes'");
479 } catch (com.sun.star.container.NoSuchElementException nee) {
480 log.println("added Element isn't part of the NameContainer");
481 } catch (com.sun.star.lang.IllegalArgumentException iae) {
482 log.println(
483 "IllegalArgumentException while getting Property 'TextUserDefinedAttributes'");
484 } catch (com.sun.star.beans.PropertyVetoException pve) {
485 log.println(
486 "PropertyVetoException while getting Property 'TextUserDefinedAttributes'");
487 } catch (com.sun.star.container.ElementExistException eee) {
488 log.println(
489 "ElementExistException while getting Property 'TextUserDefinedAttributes'");
492 tRes.tested("TextUserDefinedAttributes", res);
495 private class OwnUserDefinedAttributes implements XNameContainer{
496 Hashtable members = null;
499 public OwnUserDefinedAttributes() {
500 members = new Hashtable();
503 public Object getByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
504 return members.get(str);
507 public String[] getElementNames() {
508 Enumeration oEnum = members.keys();
509 int count = members.size();
510 String[] res = new String[count];
511 int i=0;
512 while(oEnum.hasMoreElements())
513 res[i] = (String)oEnum.nextElement();
514 return res;
517 public com.sun.star.uno.Type getElementType() {
518 Enumeration oEnum = members.keys();
519 String key = (String)oEnum.nextElement();
520 Object o = members.get(key);
521 return new Type(o.getClass());
524 public boolean hasByName(String str) {
525 return members.get(str) != null;
528 public boolean hasElements() {
529 return members.size() > 0;
532 public void insertByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.ElementExistException, com.sun.star.lang.WrappedTargetException {
533 members.put(str, obj);
536 public void removeByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
537 members.remove(str);
540 public void replaceByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
541 members.put(str, obj);
546 } //finish class _CharacterProperties