tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / PageStyle.java
blob7de28b2019a76cde28b71cf2f71965995d9766a0
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.Property;
21 import com.sun.star.beans.PropertyAttribute;
22 import com.sun.star.beans.XPropertySet;
23 import com.sun.star.container.XIndexAccess;
24 import com.sun.star.container.XNameAccess;
25 import com.sun.star.container.XNameContainer;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.style.XStyle;
28 import com.sun.star.style.XStyleFamiliesSupplier;
29 import com.sun.star.text.XText;
30 import com.sun.star.text.XTextCursor;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 import java.io.PrintWriter;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.DesktopTools;
41 import util.SOfficeFactory;
42 import util.utils;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.style.PageStyle</code>. <p>
47 * @see com.sun.star.style.PageStyle
49 public class PageStyle 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("PageStyles")); // get the page style
88 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
89 oStyle = UnoRuntime.queryInterface(
90 XStyle.class,oSFIA.getByIndex(0));
91 log.println("Chosen pool style: "+oStyle.getName());
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.PageStyle");
97 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
100 if (oMyStyle == null)
101 log.println("FAILED");
102 else
103 log.println("OK");
105 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
108 if ( oSFNC.hasByName("My Style") )
109 oSFNC.removeByName("My Style");
110 oSFNC.insertByName("My Style", oMyStyle);
112 XText oText = xTextDoc.getText();
113 XTextCursor oCursor = oText.createTextCursor();
114 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
115 Property[] props = xProp.getPropertySetInfo().getProperties();
116 for (int i=0; i<props.length; i++)
117 System.out.println("# Property: " + props[i].Name + " val: " + props[i].Type.toString() + " attr: " + props[i].Attributes);
118 xProp.setPropertyValue("PageDescName", oMyStyle.getName());
120 // oMyStyle = oStyle;
121 log.println("creating a new environment for object");
122 tEnv = new TestEnvironment(oMyStyle);
123 tEnv.addObjRelation("PoolStyle", oStyle);
125 tEnv.addObjRelation("FollowStyle", "Envelope");
126 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
128 short exclude = PropertyAttribute.READONLY;
130 String[] skipPropertiesNamed = {
131 "BackGraphicURL", "HeaderBackGraphicURL", "FooterBackGraphicURL"
134 String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude, skipPropertiesNamed);
135 tEnv.addObjRelation("PropertyNames", names);
136 tEnv.addObjRelation("SkipProperties", skipPropertiesNamed);
138 return tEnv;