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 com.sun.star.text.XText; 27 import java.io.PrintWriter; 28 29 import lib.StatusException; 30 import lib.TestCase; 31 import lib.TestEnvironment; 32 import lib.TestParameters; 33 import util.DefaultDsc; 34 import util.DrawTools; 35 import util.InstCreator; 36 import util.SOfficeFactory; 37 38 import com.sun.star.drawing.XShape; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.text.ControlCharacter; 42 import com.sun.star.text.XSimpleText; 43 import com.sun.star.text.XTextCursor; 44 import com.sun.star.text.XTextRange; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 public class SvxUnoText extends TestCase { 49 50 static XComponent xDrawDoc; 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 */ initialize( TestParameters tParam, PrintWriter log )63 protected void initialize( TestParameters tParam, PrintWriter log ) { 64 try { 65 log.println( "creating a drawdoc" ); 66 xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF()); 67 } catch ( Exception e ) { 68 // Some exception occures.FAILED 69 e.printStackTrace( log ); 70 throw new StatusException( "Couldn't create document", e ); 71 } 72 } 73 74 /** 75 * in general this method disposes the testenvironment and document 76 * 77 * @param tParam class which contains additional test parameters 78 * @param log class to log the test state and result 79 * 80 * 81 * @see TestParameters 82 * * @see PrintWriter 83 * 84 */ cleanup( TestParameters tParam, PrintWriter log )85 protected void cleanup( TestParameters tParam, PrintWriter log ) { 86 log.println( " disposing xDrawDoc " ); 87 util.DesktopTools.closeDoc(xDrawDoc); 88 } 89 90 91 /** 92 * * creating a Testenvironment for the interfaces to be tested 93 * 94 * @param tParam class which contains additional test parameters 95 * @param log class to log the test state and result 96 * 97 * @return Status class 98 * Object relations created : 99 * <ul> 100 * <li> <code>'RangeForMove'</code> for 101 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li> 102 * <li> <code>'XTextRange'</code> for 103 * {@link ifc.text._XTextRangeMover} (the range that includes moving 104 * range)</li> 105 * </ul> 106 * @see TestParameters 107 * * @see PrintWriter 108 */ createTestEnvironment(TestParameters tParam, PrintWriter log)109 protected TestEnvironment createTestEnvironment 110 (TestParameters tParam, PrintWriter log) { 111 112 XInterface oObj = null; 113 // create testobject here 114 XTextRange aRange = null; 115 XShape oShape = null; 116 117 try { 118 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ; 119 oShape = SOF.createShape 120 (xDrawDoc,5000,3500,7500,5000,"Text"); 121 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 122 123 XSimpleText text = (XSimpleText) UnoRuntime.queryInterface 124 (XSimpleText.class, oShape) ; 125 126 XTextCursor cursor = text.createTextCursor() ; 127 text.insertString(cursor, "Paragraph 1", false) ; 128 text.insertControlCharacter(cursor, 129 ControlCharacter.PARAGRAPH_BREAK, false) ; 130 cursor.setString("TextForMove"); 131 aRange = cursor; 132 XTextCursor cursor1 = text.createTextCursorByRange(text.getEnd()); 133 text.insertControlCharacter(cursor1, 134 ControlCharacter.PARAGRAPH_BREAK, false) ; 135 text.insertString(cursor1, "Paragraph 2", false); 136 text.insertControlCharacter(cursor1, 137 ControlCharacter.PARAGRAPH_BREAK, false) ; 138 text.insertString(cursor1, "Paragraph 3", false) ; 139 text.insertControlCharacter(cursor1, 140 ControlCharacter.PARAGRAPH_BREAK, false) ; 141 oObj = text.getText() ; 142 } catch (Exception e) { 143 log.println("Can't create test object") ; 144 e.printStackTrace(log) ; 145 } 146 147 // create test environment here 148 TestEnvironment tEnv = new TestEnvironment( oObj ); 149 // adding relation for XText 150 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", 151 "com.sun.star.text.TextField.DateTime"); 152 log.println( " adding InstCreator object" ); 153 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) ); 154 155 // adding relation for XTextRangeMover 156 tEnv.addObjRelation("RangeForMove", aRange); 157 tEnv.addObjRelation("XTextRange", oObj); 158 159 // adding relation for XTextRangeComapre 160 tEnv.addObjRelation("TEXT", (XText) UnoRuntime.queryInterface(XText.class, oShape)) ; 161 162 return tEnv; 163 } // finish method getTestEnvironment 164 165 } // finish class SvxUnoText 166 167