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._sw; 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.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.text.TextContentAnchorType; 41 import com.sun.star.text.XText; 42 import com.sun.star.text.XTextContent; 43 import com.sun.star.text.XTextCursor; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 public class SwXTextGraphicObject extends TestCase { 49 50 XTextDocument xTextDoc; 51 52 /** 53 * in general this method creates a testdocument 54 * 55 * @param tParam class which contains additional test parameters 56 * @param log class to log the test state and result 57 * 58 * 59 * @see TestParameters 60 * @see PrintWriter 61 * 62 */ 63 protected void initialize( TestParameters tParam, PrintWriter log ) { 64 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 65 try { 66 log.println( "creating a textdoc" ); 67 xTextDoc = SOF.createTextDoc( null );; 68 } catch ( Exception e ) { 69 // Some exception occures.FAILED 70 e.printStackTrace( log ); 71 throw new StatusException( "Couldn't create document", e ); 72 } 73 } 74 75 /** 76 * in general this method disposes the testenvironment and document 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 */ 86 protected void cleanup( TestParameters tParam, PrintWriter log ) { 87 log.println( " disposing xDrawDoc " ); 88 util.DesktopTools.closeDoc(xTextDoc); 89 } 90 91 92 /** 93 * creating a Testenvironment for the interfaces to be tested 94 * 95 * @param tParam class which contains additional test parameters 96 * @param log class to log the test state and result 97 * 98 * @return Status class 99 * 100 * @see TestParameters 101 * @see PrintWriter 102 */ 103 protected TestEnvironment createTestEnvironment 104 (TestParameters tParam, PrintWriter log) { 105 106 XInterface oObj = null; 107 Object oGObject = null; 108 Object xTextFrame = null; 109 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 110 111 Object instance = null; 112 113 try { 114 oGObject = SOF.createInstance 115 (xTextDoc,"com.sun.star.text.GraphicObject"); 116 instance = SOF.createInstance 117 (xTextDoc,"com.sun.star.text.GraphicObject"); 118 xTextFrame = SOF.createTextFrame(xTextDoc, 500, 500); 119 } 120 catch (Exception ex) { 121 log.println("Couldn't create instance"); 122 ex.printStackTrace(log); 123 throw new StatusException("Couldn't create instance", ex ); 124 } 125 126 oObj = (XInterface) oGObject; 127 128 XText the_text = xTextDoc.getText(); 129 XTextCursor the_cursor = the_text.createTextCursor(); 130 XTextContent the_content = (XTextContent) 131 UnoRuntime.queryInterface(XTextContent.class,oObj); 132 133 log.println("inserting Frame"); 134 try{ 135 XTextContent Framecontent = (XTextContent) UnoRuntime.queryInterface( 136 XTextContent.class, xTextFrame); 137 the_text.insertTextContent(the_cursor, Framecontent, true); 138 } catch (Exception e) { 139 System.out.println("Couldn't insert text frame"); 140 e.printStackTrace(); 141 throw new StatusException("Couldn't insert text frame", e ); 142 } 143 144 145 log.println( "inserting graphic" ); 146 try { 147 the_text.insertTextContent(the_cursor,the_content,true); 148 } catch (Exception e) { 149 System.out.println("Couldn't insert Content"); 150 e.printStackTrace(); 151 throw new StatusException("Couldn't insert Content", e ); 152 } 153 154 log.println( "adding graphic" ); 155 XPropertySet oProps = (XPropertySet) 156 UnoRuntime.queryInterface(XPropertySet.class,oObj); 157 try { 158 String wat = util.utils.getFullTestURL("space-metal.jpg"); 159 oProps.setPropertyValue("AnchorType", 160 TextContentAnchorType.AT_PARAGRAPH); 161 oProps.setPropertyValue("GraphicURL",wat); 162 oProps.setPropertyValue("HoriOrientPosition",new Integer(5500)); 163 oProps.setPropertyValue("VertOrientPosition",new Integer(4200)); 164 oProps.setPropertyValue("Width",new Integer(4400)); 165 oProps.setPropertyValue("Height",new Integer(4000)); 166 } catch (Exception e) { 167 System.out.println("Couldn't set property 'GraphicURL'"); 168 e.printStackTrace(); 169 throw new StatusException 170 ("Couldn't set property 'GraphicURL'", e ); 171 } 172 173 TestEnvironment tEnv = new TestEnvironment( oObj ); 174 175 log.println( "adding ObjRelation for XShape " 176 +"(get/setPosition won't work there)" ); 177 tEnv.addObjRelation("NoPos", "SwXTextGraphicObject"); 178 tEnv.addObjRelation("NoSetSize","SwXTextGraphicObject"); 179 Object ImgMap = null; 180 //creating ObjectRelation for the property 181 // 'ImageMap' of 'TextGraphicObject' 182 try { 183 XMultiServiceFactory xDocMSF = (XMultiServiceFactory) 184 UnoRuntime.queryInterface 185 (XMultiServiceFactory.class,xTextDoc); 186 ImgMap = xDocMSF.createInstance 187 ("com.sun.star.image.ImageMapRectangleObject"); 188 } 189 catch (Exception ex) { 190 ex.printStackTrace(); 191 } 192 193 tEnv.addObjRelation("IMGMAP",ImgMap); 194 195 tEnv.addObjRelation("CONTENT", (XTextContent) 196 UnoRuntime.queryInterface(XTextContent.class,instance)); 197 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 198 199 //object relation for text.BaseFrameProperties 200 tEnv.addObjRelation("TextFrame", xTextFrame); 201 202 return tEnv; 203 204 } // finish method getTestEnvironment 205 206 } // finish class SwXTextGraphicObject 207 208