xref: /AOO41X/main/qadevOOo/tests/java/mod/_sw/SwXChapterNumbering.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sw;
29 
30 import com.sun.star.beans.PropertyValue;
31 import java.io.PrintWriter;
32 
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.text.XChapterNumberingSupplier;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46  * Test for object, which is a collection of chapter numbering rules of document.
47  * Object implements the following interfaces:
48  * <ul>
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>
53  * </ul> <p>
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
64  */
65 public class SwXChapterNumbering extends TestCase {
66     XTextDocument xTextDoc;
67 
68     /**
69     * Creates text document.
70     */
71     protected void initialize( TestParameters tParam, PrintWriter log ) {
72         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)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 );
79         }
80     }
81 
82     /**
83     * Disposes text document.
84     */
85     protected void cleanup( TestParameters tParam, PrintWriter log ) {
86         log.println( "    disposing xTextDoc " );
87         util.DesktopTools.closeDoc(xTextDoc);
88     }
89 
90     /**
91     * Creating a Testenvironment for the interfaces to be tested. Chapter
92     * numbering rules are gotten from text document using interface
93     * <code>XChapterNumberingSupplier</code>.
94     */
95     public TestEnvironment createTestEnvironment(
96             TestParameters tParam, PrintWriter log ) throws StatusException {
97         XInterface oObj = null;
98 
99         XChapterNumberingSupplier oCNSupp = (XChapterNumberingSupplier)
100             UnoRuntime.queryInterface(XChapterNumberingSupplier.class,xTextDoc);
101         oObj = oCNSupp.getChapterNumberingRules();
102 
103         PropertyValue[] instance1 = null;
104         try {
105             instance1 = (PropertyValue[]) oCNSupp.getChapterNumberingRules().getByIndex(1);
106         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
107             e.printStackTrace();
108         } catch (com.sun.star.lang.WrappedTargetException e) {
109             e.printStackTrace();
110         }
111 
112         //instance1[0].Value = new Short((short)5);
113 
114         TestEnvironment tEnv = new TestEnvironment( oObj );
115 
116         tEnv.addObjRelation("INSTANCE1", instance1);
117 
118         return tEnv;
119 
120     } // finish method getTestEnvironment
121 
122 }    // finish class SwXChapterNumbering
123 
124