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