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._sw; 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.InstCreator; 37 import util.SOfficeFactory; 38 import util.ShapeDsc; 39 40 import com.sun.star.drawing.XDrawPage; 41 import com.sun.star.drawing.XDrawPageSupplier; 42 import com.sun.star.drawing.XShapes; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.drawing.DrawPage</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li> 54 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li> 55 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li> 56 * <li> <code>com::sun::star::drawing::XShapes</code></li> 57 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 58 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 59 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 60 * <li> <code>com::sun::star::container::XElementAccess</code></li> 61 * <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li> 62 * <li> <code>com::sun::star::container::XNamed</code></li> 63 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li> 64 * </ul> <p> 65 * This object test <b> is NOT </b> designed to be run in several 66 * threads concurently. 67 * @see com.sun.star.drawing.GenericDrawPage 68 * @see com.sun.star.drawing.XShapeBinder 69 * @see com.sun.star.drawing.XShapeGrouper 70 * @see com.sun.star.drawing.XShapes 71 * @see com.sun.star.lang.XServiceInfo 72 * @see com.sun.star.beans.XPropertySet 73 * @see com.sun.star.container.XIndexAccess 74 * @see com.sun.star.container.XElementAccess 75 * @see com.sun.star.drawing.XMasterPageTarget 76 * @see com.sun.star.container.XNamed 77 * @see com.sun.star.drawing.XShapeCombiner 78 * @see ifc.drawing._GenericDrawPage 79 * @see ifc.drawing._XShapeBinder 80 * @see ifc.drawing._XShapeGrouper 81 * @see ifc.drawing._XShapes 82 * @see ifc.lang._XServiceInfo 83 * @see ifc.beans._XPropertySet 84 * @see ifc.container._XIndexAccess 85 * @see ifc.container._XElementAccess 86 * @see ifc.drawing._XMasterPageTarget 87 * @see ifc.container._XNamed 88 * @see ifc.drawing._XShapeCombiner 89 */ 90 public class SwXDrawPage extends TestCase { 91 XTextDocument xTextDoc; 92 93 /** 94 * Creates text document. 95 */ 96 protected void initialize( TestParameters tParam, PrintWriter log ) { 97 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 98 try { 99 log.println( "creating a textdocument" ); 100 xTextDoc = SOF.createTextDoc( null ); 101 } catch ( com.sun.star.uno.Exception e ) { 102 e.printStackTrace( log ); 103 throw new StatusException( "Couldn't create document", e ); 104 } 105 } 106 107 /** 108 * Disposes text document. 109 */ 110 protected void cleanup( TestParameters tParam, PrintWriter log ) { 111 log.println( " disposing xTextDoc " ); 112 util.DesktopTools.closeDoc(xTextDoc); 113 } 114 115 /** 116 * Creating a Testenvironment for the interfaces to be tested. After 117 * obtaining DrawPage object several shapes are inserted to it. 118 * Object relations created : 119 * <ul> 120 * <li> <code>'Shape'</code> for 121 * {@link ifc.drawing._XShapes} : shape creator. </li> 122 * <li> <code>'DrawPage'</code> for 123 * {@link ifc.drawing._XShapeBinder}, 124 * {@link ifc.drawing._XShapeCombiner}, 125 * {@link ifc.drawing._XShapeGrouper} : DrawPage component we are 126 * testing.</li> 127 * </ul> 128 */ 129 public synchronized TestEnvironment createTestEnvironment( 130 TestParameters Param, PrintWriter log ) throws StatusException { 131 XInterface oObj = null; 132 XDrawPageSupplier XDPSupp; 133 XDrawPage xDP = null; 134 XShapes oShapes = null; 135 136 log.println( "creating a test environment" ); 137 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() ); 138 XDPSupp = (XDrawPageSupplier) UnoRuntime.queryInterface 139 (XDrawPageSupplier.class, xTextDoc); 140 xDP = XDPSupp.getDrawPage(); 141 oObj = xDP; 142 143 //dbg.printInterfaces(oObj); 144 //System.exit(0); 145 146 log.println( "inserting some Shapes" ); 147 oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oObj); 148 oShapes.add(SOF.createShape(xTextDoc,2000,1500,1000,1000,"Line")); 149 oShapes.add(SOF.createShape(xTextDoc,3000,4500,15000,1000,"Ellipse")); 150 oShapes.add(SOF.createShape(xTextDoc,5000,3500,7500,5000,"Rectangle")); 151 152 log.println( "creating a new environment for bodytext object" ); 153 TestEnvironment tEnv = new TestEnvironment( oObj ); 154 155 ShapeDsc sDsc = new ShapeDsc(15000,13500,7500,10000,"Rectangle"); 156 log.println( "adding Shape as mod relation to environment" ); 157 tEnv.addObjRelation("Shape", new InstCreator( xTextDoc, sDsc)); 158 tEnv.addObjRelation("DrawPage", oObj); 159 160 return tEnv; 161 } // finish method getTestEnvironment 162 163 } // finish class SwXDrawPage 164 165