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.InstCreator; 37 import util.ParagraphDsc; 38 import util.SOfficeFactory; 39 import util.TableDsc; 40 41 import com.sun.star.beans.XPropertySet; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.text.XText; 44 import com.sun.star.text.XTextCursor; 45 import com.sun.star.text.XTextDocument; 46 import com.sun.star.text.XTextFrame; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 /** 51 * 52 * initial description 53 * @see com.sun.star.container.XElementAccess 54 * @see com.sun.star.container.XEnumerationAccess 55 * @see com.sun.star.text.XSimpleText 56 * @see com.sun.star.text.XText 57 * @see com.sun.star.text.XTextRange 58 * @see com.sun.star.text.XTextRangeMover 59 * 60 */ 61 public class SwXTextFrameText extends TestCase { 62 XTextDocument xTextDoc; 63 64 protected void initialize( TestParameters tParam, PrintWriter log ) { 65 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 66 67 try { 68 log.println( "creating a textdocument" ); 69 xTextDoc = SOF.createTextDoc( null ); 70 } catch ( com.sun.star.uno.Exception e ) { 71 // Some exception occures.FAILED 72 e.printStackTrace( log ); 73 throw new StatusException( "Couldn't create document", e ); 74 } 75 } 76 77 protected void cleanup( TestParameters tParam, PrintWriter log ) { 78 log.println( " disposing xTextDoc " ); 79 util.DesktopTools.closeDoc(xTextDoc); 80 } 81 82 /** 83 * creating a Testenvironment for the interfaces to be tested 84 * 85 * @param tParam class which contains additional test parameters 86 * @param log class to log the test state and result 87 * 88 * @return Status class 89 * 90 * @see TestParameters 91 * @see PrintWriter 92 */ 93 public synchronized TestEnvironment createTestEnvironment 94 (TestParameters tParam, PrintWriter log ) { 95 96 XInterface oObj = null; 97 XTextFrame oFrame1 = null; 98 XPropertySet oPropSet = null; 99 XText oText = null; 100 XTextCursor oCursor = null; 101 102 // creation of testobject here 103 // first we write what we are intend to do to log file 104 log.println( "creating a test environment" ); 105 106 // get a soffice factory object 107 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 108 109 // create testobject here 110 //////////////////////////////////// 111 112 try { 113 oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500); 114 oPropSet = (XPropertySet)UnoRuntime.queryInterface 115 (XPropertySet.class, oFrame1 ); 116 //AnchorTypes: 0 = paragraph, 1 = as char, 2 = page, 117 // 3 = frame/paragraph 4= at char 118 oPropSet.setPropertyValue("AnchorType", new Integer(2)); 119 oText = xTextDoc.getText(); 120 oCursor = oText.createTextCursor(); 121 122 log.println( "inserting Frame1" ); 123 oText.insertTextContent(oCursor,oFrame1, false); 124 125 } catch (Exception Ex ) { 126 Ex.printStackTrace(log); 127 throw new StatusException("Couldn't insert TextFrame ", Ex); 128 } 129 130 XText oFText = (XText)UnoRuntime.queryInterface(XText.class, oFrame1); 131 XTextCursor oFCursor = oFText.createTextCursor(); 132 oFText.insertString(oFCursor, "SwXTextFrameText", false); 133 134 oObj = oFText.getText(); 135 136 log.println( "creating a new environment for TextFrameText object" ); 137 TestEnvironment tEnv = new TestEnvironment( oObj ); 138 139 log.println( "adding TextDocument as mod relation to environment" ); 140 tEnv.addObjRelation("TEXT", (XText) oObj); 141 142 log.println( "adding InstDescriptor object" ); 143 TableDsc tDsc = new TableDsc( 6, 4 ); 144 145 log.println( "adding InstCreator object" ); 146 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) ); 147 148 log.println( " adding Paragraph" ); 149 ParagraphDsc pDsc = new ParagraphDsc(); 150 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) ); 151 152 return tEnv; 153 } // finish method getTestEnvironment 154 155 } // finish class SwXTextFrameText 156 157