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 .
21 import java
.io
.PrintWriter
;
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
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.text.NumberingRules</code>.<p>
45 * Object implements the following interfaces :
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>
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
;
67 * Creates text document.
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 );
77 * Disposes text document.
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xTextDoc " );
82 util
.DesktopTools
.closeDoc(xTextDoc
);
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
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();
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
);
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;
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
);
162 } // finish class SwXNumberingRules