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._sd; 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.container.XIndexAccess; 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XMasterPagesSupplier; 44 import com.sun.star.drawing.XShapes; 45 import com.sun.star.lang.XComponent; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.drawing.MasterPage</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li> 58 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li> 59 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li> 60 * <li> <code>com::sun::star::drawing::XShapes</code></li> 61 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 62 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 63 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 64 * <li> <code>com::sun::star::container::XElementAccess</code></li> 65 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li> 66 * <li> <code>com::sun::star::container::XNamed</code></li> 67 * </ul> 68 * @see com.sun.star.drawing.MasterPage 69 * @see com.sun.star.drawing.GenericDrawPage 70 * @see com.sun.star.drawing.XShapeBinder 71 * @see com.sun.star.drawing.XShapeGrouper 72 * @see com.sun.star.drawing.XShapes 73 * @see com.sun.star.lang.XServiceInfo 74 * @see com.sun.star.beans.XPropertySet 75 * @see com.sun.star.container.XIndexAccess 76 * @see com.sun.star.container.XElementAccess 77 * @see com.sun.star.drawing.XShapeCombiner 78 * @see com.sun.star.container.XNamed 79 * @see ifc.drawing._GenericDrawPage 80 * @see ifc.drawing._XShapeBinder 81 * @see ifc.drawing._XShapeGrouper 82 * @see ifc.drawing._XShapes 83 * @see ifc.lang._XServiceInfo 84 * @see ifc.beans._XPropertySet 85 * @see ifc.container._XIndexAccess 86 * @see ifc.container._XElementAccess 87 * @see ifc.drawing._XShapeCombiner 88 * @see ifc.container._XNamed 89 */ 90 public class SdMasterPage extends TestCase { 91 XComponent xDrawDoc; 92 93 /** 94 * Creates Drawing document. 95 */ 96 protected void initialize(TestParameters Param, PrintWriter log) { 97 // get a soffice factory object 98 SOfficeFactory SOF = SOfficeFactory.getFactory( 99 (XMultiServiceFactory)Param.getMSF()); 100 101 try { 102 log.println( "creating a draw document" ); 103 xDrawDoc = SOF.createDrawDoc(null);; 104 } catch (com.sun.star.uno.Exception e) { 105 // Some exception occures.FAILED 106 e.printStackTrace( log ); 107 throw new StatusException("Couldn't create document", e); 108 } 109 } 110 111 /** 112 * Disposes Drawing document. 113 */ 114 protected void cleanup( TestParameters Param, PrintWriter log) { 115 log.println("disposing xDrawDoc"); 116 util.DesktopTools.closeDoc(xDrawDoc);; 117 } 118 119 /** 120 * Creating a Testenvironment for the interfaces to be tested. 121 * Retrieves the collection of the master pages from the document using the 122 * interface <code>XMasterPagesSupplier</code> and takes 123 * one of them. Inserts some shapes into the document. Creates a rectangle 124 * shape. The retrieved master page is the instance of the service 125 * <code>com.sun.star.drawing.MasterPage</code>. 126 * Object relations created : 127 * <ul> 128 * <li> <code>'DrawPage'</code> for 129 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper}, 130 * {@link ifc.drawing._XShapeCombiner}( the draw page of the retrieved 131 * master page)</li> 132 * <li> <code>'Shape'</code> for 133 * {@link ifc.drawing._XShapes}(the created rectangle shape)</li> 134 * </ul> 135 * @see com.sun.star.drawing.XMasterPagesSupplier 136 */ 137 protected TestEnvironment createTestEnvironment( 138 TestParameters Param, PrintWriter log) { 139 140 log.println( "creating a test environment" ); 141 142 // get the MasterPages here 143 log.println( "getting MasterPages" ); 144 XMasterPagesSupplier oMPS = (XMasterPagesSupplier) 145 UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDrawDoc); 146 XDrawPages oMPn = oMPS.getMasterPages(); 147 XIndexAccess oMPi = (XIndexAccess) 148 UnoRuntime.queryInterface(XIndexAccess.class, oMPn); 149 150 log.println( "getting MasterPage" ); 151 XInterface oObj = null; 152 try { 153 oObj = (XDrawPage) AnyConverter.toObject( 154 new Type(XDrawPage.class),oMPi.getByIndex(0)); 155 } catch (com.sun.star.lang.WrappedTargetException e) { 156 e.printStackTrace( log ); 157 throw new StatusException("Couldn't get MasterPage by index", e); 158 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 159 e.printStackTrace( log ); 160 throw new StatusException("Couldn't get MasterPage by index", e); 161 } catch (com.sun.star.lang.IllegalArgumentException e) { 162 e.printStackTrace( log ); 163 throw new StatusException("Couldn't get MasterPage by index", e); 164 } 165 166 // get a soffice factory object 167 SOfficeFactory SOF = SOfficeFactory.getFactory( 168 (XMultiServiceFactory)Param.getMSF()); 169 170 //put something on the masterpage 171 log.println( "inserting some Shapes" ); 172 XShapes oShapes = (XShapes) 173 UnoRuntime.queryInterface(XShapes.class, oObj); 174 oShapes.add(SOF.createShape(xDrawDoc, 2000, 1500, 1000, 1000, "Line")); 175 oShapes.add(SOF.createShape 176 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse")); 177 oShapes.add(SOF.createShape 178 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle")); 179 180 log.println( "creating a new environment for MasterPage object" ); 181 TestEnvironment tEnv = new TestEnvironment( oObj ); 182 183 log.println( "adding DrawPage as mod relation to environment" ); 184 tEnv.addObjRelation("DrawPage", oObj); 185 186 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle"); 187 log.println( "adding Shape as mod relation to environment" ); 188 tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc)); 189 190 return tEnv; 191 } // finish method createTestEnvironment 192 193 } // finish class SdMasterPage 194 195