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 
38 import com.sun.star.drawing.XDrawPage;
39 import com.sun.star.drawing.XDrawPageSupplier;
40 import com.sun.star.drawing.XShape;
41 import com.sun.star.drawing.XShapes;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 /**
48  * Test for object which is represented by service
49  * <code>com.sun.star.drawing.Shape</code>. <p>
50  * Object implements the following interfaces :
51  * <ul>
52  *  <li> <code>com::sun::star::lang::XComponent</code></li>
53  *  <li> <code>com::sun::star::drawing::XShape</code></li>
54  *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
55  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
56  *  <li> <code>com::sun::star::drawing::Shape</code></li>
57  * </ul> <p>
58  * This object test <b> is NOT </b> designed to be run in several
59  * threads concurently.
60  * @see com.sun.star.lang.XComponent
61  * @see com.sun.star.drawing.XShape
62  * @see com.sun.star.drawing.XShapeDescriptor
63  * @see com.sun.star.beans.XPropertySet
64  * @see com.sun.star.drawing.Shape
65  * @see ifc.lang._XComponent
66  * @see ifc.drawing._XShape
67  * @see ifc.drawing._XShapeDescriptor
68  * @see ifc.beans._XPropertySet
69  * @see ifc.drawing._Shape
70  */
71 public class SwXShape extends TestCase {
72     XTextDocument xTextDoc;
73     SOfficeFactory SOF;
74 
75     /**
76     * Creates text document.
77     */
78     protected void initialize( TestParameters tParam, PrintWriter log ) {
79         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
80         try {
81             log.println( "creating a textdocument" );
82             xTextDoc = SOF.createTextDoc( null );
83         } catch ( com.sun.star.uno.Exception e ) {
84             e.printStackTrace( log );
85             throw new StatusException( "Couldn't create document", e );
86         }
87     }
88 
89     /**
90     * Disposes text document.
91     */
92     protected void cleanup( TestParameters tParam, PrintWriter log ) {
93         log.println( "    disposing xTextDoc " );
94         util.DesktopTools.closeDoc(xTextDoc);
95     }
96 
97     /**
98     * Creating a Testenvironment for the interfaces to be tested. At first,
99     * DrawPage is gotten from text document using <code>XDrawPageSupplier</code>
100     * interface. Then shape (rectangle) is created and added to DrawPage
101     * obtained before, then returned as a test component.
102     */
103     public synchronized TestEnvironment createTestEnvironment(
104             TestParameters tParam, PrintWriter log ) throws StatusException {
105         XInterface oObj = null;
106         XDrawPage oDP = null;
107         XShapes oShapes = null;
108 
109         log.println( "creating a test environment" );
110         log.println( "getting Drawpage" );
111         XDrawPageSupplier oDPS = (XDrawPageSupplier)
112             UnoRuntime.queryInterface(XDrawPageSupplier.class, xTextDoc);
113         oDP = oDPS.getDrawPage();
114 
115         log.println( "getting Shape" );
116         oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oDP);
117         oObj = SOF.createShape(xTextDoc,5000,3500,7500,5000,"Rectangle");
118         oShapes.add((XShape) oObj);
119 
120         for ( int i = 0; i < 9; i++){
121             XInterface oShape = SOF.createShape(xTextDoc,
122                 5000 + 100*i,3500,7500,5000,"Rectangle");
123             oShapes.add((XShape) oShape);
124         }
125 
126         log.println( "creating a new environment for XShape object" );
127         TestEnvironment tEnv = new TestEnvironment( oObj );
128 
129         return tEnv;
130     } // finish method getTestEnvironment
131 
132 }    // finish class SwXShape
133 
134