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