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 java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.DrawTools; 37 import util.SOfficeFactory; 38 39 import com.sun.star.container.XEnumerationAccess; 40 import com.sun.star.drawing.XShape; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.text.ControlCharacter; 44 import com.sun.star.text.XSimpleText; 45 import com.sun.star.text.XTextCursor; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 49 public class SvxUnoTextContentEnum extends TestCase { 50 51 static XComponent xDrawDoc; 52 53 /** 54 * in general this method creates a testdocument 55 * 56 * @param tParam class which contains additional test parameters 57 * @param log class to log the test state and result 58 * 59 * 60 * @see TestParameters 61 * @see PrintWriter 62 * 63 */ 64 protected void initialize( TestParameters tParam, PrintWriter log ) { 65 try { 66 log.println( "creating a drawdoc" ); 67 xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF()); 68 } catch ( Exception e ) { 69 // Some exception occures.FAILED 70 e.printStackTrace( log ); 71 throw new StatusException( "Couldn't create document", e ); 72 } 73 } 74 75 /** 76 * in general this method disposes the testenvironment and document 77 * 78 * @param tParam class which contains additional test parameters 79 * @param log class to log the test state and result 80 * 81 * 82 * @see TestParameters 83 * @see PrintWriter 84 * 85 */ 86 protected void cleanup( TestParameters tParam, PrintWriter log ) { 87 log.println( " disposing xDrawDoc " ); 88 util.DesktopTools.closeDoc(xDrawDoc); 89 } 90 91 92 /** 93 * creating a Testenvironment for the interfaces to be tested 94 * 95 * @param tParam class which contains additional test parameters 96 * @param log class to log the test state and result 97 * 98 * @return Status class 99 * 100 * @see TestParameters 101 * @see PrintWriter 102 */ 103 public TestEnvironment createTestEnvironment( TestParameters tParam, 104 PrintWriter log ) 105 throws StatusException { 106 107 XInterface oObj = null; 108 // create testobject here 109 110 XEnumerationAccess xEA = null ; 111 try { 112 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ; 113 XShape oShape = SOF.createShape 114 (xDrawDoc,5000,3500,7500,5000,"Text"); 115 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ; 116 117 XSimpleText text = (XSimpleText) UnoRuntime.queryInterface 118 (XSimpleText.class, oShape) ; 119 120 XTextCursor cursor = text.createTextCursor() ; 121 122 text.insertString(cursor, "Paragraph 1", false) ; 123 text.insertControlCharacter(cursor, 124 ControlCharacter.PARAGRAPH_BREAK, false) ; 125 text.insertString(cursor, "Paragraph 2", false) ; 126 text.insertControlCharacter(cursor, 127 ControlCharacter.PARAGRAPH_BREAK, false) ; 128 text.insertString(cursor, "Paragraph 3", false) ; 129 text.insertControlCharacter(cursor, 130 ControlCharacter.PARAGRAPH_BREAK, false) ; 131 132 xEA = (XEnumerationAccess) UnoRuntime.queryInterface 133 (XEnumerationAccess.class, text) ; 134 135 oObj = xEA.createEnumeration() ; 136 } catch (Exception e) { 137 log.println("Can't create test object") ; 138 e.printStackTrace(log) ; 139 throw new StatusException("Unexpected exception", e); 140 } 141 142 // create test environment here 143 TestEnvironment tEnv = new TestEnvironment( oObj ); 144 145 // adding relation for XEnumeration test 146 tEnv.addObjRelation("ENUM", xEA) ; 147 148 return tEnv; 149 } // finish method getTestEnvironment 150 151 } 152 153