1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XNameContainer
;
32 import com
.sun
.star
.uno
.AnyConverter
;
33 import com
.sun
.star
.uno
.Type
;
34 import com
.sun
.star
.xml
.AttributeData
;
35 import java
.util
.Enumeration
;
36 import java
.util
.Hashtable
;
37 import lib
.MultiPropertyTest
;
39 import util
.ValueChanger
;
44 * Testing <code>com.sun.star.style.CharacterProperties</code>
45 * service properties :
47 * <li><code> CharFontName</code></li>
48 * <li><code> CharFontStyleName</code></li>
49 * <li><code> CharFontFamily</code></li>
50 * <li><code> CharFontCharSet</code></li>
51 * <li><code> CharFontPitch</code></li>
52 * <li><code> CharColor</code></li>
53 * <li><code> CharEscapement</code></li>
54 * <li><code> CharHeight</code></li>
55 * <li><code> CharUnderline</code></li>
56 * <li><code> CharWeight</code></li>
57 * <li><code> CharPosture</code></li>
58 * <li><code> CharAutoKerning</code></li>
59 * <li><code> CharBackColor</code></li>
60 * <li><code> CharBackTransparent</code></li>
61 * <li><code> CharCaseMap</code></li>
62 * <li><code> CharCrossedOut</code></li>
63 * <li><code> CharFlash</code></li>
64 * <li><code> CharStrikeout</code></li>
65 * <li><code> CharWordMode</code></li>
66 * <li><code> CharKerning</code></li>
67 * <li><code> CharLocale</code></li>
68 * <li><code> CharKeepTogether</code></li>
69 * <li><code> CharNoLineBreak</code></li>
70 * <li><code> CharShadowed</code></li>
71 * <li><code> CharFontType</code></li>
72 * <li><code> CharStyleName</code></li>
73 * <li><code> CharContoured</code></li>
74 * <li><code> CharCombineIsOn</code></li>
75 * <li><code> CharCombinePrefix</code></li>
76 * <li><code> CharCombineSuffix</code></li>
77 * <li><code> CharEmphasize</code></li>
78 * <li><code> CharRelief</code></li>
79 * <li><code> RubyText</code></li>
80 * <li><code> RubyAdjust</code></li>
81 * <li><code> RubyCharStyleName</code></li>
82 * <li><code> RubyIsAbove</code></li>
83 * <li><code> CharRotation</code></li>
84 * <li><code> CharRotationIsFitToLine</code></li>
85 * <li><code> CharScaleWidth</code></li>
86 * <li><code> HyperLinkURL</code></li>
87 * <li><code> HyperLinkTarget</code></li>
88 * <li><code> HyperLinkName</code></li>
89 * <li><code> TextUserDefinedAttributes</code></li>
91 * This test needs the following object relations :
93 * <li> <code>'PARA'</code>: <b>optional</b>
94 * (must implement <code>XPropertySet</code>):
95 * if this relation is specified then some properties
96 * testing is performed in a special manner. (e.g. this used in
97 * <code>sw.SwXParagraph</code> component) For details
98 * see {@link #changeProp} method description. </li>
99 * <li> <code>'PORTION'</code>: <b>optional</b>
100 * (must implement <code>XPropertySet</code>):
101 * if this relation is specified then some properties
102 * testing is performed in a special manner. (e.g. this used in
103 * <code>sw.SwXParagraph</code> component) For details
104 * see {@link #changeProp} method description. </li>
106 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
107 * @see com.sun.star.style.CharacterProperties
109 public class _CharacterProperties
extends MultiPropertyTest
{
111 public void _CharFontName() {
112 testProperty("CharFontName", "Times New Roman", "Arial") ;
115 public void _CharHeight() {
116 testProperty("CharHeight", new PropertyTester() {
117 protected Object
getNewValue(String propName
, Object old
) {
118 if (utils
.isVoid(old
)) {
119 return new Float(10) ;
121 return new Float(((Float
) old
).floatValue() + 10) ;
128 * Custom tester for properties which contains image URLs.
129 * Switches between two JPG images' URLs.
131 protected PropertyTester URLTester
= new PropertyTester() {
132 protected Object
getNewValue(String propName
, Object oldValue
) {
133 if (oldValue
.equals("http://www.sun.com"))
134 return "http://www.openoffice.org"; else
135 return "http://www.sun.com";
139 public void _HyperLinkURL() {
140 testProperty("HyperLinkURL", URLTester
) ;
143 public void _HyperLinkName() {
144 testProperty("HyperLinkName", URLTester
) ;
147 public void _HyperLinkTarget() {
148 testProperty("HyperLinkTarget", URLTester
) ;
151 public void _CharWeight() {
152 testProperty("CharWeight", new Float(com
.sun
.star
.awt
.FontWeight
.BOLD
),
153 new Float(com
.sun
.star
.awt
.FontWeight
.THIN
)) ;
156 public void _CharPosture() {
157 testProperty("CharPosture", com
.sun
.star
.awt
.FontSlant
.ITALIC
,
158 com
.sun
.star
.awt
.FontSlant
.NONE
) ;
162 * Custom tester for style name properties. If object relations "STYLENAME1"
163 * and "STYLENAME2" exists, then testing with these strings, else switches
164 * between 'Citation' and 'Emphasis' names.
166 protected PropertyTester StyleTester
= new PropertyTester() {
167 protected Object
getNewValue(String propName
, Object oldValue
) {
168 String oStyleName1
= (String
) tEnv
.getObjRelation("STYLENAME1");
169 String oStyleName2
= (String
) tEnv
.getObjRelation("STYLENAME2");
170 if ((oStyleName1
!= null) && (oStyleName2
!= null)){
171 log
.println("use strings given by object relation: '"
172 + oStyleName1
+ "' '" + oStyleName2
+"'");
173 if (oldValue
.equals( oStyleName1
))
178 if (utils
.isVoid(oldValue
) || (oldValue
.equals("Standard")))
179 return "Example"; else
185 * Custom tester for style names properties. Switches between
186 * 'Citation' and 'Emphasis' names.
188 protected PropertyTester StylesTester
= new PropertyTester() {
189 protected Object
getNewValue(String propName
, Object oldValue
) {
190 if (utils
.isVoid(oldValue
) || (oldValue
.equals("Standard")))
191 return new String
[] {"Citation"}; else
192 return new String
[] {"Emphasis"};
197 * If relations for paragraph and portion exist, then testing
198 * of this property performed using these objects, else
199 * testing is performed in common way.
201 public void _CharStyleName() {
202 log
.println("Testing with custom Property tester") ;
203 Object oPara
= tEnv
.getObjRelation("PARA");
204 Object oPort
= tEnv
.getObjRelation("PORTION");
206 testProperty("CharStyleName", StyleTester
) ;
208 changeProp((XPropertySet
) oPara
,
209 (XPropertySet
) oPort
,"CharStyleName","Standard");
214 * If relations for paragraph and portion exist, then testing
215 * of this property performed using these objects, else
216 * testing is performed in common way.
218 public void _CharStyleNames() {
219 log
.println("Testing with custom Property tester") ;
220 Object oPara
= tEnv
.getObjRelation("PARA");
221 Object oPort
= tEnv
.getObjRelation("PORTION");
223 testProperty("CharStyleNames", StylesTester
) ;
225 String
[] newNames
= {"Standard"};
226 changeProp((XPropertySet
) oPara
,
227 (XPropertySet
) oPort
,"CharStyleNames",new String
[] {"Standard"});
232 * If relations for paragraph and portion exist, then testing
233 * of this property performed using these objects, else
234 * testing is performed in common way.
236 public void _RubyCharStyleName() {
237 log
.println("Testing with custom Property tester") ;
238 Object oPara
= tEnv
.getObjRelation("PARA");
239 Object oPort
= tEnv
.getObjRelation("PORTION");
241 testProperty("RubyCharStyleName", StyleTester
) ;
243 changeProp((XPropertySet
) oPara
, (XPropertySet
)
244 oPort
,"RubyCharStyleName","Standard");
249 * If relations for paragraph and portion exist, then testing
250 * of this property performed using these objects, else
251 * testing is performed in common way.
253 public void _RubyAdjust() {
254 log
.println("Testing with custom Property tester") ;
255 Object oPara
= tEnv
.getObjRelation("PARA");
256 Object oPort
= tEnv
.getObjRelation("PORTION");
258 testProperty("RubyAdjust",new Short((short)0),new Short((short)1));
260 Short aShort
= new Short((short) 1);
261 changeProp((XPropertySet
) oPara
,
262 (XPropertySet
) oPort
,"RubyAdjust", aShort
);
264 Short aShort
= new Short((short) 1);
268 * Custom tester for the ruby text property.
270 protected PropertyTester RubyTextTester
= new PropertyTester() {
271 protected Object
getNewValue(String propName
, Object oldValue
)
272 throws java
.lang
.IllegalArgumentException
{
273 if (utils
.isVoid(oldValue
)) {
274 return new String("RubyText");
276 return ValueChanger
.changePValue(oldValue
);
282 * If relations for paragraph and portion exist, then testing
283 * of this property performed using these objects, else
284 * testing is performed in common way.
286 public void _RubyText() {
287 log
.println("Testing with custom Property tester") ;
288 Object oPara
= tEnv
.getObjRelation("PARA");
289 Object oPort
= tEnv
.getObjRelation("PORTION");
291 testProperty("RubyText", RubyTextTester
) ;
293 changeProp((XPropertySet
) oPara
, (XPropertySet
) oPort
,
299 * If relations for paragraph and portion exist, then testing
300 * of this property performed using these objects, else
301 * testing is performed in common way.
303 public void _RubyIsAbove() {
304 log
.println("Testing with custom Property tester") ;
305 Object oPara
= tEnv
.getObjRelation("PARA");
306 Object oPort
= tEnv
.getObjRelation("PORTION");
308 testProperty("RubyIsAbove") ;
310 changeProp((XPropertySet
) oPara
, (XPropertySet
) oPort
,
311 "RubyIsAbove",new Boolean(true));
316 * This property only takes values between 0..100
317 * so ist must be treated special
319 public void _CharEscapementHeight() {
320 Byte aByte
= new Byte((byte)75);
321 Byte max
= new Byte((byte)100);
322 testProperty("CharEscapementHeight", aByte
, max
) ;
327 * This property can be void, so if old value is <code> null </code>
328 * new value must be specified.
330 public void _CharRotation() {
331 Short aShort
= new Short((short) 10);
332 changeProp(oObj
,oObj
, "CharRotation", aShort
);
336 * Tests the property specified by <code>name</code> using
337 * property set <code>oProps</code>, but value after setting
338 * this property to a new value is checked using another
339 * PropertySet <code>get</code>. Special cases used for
340 * <code>CharRotation</code> property (it can have only certain values
341 * 0, 900, ...), and for <code>*StyleName</code> properties
342 * (only existing style names are accepted)
343 * @param oProps PropertySet from which property value is get
345 * @param get PropertySet where property value is checked after
347 * @param name Propety name to test.
348 * @param newVal Value used to set as new property value if
349 * the value get is null.
351 public void changeProp(XPropertySet oProps
,
352 XPropertySet get
,String name
, Object newVal
) {
354 Object gValue
= null;
355 Object sValue
= null;
356 Object ValueToSet
= null;
359 //waitForAllThreads();
360 gValue
= oProps
.getPropertyValue(name
);
362 if ( (gValue
== null) || (utils
.isVoid(gValue
)) ) {
363 log
.println("Value for "+name
+" is NULL");
367 //waitForAllThreads();
368 if (name
.equals("CharRotation")) {
369 Short s1
= new Short((short) 0);
370 Short s2
= new Short((short) 900);
371 if (gValue
.equals(s1
)) {
377 ValueToSet
= ValueChanger
.changePValue(gValue
);
379 if (name
.endsWith("StyleName")) {
380 if ( ((String
) gValue
).equals("Standard") ) {
381 ValueToSet
="Main index entry";
384 ValueToSet
="Emphasis";
388 //waitForAllThreads();
389 oProps
.setPropertyValue(name
,ValueToSet
);
390 sValue
= get
.getPropertyValue(name
);
391 if (sValue
== null) {
392 log
.println("Value for "+name
+" is NULL after setting");
396 //check get-set methods
397 if (gValue
.equals(sValue
)) {
398 log
.println("Value for '"+name
+"' hasn't changed");
399 tRes
.tested(name
, false);
401 log
.println("Property '"+name
+"' OK");
402 log
.println("old: "+gValue
.toString());
403 log
.println("new: "+ValueToSet
.toString());
404 log
.println("result: "+sValue
.toString());
405 tRes
.tested(name
, true);
408 catch (com
.sun
.star
.beans
.UnknownPropertyException ex
) {
409 if (isOptional(name
)) {
410 log
.println("Property '"+name
+
411 "' is optional and not supported");
412 tRes
.tested(name
,true);
415 log
.println("Exception occurred while testing property '" +
417 ex
.printStackTrace(log
);
418 tRes
.tested(name
, false);
420 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
421 log
.println("Exception occurred while testing property '" +
423 e
.printStackTrace(log
);
424 tRes
.tested(name
, false);
425 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
426 log
.println("Exception occurred while testing property '" +
428 e
.printStackTrace(log
);
429 tRes
.tested(name
, false);
430 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
431 log
.println("Exception occurred while testing property '" +
433 e
.printStackTrace(log
);
434 tRes
.tested(name
, false);
436 }// end of changeProp
438 public void _TextUserDefinedAttributes() {
439 XNameContainer uda
= null;
444 uda
= (XNameContainer
) AnyConverter
.toObject(
445 new Type(XNameContainer
.class),
446 oObj
.getPropertyValue("TextUserDefinedAttributes"));
447 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
448 log
.println("TextUserDefinedAttributes is empty.");
449 uda
= new _CharacterProperties
.OwnUserDefinedAttributes();
451 AttributeData attr
= new AttributeData();
452 attr
.Namespace
= "http://www.sun.com/staroffice/apitest/Cellprop";
455 uda
.insertByName("Cellprop:has-first-alien-attribute", attr
);
457 String
[] els
= uda
.getElementNames();
458 oObj
.setPropertyValue("TextUserDefinedAttributes", uda
);
459 uda
= (XNameContainer
) AnyConverter
.toObject(
460 new Type(XNameContainer
.class),
461 oObj
.getPropertyValue("TextUserDefinedAttributes"));
462 els
= uda
.getElementNames();
464 Object obj
= uda
.getByName("Cellprop:has-first-alien-attribute");
466 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
467 if (isOptional("TextUserDefinedAttributes")) {
468 log
.println("Property is optional and not supported");
471 log
.println("Don't know the Property 'TextUserDefinedAttributes'");
473 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
475 "WrappedTargetException while getting Property 'TextUserDefinedAttributes'");
476 } catch (com
.sun
.star
.container
.NoSuchElementException nee
) {
477 log
.println("added Element isn't part of the NameContainer");
478 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
480 "IllegalArgumentException while getting Property 'TextUserDefinedAttributes'");
481 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
483 "PropertyVetoException while getting Property 'TextUserDefinedAttributes'");
484 } catch (com
.sun
.star
.container
.ElementExistException eee
) {
486 "ElementExistException while getting Property 'TextUserDefinedAttributes'");
489 tRes
.tested("TextUserDefinedAttributes", res
);
492 private class OwnUserDefinedAttributes
implements XNameContainer
{
493 Hashtable members
= null;
496 public OwnUserDefinedAttributes() {
497 members
= new Hashtable();
500 public Object
getByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
501 return members
.get(str
);
504 public String
[] getElementNames() {
505 Enumeration oEnum
= members
.keys();
506 int count
= members
.size();
507 String
[] res
= new String
[count
];
509 while(oEnum
.hasMoreElements())
510 res
[i
] = (String
)oEnum
.nextElement();
514 public com
.sun
.star
.uno
.Type
getElementType() {
515 Enumeration oEnum
= members
.keys();
516 String key
= (String
)oEnum
.nextElement();
517 Object o
= members
.get(key
);
518 return new Type(o
.getClass());
521 public boolean hasByName(String str
) {
522 return members
.get(str
) != null;
525 public boolean hasElements() {
526 return members
.size() > 0;
529 public void insertByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.ElementExistException
, com
.sun
.star
.lang
.WrappedTargetException
{
530 members
.put(str
, obj
);
533 public void removeByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
537 public void replaceByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
538 members
.put(str
, obj
);
543 } //finish class _CharacterProperties