1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DefaultDsc;
33 import util.DrawTools;
34 import util.InstCreator;
35 import util.SOfficeFactory;
36 
37 import com.sun.star.beans.XPropertySet;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.style.XStyle;
42 import com.sun.star.uno.AnyConverter;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 /**
48  *
49  * initial description
50  * @see com.sun.star.beans.XPropertySet
51  * @see com.sun.star.document.LinkTarget
52  * @see com.sun.star.document.XLinkTargetSupplier
53  * @see com.sun.star.drawing.ConnectorShapeDescriptor
54  * @see com.sun.star.drawing.LineShapeDescriptor
55  * @see com.sun.star.drawing.PolyPolygonDescriptor
56  * @see com.sun.star.drawing.RotationDescriptor
57  * @see com.sun.star.drawing.ShadowDescriptor
58  * @see com.sun.star.drawing.ShapeDescriptor
59  * @see com.sun.star.drawing.Text
60  * @see com.sun.star.drawing.XConnectorShape
61  * @see com.sun.star.drawing.XShape
62  * @see com.sun.star.drawing.XShapeDescriptor
63  * @see com.sun.star.lang.XComponent
64  * @see com.sun.star.style.CharacterProperties
65  * @see com.sun.star.style.ParagraphProperties
66  * @see com.sun.star.text.XSimpleText
67  * @see com.sun.star.text.XText
68  * @see com.sun.star.text.XTextRange
69  *
70  */
71 public class SvxShapeConnector extends TestCase {
72 
73     static XComponent xDrawDoc;
74 
75     /**
76      * in general this method creates a testdocument
77      *
78      *  @param tParam    class which contains additional test parameters
79      *  @param log        class to log the test state and result
80      *
81      *
82      *  @see TestParameters
83      *  *    @see PrintWriter
84      *
85      */
initialize( TestParameters tParam, PrintWriter log )86     protected void initialize( TestParameters tParam, PrintWriter log ) {
87 
88         try {
89             log.println( "creating a drawdoc" );
90             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
91         } catch ( Exception e ) {
92             // Some exception occures.FAILED
93             e.printStackTrace( log );
94             throw new StatusException( "Couldn't create document", e );
95         }
96     }
97 
98     /**
99      * in general this method disposes the testenvironment and document
100      *
101      *  @param tParam    class which contains additional test parameters
102      *  @param log        class to log the test state and result
103      *
104      *
105      *  @see TestParameters
106      *  *    @see PrintWriter
107      *
108      */
cleanup( TestParameters tParam, PrintWriter log )109     protected void cleanup( TestParameters tParam, PrintWriter log ) {
110         log.println( "    disposing xDrawDoc " );
111         util.DesktopTools.closeDoc(xDrawDoc);
112     }
113 
114 
115     /**
116      *  *    creating a Testenvironment for the interfaces to be tested
117      *
118      *  @param tParam    class which contains additional test parameters
119      *  @param log        class to log the test state and result
120      *
121      *  @return    Status class
122      *
123      *  @see TestParameters
124      *  *    @see PrintWriter
125      */
createTestEnvironment(TestParameters tParam, PrintWriter log)126     protected TestEnvironment createTestEnvironment
127             (TestParameters tParam, PrintWriter log) {
128 
129         XInterface oObj = null;
130         XShape oShape = null;
131 
132         // creation of testobject here
133         // first we write what we are intend to do to log file
134         log.println( "creating a test environment" );
135         try {
136             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
137                 UnoRuntime.queryInterface(XMultiServiceFactory.class,xDrawDoc);
138             Object oInt = oDocMSF.createInstance
139                 ( "com.sun.star.drawing.ConnectorShape" );
140 
141             oShape = (XShape)UnoRuntime.queryInterface( XShape.class, oInt );
142             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
143         }
144         catch (Exception e) {
145             log.println("Couldn't create insance");
146             e.printStackTrace(log);
147         }
148 
149         // create testobject here
150         oObj = oShape;
151 
152         TestEnvironment tEnv = new TestEnvironment( oObj );
153 
154         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
155         oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
156         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
157 
158         for (int i=0;i<10;i++) {
159             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(
160                 SOF.createShape(xDrawDoc,
161                 3000,4500,7510+10*i,5010+10*i,"Rectangle"));
162         }
163 
164         log.println( "adding two style as ObjRelation for ShapeDescriptor" );
165         XPropertySet oShapeProps = (XPropertySet)
166                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
167         XStyle aStyle = null;
168         try {
169             aStyle = (XStyle) AnyConverter.toObject(
170                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
171         } catch (Exception e) {}
172 
173         tEnv.addObjRelation("Style1",aStyle);
174         oShapeProps = (XPropertySet)
175             UnoRuntime.queryInterface(XPropertySet.class,oShape);
176         try {
177             aStyle = (XStyle) AnyConverter.toObject(
178                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
179         } catch (Exception e) {}
180 
181         tEnv.addObjRelation("Style2",aStyle);
182 
183         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
184                                             "com.sun.star.text.TextField.URL");
185         log.println( "    adding InstCreator object" );
186         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
187         tEnv.addObjRelation("NoSetSize","SvxShapeConnector");
188         // adding relation for XConnectorShape
189         XShape oShape1 = SOF.createShape(xDrawDoc,1000,2000,1500,1000,"Line");
190         XShape oShape2 = SOF.createShape(xDrawDoc,1000,2000,4000,3000,"Line");
191         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape1);
192         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape2);
193         tEnv.addObjRelation("XConnectorShape.Shapes",
194             new XShape[] {oShape1, oShape2}) ;
195         System.out.println("IName: "+util.utils.getImplName(oObj));
196         return tEnv;
197     } // finish method getTestEnvironment
198 
199 }    // finish class SvxShapeConnector
200 
201