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
;
23 import lib
.StatusException
;
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
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
35 import com
.sun
.star
.text
.ControlCharacter
;
36 import com
.sun
.star
.text
.XText
;
37 import com
.sun
.star
.text
.XTextCursor
;
38 import com
.sun
.star
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.text.NumberingRules</code>.<p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
50 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
51 * <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * <li> <code>com::sun::star::text::NumberingRules</code></li>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurently.
56 * @see com.sun.star.beans.XPropertySet
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.container.XElementAccess
59 * @see com.sun.star.text.NumberingRules
60 * @see ifc.beans._XPropertySet
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XElementAccess
63 * @see ifc.text._NumberingRules
65 public class SwXNumberingRules
extends TestCase
{
66 XTextDocument xTextDoc
;
69 * Creates text document.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
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
);
83 * Disposes text document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xTextDoc " );
87 util
.DesktopTools
.closeDoc(xTextDoc
);
91 * Creating a Testenvironment for the interfaces to be tested.
92 * At first some strings are inserted to a text document, then style families
93 * are gotten from text document using <code>XStyleFamiliesSupplier</code>.
94 * Then style family 'NuberingRules' is retrieved, then style indexed '0'
95 * is obtained. At the end property value 'NumberingRules' is obtained from
98 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
99 XInterface oObj
= null;
100 XIndexAccess NumStyleI
= null;
102 XText oText
= xTextDoc
.getText();
103 XTextCursor oCursor
= oText
.createTextCursor();
106 for (int i
=0; i
<5; i
++) {
107 oText
.insertString(oCursor
, "The quick brown fox jumps "+
108 "over the lazy Dog", false);
109 oText
.insertControlCharacter(oCursor
,
110 ControlCharacter
.PARAGRAPH_BREAK
, false);
112 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
113 log
.println("Error, exception occurred...");
114 e
.printStackTrace(log
);
117 XStyleFamiliesSupplier oStyleFamiliesSupplier
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
120 XNameAccess oStyleFamilies
= oStyleFamiliesSupplier
.getStyleFamilies();
121 XNameContainer NumStyles
= (XNameContainer
) AnyConverter
.toObject(
122 new Type(XNameContainer
.class),
123 oStyleFamilies
.getByName("NumberingStyles"));
124 NumStyleI
= UnoRuntime
.queryInterface(XIndexAccess
.class,NumStyles
);
125 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
126 log
.println("Error, exception occurred...");
127 e
.printStackTrace(log
);
128 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
129 log
.println("Error, no such style family...");
130 e
.printStackTrace(log
);
131 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
132 log
.println("Error, exception occurred...");
133 e
.printStackTrace(log
);
136 Object instance1
= null;
139 oObj
= (XInterface
) AnyConverter
.toObject(
140 new Type(XInterface
.class),NumStyleI
.getByIndex(0));
141 XPropertySet props
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
142 oObj
= (XInterface
) AnyConverter
.toObject(
143 new Type(XInterface
.class),props
.getPropertyValue("NumberingRules"));
144 XIndexAccess nRules
= UnoRuntime
.queryInterface(XIndexAccess
.class, props
.getPropertyValue("NumberingRules"));
145 instance1
= nRules
.getByIndex(0);
146 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
147 log
.println("Error, exception occurred...");
148 e
.printStackTrace(log
);
149 } catch ( com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
150 log
.println("Error, exception occurred...");
151 e
.printStackTrace(log
);
152 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
153 log
.println("Error, exception occurred...");
154 e
.printStackTrace(log
);
155 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
156 log
.println("Error, exception occurred...");
157 e
.printStackTrace(log
);
160 TestEnvironment tEnv
= new TestEnvironment( oObj
);
162 tEnv
.addObjRelation("INSTANCE1", instance1
);
166 } // finish class SwXNumberingRules