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 package mod._sd; 28 29 import com.sun.star.beans.PropertyVetoException; 30 import com.sun.star.beans.UnknownPropertyException; 31 import com.sun.star.beans.XPropertySet; 32 import com.sun.star.drawing.XShape; 33 import com.sun.star.frame.XController; 34 import com.sun.star.frame.XModel; 35 import com.sun.star.lang.WrappedTargetException; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.view.XSelectionSupplier; 40 import ifc.view._XPrintJobBroadcaster; 41 import java.io.File; 42 43 import java.io.PrintWriter; 44 45 import lib.StatusException; 46 import lib.TestCase; 47 import lib.TestEnvironment; 48 import lib.TestParameters; 49 50 import util.DrawTools; 51 import util.SOfficeFactory; 52 import util.utils; 53 54 55 /** 56 * Test for object which is represented by service 57 * <code>com.sun.star.presentation.PresentationDocument</code>. <p> 58 * Object implements the following interfaces : 59 * <ul> 60 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li> 61 * <li> <code>com::sun::star::drawing::XMasterPagesSupplier</code></li> 62 * <li> <code>com::sun::star::presentation::XCustomPresentationSupplier</code></li> 63 * <li> <code>com::sun::star::document::XLinkTargetSupplier</code></li> 64 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 65 * <li> <code>com::sun::star::drawing::XLayerSupplier</code></li> 66 * <li> <code>com::sun::star::presentation::XPresentationSupplier</code></li> 67 * <li> <code>com::sun::star::style::XStyleFamiliesSupplier</code></li> 68 * <li> <code>com::sun::star::drawing::DrawingDocument</code></li> 69 * <li> <code>com::sun::star::drawing::XDrawPageDuplicator</code></li> 70 * <li> <code>com::sun::star::drawing::XDrawPagesSupplier</code></li> 71 * </ul> 72 * @see com.sun.star.presentation.PresentationDocument 73 * @see com.sun.star.lang.XMultiServiceFactory 74 * @see com.sun.star.drawing.XMasterPagesSupplier 75 * @see com.sun.star.presentation.XCustomPresentationSupplier 76 * @see com.sun.star.document.XLinkTargetSupplier 77 * @see com.sun.star.beans.XPropertySet 78 * @see com.sun.star.drawing.XLayerSupplier 79 * @see com.sun.star.presentation.XPresentationSupplier 80 * @see com.sun.star.style.XStyleFamiliesSupplier 81 * @see com.sun.star.drawing.DrawingDocument 82 * @see com.sun.star.drawing.XDrawPageDuplicator 83 * @see com.sun.star.drawing.XDrawPagesSupplier 84 * @see ifc.lang._XMultiServiceFactory 85 * @see ifc.drawing._XMasterPagesSupplier 86 * @see ifc.presentation._XCustomPresentationSupplier 87 * @see ifc.document._XLinkTargetSupplier 88 * @see ifc.beans._XPropertySet 89 * @see ifc.drawing._XLayerSupplier 90 * @see ifc.presentation._XPresentationSupplier 91 * @see ifc.style._XStyleFamiliesSupplier 92 * @see ifc.drawing._DrawingDocument 93 * @see ifc.drawing._XDrawPageDuplicator 94 * @see ifc.drawing._XDrawPagesSupplier 95 */ 96 public class SdXImpressDocument extends TestCase { 97 XComponent xImpressDoc; 98 XComponent xImpressDoc2; 99 100 /** 101 * Called while disposing a <code>TestEnvironment</code>. 102 * Disposes Impress document. 103 * @param tParam test parameters 104 * @param tEnv the environment to cleanup 105 * @param log writer to log information while testing 106 */ 107 protected void cleanup(TestParameters Param, PrintWriter log) { 108 log.println("disposing xImpressDoc"); 109 util.DesktopTools.closeDoc(xImpressDoc);; 110 util.DesktopTools.closeDoc(xImpressDoc2);; 111 } 112 113 /** 114 * Creating a Testenvironment for the interfaces to be tested. 115 * Creates new impress document that is the instance of the service 116 * <code>com.sun.star.presentation.PresentationDocument</code>. 117 * @see com.sun.star.presentation.PresentationDocument 118 */ 119 public synchronized TestEnvironment createTestEnvironment(TestParameters Param, 120 PrintWriter log) 121 throws StatusException { 122 log.println("creating a test environment"); 123 124 // get a soffice factory object 125 SOfficeFactory SOF = SOfficeFactory.getFactory( 126 (XMultiServiceFactory) Param.getMSF()); 127 128 try { 129 log.println("creating two impress documents"); 130 xImpressDoc2 = SOF.createImpressDoc(null); 131 xImpressDoc = SOF.createImpressDoc(null); 132 } catch (com.sun.star.uno.Exception e) { 133 e.printStackTrace(log); 134 throw new StatusException("Couldn't create documents", e); 135 } 136 137 XModel xModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 138 xImpressDoc); 139 XModel xModel2 = (XModel) UnoRuntime.queryInterface(XModel.class, 140 xImpressDoc2); 141 142 XController cont1 = xModel1.getCurrentController(); 143 XController cont2 = xModel2.getCurrentController(); 144 145 cont1.getFrame().setName("cont1"); 146 cont2.getFrame().setName("cont2"); 147 148 XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface( 149 XSelectionSupplier.class, cont1); 150 151 XShape aShape = SOF.createShape(xImpressDoc, 5000, 3500, 7500, 5000, 152 "Rectangle"); 153 154 155 XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aShape); 156 157 try { 158 xShapeProps.setPropertyValue("FillStyle", com.sun.star.drawing.FillStyle.SOLID); 159 xShapeProps.setPropertyValue("FillTransparence", new Integer(50)); 160 } catch (UnknownPropertyException ex) { 161 ex.printStackTrace(log); 162 throw new StatusException("Couldn't make shape transparent", ex); 163 } catch (PropertyVetoException ex) { 164 ex.printStackTrace(log); 165 throw new StatusException("Couldn't make shape transparent", ex); 166 } catch (com.sun.star.lang.IllegalArgumentException ex) { 167 ex.printStackTrace(log); 168 throw new StatusException("Couldn't make shape transparent", ex); 169 } catch (WrappedTargetException ex) { 170 ex.printStackTrace(log); 171 throw new StatusException("Couldn't make shape transparent", ex); 172 } 173 174 DrawTools.getDrawPage(xImpressDoc, 0).add(aShape); 175 176 log.println("creating a new environment for drawpage object"); 177 178 TestEnvironment tEnv = new TestEnvironment(xImpressDoc); 179 180 log.println("adding Controller as ObjRelation for XModel"); 181 tEnv.addObjRelation("CONT2", cont2); 182 183 log.println("Adding SelectionSupplier and Shape to select for XModel"); 184 tEnv.addObjRelation("SELSUPP", sel); 185 tEnv.addObjRelation("TOSELECT", aShape); 186 187 // create object relation for XPrintJobBroadcaster 188 String fileName = utils.getOfficeTempDirSys((XMultiServiceFactory) Param.getMSF())+"printfile.prt" ; 189 File f = new File(fileName); 190 if (f.exists()) { 191 f.delete(); 192 } 193 _XPrintJobBroadcaster.MyPrintJobListener listener = new _XPrintJobBroadcaster.MyPrintJobListener(xImpressDoc, fileName); 194 tEnv.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener); 195 196 return tEnv; 197 } // finish method getTestEnvironment 198 199 } // finish class SdDrawPage 200