xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/SvxShapeConnector.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 /**
52  *
53  * initial description
54  * @see com.sun.star.beans.XPropertySet
55  * @see com.sun.star.document.LinkTarget
56  * @see com.sun.star.document.XLinkTargetSupplier
57  * @see com.sun.star.drawing.ConnectorShapeDescriptor
58  * @see com.sun.star.drawing.LineShapeDescriptor
59  * @see com.sun.star.drawing.PolyPolygonDescriptor
60  * @see com.sun.star.drawing.RotationDescriptor
61  * @see com.sun.star.drawing.ShadowDescriptor
62  * @see com.sun.star.drawing.ShapeDescriptor
63  * @see com.sun.star.drawing.Text
64  * @see com.sun.star.drawing.XConnectorShape
65  * @see com.sun.star.drawing.XShape
66  * @see com.sun.star.drawing.XShapeDescriptor
67  * @see com.sun.star.lang.XComponent
68  * @see com.sun.star.style.CharacterProperties
69  * @see com.sun.star.style.ParagraphProperties
70  * @see com.sun.star.text.XSimpleText
71  * @see com.sun.star.text.XText
72  * @see com.sun.star.text.XTextRange
73  *
74  */
75 public class SvxShapeConnector extends TestCase {
76 
77     static XComponent xDrawDoc;
78 
79     /**
80      * in general this method creates a testdocument
81      *
82      *  @param tParam    class which contains additional test parameters
83      *  @param log        class to log the test state and result
84      *
85      *
86      *  @see TestParameters
87      *  *    @see PrintWriter
88      *
89      */
90     protected void initialize( TestParameters tParam, PrintWriter log ) {
91 
92         try {
93             log.println( "creating a drawdoc" );
94             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
95         } catch ( Exception e ) {
96             // Some exception occures.FAILED
97             e.printStackTrace( log );
98             throw new StatusException( "Couldn't create document", e );
99         }
100     }
101 
102     /**
103      * in general this method disposes the testenvironment and document
104      *
105      *  @param tParam    class which contains additional test parameters
106      *  @param log        class to log the test state and result
107      *
108      *
109      *  @see TestParameters
110      *  *    @see PrintWriter
111      *
112      */
113     protected void cleanup( TestParameters tParam, PrintWriter log ) {
114         log.println( "    disposing xDrawDoc " );
115         util.DesktopTools.closeDoc(xDrawDoc);
116     }
117 
118 
119     /**
120      *  *    creating a Testenvironment for the interfaces to be tested
121      *
122      *  @param tParam    class which contains additional test parameters
123      *  @param log        class to log the test state and result
124      *
125      *  @return    Status class
126      *
127      *  @see TestParameters
128      *  *    @see PrintWriter
129      */
130     protected TestEnvironment createTestEnvironment
131             (TestParameters tParam, PrintWriter log) {
132 
133         XInterface oObj = null;
134         XShape oShape = null;
135 
136         // creation of testobject here
137         // first we write what we are intend to do to log file
138         log.println( "creating a test environment" );
139         try {
140             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
141                 UnoRuntime.queryInterface(XMultiServiceFactory.class,xDrawDoc);
142             Object oInt = oDocMSF.createInstance
143                 ( "com.sun.star.drawing.ConnectorShape" );
144 
145             oShape = (XShape)UnoRuntime.queryInterface( XShape.class, oInt );
146             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
147         }
148         catch (Exception e) {
149             log.println("Couldn't create insance");
150             e.printStackTrace(log);
151         }
152 
153         // create testobject here
154         oObj = oShape;
155 
156         TestEnvironment tEnv = new TestEnvironment( oObj );
157 
158         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
159         oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
160         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
161 
162         for (int i=0;i<10;i++) {
163             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(
164                 SOF.createShape(xDrawDoc,
165                 3000,4500,7510+10*i,5010+10*i,"Rectangle"));
166         }
167 
168         log.println( "adding two style as ObjRelation for ShapeDescriptor" );
169         XPropertySet oShapeProps = (XPropertySet)
170                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
171         XStyle aStyle = null;
172         try {
173             aStyle = (XStyle) AnyConverter.toObject(
174                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
175         } catch (Exception e) {}
176 
177         tEnv.addObjRelation("Style1",aStyle);
178         oShapeProps = (XPropertySet)
179             UnoRuntime.queryInterface(XPropertySet.class,oShape);
180         try {
181             aStyle = (XStyle) AnyConverter.toObject(
182                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
183         } catch (Exception e) {}
184 
185         tEnv.addObjRelation("Style2",aStyle);
186 
187         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
188                                             "com.sun.star.text.TextField.URL");
189         log.println( "    adding InstCreator object" );
190         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
191         tEnv.addObjRelation("NoSetSize","SvxShapeConnector");
192         // adding relation for XConnectorShape
193         XShape oShape1 = SOF.createShape(xDrawDoc,1000,2000,1500,1000,"Line");
194         XShape oShape2 = SOF.createShape(xDrawDoc,1000,2000,4000,3000,"Line");
195         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape1);
196         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape2);
197         tEnv.addObjRelation("XConnectorShape.Shapes",
198             new XShape[] {oShape1, oShape2}) ;
199         System.out.println("IName: "+util.utils.getImplName(oObj));
200         return tEnv;
201     } // finish method getTestEnvironment
202 
203 }    // finish class SvxShapeConnector
204 
205