bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / ParagraphStyle.java
blobaad213a58d2c5ce16085ae831db95ab8b3888da0
1 /*
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 .
18 package mod._sw;
20 import com.sun.star.beans.PropertyAttribute;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.container.XIndexAccess;
23 import com.sun.star.container.XNameAccess;
24 import com.sun.star.container.XNameContainer;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.style.XStyle;
27 import com.sun.star.style.XStyleFamiliesSupplier;
28 import com.sun.star.text.XText;
29 import com.sun.star.text.XTextCursor;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.DesktopTools;
39 import util.SOfficeFactory;
40 import util.utils;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.style.ParagraphStyle</code>. <p>
46 * @see com.sun.star.style.ParagraphStyle
48 public class ParagraphStyle extends TestCase {
50 XTextDocument xTextDoc;
51 SOfficeFactory SOF = null;
53 /**
54 * Creates text document.
56 @Override
57 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 SOF = SOfficeFactory.getFactory( tParam.getMSF() );
59 try {
60 log.println( "creating a textdocument" );
61 xTextDoc = SOF.createTextDoc( null );
62 } catch ( com.sun.star.uno.Exception e ) {
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * Disposes text document.
71 @Override
72 protected void cleanup( TestParameters tParam, PrintWriter log ) {
73 log.println( " disposing xTextDoc " );
74 DesktopTools.closeDoc(xTextDoc);
77 @Override
78 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
79 TestEnvironment tEnv = null;
80 XNameAccess oSFNA = null;
81 XStyle oStyle = null;
82 XStyle oMyStyle = null;
84 log.println("creating a test environment");
86 try {
87 log.println("getting style");
88 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
89 xTextDoc);
90 XNameAccess oSF = oSFS.getStyleFamilies();
91 oSFNA = UnoRuntime.queryInterface(
92 XNameAccess.class,oSF.getByName("ParagraphStyles"));
93 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
94 oSFNA.getElementNames();
95 oStyle = UnoRuntime.queryInterface(
96 XStyle.class,oSFIA.getByIndex(1));
97 } catch ( com.sun.star.lang.WrappedTargetException e ) {
98 log.println("Error: exception occurred.");
99 e.printStackTrace(log);
100 throw new StatusException( "Couldn't create environment ", e );
101 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) {
102 log.println("Error: exception occurred.");
103 e.printStackTrace(log);
104 throw new StatusException( "Couldn't create environment ", e );
105 } catch ( com.sun.star.container.NoSuchElementException e ) {
106 log.println("Error: exception occurred.");
107 e.printStackTrace(log);
108 throw new StatusException( "Couldn't create environment ", e );
111 try {
112 log.print("Creating a user-defined style... ");
113 XMultiServiceFactory oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
114 XInterface oInt = (XInterface)
115 oMSF.createInstance("com.sun.star.style.ParagraphStyle");
116 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
117 } catch ( com.sun.star.uno.Exception e ) {
118 log.println("Error: exception occurred.");
119 e.printStackTrace(log);
120 throw new StatusException( "Couldn't create environment ", e );
124 if (oMyStyle == null)
125 log.println("FAILED");
126 else
127 log.println("OK");
128 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
130 try {
131 if ( oSFNC.hasByName("My Style") )
132 oSFNC.removeByName("My Style");
133 oSFNC.insertByName("My Style", oMyStyle);
134 } catch ( com.sun.star.lang.WrappedTargetException e ) {
135 e.printStackTrace(log);
136 throw new StatusException( "Couldn't create environment ", e );
137 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
138 e.printStackTrace(log);
139 throw new StatusException( "Couldn't create environment ", e );
140 } catch ( com.sun.star.container.NoSuchElementException e ) {
141 e.printStackTrace(log);
142 throw new StatusException( "Couldn't create environment ", e );
143 } catch ( com.sun.star.container.ElementExistException e ) {
144 e.printStackTrace(log);
145 throw new StatusException( "Couldn't create environment ", e );
148 XText oText = xTextDoc.getText();
149 XTextCursor oCursor = oText.createTextCursor();
150 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
152 try {
153 xProp.setPropertyValue("ParaStyleName", oMyStyle.getName());
154 } catch ( com.sun.star.lang.WrappedTargetException e ) {
155 e.printStackTrace( log );
156 throw new StatusException( "Couldn't create environment ", e );
157 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
158 e.printStackTrace( log );
159 throw new StatusException( "Couldn't create environment ", e );
160 } catch ( com.sun.star.beans.PropertyVetoException e ) {
161 e.printStackTrace( log );
162 throw new StatusException( "Couldn't create environment ", e );
163 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
164 e.printStackTrace( log );
165 throw new StatusException( "Couldn't create environment ", e );
168 log.println("creating a new environment for object");
169 tEnv = new TestEnvironment(oMyStyle);
170 tEnv.addObjRelation("PoolStyle", oStyle);
172 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
173 short exclude = PropertyAttribute.READONLY;
174 String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude);
175 tEnv.addObjRelation("PropertyNames", names);
177 return tEnv;