merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / PageStyle.java
blobdb392da1b8489bd4f17a0f5adf9a4923d842f5e6
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: PageStyle.java,v $
10 * $Revision: 1.4 $
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 mod._sw;
32 import com.sun.star.beans.Property;
33 import com.sun.star.beans.PropertyAttribute;
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.container.XNameAccess;
37 import com.sun.star.container.XNameContainer;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.style.XStyle;
40 import com.sun.star.style.XStyleFamiliesSupplier;
41 import com.sun.star.text.XText;
42 import com.sun.star.text.XTextCursor;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import java.io.PrintWriter;
47 import lib.StatusException;
48 import lib.TestCase;
49 import lib.TestEnvironment;
50 import lib.TestParameters;
51 import util.DesktopTools;
52 import util.SOfficeFactory;
53 import util.utils;
55 /**
56 * Test for object which is represented by service
57 * <code>com.sun.star.style.PageStyle</code>. <p>
58 * @see com.sun.star.style.PageStyle
60 public class PageStyle extends TestCase {
62 XTextDocument xTextDoc;
63 SOfficeFactory SOF = null;
65 /**
66 * Creates text document.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 log.println( "creating a textdocument" );
72 xTextDoc = SOF.createTextDoc( null );
73 } catch ( com.sun.star.uno.Exception e ) {
74 e.printStackTrace( log );
75 throw new StatusException( "Couldn't create document", e );
79 /**
80 * Disposes text document.
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xTextDoc " );
84 DesktopTools.closeDoc(xTextDoc);
87 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
88 TestEnvironment tEnv = null;
89 XNameAccess oSFNA = null;
90 XStyle oStyle = null;
91 XStyle oMyStyle = null;
93 log.println("creating a test environment");
95 try {
96 log.println("getting style");
97 XStyleFamiliesSupplier oSFS = (XStyleFamiliesSupplier)
98 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
99 xTextDoc);
100 XNameAccess oSF = oSFS.getStyleFamilies();
101 oSFNA = (XNameAccess) UnoRuntime.queryInterface(
102 XNameAccess.class,oSF.getByName("PageStyles")); // get the page style
103 XIndexAccess oSFIA = (XIndexAccess)
104 UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
105 oStyle = (XStyle) UnoRuntime.queryInterface(
106 XStyle.class,oSFIA.getByIndex(0));
107 log.println("Chosen pool style: "+oStyle.getName());
109 } catch ( com.sun.star.lang.WrappedTargetException e ) {
110 log.println("Error: exception occured.");
111 e.printStackTrace(log);
112 throw new StatusException( "Couldn't create environment ", e );
113 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) {
114 log.println("Error: exception occured.");
115 e.printStackTrace(log);
116 throw new StatusException( "Couldn't create environment ", e );
117 } catch ( com.sun.star.container.NoSuchElementException e ) {
118 log.println("Error: exception occured.");
119 e.printStackTrace(log);
120 throw new StatusException( "Couldn't create environment ", e );
123 try {
124 log.print("Creating a user-defined style... ");
125 XMultiServiceFactory oMSF = (XMultiServiceFactory)
126 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
127 XInterface oInt = (XInterface)
128 oMSF.createInstance("com.sun.star.style.PageStyle");
129 // oMSF.createInstanceWithArguments("com.sun.star.style.PageStyle",new Object[]{oStyle});
130 oMyStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class, oInt);
131 } catch ( com.sun.star.uno.Exception e ) {
132 log.println("Error: exception occured.");
133 e.printStackTrace(log);
134 throw new StatusException( "Couldn't create environment ", e );
138 if (oMyStyle == null)
139 log.println("FAILED");
140 else
141 log.println("OK");
143 XNameContainer oSFNC = (XNameContainer)
144 UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
147 try {
148 if ( oSFNC.hasByName("My Style") )
149 oSFNC.removeByName("My Style");
150 oSFNC.insertByName("My Style", oMyStyle);
151 } catch ( com.sun.star.lang.WrappedTargetException e ) {
152 e.printStackTrace(log);
153 throw new StatusException( "Couldn't create environment ", e );
154 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
155 e.printStackTrace(log);
156 throw new StatusException( "Couldn't create environment ", e );
157 } catch ( com.sun.star.container.NoSuchElementException e ) {
158 e.printStackTrace(log);
159 throw new StatusException( "Couldn't create environment ", e );
160 } catch ( com.sun.star.container.ElementExistException e ) {
161 e.printStackTrace(log);
162 throw new StatusException( "Couldn't create environment ", e );
165 XText oText = xTextDoc.getText();
166 XTextCursor oCursor = oText.createTextCursor();
167 XPropertySet xProp = (XPropertySet)
168 UnoRuntime.queryInterface(XPropertySet.class, oCursor);
169 Property[] props = xProp.getPropertySetInfo().getProperties();
170 for (int i=0; i<props.length; i++)
171 System.out.println("# Property: " + props[i].Name + " val: " + props[i].Type.toString() + " attr: " + props[i].Attributes);
172 try {
173 xProp.setPropertyValue("PageDescName", oMyStyle.getName());
174 } catch ( com.sun.star.lang.WrappedTargetException e ) {
175 e.printStackTrace( log );
176 throw new StatusException( "Couldn't create environment ", e );
177 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
178 e.printStackTrace( log );
179 throw new StatusException( "Couldn't create environment ", e );
180 } catch ( com.sun.star.beans.PropertyVetoException e ) {
181 e.printStackTrace( log );
182 throw new StatusException( "Couldn't create environment ", e );
183 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
184 e.printStackTrace( log );
185 throw new StatusException( "Couldn't create environment ", e );
188 // oMyStyle = oStyle;
189 log.println("creating a new environment for object");
190 tEnv = new TestEnvironment(oMyStyle);
191 tEnv.addObjRelation("PoolStyle", oStyle);
193 tEnv.addObjRelation("FollowStyle", "Envelope");
194 XPropertySet xStyleProp = (XPropertySet)
195 UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
197 short exclude = PropertyAttribute.MAYBEVOID + PropertyAttribute.READONLY;
198 String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude);
199 tEnv.addObjRelation("PropertyNames", names);
201 return tEnv;