merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / style / _ParagraphProperties.java
blob559de78c5d36ce65f8178b6dbecf0795472746a5
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: _ParagraphProperties.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
30 package ifc.style;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.beans.UnknownPropertyException;
34 import com.sun.star.container.XIndexReplace;
35 import com.sun.star.container.XNameContainer;
36 import com.sun.star.lang.WrappedTargetException;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.xml.AttributeData;
40 import ifc.text._NumberingLevel;
41 import java.util.Enumeration;
42 import java.util.Hashtable;
44 import lib.MultiPropertyTest;
45 import lib.Status;
46 import share.LogWriter;
49 import util.utils;
52 /**
53 * Testing <code>com.sun.star.style.ParagraphProperties</code>
54 * service properties :
55 * <ul>
56 * <li><code> ParaAdjust</code></li>
57 * <li><code> ParaLineSpacing</code></li>
58 * <li><code> ParaBackColor</code></li>
59 * <li><code> ParaBackTransparent</code></li>
60 * <li><code> ParaBackGraphicURL</code></li>
61 * <li><code> ParaBackGraphicFilter</code></li>
62 * <li><code> ParaBackGraphicLocation</code></li>
63 * <li><code> ParaLastLineAdjust</code></li>
64 * <li><code> ParaExpandSingleWord</code></li>
65 * <li><code> ParaLeftMargin</code></li>
66 * <li><code> ParaRightMargin</code></li>
67 * <li><code> ParaTopMargin</code></li>
68 * <li><code> ParaBottomMargin</code></li>
69 * <li><code> ParaLineNumberCount</code></li>
70 * <li><code> ParaLineNumberStartValue</code></li>
71 * <li><code> ParaIsHyphenation</code></li>
72 * <li><code> PageDescName</code></li>
73 * <li><code> PageNumberOffset</code></li>
74 * <li><code> ParaRegisterModeActive</code></li>
75 * <li><code> ParaTabStops</code></li>
76 * <li><code> ParaStyleName</code></li>
77 * <li><code> DropCapFormat</code></li>
78 * <li><code> DropCapWholeWord</code></li>
79 * <li><code> ParaKeepTogether</code></li>
80 * <li><code> ParaSplit</code></li>
81 * <li><code> NumberingLevel</code></li>
82 * <li><code> NumberingRules</code></li>
83 * <li><code> NumberingStartValue</code></li>
84 * <li><code> ParaIsNumberingRestart</code></li>
85 * <li><code> NumberingStyleName</code></li>
86 * <li><code> ParaOrphans</code></li>
87 * <li><code> ParaWidows</code></li>
88 * <li><code> ParaShadowFormat</code></li>
89 * <li><code> IsHangingPunctuation</code></li>
90 * <li><code> IsCharacterDistance</code></li>
91 * <li><code> IsForbiddenRules</code></li>
92 * <li><code> LeftBorder</code></li>
93 * <li><code> RightBorder</code></li>
94 * <li><code> TopBorder</code></li>
95 * <li><code> BottomBorder</code></li>
96 * <li><code> BorderDistance</code></li>
97 * <li><code> LeftBorderDistance</code></li>
98 * <li><code> RightBorderDistance</code></li>
99 * <li><code> TopBorderDistance</code></li>
100 * <li><code> BottomBorderDistance</code></li>
101 * </ul> <p>
102 * This test needs the following object relations :
103 * <ul>
104 * <li> <code>'NRULES'</code> : <b>optional</b>
105 * (service <code>com.sun.star.text.NumberingRules</code>):
106 * instance of the service which can be set as 'NumberingRules'
107 * property new value. If the relation doesn't then two
108 * different <code>NumberingRules</code> objects are tried
109 * to be obtained by setting different 'NumberingStyleName'
110 * property styles and getting 'NumberingRules' property values.</li>
111 * <ul> <p>
112 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
113 * @see com.sun.star.style.ParagraphProperties
115 public class _ParagraphProperties extends MultiPropertyTest {
117 * Custom tester for numbering style properties. Switches between
118 * 'Numbering 1' and 'Numbering 2' styles.
120 protected PropertyTester NumberingStyleTester = new PropertyTester() {
121 protected Object getNewValue(String propName, Object oldValue)
122 throws java.lang.IllegalArgumentException {
123 if ((oldValue != null) && (oldValue.equals("Numbering 1"))) {
124 return "Numbering 2";
125 } else {
126 return "Numbering 1";
132 * Custom tester for paragraph style properties. Switches between
133 * 'Salutation' and 'Heading' styles.
135 protected PropertyTester charStyleTester = new PropertyTester() {
136 protected Object getNewValue(String propName, Object oldValue) {
137 if (!utils.isVoid(oldValue) && (oldValue.equals("Example"))) {
138 return "Emphasis";
139 } else {
140 return "Example";
146 * Custom tester for paragraph style properties. Switches between
147 * 'Salutation' and 'Heading' styles.
149 protected PropertyTester ParaStyleTester = new PropertyTester() {
150 protected Object getNewValue(String propName, Object oldValue) {
151 if (!utils.isVoid(oldValue) && (oldValue.equals("Heading"))) {
152 return "Salutation";
153 } else {
154 return "Heading";
160 * Custom tester for PageDescName properties. Switches between
161 * 'HTML' and 'Standard' descriptor names.
163 protected PropertyTester PageDescTester = new PropertyTester() {
164 protected Object getNewValue(String propName, Object oldValue) {
165 if (!util.utils.isVoid(oldValue) &&
166 (oldValue.equals("Default"))) {
167 return "HTML";
168 } else {
169 return "Default";
175 * Custom tester for properties which have <code>short</code> type
176 * and can be void, so if they have void value, the new value must
177 * be specified. Switches between two different values.
179 protected PropertyTester ShortTester = new PropertyTester() {
180 protected Object getNewValue(String propName, Object oldValue) {
181 if ((oldValue != null) &&
182 (oldValue.equals(new Short((short) 0)))) {
183 return new Short((short) 2);
184 } else {
185 return new Short((short) 0);
191 * Custom tester for properties which have <code>boolean</code> type
192 * and can be void, so if they have void value, the new value must
193 * be specified. Switches between true and false.
195 protected PropertyTester BooleanTester = new PropertyTester() {
196 protected Object getNewValue(String propName, Object oldValue) {
197 if ((oldValue != null) &&
198 (oldValue.equals(new Boolean((boolean) false)))) {
199 return new Boolean((boolean) true);
200 } else {
201 return new Boolean((boolean) false);
207 * Custom tester for properties which contains image URLs.
208 * Switches between two JPG images' URLs.
210 protected PropertyTester URLTester = new PropertyTester() {
211 protected Object getNewValue(String propName, Object oldValue) {
212 if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) {
213 return util.utils.getFullTestURL("crazy-blue.jpg");
214 } else {
215 return util.utils.getFullTestURL("space-metal.jpg");
220 protected PropertyTester rules = null;
223 * Creates tester for 'NumberingRules' depending on relation.
225 public void before() {
226 final Object nRules = tEnv.getObjRelation("NRULES");
228 if (nRules != null) {
229 rules = new PropertyTester() {
230 protected Object getNewValue(String propName, Object oldValue) {
231 return nRules;
235 } else {
236 Object rules1 = null;
237 Object rules2 = null;
239 try {
240 oObj.setPropertyValue("NumberingStyleName", "Numbering 1");
241 rules1 = oObj.getPropertyValue("NumberingRules");
242 oObj.setPropertyValue("NumberingStyleName", "Numbering 2");
243 rules2 = oObj.getPropertyValue("NumberingRules");
244 } catch (com.sun.star.lang.WrappedTargetException e) {
245 log.println("WARNING !!! Exception getting numbering rules :");
246 e.printStackTrace(log);
247 } catch (com.sun.star.lang.IllegalArgumentException e) {
248 log.println("WARNING !!! Exception getting numbering rules :");
249 e.printStackTrace(log);
250 } catch (com.sun.star.beans.PropertyVetoException e) {
251 log.println("WARNING !!! Exception getting numbering rules :");
252 e.printStackTrace(log);
253 } catch (com.sun.star.beans.UnknownPropertyException e) {
254 log.println("Property 'NumberingStyleName' is not supported.");
257 rules = new PropertyValueSwitcher(rules1, rules2);
262 * Tested with custom property tester.
264 public void _NumberingStyleName() {
265 log.println("Testing with custom Property tester");
266 testProperty("NumberingStyleName", NumberingStyleTester);
270 * Tested with custom property tester.
272 public void _DropCapCharStyleName() {
273 log.println("Testing with custom Property tester");
274 testProperty("DropCapCharStyleName", charStyleTester);
278 * Tested with custom property tester.
280 public void _ParaStyleName() {
281 log.println("Testing with custom Property tester");
282 testProperty("ParaStyleName", ParaStyleTester);
286 * Tested with custom property tester.
288 public void _PageDescName() {
289 log.println("Testing with custom Property tester");
290 testProperty("PageDescName", PageDescTester);
294 * Tested with custom property tester. Before testing property
295 * <code>ParaAdjust</code> is setting to value <code>BLOCK</code>
296 * because setting the property <code>ParaLastLineAdjust</code>
297 * makes sense only in this case.
299 public void _ParaLastLineAdjust() {
300 log.println("Testing with custom Property tester");
302 try {
303 oObj.setPropertyValue("ParaAdjust",
304 com.sun.star.style.ParagraphAdjust.BLOCK);
305 } catch (com.sun.star.lang.WrappedTargetException e) {
306 log.println("Exception occured setting property 'ParagraphAdjust'" + e);
307 } catch (com.sun.star.lang.IllegalArgumentException e) {
308 log.println("Exception occured setting property 'ParagraphAdjust'" + e);
309 } catch (com.sun.star.beans.UnknownPropertyException e) {
310 log.println("Exception occured setting property 'ParagraphAdjust'" + e);
311 } catch (com.sun.star.beans.PropertyVetoException e) {
312 log.println("Exception occured setting property 'ParagraphAdjust'" + e);
315 testProperty("ParaLastLineAdjust", ShortTester);
319 * Tested with custom property tester.
321 public void _ParaBackGraphicURL() {
322 log.println("Testing with custom Property tester");
323 testProperty("ParaBackGraphicURL", URLTester);
327 * Tested with custom property tester. <p>
328 * The following property tests are to be completed successfully before :
329 * <ul>
330 * <li> <code> NumberingStyleName </code> : a numbering style must
331 * be set before testing this property </li>
332 * </ul>
334 public void _NumberingLevel() {
335 requiredMethod("NumberingStyleName");
336 log.println("Testing with custom Property tester");
337 testProperty("NumberingLevel", ShortTester);
341 * Tested with custom property tester. <p>
343 public void _ParaIsConnectBorder() {
345 log.println("Testing with custom Property tester");
346 testProperty("ParaIsConnectBorder", BooleanTester);
350 * Tested with custom property tester.
352 public void _ParaVertAlignment() {
353 log.println("Testing with custom Property tester");
354 testProperty("ParaVertAlignment", ShortTester);
358 * Tested with com.sun.star.text.NumberingLevel <p>
359 * The value of this property is a com.sun.star.container.XIndexReplace which is represneted by
360 * com.sun.star.text.NumberingLevel.
361 * The following property tests are to be completed successfully before :
362 * <ul>
363 * <li> <code> NumberingStyleName </code> : a numbering style must
364 * be set before testing this property </li>
365 * </ul>
366 * @see com.sun.star.text.NumberlingLevel
367 * @see com.sun.star.container.XIndexReplace
368 * @see ifc.text._NumberingLevel
370 public void _NumberingRules() {
371 requiredMethod("NumberingStyleName");
373 XIndexReplace NumberingRules = null;
374 PropertyValue[] propertyValues = null;
375 try {
376 NumberingRules = (XIndexReplace) AnyConverter.toObject(
377 new Type(XIndexReplace.class), oObj.getPropertyValue("NumberingRules"));
378 } catch (com.sun.star.lang.IllegalArgumentException ex) {
379 Status.failed( "could not get NumberingRuels: "+ ex.toString() );
380 return;
381 } catch (UnknownPropertyException ex) {
382 Status.failed( "could not get NumberingRuels: "+ ex.toString() );
383 return;
384 } catch (WrappedTargetException ex) {
385 Status.failed( "could not get NumberingRuels: "+ ex.toString() );
386 return;
388 try {
389 propertyValues = (PropertyValue[]) NumberingRules.getByIndex(0);
391 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
392 Status.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex.toString() );
393 return;
394 } catch (WrappedTargetException ex) {
395 Status.failed( "could not get NumberlingLevel-Array from NumberingRuels: "+ ex.toString() );
396 return;
399 _NumberingLevel numb = new _NumberingLevel((LogWriter)log, tParam, propertyValues);
401 boolean result = numb.testPropertieArray();
403 tRes.tested("NumberingRules", result);
406 public void _ParaUserDefinedAttributes() {
407 XNameContainer uda = null;
408 boolean res = false;
410 try {
411 try{
412 uda = (XNameContainer) AnyConverter.toObject(
413 new Type(XNameContainer.class),
414 oObj.getPropertyValue("ParaUserDefinedAttributes"));
415 } catch (com.sun.star.lang.IllegalArgumentException e){
416 log.println("ParaUserDefinedAttributes is empty.");
417 uda = new _ParagraphProperties.OwnUserDefinedAttributes();
419 AttributeData attr = new AttributeData();
420 attr.Namespace = "http://www.sun.com/staroffice/apitest/Cellprop";
421 attr.Type = "CDATA";
422 attr.Value = "true";
423 uda.insertByName("Cellprop:has-first-alien-attribute", attr);
425 String[] els = uda.getElementNames();
426 oObj.setPropertyValue("ParaUserDefinedAttributes", uda);
427 uda = (XNameContainer) AnyConverter.toObject(
428 new Type(XNameContainer.class),
429 oObj.getPropertyValue("ParaUserDefinedAttributes"));
430 els = uda.getElementNames();
432 Object obj = uda.getByName("Cellprop:has-first-alien-attribute");
433 res = true;
434 } catch (com.sun.star.beans.UnknownPropertyException upe) {
435 if (isOptional("ParaUserDefinedAttributes")) {
436 log.println("Property is optional and not supported");
437 res = true;
438 } else {
439 log.println("Don't know the Property 'ParaUserDefinedAttributes'");
441 } catch (com.sun.star.lang.WrappedTargetException wte) {
442 log.println(
443 "WrappedTargetException while getting Property 'ParaUserDefinedAttributes'");
444 } catch (com.sun.star.container.NoSuchElementException nee) {
445 log.println("added Element isn't part of the NameContainer");
446 } catch (com.sun.star.lang.IllegalArgumentException iae) {
447 log.println(
448 "IllegalArgumentException while getting Property 'ParaUserDefinedAttributes'");
449 } catch (com.sun.star.beans.PropertyVetoException pve) {
450 log.println(
451 "PropertyVetoException while getting Property 'ParaUserDefinedAttributes'");
452 } catch (com.sun.star.container.ElementExistException eee) {
453 log.println(
454 "ElementExistException while getting Property 'ParaUserDefinedAttributes'");
457 tRes.tested("ParaUserDefinedAttributes", res);
460 private class OwnUserDefinedAttributes implements XNameContainer{
461 Hashtable members = null;
464 public OwnUserDefinedAttributes() {
465 members = new Hashtable();
468 public Object getByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
469 return members.get(str);
472 public String[] getElementNames() {
473 Enumeration oEnum = members.keys();
474 int count = members.size();
475 String[] res = new String[count];
476 int i=0;
477 while(oEnum.hasMoreElements())
478 res[i] = (String)oEnum.nextElement();
479 return res;
482 public com.sun.star.uno.Type getElementType() {
483 Enumeration oEnum = members.keys();
484 String key = (String)oEnum.nextElement();
485 Object o = members.get(key);
486 return new Type(o.getClass());
489 public boolean hasByName(String str) {
490 return members.get(str) != null;
493 public boolean hasElements() {
494 return members.size() > 0;
497 public void insertByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.ElementExistException, com.sun.star.lang.WrappedTargetException {
498 members.put(str, obj);
501 public void removeByName(String str) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
502 members.remove(str);
505 public void replaceByName(String str, Object obj) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException {
506 members.put(str, obj);
510 } // finish class _ParagraphProperties