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._sc;
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.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.drawing.XShape;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 public class ScShapeObj extends TestCase {
46 
47     static XComponent xSheetDoc;
48 
49     protected void initialize( TestParameters tParam, PrintWriter log ) {
50 
51         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
52 
53         try {
54             log.println( "creating a sheetdoc" );
55             xSheetDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class, SOF.createCalcDoc(null));
56         } catch ( com.sun.star.uno.Exception e ) {
57             // Some exception occures.FAILED
58             e.printStackTrace( log );
59             throw new StatusException( "Couldn't create document", e );
60         }
61     }
62 
63     protected void cleanup( TestParameters tParam, PrintWriter log ) {
64         log.println( "    disposing xSheetDoc " );
65         util.DesktopTools.closeDoc(xSheetDoc);
66     }
67 
68     /**
69      * Creating a Testenvironment for the interfaces to be tested.
70      * Creates an instance of the service
71      * <code>com.sun.star.drawing.EllipseShape</code> as tested component
72      * and adds it to the document.
73      *     Object relations created :
74      * <ul>
75      *  <li> <code>'Style1', 'Style2'</code> for
76      *      {@link ifc.drawing._Shape} :
77      *       two values of 'Style' property. The first is taken
78      *       from the shape tested, the second from another
79      *       shape added to the draw page. </li>
80      *  <li> <code>'XTEXTINFO'</code> for
81      *      {@link ifc.text._XText} :
82      *      creator which can create instnaces of
83      *      <code>com.sun.star.text.TextField.URL</code>
84      *      service. </li>
85      * </ul>
86      */
87     protected TestEnvironment createTestEnvironment
88             (TestParameters tParam, PrintWriter log) {
89 
90         XInterface oObj = null;
91         XShape oShape = null;
92 
93         // creation of testobject here
94         // first we write what we are intend to do to log file
95         log.println( "creating a test environment" );
96 
97         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
98         oShape = SOF.createShape(xSheetDoc,5000, 3500, 7500, 5000,"Rectangle");
99         DrawTools.getShapes(DrawTools.getDrawPage(xSheetDoc,0)).add(oShape);
100         oObj = oShape ;
101 
102         for (int i=0; i < 10; i++) {
103             DrawTools.getShapes(DrawTools.getDrawPage(xSheetDoc,0)).add(
104                 SOF.createShape(xSheetDoc,
105                     5000, 3500, 7510 + 10 * i, 5010 + 10 * i, "Rectangle"));
106         }
107 
108         // create test environment here
109         TestEnvironment tEnv = new TestEnvironment( oShape );
110 
111         log.println("Implementation name: "+util.utils.getImplName(oObj));
112         tEnv.addObjRelation("DOCUMENT",xSheetDoc);
113 
114         return tEnv;
115     } // finish method getTestEnvironment
116 
117 }    // finish class ScShapeObj
118