tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / CharacterStyle.java
blob8f7c3b18169bd84966fca6b5f423bc7fd67b7d26
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 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.CharacterStyle</code>. <p>
47 * @see com.sun.star.style.CharacterStyle
49 public class CharacterStyle extends TestCase {
50 private XTextDocument xTextDoc;
52 /**
53 * Creates text document.
55 @Override
56 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
57 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
58 log.println( "creating a textdocument" );
59 xTextDoc = SOF.createTextDoc( null );
62 /**
63 * Disposes text document.
65 @Override
66 protected void cleanup( TestParameters tParam, PrintWriter log ) {
67 log.println( " disposing xTextDoc " );
68 DesktopTools.closeDoc(xTextDoc);
71 /**
72 * Creating a TestEnvironment for the interfaces to be tested.
73 * At first style families are gotten from a text document using
74 * <code>XStyleFamiliesSupplier</code> interface, then family indexed '0' is
75 * gotten from this style family using <code>XIndexAccess</code> interface.
76 * Next, method creates an instance of the service
77 * <code>com.sun.star.style.CharacterStyle</code> and inserts it to a
78 * previously obtained style family using <code>XNameContainer</code>
79 * interface. Finally, method creates a cursor of a major text of text
80 * document and sets it's property 'CharStyleName' value to the name of
81 * previously created style's name.
82 * Object relations created :
83 * <ul>
84 * <li> <code>'PoolStyle'</code> for
85 * {@link ifc.style._XStyle} : style indexed '10' obtained from
86 * StyleFamily indexed '0' from text document using
87 * <code>XIndexAccess</code> interface.</li>
88 * </ul>
90 @Override
91 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
93 TestEnvironment tEnv = null;
94 XNameAccess oSFNA = null;
95 XStyle oStyle = null;
96 XStyle oMyStyle = null;
98 log.println("creating a test environment");
100 log.println("getting style");
101 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
102 xTextDoc);
103 XNameAccess oSF = oSFS.getStyleFamilies();
104 XIndexAccess oSFsIA = UnoRuntime.queryInterface(XIndexAccess.class, oSF);
105 oSFNA = UnoRuntime.queryInterface(
106 XNameAccess.class,oSFsIA.getByIndex(0));
107 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
108 oStyle = UnoRuntime.queryInterface(
109 XStyle.class,oSFIA.getByIndex(0));
111 log.print("Creating a user-defined style... ");
112 XMultiServiceFactory oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
113 XInterface oInt = (XInterface)
114 oMSF.createInstance("com.sun.star.style.CharacterStyle");
115 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
118 if (oMyStyle == null)
119 log.println("FAILED");
120 else
121 log.println("OK");
122 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
124 if ( oSFNC.hasByName("My Style") )
125 oSFNC.removeByName("My Style");
126 oSFNC.insertByName("My Style", oMyStyle);
128 XText oText = xTextDoc.getText();
129 XTextCursor oCursor = oText.createTextCursor();
130 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
132 xProp.setPropertyValue("CharStyleName", oMyStyle.getName());
134 log.println("creating a new environment for object");
135 tEnv = new TestEnvironment(oMyStyle);
136 tEnv.addObjRelation("PoolStyle", oStyle);
138 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
140 String[] skipPropertiesNamed = {};
142 short exclude = PropertyAttribute.READONLY;
143 tEnv.addObjRelation("PropertyNames",utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude, skipPropertiesNamed));
145 return tEnv;