tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / ConditionalParagraphStyle.java
blobfbcc9e2b0f649b01dd26a879772c7696a1a66637
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.Status;
37 import lib.StatusException;
38 import lib.TestCase;
39 import lib.TestEnvironment;
40 import lib.TestParameters;
41 import util.DesktopTools;
42 import util.SOfficeFactory;
43 import util.utils;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.style.ConditionalParagraphStyle</code>. <p>
48 * @see com.sun.star.style.ConditionalParagraphStyle
50 public class ConditionalParagraphStyle extends TestCase {
52 XTextDocument xTextDoc;
53 SOfficeFactory SOF = null;
55 /**
56 * Creates text document.
58 @Override
59 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
60 SOF = SOfficeFactory.getFactory( tParam.getMSF() );
61 log.println( "creating a textdocument" );
62 xTextDoc = SOF.createTextDoc( null );
65 /**
66 * Disposes text document.
68 @Override
69 protected void cleanup( TestParameters tParam, PrintWriter log ) {
70 log.println( " disposing xTextDoc " );
71 DesktopTools.closeDoc(xTextDoc);
74 /**
75 * Create a new instance of the conditional
76 * paragraph style, and insert it into the document.
77 * @see com.sun.star.style.ConditionalParagraphStyle
78 * @param tParam The test parameters
79 * @param log The log writer.
81 @Override
82 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
83 TestEnvironment tEnv = null;
84 XNameAccess oSFNA = null;
85 XStyle oStyle = null;
86 XStyle oMyStyle = null;
88 log.println("creating a test environment");
90 log.println("getting style");
91 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
92 xTextDoc);
93 XNameAccess oSF = oSFS.getStyleFamilies();
94 oSFNA = UnoRuntime.queryInterface(
95 XNameAccess.class,oSF.getByName("ParagraphStyles"));
96 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSFNA);
97 oStyle = UnoRuntime.queryInterface(
98 XStyle.class,oSFIA.getByIndex(1));
100 log.print("Creating a user-defined style... ");
101 XMultiServiceFactory oMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
102 XInterface oInt = (XInterface)
103 oMSF.createInstance("com.sun.star.style.ConditionalParagraphStyle");
104 oMyStyle = UnoRuntime.queryInterface(XStyle.class, oInt);
107 if (oMyStyle == null) {
108 log.println("FAILED");
109 throw new StatusException(Status.failed("Couldn't create an own style "));
111 else {
112 log.println("OK");
115 XNameContainer oSFNC = UnoRuntime.queryInterface(XNameContainer.class, oSFNA);
117 if ( oSFNC.hasByName("My Style") )
118 oSFNC.removeByName("My Style");
119 oSFNC.insertByName("My Style", oMyStyle);
121 XText oText = xTextDoc.getText();
122 XTextCursor oCursor = oText.createTextCursor();
123 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oCursor);
124 xProp.setPropertyValue("ParaStyleName", oMyStyle.getName());
126 log.println("creating a new environment for object");
127 tEnv = new TestEnvironment(oMyStyle);
128 tEnv.addObjRelation("PoolStyle", oStyle);
130 XPropertySet xStyleProp = UnoRuntime.queryInterface(XPropertySet.class, oMyStyle);
131 short exclude = PropertyAttribute.READONLY;
132 String[] skipPropertiesNamed = { "ParaBackGraphicURL" };
134 String[] names = utils.getFilteredPropertyNames(xStyleProp, (short)0, exclude, skipPropertiesNamed);
136 tEnv.addObjRelation("PropertyNames", names);
137 tEnv.addObjRelation("SkipProperties", skipPropertiesNamed);
139 return tEnv;