tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXNumberingRules.java
blobcfc9572288177c9dc896000f9d64fd0bdeba6e31
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.XPropertySet;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.style.XStyleFamiliesSupplier;
33 import com.sun.star.text.ControlCharacter;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.text.NumberingRules</code>.<p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
48 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::text::NumberingRules</code></li>
51 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurrently.
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.container.XIndexAccess
56 * @see com.sun.star.container.XElementAccess
57 * @see com.sun.star.text.NumberingRules
58 * @see ifc.beans._XPropertySet
59 * @see ifc.container._XIndexAccess
60 * @see ifc.container._XElementAccess
61 * @see ifc.text._NumberingRules
63 public class SwXNumberingRules extends TestCase {
64 XTextDocument xTextDoc;
66 /**
67 * Creates text document.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
72 log.println( "creating a textdocument" );
73 xTextDoc = SOF.createTextDoc( null );
76 /**
77 * Disposes text document.
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xTextDoc " );
82 util.DesktopTools.closeDoc(xTextDoc);
85 /**
86 * Creating a TestEnvironment for the interfaces to be tested.
87 * At first some strings are inserted to a text document, then style families
88 * are gotten from text document using <code>XStyleFamiliesSupplier</code>.
89 * Then style family 'NumberingRules' is retrieved, then style indexed '0'
90 * is obtained. At the end property value 'NumberingRules' is obtained from
91 * given style.
93 @Override
94 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
95 XInterface oObj = null;
96 XIndexAccess NumStyleI = null;
98 XText oText = xTextDoc.getText();
99 XTextCursor oCursor = oText.createTextCursor();
101 try {
102 for (int i=0; i<5; i++) {
103 oText.insertString(oCursor, "The quick brown fox jumps "+
104 "over the lazy Dog", false);
105 oText.insertControlCharacter(oCursor,
106 ControlCharacter.PARAGRAPH_BREAK, false);
108 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
109 log.println("Error, exception occurred...");
110 e.printStackTrace(log);
113 XStyleFamiliesSupplier oStyleFamiliesSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
115 try {
116 XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
117 XNameContainer NumStyles = (XNameContainer) AnyConverter.toObject(
118 new Type(XNameContainer.class),
119 oStyleFamilies.getByName("NumberingStyles"));
120 NumStyleI = UnoRuntime.queryInterface(XIndexAccess.class,NumStyles);
121 } catch ( com.sun.star.lang.WrappedTargetException e ) {
122 log.println("Error, exception occurred...");
123 e.printStackTrace(log);
124 } catch ( com.sun.star.container.NoSuchElementException e ) {
125 log.println("Error, no such style family...");
126 e.printStackTrace(log);
127 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
128 log.println("Error, exception occurred...");
129 e.printStackTrace(log);
132 Object instance1 = null;
134 try {
135 oObj = (XInterface) AnyConverter.toObject(
136 new Type(XInterface.class),NumStyleI.getByIndex(0));
137 XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, oObj);
138 oObj = (XInterface) AnyConverter.toObject(
139 new Type(XInterface.class),props.getPropertyValue("NumberingRules"));
140 XIndexAccess nRules = UnoRuntime.queryInterface(XIndexAccess.class, props.getPropertyValue("NumberingRules"));
141 instance1 = nRules.getByIndex(0);
142 } catch ( com.sun.star.lang.WrappedTargetException e ) {
143 log.println("Error, exception occurred...");
144 e.printStackTrace(log);
145 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) {
146 log.println("Error, exception occurred...");
147 e.printStackTrace(log);
148 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
149 log.println("Error, exception occurred...");
150 e.printStackTrace(log);
151 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
152 log.println("Error, exception occurred...");
153 e.printStackTrace(log);
156 TestEnvironment tEnv = new TestEnvironment( oObj );
158 tEnv.addObjRelation("INSTANCE1", instance1);
159 return tEnv;
162 } // finish class SwXNumberingRules