2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.util
.HashMap
;
22 import java
.util
.Iterator
;
24 import lib
.MultiPropertyTest
;
25 import util
.ValueChanger
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.container
.XNameContainer
;
30 import com
.sun
.star
.uno
.AnyConverter
;
31 import com
.sun
.star
.uno
.Type
;
32 import com
.sun
.star
.xml
.AttributeData
;
36 * Testing <code>com.sun.star.style.CharacterProperties</code>
37 * service properties :
39 * <li><code> CharFontName</code></li>
40 * <li><code> CharFontStyleName</code></li>
41 * <li><code> CharFontFamily</code></li>
42 * <li><code> CharFontCharSet</code></li>
43 * <li><code> CharFontPitch</code></li>
44 * <li><code> CharColor</code></li>
45 * <li><code> CharEscapement</code></li>
46 * <li><code> CharHeight</code></li>
47 * <li><code> CharUnderline</code></li>
48 * <li><code> CharWeight</code></li>
49 * <li><code> CharPosture</code></li>
50 * <li><code> CharAutoKerning</code></li>
51 * <li><code> CharBackColor</code></li>
52 * <li><code> CharBackTransparent</code></li>
53 * <li><code> CharCaseMap</code></li>
54 * <li><code> CharCrossedOut</code></li>
55 * <li><code> CharFlash</code></li>
56 * <li><code> CharStrikeout</code></li>
57 * <li><code> CharWordMode</code></li>
58 * <li><code> CharKerning</code></li>
59 * <li><code> CharLocale</code></li>
60 * <li><code> CharKeepTogether</code></li>
61 * <li><code> CharNoLineBreak</code></li>
62 * <li><code> CharShadowed</code></li>
63 * <li><code> CharFontType</code></li>
64 * <li><code> CharStyleName</code></li>
65 * <li><code> CharContoured</code></li>
66 * <li><code> CharCombineIsOn</code></li>
67 * <li><code> CharCombinePrefix</code></li>
68 * <li><code> CharCombineSuffix</code></li>
69 * <li><code> CharEmphasize</code></li>
70 * <li><code> CharRelief</code></li>
71 * <li><code> RubyText</code></li>
72 * <li><code> RubyAdjust</code></li>
73 * <li><code> RubyCharStyleName</code></li>
74 * <li><code> RubyIsAbove</code></li>
75 * <li><code> CharRotation</code></li>
76 * <li><code> CharRotationIsFitToLine</code></li>
77 * <li><code> CharScaleWidth</code></li>
78 * <li><code> HyperLinkURL</code></li>
79 * <li><code> HyperLinkTarget</code></li>
80 * <li><code> HyperLinkName</code></li>
81 * <li><code> TextUserDefinedAttributes</code></li>
83 * This test needs the following object relations :
85 * <li> <code>'PARA'</code>: <b>optional</b>
86 * (must implement <code>XPropertySet</code>):
87 * if this relation is specified then some properties
88 * testing is performed in a special manner. (e.g. this used in
89 * <code>sw.SwXParagraph</code> component) For details
90 * see {@link #changeProp} method description. </li>
91 * <li> <code>'PORTION'</code>: <b>optional</b>
92 * (must implement <code>XPropertySet</code>):
93 * if this relation is specified then some properties
94 * testing is performed in a special manner. (e.g. this used in
95 * <code>sw.SwXParagraph</code> component) For details
96 * see {@link #changeProp} method description. </li>
98 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
99 * @see com.sun.star.style.CharacterProperties
101 public class _CharacterProperties
extends MultiPropertyTest
{
103 public void _CharFontName() {
104 testProperty("CharFontName", "Times New Roman", "Arial") ;
107 public void _CharHeight() {
108 testProperty("CharHeight", new PropertyTester() {
109 protected Object
getNewValue(String propName
, Object old
) {
110 if (utils
.isVoid(old
)) {
111 return new Float(10) ;
113 return new Float(((Float
) old
).floatValue() + 10) ;
120 * Custom tester for properties which contains image URLs.
121 * Switches between two JPG images' URLs.
123 protected PropertyTester URLTester
= new PropertyTester() {
124 protected Object
getNewValue(String propName
, Object oldValue
) {
125 if (oldValue
.equals("http://www.sun.com"))
126 return "http://www.openoffice.org"; else
127 return "http://www.sun.com";
131 public void _HyperLinkURL() {
132 testProperty("HyperLinkURL", URLTester
) ;
135 public void _HyperLinkName() {
136 testProperty("HyperLinkName", URLTester
) ;
139 public void _HyperLinkTarget() {
140 testProperty("HyperLinkTarget", URLTester
) ;
143 public void _CharWeight() {
144 testProperty("CharWeight", new Float(com
.sun
.star
.awt
.FontWeight
.BOLD
),
145 new Float(com
.sun
.star
.awt
.FontWeight
.THIN
)) ;
148 public void _CharPosture() {
149 testProperty("CharPosture", com
.sun
.star
.awt
.FontSlant
.ITALIC
,
150 com
.sun
.star
.awt
.FontSlant
.NONE
) ;
154 * Custom tester for style name properties. If object relations "STYLENAME1"
155 * and "STYLENAME2" exists, then testing with these strings, else switches
156 * between 'Citation' and 'Emphasis' names.
158 protected PropertyTester StyleTester
= new PropertyTester() {
159 protected Object
getNewValue(String propName
, Object oldValue
) {
160 String oStyleName1
= (String
) tEnv
.getObjRelation("STYLENAME1");
161 String oStyleName2
= (String
) tEnv
.getObjRelation("STYLENAME2");
162 if ((oStyleName1
!= null) && (oStyleName2
!= null)){
163 log
.println("use strings given by object relation: '"
164 + oStyleName1
+ "' '" + oStyleName2
+"'");
165 if (oldValue
.equals( oStyleName1
))
170 if (utils
.isVoid(oldValue
) || (oldValue
.equals("Standard")))
171 return "Example"; else
177 * Custom tester for style names properties. Switches between
178 * 'Citation' and 'Emphasis' names.
180 protected PropertyTester StylesTester
= new PropertyTester() {
181 protected Object
getNewValue(String propName
, Object oldValue
) {
182 if (utils
.isVoid(oldValue
) || (oldValue
.equals("Standard")))
183 return new String
[] {"Citation"}; else
184 return new String
[] {"Emphasis"};
189 * If relations for paragraph and portion exist, then testing
190 * of this property performed using these objects, else
191 * testing is performed in common way.
193 public void _CharStyleName() {
194 log
.println("Testing with custom Property tester") ;
195 Object oPara
= tEnv
.getObjRelation("PARA");
196 Object oPort
= tEnv
.getObjRelation("PORTION");
198 testProperty("CharStyleName", StyleTester
) ;
200 changeProp((XPropertySet
) oPara
,
201 (XPropertySet
) oPort
,"CharStyleName","Standard");
206 * If relations for paragraph and portion exist, then testing
207 * of this property performed using these objects, else
208 * testing is performed in common way.
210 public void _CharStyleNames() {
211 log
.println("Testing with custom Property tester") ;
212 Object oPara
= tEnv
.getObjRelation("PARA");
213 Object oPort
= tEnv
.getObjRelation("PORTION");
215 testProperty("CharStyleNames", StylesTester
) ;
217 changeProp((XPropertySet
) oPara
,
218 (XPropertySet
) oPort
,"CharStyleNames",new String
[] {"Standard"});
223 * If relations for paragraph and portion exist, then testing
224 * of this property performed using these objects, else
225 * testing is performed in common way.
227 public void _RubyCharStyleName() {
228 log
.println("Testing with custom Property tester") ;
229 Object oPara
= tEnv
.getObjRelation("PARA");
230 Object oPort
= tEnv
.getObjRelation("PORTION");
232 testProperty("RubyCharStyleName", StyleTester
) ;
234 changeProp((XPropertySet
) oPara
, (XPropertySet
)
235 oPort
,"RubyCharStyleName","Standard");
240 * If relations for paragraph and portion exist, then testing
241 * of this property performed using these objects, else
242 * testing is performed in common way.
244 public void _RubyAdjust() {
245 log
.println("Testing with custom Property tester") ;
246 Object oPara
= tEnv
.getObjRelation("PARA");
247 Object oPort
= tEnv
.getObjRelation("PORTION");
249 testProperty("RubyAdjust",new Short((short)0),new Short((short)1));
251 Short aShort
= new Short((short) 1);
252 changeProp((XPropertySet
) oPara
,
253 (XPropertySet
) oPort
,"RubyAdjust", aShort
);
255 new Short((short) 1);
259 * Custom tester for the ruby text property.
261 protected PropertyTester RubyTextTester
= new PropertyTester() {
262 protected Object
getNewValue(String propName
, Object oldValue
)
263 throws java
.lang
.IllegalArgumentException
{
264 if (utils
.isVoid(oldValue
)) {
265 return new String("RubyText");
267 return ValueChanger
.changePValue(oldValue
);
273 * If relations for paragraph and portion exist, then testing
274 * of this property performed using these objects, else
275 * testing is performed in common way.
277 public void _RubyText() {
278 log
.println("Testing with custom Property tester") ;
279 Object oPara
= tEnv
.getObjRelation("PARA");
280 Object oPort
= tEnv
.getObjRelation("PORTION");
282 testProperty("RubyText", RubyTextTester
) ;
284 changeProp((XPropertySet
) oPara
, (XPropertySet
) oPort
,
290 * If relations for paragraph and portion exist, then testing
291 * of this property performed using these objects, else
292 * testing is performed in common way.
294 public void _RubyIsAbove() {
295 log
.println("Testing with custom Property tester") ;
296 Object oPara
= tEnv
.getObjRelation("PARA");
297 Object oPort
= tEnv
.getObjRelation("PORTION");
299 testProperty("RubyIsAbove") ;
301 changeProp((XPropertySet
) oPara
, (XPropertySet
) oPort
,
302 "RubyIsAbove",new Boolean(true));
307 * This property only takes values between 0..100
308 * so ist must be treated special
310 public void _CharEscapementHeight() {
311 Byte aByte
= new Byte((byte)75);
312 Byte max
= new Byte((byte)100);
313 testProperty("CharEscapementHeight", aByte
, max
) ;
318 * This property can be void, so if old value is <code> null </code>
319 * new value must be specified.
321 public void _CharRotation() {
322 Short aShort
= new Short((short) 10);
323 changeProp(oObj
,oObj
, "CharRotation", aShort
);
327 * Tests the property specified by <code>name</code> using
328 * property set <code>oProps</code>, but value after setting
329 * this property to a new value is checked using another
330 * PropertySet <code>get</code>. Special cases used for
331 * <code>CharRotation</code> property (it can have only certain values
332 * 0, 900, ...), and for <code>*StyleName</code> properties
333 * (only existing style names are accepted)
334 * @param oProps PropertySet from which property value is get
336 * @param get PropertySet where property value is checked after
338 * @param name Propety name to test.
339 * @param newVal Value used to set as new property value if
340 * the value get is null.
342 public void changeProp(XPropertySet oProps
,
343 XPropertySet get
,String name
, Object newVal
) {
345 Object gValue
= null;
346 Object sValue
= null;
347 Object ValueToSet
= null;
350 //waitForAllThreads();
351 gValue
= oProps
.getPropertyValue(name
);
353 if ( (gValue
== null) || (utils
.isVoid(gValue
)) ) {
354 log
.println("Value for "+name
+" is NULL");
358 //waitForAllThreads();
359 if (name
.equals("CharRotation")) {
360 Short s1
= new Short((short) 0);
361 Short s2
= new Short((short) 900);
362 if (gValue
.equals(s1
)) {
368 ValueToSet
= ValueChanger
.changePValue(gValue
);
370 if (name
.endsWith("StyleName")) {
371 if ( ((String
) gValue
).equals("Standard") ) {
372 ValueToSet
="Main index entry";
375 ValueToSet
="Emphasis";
379 //waitForAllThreads();
380 oProps
.setPropertyValue(name
,ValueToSet
);
381 sValue
= get
.getPropertyValue(name
);
382 if (sValue
== null) {
383 log
.println("Value for "+name
+" is NULL after setting");
387 //check get-set methods
388 if (gValue
.equals(sValue
)) {
389 log
.println("Value for '"+name
+"' hasn't changed");
390 tRes
.tested(name
, false);
392 log
.println("Property '"+name
+"' OK");
393 log
.println("old: "+gValue
.toString());
394 log
.println("new: "+ValueToSet
.toString());
395 log
.println("result: "+sValue
.toString());
396 tRes
.tested(name
, true);
399 catch (com
.sun
.star
.beans
.UnknownPropertyException ex
) {
400 if (isOptional(name
)) {
401 log
.println("Property '"+name
+
402 "' is optional and not supported");
403 tRes
.tested(name
,true);
406 log
.println("Exception occurred while testing property '" +
408 ex
.printStackTrace(log
);
409 tRes
.tested(name
, false);
411 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
412 log
.println("Exception occurred while testing property '" +
414 e
.printStackTrace(log
);
415 tRes
.tested(name
, false);
416 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
417 log
.println("Exception occurred while testing property '" +
419 e
.printStackTrace(log
);
420 tRes
.tested(name
, false);
421 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
422 log
.println("Exception occurred while testing property '" +
424 e
.printStackTrace(log
);
425 tRes
.tested(name
, false);
427 }// end of changeProp
429 public void _TextUserDefinedAttributes() {
430 XNameContainer uda
= null;
435 uda
= (XNameContainer
) AnyConverter
.toObject(
436 new Type(XNameContainer
.class),
437 oObj
.getPropertyValue("TextUserDefinedAttributes"));
438 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
439 log
.println("TextUserDefinedAttributes is empty.");
440 uda
= new _CharacterProperties
.OwnUserDefinedAttributes();
442 AttributeData attr
= new AttributeData();
443 attr
.Namespace
= "http://www.sun.com/staroffice/apitest/Cellprop";
446 uda
.insertByName("Cellprop:has-first-alien-attribute", attr
);
448 uda
.getElementNames();
449 oObj
.setPropertyValue("TextUserDefinedAttributes", uda
);
450 uda
= (XNameContainer
) AnyConverter
.toObject(
451 new Type(XNameContainer
.class),
452 oObj
.getPropertyValue("TextUserDefinedAttributes"));
453 uda
.getElementNames();
455 uda
.getByName("Cellprop:has-first-alien-attribute");
457 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
458 if (isOptional("TextUserDefinedAttributes")) {
459 log
.println("Property is optional and not supported");
462 log
.println("Don't know the Property 'TextUserDefinedAttributes'");
464 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
466 "WrappedTargetException while getting Property 'TextUserDefinedAttributes'");
467 } catch (com
.sun
.star
.container
.NoSuchElementException nee
) {
468 log
.println("added Element isn't part of the NameContainer");
469 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
471 "IllegalArgumentException while getting Property 'TextUserDefinedAttributes'");
472 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
474 "PropertyVetoException while getting Property 'TextUserDefinedAttributes'");
475 } catch (com
.sun
.star
.container
.ElementExistException eee
) {
477 "ElementExistException while getting Property 'TextUserDefinedAttributes'");
480 tRes
.tested("TextUserDefinedAttributes", res
);
483 private class OwnUserDefinedAttributes
implements XNameContainer
{
484 HashMap
<String
, Object
> members
= null;
487 public OwnUserDefinedAttributes() {
488 members
= new HashMap
<String
, Object
>();
491 public Object
getByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
492 return members
.get(str
);
495 public String
[] getElementNames() {
496 Iterator
<String
> oEnum
= members
.keySet().iterator();
497 int count
= members
.size();
498 String
[] res
= new String
[count
];
500 while(oEnum
.hasNext())
501 res
[i
++] = oEnum
.next();
505 public com
.sun
.star
.uno
.Type
getElementType() {
506 Iterator
<String
> oEnum
= members
.keySet().iterator();
507 String key
= oEnum
.next();
508 Object o
= members
.get(key
);
509 return new Type(o
.getClass());
512 public boolean hasByName(String str
) {
513 return members
.get(str
) != null;
516 public boolean hasElements() {
517 return members
.size() > 0;
520 public void insertByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.ElementExistException
, com
.sun
.star
.lang
.WrappedTargetException
{
521 members
.put(str
, obj
);
524 public void removeByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
528 public void replaceByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
529 members
.put(str
, obj
);
534 } //finish class _CharacterProperties