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