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.InstCreator;
37 import util.ParagraphDsc;
38 import util.SOfficeFactory;
39 import util.TableDsc;
40 
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46  * Test for object which is represented by service
47  * <code>com.sun.star.text.Text</code>.<p>
48  * Object implements the following interfaces :
49  * <ul>
50  *  <li> <code>com::sun::star::text::XTextRangeMover</code></li>
51  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
52  *  <li> <code>com::sun::star::text::XTextRange</code></li>
53  *  <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
54  *  <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
55  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
56  *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
57  *  <li> <code>com::sun::star::text::XText</code></li>
58  * </ul> <p>
59  * This object test <b> is NOT </b> designed to be run in several
60  * threads concurently.
61  * @see com.sun.star.text.XTextRangeMover
62  * @see com.sun.star.text.XSimpleText
63  * @see com.sun.star.text.XTextRange
64  * @see com.sun.star.text.XRelativeTextContentInsert
65  * @see com.sun.star.text.XTextRangeCompare
66  * @see com.sun.star.container.XElementAccess
67  * @see com.sun.star.container.XEnumerationAccess
68  * @see com.sun.star.text.XText
69  * @see ifc.text._XTextRangeMover
70  * @see ifc.text._XSimpleText
71  * @see ifc.text._XTextRange
72  * @see ifc.text._XRelativeTextContentInsert
73  * @see ifc.text._XTextRangeCompare
74  * @see ifc.container._XElementAccess
75  * @see ifc.container._XEnumerationAccess
76  * @see ifc.text._XText
77  */
78 public class SwXBodyText extends TestCase {
79     XTextDocument xTextDoc = null;;
80     SOfficeFactory SOF = null;
81 
82     /**
83     * Creates text document.
84     */
85     protected void initialize( TestParameters tParam, PrintWriter log ) {
86         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
87         try {
88             log.println( "creating a textdocument" );
89             xTextDoc = SOF.createTextDoc( null );
90         } catch ( com.sun.star.uno.Exception e ) {
91             e.printStackTrace( log );
92             throw new StatusException( "Couldn't create document", e );
93         }
94     }
95 
96     /**
97     * Disposes text document.
98     */
99     protected void cleanup( TestParameters tParam, PrintWriter log ) {
100         log.println( "    disposing xTextDoc " );
101         util.DesktopTools.closeDoc(xTextDoc);
102     }
103 
104     /**
105     * Creating a Testenvironment for the interfaces to be tested.
106     * Obtains body text from text document.
107     * Object relations created :
108     * <ul>
109     *  <li> <code>'TEXT'</code> for
110     *    {@link ifc.text._XTextRangeCompare} : text</li>
111     *  <li> <code>'XTEXTINFO'</code> for
112     *    {@link ifc.text._XRelativeTextContentInsert},
113     *    {@link ifc.text._XText} : creates 6x4 tables</li>
114     *  <li> <code>'PARA'</code> for
115     *    {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
116     * </ul>
117     */
118     public synchronized TestEnvironment createTestEnvironment(
119             TestParameters Param, PrintWriter log ) throws StatusException {
120         XInterface oObj = null;
121 
122         log.println( "creating a test environment" );
123 
124         // get the bodytext of textdocument here
125         log.println( "    getting the bodytext of textdocument with getText()" );
126         oObj = xTextDoc.getText();
127 
128         log.println( "    creating a new environment for bodytext object" );
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130 
131         log.println(" adding Text as ObjRelation");
132         tEnv.addObjRelation("TEXT", oObj );
133 
134         log.println( "    adding InstDescriptor object" );
135         TableDsc tDsc = new TableDsc( 6, 4 );
136 
137         log.println( "    adding InstCreator object" );
138         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
139 
140         log.println( "    adding Paragraph" );
141         ParagraphDsc pDsc = new ParagraphDsc();
142         tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
143 
144         return tEnv;
145     } // finish method getTestEnvironment
146 
147 }    // finish class SwXBodyText
148 
149