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._fwk; 29 30 import com.sun.star.beans.XPropertySet; 31 import com.sun.star.frame.XFrame; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.uno.XInterface; 35 import java.io.PrintWriter; 36 import com.sun.star.text.XText; 37 import com.sun.star.text.XTextCursor; 38 import com.sun.star.text.XTextDocument; 39 import com.sun.star.util.XCloseable; 40 import lib.StatusException; 41 import lib.TestCase; 42 import lib.TestEnvironment; 43 import lib.TestParameters; 44 import util.WriterTools; 45 46 /** 47 */ 48 public class LayoutManager extends TestCase { 49 XInterface xManager = null; 50 XTextDocument xTextDoc; 51 52 /** 53 * Cleanup: close the created document 54 * @param tParam The test parameters. 55 * @param The log writer. 56 * @return The test environment. 57 */ 58 protected void cleanup(TestParameters tParam, PrintWriter log) { 59 log.println(" disposing xTextDoc "); 60 61 try { 62 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 63 XCloseable.class, xTextDoc); 64 closer.close(true); 65 } catch (com.sun.star.util.CloseVetoException e) { 66 log.println("couldn't close document"); 67 } catch (com.sun.star.lang.DisposedException e) { 68 log.println("couldn't close document"); 69 } 70 } 71 72 /** 73 * Create test environment: 74 * <ul> 75 * <li>Create test doc</li> 76 * <li>Get the frame</li> 77 * <li>Get the LayoutManager from the frame</li> 78 * </ul> 79 * @param tParam The test parameters. 80 * @param The log writer. 81 * @return The test environment. 82 */ 83 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 84 TestEnvironment tEnv = null; 85 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 86 87 log.println("Creating instance..."); 88 89 xTextDoc = WriterTools.createTextDoc(xMSF); 90 91 XText xText = xTextDoc.getText(); 92 XTextCursor xTextCursor = xText.createTextCursor(); 93 94 for (int i = 0; i < 11; i++) { 95 xText.insertString(xTextCursor, "A sample text and why not? ", false); 96 } 97 98 XFrame xFrame = xTextDoc.getCurrentController().getFrame(); 99 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xFrame); 100 try { 101 Object any = xProp.getPropertyValue("LayoutManager"); 102 xManager = (XInterface)UnoRuntime.queryInterface(XInterface.class, any); 103 } 104 catch(com.sun.star.beans.UnknownPropertyException e) { 105 e.printStackTrace(log); 106 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e); 107 } 108 catch(com.sun.star.lang.WrappedTargetException e) { 109 e.printStackTrace(log); 110 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e); 111 } 112 113 // just to make sure, it's the right one. 114 log.println("TestObject: " + util.utils.getImplName(xManager)); 115 tEnv = new TestEnvironment(xManager); 116 117 tEnv.addObjRelation("XLayoutManager.TextDoc", xTextDoc); 118 tEnv.addObjRelation("XLayoutManager.Frame",xFrame); 119 120 return tEnv; 121 } 122 } 123 124 125