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 java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 import util.dbg;
38 
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.text.ControlCharacter;
42 import com.sun.star.text.XLineNumberingProperties;
43 import com.sun.star.text.XText;
44 import com.sun.star.text.XTextCursor;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 
48 /**
49  * Test for object which is represented by service
50  * <code>com.sun.star.text.LineNumberingProperties</code>. <p>
51  * Object implements the following interfaces :
52  * <ul>
53  *  <li> <code>com::sun::star::text::LineNumberingProperties</code></li>
54  * </ul> <p>
55  * This object test <b> is NOT </b> designed to be run in several
56  * threads concurently.
57  * @see com.sun.star.text.LineNumberingProperties
58  * @see ifc.text._LineNumberingProperties
59  */
60 public class SwXLineNumberingProperties extends TestCase {
61     XTextDocument xTextDoc;
62 
63     /**
64     * Creates text document.
65     */
66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68         try {
69             log.println( "creating a textdocument" );
70             xTextDoc = SOF.createTextDoc( null );
71         } catch ( com.sun.star.uno.Exception e ) {
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78     * Disposes text document.
79     */
80     protected void cleanup( TestParameters tParam, PrintWriter log ) {
81         log.println( "    disposing xTextDoc " );
82         util.DesktopTools.closeDoc(xTextDoc);
83     }
84 
85 
86     /**
87     * Creating a Testenvironment for the interfaces to be tested. After inserting
88     * string and control character to the text document, line numbering
89     * properties are gotten using <code>XLineNumberingProperties</code> interface.
90     */
91     public TestEnvironment createTestEnvironment(
92             TestParameters tParam, PrintWriter log ) throws StatusException {
93 
94         // insert some Text
95         XText oText = xTextDoc.getText();
96         XTextCursor oCursor = oText.createTextCursor();
97         try {
98             for (int i=0; i<5; i++) {
99                 oText.insertString(oCursor, "The quick brown fox jumps "+
100                     "over the lazy Dog", false);
101                 oText.insertControlCharacter(oCursor,
102                     ControlCharacter.PARAGRAPH_BREAK, false );
103             }
104         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
105             e.printStackTrace(log);
106             log.println("Exception occured: " + e);
107         }
108 
109         XLineNumberingProperties oLNP = (XLineNumberingProperties)
110                 UnoRuntime.queryInterface(XLineNumberingProperties.class,xTextDoc);
111         XPropertySet lineNumProps = oLNP.getLineNumberingProperties();
112         dbg.printPropertiesNames(lineNumProps);
113         TestEnvironment tEnv = new TestEnvironment(lineNumProps);
114         return tEnv;
115 
116     } // finish method getTestEnvironment
117 
118 }    // finish class SwXLineNumberingProperties
119 
120