1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package mod._sd; 19 20 import com.sun.star.beans.XPropertySet; 21 import com.sun.star.drawing.XShape; 22 import com.sun.star.frame.XController; 23 import com.sun.star.frame.XModel; 24 import com.sun.star.lang.XComponent; 25 import com.sun.star.uno.UnoRuntime; 26 import com.sun.star.view.XSelectionSupplier; 27 import ifc.view._XPrintJobBroadcaster; 28 import java.io.File; 29 30 import java.io.PrintWriter; 31 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 36 import util.DrawTools; 37 import util.SOfficeFactory; 38 import util.utils; 39 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.presentation.PresentationDocument</code>. <p> 44 * Object implements the following interfaces : 45 * <ul> 46 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li> 47 * <li> <code>com::sun::star::drawing::XMasterPagesSupplier</code></li> 48 * <li> <code>com::sun::star::presentation::XCustomPresentationSupplier</code></li> 49 * <li> <code>com::sun::star::document::XLinkTargetSupplier</code></li> 50 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 51 * <li> <code>com::sun::star::drawing::XLayerSupplier</code></li> 52 * <li> <code>com::sun::star::presentation::XPresentationSupplier</code></li> 53 * <li> <code>com::sun::star::style::XStyleFamiliesSupplier</code></li> 54 * <li> <code>com::sun::star::drawing::DrawingDocument</code></li> 55 * <li> <code>com::sun::star::drawing::XDrawPageDuplicator</code></li> 56 * <li> <code>com::sun::star::drawing::XDrawPagesSupplier</code></li> 57 * </ul> 58 * @see com.sun.star.presentation.PresentationDocument 59 * @see com.sun.star.lang.XMultiServiceFactory 60 * @see com.sun.star.drawing.XMasterPagesSupplier 61 * @see com.sun.star.presentation.XCustomPresentationSupplier 62 * @see com.sun.star.document.XLinkTargetSupplier 63 * @see com.sun.star.beans.XPropertySet 64 * @see com.sun.star.drawing.XLayerSupplier 65 * @see com.sun.star.presentation.XPresentationSupplier 66 * @see com.sun.star.style.XStyleFamiliesSupplier 67 * @see com.sun.star.drawing.DrawingDocument 68 * @see com.sun.star.drawing.XDrawPageDuplicator 69 * @see com.sun.star.drawing.XDrawPagesSupplier 70 * @see ifc.lang._XMultiServiceFactory 71 * @see ifc.drawing._XMasterPagesSupplier 72 * @see ifc.presentation._XCustomPresentationSupplier 73 * @see ifc.document._XLinkTargetSupplier 74 * @see ifc.beans._XPropertySet 75 * @see ifc.drawing._XLayerSupplier 76 * @see ifc.presentation._XPresentationSupplier 77 * @see ifc.style._XStyleFamiliesSupplier 78 * @see ifc.drawing._DrawingDocument 79 * @see ifc.drawing._XDrawPageDuplicator 80 * @see ifc.drawing._XDrawPagesSupplier 81 */ 82 public class SdXImpressDocument extends TestCase { 83 XComponent xImpressDoc; 84 XComponent xImpressDoc2; 85 86 /** 87 * Called while disposing a <code>TestEnvironment</code>. 88 * Disposes Impress document. 89 * @param Param test parameters 90 * @param log writer to log information while testing 91 */ 92 @Override cleanup(TestParameters Param, PrintWriter log)93 protected void cleanup(TestParameters Param, PrintWriter log) { 94 log.println("disposing xImpressDoc"); 95 util.DesktopTools.closeDoc(xImpressDoc); 96 util.DesktopTools.closeDoc(xImpressDoc2); 97 } 98 99 /** 100 * Creating a TestEnvironment for the interfaces to be tested. 101 * Creates new impress document that is the instance of the service 102 * <code>com.sun.star.presentation.PresentationDocument</code>. 103 * @see com.sun.star.presentation.PresentationDocument 104 */ 105 @Override createTestEnvironment(TestParameters Param, PrintWriter log)106 public TestEnvironment createTestEnvironment(TestParameters Param, 107 PrintWriter log) 108 throws Exception { 109 log.println("creating a test environment"); 110 111 // get a soffice factory object 112 SOfficeFactory SOF = SOfficeFactory.getFactory( 113 Param.getMSF()); 114 115 log.println("creating two impress documents"); 116 xImpressDoc2 = SOF.createImpressDoc(null); 117 xImpressDoc = SOF.createImpressDoc(null); 118 119 XModel xModel1 = UnoRuntime.queryInterface(XModel.class, 120 xImpressDoc); 121 XModel xModel2 = UnoRuntime.queryInterface(XModel.class, 122 xImpressDoc2); 123 124 XController cont1 = xModel1.getCurrentController(); 125 XController cont2 = xModel2.getCurrentController(); 126 127 cont1.getFrame().setName("cont1"); 128 cont2.getFrame().setName("cont2"); 129 130 XSelectionSupplier sel = UnoRuntime.queryInterface( 131 XSelectionSupplier.class, cont1); 132 133 XShape aShape = SOF.createShape(xImpressDoc, 5000, 3500, 7500, 5000, 134 "Rectangle"); 135 136 137 XPropertySet xShapeProps = UnoRuntime.queryInterface(XPropertySet.class, aShape); 138 139 xShapeProps.setPropertyValue("FillStyle", com.sun.star.drawing.FillStyle.SOLID); 140 xShapeProps.setPropertyValue("FillTransparence", Integer.valueOf(50)); 141 142 DrawTools.getDrawPage(xImpressDoc, 0).add(aShape); 143 144 log.println("creating a new environment for drawpage object"); 145 146 TestEnvironment tEnv = new TestEnvironment(xImpressDoc); 147 148 log.println("adding Controller as ObjRelation for XModel"); 149 tEnv.addObjRelation("CONT2", cont2); 150 151 log.println("Adding SelectionSupplier and Shape to select for XModel"); 152 tEnv.addObjRelation("SELSUPP", sel); 153 tEnv.addObjRelation("TOSELECT", aShape); 154 155 // create object relation for XPrintJobBroadcaster 156 String fileName = utils.getOfficeTempDirSys(Param.getMSF())+"printfile.prt" ; 157 File f = new File(fileName); 158 if (f.exists()) { 159 boolean bDeleteOk = f.delete(); 160 if (!bDeleteOk) { 161 System.out.println("delete failed"); 162 } 163 } 164 _XPrintJobBroadcaster.MyPrintJobListener listener = new _XPrintJobBroadcaster.MyPrintJobListener(xImpressDoc, fileName); 165 tEnv.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener); 166 167 return tEnv; 168 } // finish method getTestEnvironment 169 170 } // finish class SdDrawPage 171