1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sw;
25 
26 import com.sun.star.beans.PropertyValue;
27 import java.io.PrintWriter;
28 
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XChapterNumberingSupplier;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42  * Test for object, which is a collection of chapter numbering rules of document.
43  * Object implements the following interfaces:
44  * <ul>
45  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
46  *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
47  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
48  *  <li> <code>com::sun::star::text::NumberingRules</code></li>
49  * </ul> <p>
50  * This object test <b> is NOT </b> designed to be run in several
51  * threads concurently.
52  * @see com.sun.star.beans.XPropertySet
53  * @see com.sun.star.container.XIndexAccess
54  * @see com.sun.star.container.XElementAccess
55  * @see com.sun.star.text.NumberingRules
56  * @see ifc.beans._XPropertySet
57  * @see ifc.container._XIndexAccess
58  * @see ifc.container._XElementAccess
59  * @see ifc.text._NumberingRules
60  */
61 public class SwXChapterNumbering extends TestCase {
62     XTextDocument xTextDoc;
63 
64     /**
65     * Creates text document.
66     */
initialize( TestParameters tParam, PrintWriter log )67     protected void initialize( TestParameters tParam, PrintWriter log ) {
68         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
69         try {
70             log.println( "creating a textdocument" );
71             xTextDoc = SOF.createTextDoc( null );
72         } catch ( com.sun.star.uno.Exception e ) {
73             e.printStackTrace( log );
74             throw new StatusException( "Couldn't create document", e );
75         }
76     }
77 
78     /**
79     * Disposes text document.
80     */
cleanup( TestParameters tParam, PrintWriter log )81     protected void cleanup( TestParameters tParam, PrintWriter log ) {
82         log.println( "    disposing xTextDoc " );
83         util.DesktopTools.closeDoc(xTextDoc);
84     }
85 
86     /**
87     * Creating a Testenvironment for the interfaces to be tested. Chapter
88     * numbering rules are gotten from text document using interface
89     * <code>XChapterNumberingSupplier</code>.
90     */
createTestEnvironment( TestParameters tParam, PrintWriter log )91     public TestEnvironment createTestEnvironment(
92             TestParameters tParam, PrintWriter log ) throws StatusException {
93         XInterface oObj = null;
94 
95         XChapterNumberingSupplier oCNSupp = (XChapterNumberingSupplier)
96             UnoRuntime.queryInterface(XChapterNumberingSupplier.class,xTextDoc);
97         oObj = oCNSupp.getChapterNumberingRules();
98 
99         PropertyValue[] instance1 = null;
100         try {
101             instance1 = (PropertyValue[]) oCNSupp.getChapterNumberingRules().getByIndex(1);
102         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
103             e.printStackTrace();
104         } catch (com.sun.star.lang.WrappedTargetException e) {
105             e.printStackTrace();
106         }
107 
108         //instance1[0].Value = new Short((short)5);
109 
110         TestEnvironment tEnv = new TestEnvironment( oObj );
111 
112         tEnv.addObjRelation("INSTANCE1", instance1);
113 
114         return tEnv;
115 
116     } // finish method getTestEnvironment
117 
118 }    // finish class SwXChapterNumbering
119 
120