xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/SvxShapeDimensioning.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._svx;
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.DefaultDsc;
37 import util.DrawTools;
38 import util.InstCreator;
39 import util.SOfficeFactory;
40 
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.drawing.XShape;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.style.XStyle;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 
51 public class SvxShapeDimensioning extends TestCase {
52 
53     static XComponent xDrawDoc;
54 
55     /**
56      * in general this method creates a testdocument
57      *
58      *  @param tParam    class which contains additional test parameters
59      *  @param log        class to log the test state and result
60      *
61      *
62      *  @see TestParameters
63      *    @see PrintWriter
64      *
65      */
66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67 
68         try {
69             log.println( "creating a drawdoc" );
70             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
71         } catch ( Exception e ) {
72             // Some exception occures.FAILED
73             e.printStackTrace( log );
74             throw new StatusException( "Couldn't create document", e );
75         }
76     }
77 
78     /**
79      * in general this method disposes the testenvironment and document
80      *
81      *  @param tParam    class which contains additional test parameters
82      *  @param log        class to log the test state and result
83      *
84      *
85      *  @see TestParameters
86      *    @see PrintWriter
87      *
88      */
89     protected void cleanup( TestParameters tParam, PrintWriter log ) {
90         log.println( "    disposing xDrawDoc " );
91         util.DesktopTools.closeDoc(xDrawDoc);
92     }
93 
94 
95     /**
96      *    creating a Testenvironment for the interfaces to be tested
97      *
98      *  @param tParam    class which contains additional test parameters
99      *  @param log        class to log the test state and result
100      *
101      *  @return    Status class
102      *
103      *  @see TestParameters
104      *    @see PrintWriter
105      */
106     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
107 
108         XInterface oObj = null;
109         XShape oShape = null;
110 
111         // creation of testobject here
112         // first we write what we are intend to do to log file
113         log.println( "creating a test environment" );
114 
115         try {
116 
117             SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
118               oShape = SOF.createShape(xDrawDoc,4000,4000,3000,3000,"Measure");
119 
120             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
121 
122             for (int i=0;i<10;i++) {
123                 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(
124                     SOF.createShape(xDrawDoc,
125                     3000,4500,7510+10*i,5010+10*i,"Rectangle"));
126             }
127 
128             oObj = oShape ;
129 
130             //SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
131             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
132             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
133         }
134         catch (Exception e) {
135             log.println("Couldn't create insance");
136             e.printStackTrace(log);
137         }
138 
139         // test environment creation
140 
141          TestEnvironment tEnv = new TestEnvironment(oObj);
142 
143         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
144         XPropertySet oShapeProps = (XPropertySet)
145                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
146         XStyle aStyle = null;
147         try {
148             aStyle = (XStyle) AnyConverter.toObject(
149                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
150         } catch (Exception e) {}
151         tEnv.addObjRelation("Style1",aStyle);
152         oShapeProps = (XPropertySet)
153             UnoRuntime.queryInterface(XPropertySet.class,oShape);
154         try {
155             aStyle = (XStyle) AnyConverter.toObject(
156                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
157         } catch (Exception e) {}
158         tEnv.addObjRelation("Style2",aStyle);
159 
160         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
161                                             "com.sun.star.text.TextField.URL");
162         log.println( "    adding InstCreator object" );
163         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
164 
165         return tEnv;
166     } // finish method getTestEnvironment
167 
168 }    // finish class SvxShapeDimensioning
169 
170