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._svx; 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.DrawTools; 33 import util.SOfficeFactory; 34 35 import com.sun.star.drawing.XShape; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.text.XText; 39 import com.sun.star.text.XTextContent; 40 import com.sun.star.text.XTextCursor; 41 import com.sun.star.uno.UnoRuntime; 42 import com.sun.star.uno.XInterface; 43 44 /** 45 * 46 * initial description 47 * @see ifc._XComponent 48 * @see ifc._TextContent 49 * @see ifc._XTextContent 50 * @see ifc._XTextField 51 * 52 */ 53 public class SvxUnoTextField extends TestCase { 54 55 static XComponent xDrawDoc; 56 57 /** 58 * in general this method creates a testdocument 59 * 60 * @param tParam class which contains additional test parameters 61 * @param log class to log the test state and result 62 * 63 * 64 * @see TestParameters 65 * @see PrintWriter 66 * 67 */ 68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 70 try { 71 log.println( "creating a drawdoc" ); 72 xDrawDoc = DrawTools.createDrawDoc( (XMultiServiceFactory) tParam.getMSF()); 73 } catch ( Exception e ) { 74 // Some exception occures.FAILED 75 e.printStackTrace( log ); 76 throw new StatusException( "Couldn't create document", e ); 77 } 78 } 79 80 /** 81 * in general this method disposes the testenvironment and document 82 * 83 * @param tParam class which contains additional test parameters 84 * @param log class to log the test state and result 85 * 86 * 87 * @see TestParameters 88 * @see PrintWriter 89 * 90 */ 91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing xDrawDoc " ); 93 util.DesktopTools.closeDoc(xDrawDoc); 94 } 95 /** 96 * creating a Testenvironment for the interfaces to be tested 97 * 98 * @param tParam class which contains additional test parameters 99 * @param log class to log the test state and result 100 * 101 * @return Status class 102 * 103 * @see TestParameters 104 * @see PrintWriter 105 */ 106 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 107 108 XInterface oObj = null; 109 XShape oShape = null; 110 111 // creation of testobject here 112 // first we write what we are intend to do to log file 113 log.println( "creating a test environment" ); 114 try { 115 116 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF()); 117 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle"); 118 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 119 } 120 catch (Exception e) { 121 log.println("Couldn't create Shape"); 122 e.printStackTrace(log); 123 throw new StatusException("Couldn't create Shape ",e); 124 } 125 126 XTextCursor the_Cursor = null; 127 128 // create testobject here 129 try { 130 131 XText the_Text = (XText) UnoRuntime.queryInterface(XText.class,oShape); 132 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 133 UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc ); 134 the_Cursor = the_Text.createTextCursor(); 135 oObj = (XInterface) 136 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" ); 137 XTextContent the_Field = (XTextContent) 138 UnoRuntime.queryInterface(XTextContent.class,oObj); 139 140 141 the_Text.insertTextContent(the_Cursor,the_Field,false); 142 } 143 catch (Exception ex) { 144 log.println("Couldn't create Textfield"); 145 ex.printStackTrace(log); 146 throw new StatusException("Couldn't create TextField ",ex); 147 } 148 149 log.println( "creating a new environment for FieldMaster object" ); 150 TestEnvironment tEnv = new TestEnvironment( oObj ); 151 tEnv.addObjRelation("RANGE", the_Cursor); 152 153 return tEnv; 154 } // finish method getTestEnvironment 155 156 } // finish class SvxUnoTextField 157 158