tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxGraphicObject.java
blobd544d0294feba5a156a3113e75e9244fde3e15c9
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DefaultDsc;
27 import util.DrawTools;
28 import util.InstCreator;
29 import util.SOfficeFactory;
31 import com.sun.star.awt.XBitmap;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.drawing.XShape;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.style.XStyle;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.GraphicObject</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
48 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
49 * <li> <code>com::sun::star::text::XSimpleText</code></li>
50 * <li> <code>com::sun::star::drawing::XShape</code></li>
51 * <li> <code>com::sun::star::drawing::GraphicObjectShape</code></li>
52 * <li> <code>com::sun::star::drawing::Shape</code></li>
53 * <li> <code>com::sun::star::text::XTextRange</code></li>
54 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
55 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
57 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
58 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
59 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
60 * <li> <code>com::sun::star::text::XText</code></li>
61 * <li> <code>com::sun::star::lang::XComponent</code></li>
62 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurrently.
67 * @see com.sun.star.drawing.ShadowProperties
68 * @see com.sun.star.drawing.RotationDescriptor
69 * @see com.sun.star.text.XSimpleText
70 * @see com.sun.star.drawing.XShape
71 * @see com.sun.star.drawing.GraphicObjectShape
72 * @see com.sun.star.drawing.Shape
73 * @see com.sun.star.text.XTextRange
74 * @see com.sun.star.drawing.XGluePointsSupplier
75 * @see com.sun.star.beans.XPropertySet
76 * @see com.sun.star.drawing.TextProperties
77 * @see com.sun.star.style.CharacterProperties
78 * @see com.sun.star.drawing.XShapeDescriptor
79 * @see com.sun.star.style.ParagraphProperties
80 * @see com.sun.star.text.XText
81 * @see com.sun.star.lang.XComponent
82 * @see ifc.drawing._ShadowProperties
83 * @see ifc.drawing._RotationDescriptor
84 * @see ifc.text._XSimpleText
85 * @see ifc.drawing._XShape
86 * @see ifc.drawing._GraphicObjectShape
87 * @see ifc.drawing._Shape
88 * @see ifc.text._XTextRange
89 * @see ifc.drawing._XGluePointsSupplier
90 * @see ifc.beans._XPropertySet
91 * @see ifc.drawing._TextProperties
92 * @see ifc.style._CharacterProperties
93 * @see ifc.drawing._XShapeDescriptor
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.text._XText
96 * @see ifc.lang._XComponent
98 public class SvxGraphicObject extends TestCase {
100 static XComponent xDrawDoc;
103 * Creates a new Draw document.
105 @Override
106 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
108 log.println( "creating a drawdoc" );
109 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
113 * Disposes the Draw document created before
115 @Override
116 protected void cleanup( TestParameters tParam, PrintWriter log ) {
117 log.println( " disposing xDrawDoc " );
118 util.DesktopTools.closeDoc(xDrawDoc);
122 * Creating a TestEnvironment for the interfaces to be tested.
123 * Creates an instance of the service
124 * <code>com.sun.star.drawing.GraphicObject</code> as a tested
125 * component and inserts it to one of draw pages of the document.
126 * <p>
128 * Object relations created :
129 * <ul>
130 * <li> <code>'Style1', 'Style2'</code> for
131 * {@link ifc.drawing._Shape} :
132 * two values of 'Style' property. The first is taken
133 * from the shape tested, the second from another
134 * shape added to the draw page. </li>
135 * <li> <code>'Bitmap1', 'Bitmap2'</code> for
136 * {@link ifc.drawing._GraphicObjectShape} :</li>
137 * two bitmap objects which are created by setting
138 * 'GraphicURL' property of component tested and
139 * getting its 'GraphicObjectFillBitmap' property.
140 * <li> <code>'IMAP'</code> for
141 * {@link ifc.drawing._GraphicObjectShape} :
142 * <code>com.sun.star.image.ImageMapRectangleObject</code>
143 * service instance. </li>
144 * <li> <code>'XTEXTINFO'</code> for
145 * {@link ifc.text._XText} :
146 * creator which can create instances of
147 * <code>com.sun.star.text.TextField.URL</code>
148 * service. </li>
149 * </ul>
151 @Override
152 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
154 XInterface oObj = null;
155 XShape oShape = null;
156 Object imap=null;
158 // creation of testobject here
159 // first we write what we are intend to do to log file
160 log.println( "creating a test environment" );
162 // create testobject here
163 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
164 oShape = SOF.createShape(xDrawDoc,5000,5000,1500,1000,"GraphicObject");
165 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
166 oObj = oShape;
168 TestEnvironment tEnv = new TestEnvironment( oShape );
170 // adding two styles as ObjRelation for Shape
171 oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
172 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
174 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
175 XStyle aStyle = null;
176 try {
177 aStyle = (XStyle) AnyConverter.toObject(
178 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
179 } catch (com.sun.star.lang.WrappedTargetException e) {
180 } catch (com.sun.star.beans.UnknownPropertyException e) {
181 } catch (com.sun.star.lang.IllegalArgumentException e) {
183 tEnv.addObjRelation("Style1",aStyle);
185 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
186 try {
187 aStyle = (XStyle) AnyConverter.toObject(
188 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
189 } catch (com.sun.star.lang.WrappedTargetException e) {
190 } catch (com.sun.star.beans.UnknownPropertyException e) {
191 } catch (com.sun.star.lang.IllegalArgumentException e) {
193 tEnv.addObjRelation("Style2",aStyle);
196 // adding graphic as ObjRelation for GraphicObjectShape
197 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
198 XBitmap aBitmap = null;
199 try {
200 oShapeProps.setPropertyValue(
201 "GraphicURL",util.utils.getFullTestURL("space-metal.jpg"));
202 aBitmap = (XBitmap) AnyConverter.toObject(
203 new Type(XBitmap.class),oShapeProps.getPropertyValue
204 ("GraphicObjectFillBitmap"));
205 } catch (com.sun.star.lang.WrappedTargetException e) {
206 } catch (com.sun.star.lang.IllegalArgumentException e) {
207 } catch (com.sun.star.beans.PropertyVetoException e) {
208 } catch (com.sun.star.beans.UnknownPropertyException e) {
212 tEnv.addObjRelation("Bitmap1",aBitmap);
214 try {
215 oShapeProps.setPropertyValue(
216 "GraphicURL",util.utils.getFullTestURL("crazy-blue.jpg"));
217 aBitmap = (XBitmap) AnyConverter.toObject(
218 new Type(XBitmap.class),oShapeProps.getPropertyValue
219 ("GraphicObjectFillBitmap"));
220 } catch (com.sun.star.lang.WrappedTargetException e) {
221 } catch (com.sun.star.lang.IllegalArgumentException e) {
222 } catch (com.sun.star.beans.PropertyVetoException e) {
223 } catch (com.sun.star.beans.UnknownPropertyException e) {
226 tEnv.addObjRelation("Bitmap2",aBitmap);
228 try {
229 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class,xDrawDoc);
230 imap = oDocMSF.createInstance
231 ( "com.sun.star.image.ImageMapRectangleObject" );
232 } catch (com.sun.star.uno.Exception e) {
233 log.println("Couldn't create instance");
234 e.printStackTrace(log);
238 tEnv.addObjRelation("IMAP",imap);
239 tEnv.addObjRelation("ImapObject",imap);
241 // adding relation for XText interface
242 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
243 "com.sun.star.text.TextField.URL");
244 log.println( " adding InstCreator object" );
245 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
247 tEnv.addObjRelation("NoShear",Boolean.TRUE);
249 return tEnv;
251 } // finish method getTestEnvironment
253 } // finish class SvxGraphicObject