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 .
20 import ifc
.text
._NumberingLevel
;
22 import java
.util
.HashMap
;
24 import lib
.MultiPropertyTest
;
26 import share
.LogWriter
;
29 import com
.sun
.star
.beans
.PropertyValue
;
30 import com
.sun
.star
.beans
.UnknownPropertyException
;
31 import com
.sun
.star
.container
.XIndexReplace
;
32 import com
.sun
.star
.container
.XNameContainer
;
33 import com
.sun
.star
.lang
.WrappedTargetException
;
34 import com
.sun
.star
.uno
.AnyConverter
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.xml
.AttributeData
;
40 * Testing <code>com.sun.star.style.ParagraphProperties</code>
41 * service properties :
43 * <li><code> ParaAdjust</code></li>
44 * <li><code> ParaLineSpacing</code></li>
45 * <li><code> ParaBackColor</code></li>
46 * <li><code> ParaBackTransparent</code></li>
47 * <li><code> ParaBackGraphicURL</code></li>
48 * <li><code> ParaBackGraphicFilter</code></li>
49 * <li><code> ParaBackGraphicLocation</code></li>
50 * <li><code> ParaLastLineAdjust</code></li>
51 * <li><code> ParaExpandSingleWord</code></li>
52 * <li><code> ParaLeftMargin</code></li>
53 * <li><code> ParaRightMargin</code></li>
54 * <li><code> ParaTopMargin</code></li>
55 * <li><code> ParaBottomMargin</code></li>
56 * <li><code> ParaLineNumberCount</code></li>
57 * <li><code> ParaLineNumberStartValue</code></li>
58 * <li><code> ParaIsHyphenation</code></li>
59 * <li><code> PageDescName</code></li>
60 * <li><code> PageNumberOffset</code></li>
61 * <li><code> ParaRegisterModeActive</code></li>
62 * <li><code> ParaTabStops</code></li>
63 * <li><code> ParaStyleName</code></li>
64 * <li><code> DropCapFormat</code></li>
65 * <li><code> DropCapWholeWord</code></li>
66 * <li><code> ParaKeepTogether</code></li>
67 * <li><code> ParaSplit</code></li>
68 * <li><code> NumberingLevel</code></li>
69 * <li><code> NumberingRules</code></li>
70 * <li><code> NumberingStartValue</code></li>
71 * <li><code> ParaIsNumberingRestart</code></li>
72 * <li><code> NumberingStyleName</code></li>
73 * <li><code> ParaOrphans</code></li>
74 * <li><code> ParaWidows</code></li>
75 * <li><code> ParaShadowFormat</code></li>
76 * <li><code> IsHangingPunctuation</code></li>
77 * <li><code> IsCharacterDistance</code></li>
78 * <li><code> IsForbiddenRules</code></li>
79 * <li><code> LeftBorder</code></li>
80 * <li><code> RightBorder</code></li>
81 * <li><code> TopBorder</code></li>
82 * <li><code> BottomBorder</code></li>
83 * <li><code> BorderDistance</code></li>
84 * <li><code> LeftBorderDistance</code></li>
85 * <li><code> RightBorderDistance</code></li>
86 * <li><code> TopBorderDistance</code></li>
87 * <li><code> BottomBorderDistance</code></li>
89 * This test needs the following object relations :
91 * <li> <code>'NRULES'</code> : <b>optional</b>
92 * (service <code>com.sun.star.text.NumberingRules</code>):
93 * instance of the service which can be set as 'NumberingRules'
94 * property new value. If the relation doesn't then two
95 * different <code>NumberingRules</code> objects are tried
96 * to be obtained by setting different 'NumberingStyleName'
97 * property styles and getting 'NumberingRules' property values.</li>
99 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
100 * @see com.sun.star.style.ParagraphProperties
102 public class _ParagraphProperties
extends MultiPropertyTest
{
104 * Custom tester for numbering style properties. Switches between
105 * 'Numbering 1' and 'Numbering 2' styles.
107 protected PropertyTester NumberingStyleTester
= new PropertyTester() {
108 protected Object
getNewValue(String propName
, Object oldValue
)
109 throws java
.lang
.IllegalArgumentException
{
110 if ((oldValue
!= null) && (oldValue
.equals("Numbering 1"))) {
111 return "Numbering 2";
113 return "Numbering 1";
119 * Custom tester for paragraph style properties. Switches between
120 * 'Salutation' and 'Heading' styles.
122 protected PropertyTester charStyleTester
= new PropertyTester() {
123 protected Object
getNewValue(String propName
, Object oldValue
) {
124 if (!utils
.isVoid(oldValue
) && (oldValue
.equals("Example"))) {
133 * Custom tester for paragraph style properties. Switches between
134 * 'Salutation' and 'Heading' styles.
136 protected PropertyTester ParaStyleTester
= new PropertyTester() {
137 protected Object
getNewValue(String propName
, Object oldValue
) {
138 if (!utils
.isVoid(oldValue
) && (oldValue
.equals("Heading"))) {
147 * Custom tester for PageDescName properties. Switches between
148 * 'HTML' and 'Standard' descriptor names.
150 protected PropertyTester PageDescTester
= new PropertyTester() {
151 protected Object
getNewValue(String propName
, Object oldValue
) {
152 if (!util
.utils
.isVoid(oldValue
) &&
153 (oldValue
.equals("Default"))) {
162 * Custom tester for properties which have <code>short</code> type
163 * and can be void, so if they have void value, the new value must
164 * be specified. Switches between two different values.
166 protected PropertyTester ShortTester
= new PropertyTester() {
167 protected Object
getNewValue(String propName
, Object oldValue
) {
168 if ((oldValue
!= null) &&
169 (oldValue
.equals(new Short((short) 0)))) {
170 return new Short((short) 2);
172 return new Short((short) 0);
178 * Custom tester for properties which have <code>boolean</code> type
179 * and can be void, so if they have void value, the new value must
180 * be specified. Switches between true and false.
182 protected PropertyTester BooleanTester
= new PropertyTester() {
183 protected Object
getNewValue(String propName
, Object oldValue
) {
184 if ((oldValue
!= null) &&
185 (oldValue
.equals(new Boolean(false)))) {
186 return new Boolean(true);
188 return new Boolean(false);
194 * Custom tester for properties which contains image URLs.
195 * Switches between two JPG images' URLs.
197 protected PropertyTester URLTester
= new PropertyTester() {
198 protected Object
getNewValue(String propName
, Object oldValue
) {
199 if (oldValue
.equals(util
.utils
.getFullTestURL("space-metal.jpg"))) {
200 return util
.utils
.getFullTestURL("crazy-blue.jpg");
202 return util
.utils
.getFullTestURL("space-metal.jpg");
207 protected PropertyTester rules
= null;
210 * Creates tester for 'NumberingRules' depending on relation.
212 public void before() {
213 final Object nRules
= tEnv
.getObjRelation("NRULES");
215 if (nRules
!= null) {
216 rules
= new PropertyTester() {
217 protected Object
getNewValue(String propName
, Object oldValue
) {
223 Object rules1
= null;
224 Object rules2
= null;
227 oObj
.setPropertyValue("NumberingStyleName", "Numbering 1");
228 rules1
= oObj
.getPropertyValue("NumberingRules");
229 oObj
.setPropertyValue("NumberingStyleName", "Numbering 2");
230 rules2
= oObj
.getPropertyValue("NumberingRules");
231 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
232 log
.println("WARNING !!! Exception getting numbering rules :");
233 e
.printStackTrace(log
);
234 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
235 log
.println("WARNING !!! Exception getting numbering rules :");
236 e
.printStackTrace(log
);
237 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
238 log
.println("WARNING !!! Exception getting numbering rules :");
239 e
.printStackTrace(log
);
240 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
241 log
.println("Property 'NumberingStyleName' is not supported.");
244 rules
= new PropertyValueSwitcher(rules1
, rules2
);
249 * Tested with custom property tester.
251 public void _NumberingStyleName() {
252 log
.println("Testing with custom Property tester");
253 testProperty("NumberingStyleName", NumberingStyleTester
);
257 * Tested with custom property tester.
259 public void _DropCapCharStyleName() {
260 log
.println("Testing with custom Property tester");
261 testProperty("DropCapCharStyleName", charStyleTester
);
265 * Tested with custom property tester.
267 public void _ParaStyleName() {
268 log
.println("Testing with custom Property tester");
269 testProperty("ParaStyleName", ParaStyleTester
);
273 * Tested with custom property tester.
275 public void _PageDescName() {
276 log
.println("Testing with custom Property tester");
277 testProperty("PageDescName", PageDescTester
);
281 * Tested with custom property tester. Before testing property
282 * <code>ParaAdjust</code> is setting to value <code>BLOCK</code>
283 * because setting the property <code>ParaLastLineAdjust</code>
284 * makes sense only in this case.
286 public void _ParaLastLineAdjust() {
287 log
.println("Testing with custom Property tester");
290 oObj
.setPropertyValue("ParaAdjust",
291 com
.sun
.star
.style
.ParagraphAdjust
.BLOCK
);
292 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
293 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
294 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
295 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
296 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
297 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
298 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
299 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
302 testProperty("ParaLastLineAdjust", ShortTester
);
306 * Tested with custom property tester.
308 public void _ParaBackGraphicURL() {
309 log
.println("Testing with custom Property tester");
310 testProperty("ParaBackGraphicURL", URLTester
);
314 * Tested with custom property tester. <p>
315 * The following property tests are to be completed successfully before :
317 * <li> <code> NumberingStyleName </code> : a numbering style must
318 * be set before testing this property </li>
321 public void _NumberingLevel() {
322 requiredMethod("NumberingStyleName");
323 log
.println("Testing with custom Property tester");
324 testProperty("NumberingLevel", ShortTester
);
328 * Tested with custom property tester. <p>
330 public void _ParaIsConnectBorder() {
332 log
.println("Testing with custom Property tester");
333 testProperty("ParaIsConnectBorder", BooleanTester
);
337 * Tested with custom property tester.
339 public void _ParaVertAlignment() {
340 log
.println("Testing with custom Property tester");
341 testProperty("ParaVertAlignment", ShortTester
);
345 * Tested with com.sun.star.text.NumberingLevel <p>
346 * The value of this property is a com.sun.star.container.XIndexReplace which is represneted by
347 * com.sun.star.text.NumberingLevel.
348 * The following property tests are to be completed successfully before :
350 * <li> <code> NumberingStyleName </code> : a numbering style must
351 * be set before testing this property </li>
353 * @see com.sun.star.text.NumberlingLevel
354 * @see com.sun.star.container.XIndexReplace
355 * @see ifc.text._NumberingLevel
357 public void _NumberingRules() {
358 requiredMethod("NumberingStyleName");
360 XIndexReplace NumberingRules
= null;
361 PropertyValue
[] propertyValues
= null;
363 NumberingRules
= (XIndexReplace
) AnyConverter
.toObject(
364 new Type(XIndexReplace
.class), oObj
.getPropertyValue("NumberingRules"));
365 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
366 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
368 } catch (UnknownPropertyException ex
) {
369 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
371 } catch (WrappedTargetException ex
) {
372 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
376 propertyValues
= (PropertyValue
[]) NumberingRules
.getByIndex(0);
378 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
379 Status
.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex
.toString() );
381 } catch (WrappedTargetException ex
) {
382 Status
.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex
.toString() );
386 _NumberingLevel numb
= new _NumberingLevel((LogWriter
)log
, tParam
, propertyValues
);
388 boolean result
= numb
.testPropertieArray();
390 tRes
.tested("NumberingRules", result
);
393 public void _ParaUserDefinedAttributes() {
394 XNameContainer uda
= null;
399 uda
= (XNameContainer
) AnyConverter
.toObject(
400 new Type(XNameContainer
.class),
401 oObj
.getPropertyValue("ParaUserDefinedAttributes"));
402 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
403 log
.println("ParaUserDefinedAttributes is empty.");
404 uda
= new _ParagraphProperties
.OwnUserDefinedAttributes();
406 AttributeData attr
= new AttributeData();
407 attr
.Namespace
= "http://www.sun.com/staroffice/apitest/Cellprop";
410 uda
.insertByName("Cellprop:has-first-alien-attribute", attr
);
412 uda
.getElementNames();
413 oObj
.setPropertyValue("ParaUserDefinedAttributes", uda
);
414 uda
= (XNameContainer
) AnyConverter
.toObject(
415 new Type(XNameContainer
.class),
416 oObj
.getPropertyValue("ParaUserDefinedAttributes"));
417 uda
.getElementNames();
419 uda
.getByName("Cellprop:has-first-alien-attribute");
421 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
422 if (isOptional("ParaUserDefinedAttributes")) {
423 log
.println("Property is optional and not supported");
426 log
.println("Don't know the Property 'ParaUserDefinedAttributes'");
428 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
430 "WrappedTargetException while getting Property 'ParaUserDefinedAttributes'");
431 } catch (com
.sun
.star
.container
.NoSuchElementException nee
) {
432 log
.println("added Element isn't part of the NameContainer");
433 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
435 "IllegalArgumentException while getting Property 'ParaUserDefinedAttributes'");
436 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
438 "PropertyVetoException while getting Property 'ParaUserDefinedAttributes'");
439 } catch (com
.sun
.star
.container
.ElementExistException eee
) {
441 "ElementExistException while getting Property 'ParaUserDefinedAttributes'");
444 tRes
.tested("ParaUserDefinedAttributes", res
);
447 private class OwnUserDefinedAttributes
implements XNameContainer
{
448 HashMap
<String
, Object
> members
= null;
451 public OwnUserDefinedAttributes() {
452 members
= new HashMap
<String
, Object
>();
455 public Object
getByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
456 return members
.get(str
);
459 public String
[] getElementNames() {
460 java
.util
.Set
<String
> keySet
= members
.keySet();
461 return keySet
.toArray(new String
[keySet
.size()]);
464 public com
.sun
.star
.uno
.Type
getElementType() {
465 String key
= members
.keySet().iterator().next();
466 Object o
= members
.get(key
);
467 return new Type(o
.getClass());
470 public boolean hasByName(String str
) {
471 return members
.get(str
) != null;
474 public boolean hasElements() {
475 return members
.size() > 0;
478 public void insertByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.ElementExistException
, com
.sun
.star
.lang
.WrappedTargetException
{
479 members
.put(str
, obj
);
482 public void removeByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
486 public void replaceByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
487 members
.put(str
, obj
);
491 } // finish class _ParagraphProperties