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() {
109 protected Object
getNewValue(String propName
, Object oldValue
)
110 throws java
.lang
.IllegalArgumentException
{
111 if ((oldValue
!= null) && (oldValue
.equals("Numbering 1"))) {
112 return "Numbering 2";
114 return "Numbering 1";
120 * Custom tester for paragraph style properties. Switches between
121 * 'Salutation' and 'Heading' styles.
123 protected PropertyTester charStyleTester
= new PropertyTester() {
125 protected Object
getNewValue(String propName
, Object oldValue
) {
126 if (!utils
.isVoid(oldValue
) && (oldValue
.equals("Example"))) {
135 * Custom tester for paragraph style properties. Switches between
136 * 'Salutation' and 'Heading' styles.
138 protected PropertyTester ParaStyleTester
= new PropertyTester() {
140 protected Object
getNewValue(String propName
, Object oldValue
) {
141 if (!utils
.isVoid(oldValue
) && (oldValue
.equals("Heading"))) {
150 * Custom tester for PageDescName properties. Switches between
151 * 'HTML' and 'Standard' descriptor names.
153 protected PropertyTester PageDescTester
= new PropertyTester() {
155 protected Object
getNewValue(String propName
, Object oldValue
) {
156 if (!util
.utils
.isVoid(oldValue
) &&
157 (oldValue
.equals("Default"))) {
166 * Custom tester for properties which have <code>short</code> type
167 * and can be void, so if they have void value, the new value must
168 * be specified. Switches between two different values.
170 protected PropertyTester ShortTester
= new PropertyTester() {
172 protected Object
getNewValue(String propName
, Object oldValue
) {
173 if ((oldValue
!= null) &&
174 (oldValue
.equals(Short
.valueOf((short) 0)))) {
175 return Short
.valueOf((short) 2);
177 return Short
.valueOf((short) 0);
183 * Custom tester for properties which have <code>boolean</code> type
184 * and can be void, so if they have void value, the new value must
185 * be specified. Switches between true and false.
187 protected PropertyTester BooleanTester
= new PropertyTester() {
189 protected Object
getNewValue(String propName
, Object oldValue
) {
190 if ((oldValue
!= null) &&
191 (oldValue
.equals(Boolean
.FALSE
))) {
194 return Boolean
.FALSE
;
200 * Custom tester for properties which contains image URLs.
201 * Switches between two JPG images' URLs.
203 protected PropertyTester URLTester
= new PropertyTester() {
205 protected Object
getNewValue(String propName
, Object oldValue
) {
206 if (oldValue
.equals(util
.utils
.getFullTestURL("space-metal.jpg"))) {
207 return util
.utils
.getFullTestURL("crazy-blue.jpg");
209 return util
.utils
.getFullTestURL("space-metal.jpg");
214 protected PropertyTester rules
= null;
217 * Creates tester for 'NumberingRules' depending on relation.
220 public void before() {
221 final Object nRules
= tEnv
.getObjRelation("NRULES");
223 if (nRules
!= null) {
224 rules
= new PropertyTester() {
226 protected Object
getNewValue(String propName
, Object oldValue
) {
232 Object rules1
= null;
233 Object rules2
= null;
236 oObj
.setPropertyValue("NumberingStyleName", "Numbering 1");
237 rules1
= oObj
.getPropertyValue("NumberingRules");
238 oObj
.setPropertyValue("NumberingStyleName", "Numbering 2");
239 rules2
= oObj
.getPropertyValue("NumberingRules");
240 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
241 log
.println("WARNING !!! Exception getting numbering rules :");
242 e
.printStackTrace(log
);
243 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
244 log
.println("WARNING !!! Exception getting numbering rules :");
245 e
.printStackTrace(log
);
246 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
247 log
.println("WARNING !!! Exception getting numbering rules :");
248 e
.printStackTrace(log
);
249 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
250 log
.println("Property 'NumberingStyleName' is not supported.");
253 rules
= new PropertyValueSwitcher(rules1
, rules2
);
258 * Tested with custom property tester.
260 public void _NumberingStyleName() {
261 log
.println("Testing with custom Property tester");
262 testProperty("NumberingStyleName", NumberingStyleTester
);
266 * Tested with custom property tester.
268 public void _DropCapCharStyleName() {
269 log
.println("Testing with custom Property tester");
270 testProperty("DropCapCharStyleName", charStyleTester
);
274 * Tested with custom property tester.
276 public void _ParaStyleName() {
277 log
.println("Testing with custom Property tester");
278 testProperty("ParaStyleName", ParaStyleTester
);
282 * Tested with custom property tester.
284 public void _PageDescName() {
285 log
.println("Testing with custom Property tester");
286 testProperty("PageDescName", PageDescTester
);
290 * Tested with custom property tester. Before testing property
291 * <code>ParaAdjust</code> is setting to value <code>BLOCK</code>
292 * because setting the property <code>ParaLastLineAdjust</code>
293 * makes sense only in this case.
295 public void _ParaLastLineAdjust() {
296 log
.println("Testing with custom Property tester");
299 oObj
.setPropertyValue("ParaAdjust",
300 com
.sun
.star
.style
.ParagraphAdjust
.BLOCK
);
301 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
302 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
303 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
304 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
305 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
306 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
307 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
308 log
.println("Exception occurred setting property 'ParagraphAdjust'" + e
);
311 testProperty("ParaLastLineAdjust", ShortTester
);
315 * Tested with custom property tester.
317 public void _ParaBackGraphicURL() {
318 log
.println("Testing with custom Property tester");
319 testProperty("ParaBackGraphicURL", URLTester
);
323 * Tested with custom property tester. <p>
324 * The following property tests are to be completed successfully before :
326 * <li> <code> NumberingStyleName </code> : a numbering style must
327 * be set before testing this property </li>
330 public void _NumberingLevel() {
331 requiredMethod("NumberingStyleName");
332 log
.println("Testing with custom Property tester");
333 testProperty("NumberingLevel", ShortTester
);
337 * Tested with custom property tester. <p>
339 public void _ParaIsConnectBorder() {
341 log
.println("Testing with custom Property tester");
342 testProperty("ParaIsConnectBorder", BooleanTester
);
346 * Tested with custom property tester.
348 public void _ParaVertAlignment() {
349 log
.println("Testing with custom Property tester");
350 testProperty("ParaVertAlignment", ShortTester
);
354 * Tested with com.sun.star.text.NumberingLevel <p>
355 * The value of this property is a com.sun.star.container.XIndexReplace which is represneted by
356 * com.sun.star.text.NumberingLevel.
357 * The following property tests are to be completed successfully before :
359 * <li> <code> NumberingStyleName </code> : a numbering style must
360 * be set before testing this property </li>
362 * @see com.sun.star.text.NumberlingLevel
363 * @see com.sun.star.container.XIndexReplace
364 * @see ifc.text._NumberingLevel
366 public void _NumberingRules() {
367 requiredMethod("NumberingStyleName");
369 XIndexReplace NumberingRules
= null;
370 PropertyValue
[] propertyValues
= null;
372 NumberingRules
= (XIndexReplace
) AnyConverter
.toObject(
373 new Type(XIndexReplace
.class), oObj
.getPropertyValue("NumberingRules"));
374 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
375 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
377 } catch (UnknownPropertyException ex
) {
378 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
380 } catch (WrappedTargetException ex
) {
381 Status
.failed( "could not get NumberingRuels: "+ ex
.toString() );
385 propertyValues
= (PropertyValue
[]) NumberingRules
.getByIndex(0);
387 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
388 Status
.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex
.toString() );
390 } catch (WrappedTargetException ex
) {
391 Status
.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex
.toString() );
395 _NumberingLevel numb
= new _NumberingLevel((LogWriter
)log
, tParam
, propertyValues
);
397 boolean result
= numb
.testPropertieArray();
399 tRes
.tested("NumberingRules", result
);
402 public void _ParaUserDefinedAttributes() {
403 XNameContainer uda
= null;
408 uda
= (XNameContainer
) AnyConverter
.toObject(
409 new Type(XNameContainer
.class),
410 oObj
.getPropertyValue("ParaUserDefinedAttributes"));
411 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
412 log
.println("ParaUserDefinedAttributes is empty.");
413 uda
= new _ParagraphProperties
.OwnUserDefinedAttributes();
415 AttributeData attr
= new AttributeData();
416 attr
.Namespace
= "http://www.sun.com/staroffice/apitest/Cellprop";
419 uda
.insertByName("Cellprop:has-first-alien-attribute", attr
);
421 uda
.getElementNames();
422 oObj
.setPropertyValue("ParaUserDefinedAttributes", uda
);
423 uda
= (XNameContainer
) AnyConverter
.toObject(
424 new Type(XNameContainer
.class),
425 oObj
.getPropertyValue("ParaUserDefinedAttributes"));
426 uda
.getElementNames();
428 uda
.getByName("Cellprop:has-first-alien-attribute");
430 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
431 if (isOptional("ParaUserDefinedAttributes")) {
432 log
.println("Property is optional and not supported");
435 log
.println("Don't know the Property 'ParaUserDefinedAttributes'");
437 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
439 "WrappedTargetException while getting Property 'ParaUserDefinedAttributes'");
440 } catch (com
.sun
.star
.container
.NoSuchElementException nee
) {
441 log
.println("added Element isn't part of the NameContainer");
442 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
444 "IllegalArgumentException while getting Property 'ParaUserDefinedAttributes'");
445 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
447 "PropertyVetoException while getting Property 'ParaUserDefinedAttributes'");
448 } catch (com
.sun
.star
.container
.ElementExistException eee
) {
450 "ElementExistException while getting Property 'ParaUserDefinedAttributes'");
453 tRes
.tested("ParaUserDefinedAttributes", res
);
456 private class OwnUserDefinedAttributes
implements XNameContainer
{
457 HashMap
<String
, Object
> members
= null;
460 public OwnUserDefinedAttributes() {
461 members
= new HashMap
<String
, Object
>();
464 public Object
getByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
465 return members
.get(str
);
468 public String
[] getElementNames() {
469 java
.util
.Set
<String
> keySet
= members
.keySet();
470 return keySet
.toArray(new String
[keySet
.size()]);
473 public com
.sun
.star
.uno
.Type
getElementType() {
474 String key
= members
.keySet().iterator().next();
475 Object o
= members
.get(key
);
476 return new Type(o
.getClass());
479 public boolean hasByName(String str
) {
480 return members
.get(str
) != null;
483 public boolean hasElements() {
484 return members
.size() > 0;
487 public void insertByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.ElementExistException
, com
.sun
.star
.lang
.WrappedTargetException
{
488 members
.put(str
, obj
);
491 public void removeByName(String str
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
495 public void replaceByName(String str
, Object obj
) throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.lang
.WrappedTargetException
{
496 members
.put(str
, obj
);
500 } // finish class _ParagraphProperties