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