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