merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXNumberingRules.java
blob74c83561bc2831c394787275b3266fcc7e5c3c37
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: SwXNumberingRules.java,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.container.XIndexAccess;
43 import com.sun.star.container.XNameAccess;
44 import com.sun.star.container.XNameContainer;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.style.XStyleFamiliesSupplier;
47 import com.sun.star.text.ControlCharacter;
48 import com.sun.star.text.XText;
49 import com.sun.star.text.XTextCursor;
50 import com.sun.star.text.XTextDocument;
51 import com.sun.star.uno.AnyConverter;
52 import com.sun.star.uno.Type;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.text.NumberingRules</code>.<p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
62 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
63 * <li> <code>com::sun::star::container::XElementAccess</code></li>
64 * <li> <code>com::sun::star::text::NumberingRules</code></li>
65 * </ul> <p>
66 * This object test <b> is NOT </b> designed to be run in several
67 * threads concurently.
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.container.XIndexAccess
70 * @see com.sun.star.container.XElementAccess
71 * @see com.sun.star.text.NumberingRules
72 * @see ifc.beans._XPropertySet
73 * @see ifc.container._XIndexAccess
74 * @see ifc.container._XElementAccess
75 * @see ifc.text._NumberingRules
77 public class SwXNumberingRules extends TestCase {
78 XTextDocument xTextDoc;
80 /**
81 * Creates text document.
83 protected void initialize( TestParameters tParam, PrintWriter log ) {
84 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
85 try {
86 log.println( "creating a textdocument" );
87 xTextDoc = SOF.createTextDoc( null );
88 } catch ( com.sun.star.uno.Exception e ) {
89 e.printStackTrace( log );
90 throw new StatusException( "Couldn't create document", e );
94 /**
95 * Disposes text document.
97 protected void cleanup( TestParameters tParam, PrintWriter log ) {
98 log.println( " disposing xTextDoc " );
99 util.DesktopTools.closeDoc(xTextDoc);
103 * Creating a Testenvironment for the interfaces to be tested.
104 * At first some strings are inserted to a text document, then style families
105 * are gotten from text document using <code>XStyleFamiliesSupplier</code>.
106 * Then style family 'NuberingRules' is retrieved, then style indexed '0'
107 * is obtained. At the end property value 'NumberingRules' is obtained from
108 * given style.
110 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
111 XInterface oObj = null;
112 XIndexAccess NumStyleI = null;
114 XText oText = xTextDoc.getText();
115 XTextCursor oCursor = oText.createTextCursor();
117 try {
118 for (int i=0; i<5; i++) {
119 oText.insertString(oCursor, "The quick brown fox jumps "+
120 "over the lazy Dog", false);
121 oText.insertControlCharacter(oCursor,
122 ControlCharacter.PARAGRAPH_BREAK, false);
124 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
125 log.println("Error, exception occured...");
126 e.printStackTrace(log);
129 XStyleFamiliesSupplier oStyleFamiliesSupplier = (XStyleFamiliesSupplier)
130 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
132 try {
133 XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
134 XNameContainer NumStyles = (XNameContainer) AnyConverter.toObject(
135 new Type(XNameContainer.class),
136 oStyleFamilies.getByName("NumberingStyles"));
137 NumStyleI = (XIndexAccess)
138 UnoRuntime.queryInterface(XIndexAccess.class,NumStyles);
139 } catch ( com.sun.star.lang.WrappedTargetException e ) {
140 log.println("Error, exception occured...");
141 e.printStackTrace(log);
142 } catch ( com.sun.star.container.NoSuchElementException e ) {
143 log.println("Error, no such style family...");
144 e.printStackTrace(log);
145 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
146 log.println("Error, exception occured...");
147 e.printStackTrace(log);
150 Object instance1 = null;
152 try {
153 oObj = (XInterface) AnyConverter.toObject(
154 new Type(XInterface.class),NumStyleI.getByIndex(0));
155 XPropertySet props = (XPropertySet)
156 UnoRuntime.queryInterface(XPropertySet.class, oObj);
157 oObj = (XInterface) AnyConverter.toObject(
158 new Type(XInterface.class),props.getPropertyValue("NumberingRules"));
159 XIndexAccess nRules = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, props.getPropertyValue("NumberingRules"));
160 instance1 = nRules.getByIndex(0);
161 } catch ( com.sun.star.lang.WrappedTargetException e ) {
162 log.println("Error, exception occured...");
163 e.printStackTrace(log);
164 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) {
165 log.println("Error, exception occured...");
166 e.printStackTrace(log);
167 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
168 log.println("Error, exception occured...");
169 e.printStackTrace(log);
170 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
171 log.println("Error, exception occured...");
172 e.printStackTrace(log);
175 TestEnvironment tEnv = new TestEnvironment( oObj );
177 tEnv.addObjRelation("INSTANCE1", instance1);
178 return tEnv;
181 } // finish class SwXNumberingRules