tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXStyle.java
blob6a01b029e1159904acc318884ed09a67ec790389
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.Property;
29 import com.sun.star.beans.PropertyAttribute;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.container.XNameAccess;
33 import com.sun.star.container.XNameContainer;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.style.XStyle;
36 import com.sun.star.style.XStyleFamiliesSupplier;
37 import com.sun.star.text.XText;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.style.Style</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::container::XNamed</code></li>
51 * <li> <code>com::sun::star::style::Style</code></li>
52 * <li> <code>com::sun::star::style::XStyle</code></li>
53 * </ul> <p>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurrently.
56 * @see com.sun.star.container.XNamed
57 * @see com.sun.star.style.Style
58 * @see com.sun.star.style.XStyle
59 * @see ifc.container._XNamed
60 * @see ifc.style._Style
61 * @see ifc.style._XStyle
63 public class SwXStyle extends TestCase {
64 XTextDocument xTextDoc;
65 SOfficeFactory SOF = null;
67 /**
68 * Creates text document.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
72 SOF = SOfficeFactory.getFactory( tParam.getMSF() );
73 log.println( "creating a textdocument" );
74 xTextDoc = SOF.createTextDoc( null );
77 /**
78 * Disposes text document.
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xTextDoc " );
83 util.DesktopTools.closeDoc(xTextDoc);
86 /**
87 * Creating a TestEnvironment for the interfaces to be tested.
88 * At first style families are gotten from a text document using
89 * <code>XStyleFamiliesSupplier</code> interface, then family indexed '0' is
90 * gotten from this style family using <code>XIndexAccess</code> interface.
91 * Next, method creates an instance of the service
92 * <code>com.sun.star.style.CharacterStyle</code> and inserts it to a
93 * previously obtained style family using <code>XNameContainer</code>
94 * interface. Finally, method creates a cursor of a major text of text
95 * document and sets it's property 'CharStyleName' value to the name of
96 * previously created style's name.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'PoolStyle'</code> for
100 * {@link ifc.style._XStyle} : style indexed '10' obtained from
101 * StyleFamily indexed '0' from text document using
102 * <code>XIndexAccess</code> interface.</li>
103 * </ul>
105 @Override
106 protected TestEnvironment createTestEnvironment
107 (TestParameters Param, PrintWriter log) throws Exception {
109 TestEnvironment tEnv = null;
110 XNameAccess oSFNA = null;
111 XStyle oStyle = null;
112 XStyle oMyStyle = null;
114 log.println("creating a test environment");
116 log.println("getting style");
117 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
118 xTextDoc);
119 XNameAccess oSF = oSFS.getStyleFamilies();
120 XIndexAccess oSFsIA = UnoRuntime.queryInterface(XIndexAccess.class, oSF);
121 oSFNA = (XNameAccess) AnyConverter.toObject(
122 new Type(XNameAccess.class),oSFsIA.getByIndex(0));
123 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
124 oStyle = (XStyle) AnyConverter.toObject(
125 new Type(XStyle.class),oSFIA.getByIndex(10));
127 log.print("Creating a user-defined style... ");
128 XMultiServiceFactory oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
129 XInterface oInt = (XInterface)
130 oMSF.createInstance("com.sun.star.style.CharacterStyle");
131 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
134 if (oMyStyle == null)
135 log.println("FAILED");
136 else
137 log.println("OK");
138 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
140 if ( oSFNC.hasByName("My Style") )
141 oSFNC.removeByName("My Style");
142 oSFNC.insertByName("My Style", oMyStyle);
144 XText oText = xTextDoc.getText();
145 XTextCursor oCursor = oText.createTextCursor();
146 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
148 xProp.setPropertyValue("CharStyleName", oMyStyle.getName());
150 log.println("creating a new environment for object");
151 tEnv = new TestEnvironment(oMyStyle);
152 tEnv.addObjRelation("PoolStyle", oStyle);
154 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
155 tEnv.addObjRelation("PropertyNames",getPropertyNames(xStyleProp));
157 return tEnv;
160 public String[] getPropertyNames(XPropertySet props) {
161 Property[] the_props = props.getPropertySetInfo().getProperties();
162 String[] names = new String[the_props.length];
163 String placebo = "";
164 for (int i=0;i<the_props.length;i++) {
165 boolean isWritable =
166 ((the_props[i].Attributes & PropertyAttribute.READONLY) == 0);
167 if (isWritable) placebo=the_props[i].Name;
169 for (int i=0;i<the_props.length;i++) {
170 boolean isWritable =
171 ((the_props[i].Attributes & PropertyAttribute.READONLY) == 0);
172 if (isWritable) {
173 names[i]=the_props[i].Name;
174 } else {
175 names[i] = placebo;
178 return names;
181 } // finish class SwXStyle