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 .
20 import com
.sun
.star
.beans
.XPropertySet
;
21 import com
.sun
.star
.document
.XExporter
;
22 import com
.sun
.star
.drawing
.XShape
;
23 import com
.sun
.star
.lang
.XComponent
;
24 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.XInterface
;
27 import com
.sun
.star
.util
.URL
;
29 import java
.io
.PrintWriter
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
35 import util
.DrawTools
;
36 import util
.SOfficeFactory
;
41 * Test for object which is represented by service
42 * <code>com.sun.star.drawing.GraphicExportFilter</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::document::XFilter</code></li>
47 * <li> <code>com::sun::star::document::XMimeTypeInfo</code></li>
48 * <li> <code>com::sun::star::document::XExporter</code></li>
51 * The following files used by this test :
53 * <li><b> space-metal.jpg </b> : the file used for GraphicObject
54 * creation. This image must be then exported. </li>
57 * This object test <b> is NOT </b> designed to be run in several
58 * threads concurrently.
60 * @see com.sun.star.document.XFilter
61 * @see com.sun.star.document.XMimeTypeInfo
62 * @see com.sun.star.document.XExporter
63 * @see ifc.document._XFilter
64 * @see ifc.document._XMimeTypeInfo
65 * @see ifc.document._XExporter
67 public class GraphicExporter
extends TestCase
{
68 static XComponent xDrawDoc
;
71 * Creates a new draw document.
74 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
75 log
.println("creating a drawdoc");
76 xDrawDoc
= DrawTools
.createDrawDoc(
81 * Disposes the draw document created before
84 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
85 log
.println(" disposing xDrawDoc ");
86 util
.DesktopTools
.closeDoc(xDrawDoc
);
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.drawing.GraphicExportFilter</code> as
93 * a tested component. Then a <code>GraphicObjectShape</code>
94 * instance is added into the document and its image is obtained
95 * from JPEG file. This shape content is intended to be exported.
97 * Object relations created :
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} :
101 * descriptor which contains target file name in
102 * the temporary directory, file type (JPEG)
104 * <li> <code>'XFilter.Checker'</code> for
105 * {@link ifc.document._XFilter} :
106 * checks if the target file exists.
107 * In the case if SOffice is started in 'Hide' mode
108 * ('soapi.test.hidewindows' test parameter is 'true')
109 * the checker always returns <code>true</code>.
111 * <li> <code>'SourceDocument'</code> for
112 * {@link ifc.document._XExporter} :
113 * the <code>GraphicObjectShape</code> component
119 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
120 PrintWriter log
) throws Exception
{
121 XInterface oObj
= null;
122 XShape oShape
= null;
126 // creation of testobject here
127 // first we write what we are intend to do to log file
128 log
.println("creating a test environment");
131 go
= tParam
.getMSF().createInstance(
132 "com.sun.star.drawing.GraphicExportFilter");
133 } catch (com
.sun
.star
.uno
.Exception e
) {
134 log
.println("Couldn't create instance");
135 e
.printStackTrace(log
);
138 // create testobject here
139 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
141 oShape
= SOF
.createShape(xDrawDoc
, 5000, 5000, 1500, 1000,
143 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
, 0)).add(oShape
);
145 XPropertySet oShapeProps
= UnoRuntime
.queryInterface(
146 XPropertySet
.class, oShape
);
147 XComponent xComp
= null;
149 oShapeProps
.setPropertyValue("GraphicURL",
150 util
.utils
.getFullTestURL(
152 xComp
= UnoRuntime
.queryInterface(XComponent
.class,
155 XExporter xEx
= UnoRuntime
.queryInterface(
156 XExporter
.class, go
);
157 xEx
.setSourceDocument(xComp
);
159 final URL aURL
= new URL();
160 aURL
.Complete
= util
.utils
.getOfficeTemp(
164 final XSimpleFileAccess fAcc
;
166 Object oFAcc
= tParam
.getMSF().createInstance(
167 "com.sun.star.ucb.SimpleFileAccess");
168 fAcc
= UnoRuntime
.queryInterface(
169 XSimpleFileAccess
.class, oFAcc
);
171 if (fAcc
.exists(aURL
.Complete
)) {
172 fAcc
.kill(aURL
.Complete
);
175 oObj
= (XInterface
) go
;
176 log
.println("ImplName " + util
.utils
.getImplName(oObj
));
178 TestEnvironment tEnv
= new TestEnvironment(oObj
);
179 tEnv
.addObjRelation("MediaDescriptor",
180 XMLTools
.createMediaDescriptor(
182 "FilterName", "URL", "MediaType"
183 }, new Object
[] { "JPG", aURL
, "image/jpeg" }));
184 tEnv
.addObjRelation("SourceDocument", xComp
);
186 log
.println("adding ObjRelation for XFilter");
187 log
.println("This Component doesn't really support the cancel method");
188 log
.println("See #101725");
189 tEnv
.addObjRelation("NoFilter.cancel()", Boolean
.TRUE
);
191 final String hideMode
= (String
) tParam
.get("soapi.test.hidewindows");
192 tEnv
.addObjRelation("XFilter.Checker",
193 new ifc
.document
._XFilter
.FilterChecker() {
194 public boolean checkFilter() {
196 if ((hideMode
!= null) && hideMode
.equals("true")) {
200 return fAcc
.exists(aURL
.Complete
);
201 } catch (com
.sun
.star
.uno
.Exception e
) {
208 } // finish method getTestEnvironment
209 } // finish class GraphicExporter