bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextGraphicObject.java
blobd2e661700a959556a6c64a231e9572e5cf3b81c2
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._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.TextContentAnchorType;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextContent;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 public class SwXTextGraphicObject extends TestCase {
41 XTextDocument xTextDoc;
43 /**
44 * in general this method creates a testdocument
46 * @param tParam class which contains additional test parameters
47 * @param log class to log the test state and result
50 * @see TestParameters
51 * @see PrintWriter
54 @Override
55 protected void initialize( TestParameters tParam, PrintWriter log ) {
56 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
57 try {
58 log.println( "creating a textdoc" );
59 xTextDoc = SOF.createTextDoc( null );
60 } catch ( Exception e ) {
61 // Some exception occurs.FAILED
62 e.printStackTrace( log );
63 throw new StatusException( "Couldn't create document", e );
67 /**
68 * in general this method disposes the testenvironment and document
70 * @param tParam class which contains additional test parameters
71 * @param log class to log the test state and result
74 * @see TestParameters
75 * @see PrintWriter
78 @Override
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xDrawDoc " );
81 util.DesktopTools.closeDoc(xTextDoc);
85 /**
86 * creating a Testenvironment for the interfaces to be tested
88 * @param tParam class which contains additional test parameters
89 * @param log class to log the test state and result
91 * @return Status class
93 * @see TestParameters
94 * @see PrintWriter
96 @Override
97 protected TestEnvironment createTestEnvironment
98 (TestParameters tParam, PrintWriter log) {
100 XInterface oObj = null;
101 Object oGObject = null;
102 Object xTextFrame = null;
103 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
105 Object instance = null;
107 try {
108 oGObject = SOF.createInstance
109 (xTextDoc,"com.sun.star.text.GraphicObject");
110 instance = SOF.createInstance
111 (xTextDoc,"com.sun.star.text.GraphicObject");
112 xTextFrame = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
114 catch (Exception ex) {
115 log.println("Couldn't create instance");
116 ex.printStackTrace(log);
117 throw new StatusException("Couldn't create instance", ex );
120 oObj = (XInterface) oGObject;
122 XText the_text = xTextDoc.getText();
123 XTextCursor the_cursor = the_text.createTextCursor();
124 XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class,oObj);
126 log.println("inserting Frame");
127 try{
128 XTextContent Framecontent = UnoRuntime.queryInterface(
129 XTextContent.class, xTextFrame);
130 the_text.insertTextContent(the_cursor, Framecontent, true);
131 } catch (Exception e) {
132 System.out.println("Couldn't insert text frame");
133 e.printStackTrace();
134 throw new StatusException("Couldn't insert text frame", e );
138 log.println( "inserting graphic" );
139 try {
140 the_text.insertTextContent(the_cursor,the_content,true);
141 } catch (Exception e) {
142 System.out.println("Couldn't insert Content");
143 e.printStackTrace();
144 throw new StatusException("Couldn't insert Content", e );
147 log.println( "adding graphic" );
148 XPropertySet oProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
149 try {
150 String wat = util.utils.getFullTestURL("space-metal.jpg");
151 oProps.setPropertyValue("AnchorType",
152 TextContentAnchorType.AT_PARAGRAPH);
153 oProps.setPropertyValue("GraphicURL",wat);
154 oProps.setPropertyValue("HoriOrientPosition",Integer.valueOf(5500));
155 oProps.setPropertyValue("VertOrientPosition",Integer.valueOf(4200));
156 oProps.setPropertyValue("Width",Integer.valueOf(4400));
157 oProps.setPropertyValue("Height",Integer.valueOf(4000));
158 } catch (Exception e) {
159 System.out.println("Couldn't set property 'GraphicURL'");
160 e.printStackTrace();
161 throw new StatusException
162 ("Couldn't set property 'GraphicURL'", e );
165 TestEnvironment tEnv = new TestEnvironment( oObj );
167 log.println( "adding ObjRelation for XShape "
168 +"(get/setPosition won't work there)" );
169 tEnv.addObjRelation("NoPos", "SwXTextGraphicObject");
170 tEnv.addObjRelation("NoSetSize","SwXTextGraphicObject");
171 Object ImgMap = null;
172 //creating ObjectRelation for the property
173 // 'ImageMap' of 'TextGraphicObject'
174 try {
175 XMultiServiceFactory xDocMSF = UnoRuntime.queryInterface
176 (XMultiServiceFactory.class,xTextDoc);
177 ImgMap = xDocMSF.createInstance
178 ("com.sun.star.image.ImageMapRectangleObject");
180 catch (Exception ex) {
181 ex.printStackTrace();
184 tEnv.addObjRelation("IMGMAP",ImgMap);
186 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
187 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
189 //object relation for text.BaseFrameProperties
190 tEnv.addObjRelation("TextFrame", xTextFrame);
192 return tEnv;
194 } // finish method getTestEnvironment
196 } // finish class SwXTextGraphicObject