tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / ParagraphStyle.java
blobb85a83ab32a2c8d5fc45acbac0546d94a2cecc59
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;
34 import java.io.PrintWriter;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.DesktopTools;
40 import util.SOfficeFactory;
41 import util.utils;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.style.ParagraphStyle</code>. <p>
47 * @see com.sun.star.style.ParagraphStyle
49 public class ParagraphStyle extends TestCase {
51 XTextDocument xTextDoc;
52 SOfficeFactory SOF = null;
54 /**
55 * Creates text document.
57 @Override
58 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
59 SOF = SOfficeFactory.getFactory( tParam.getMSF() );
60 log.println( "creating a textdocument" );
61 xTextDoc = SOF.createTextDoc( null );
64 /**
65 * Disposes text document.
67 @Override
68 protected void cleanup( TestParameters tParam, PrintWriter log ) {
69 log.println( " disposing xTextDoc " );
70 DesktopTools.closeDoc(xTextDoc);
73 @Override
74 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
75 TestEnvironment tEnv = null;
76 XNameAccess oSFNA = null;
77 XStyle oStyle = null;
78 XStyle oMyStyle = null;
80 log.println("creating a test environment");
82 log.println("getting style");
83 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
84 xTextDoc);
85 XNameAccess oSF = oSFS.getStyleFamilies();
86 oSFNA = UnoRuntime.queryInterface(
87 XNameAccess.class,oSF.getByName("ParagraphStyles"));
88 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
89 oSFNA.getElementNames();
90 oStyle = UnoRuntime.queryInterface(
91 XStyle.class,oSFIA.getByIndex(1));
93 log.print("Creating a user-defined style... ");
94 XMultiServiceFactory oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
95 XInterface oInt = (XInterface)
96 oMSF.createInstance("com.sun.star.style.ParagraphStyle");
97 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
100 if (oMyStyle == null)
101 log.println("FAILED");
102 else
103 log.println("OK");
104 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
106 if ( oSFNC.hasByName("My Style") )
107 oSFNC.removeByName("My Style");
108 oSFNC.insertByName("My Style", oMyStyle);
110 XText oText = xTextDoc.getText();
111 XTextCursor oCursor = oText.createTextCursor();
112 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
114 xProp.setPropertyValue("ParaStyleName", oMyStyle.getName());
116 log.println("creating a new environment for object");
117 tEnv = new TestEnvironment(oMyStyle);
118 tEnv.addObjRelation("PoolStyle", oStyle);
120 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
121 short exclude = PropertyAttribute.READONLY;
123 String[] skipPropertiesNamed = { "ParaBackGraphicURL" };
125 String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude, skipPropertiesNamed);
126 tEnv.addObjRelation("PropertyNames", names);
128 return tEnv;