Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLExporter.java
blob61b1898760ce03f8de1a6b0ed79710a60da1a8bc
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 .
19 package mod._xmloff.Impress;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
28 import util.XMLTools;
30 import com.sun.star.container.XNamed;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.Any;
38 import com.sun.star.uno.Exception;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.xml.sax.XDocumentHandler;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.comp.Impress.XMLExporter</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li><code>com::sun::star::lang::XInitialization</code></li>
50 * <li><code>com::sun::star::document::ExportFilter</code></li>
51 * <li><code>com::sun::star::document::XFilter</code></li>
52 * <li><code>com::sun::star::document::XExporter</code></li>
53 * <li><code>com::sun::star::beans::XPropertySet</code></li>
54 * </ul>
55 * @see com.sun.star.lang.XInitialization
56 * @see com.sun.star.document.ExportFilter
57 * @see com.sun.star.document.XFilter
58 * @see com.sun.star.document.XExporter
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.lang._XInitialization
61 * @see ifc.document._ExportFilter
62 * @see ifc.document._XFilter
63 * @see ifc.document._XExporter
64 * @see ifc.beans._XPropertySet
66 public class XMLExporter extends TestCase {
67 XComponent xImpressDoc = null;
69 /**
70 * New impress document created.
72 @Override
73 protected void initialize( TestParameters tParam, PrintWriter log ) {
75 // get a soffice factory object
76 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
78 try {
79 log.println( "creating an impress document" );
80 xImpressDoc = SOF.createImpressDoc(null);
81 } catch ( Exception e ) {
82 // Some exception occurs.FAILED
83 e.printStackTrace( log );
84 throw new StatusException( "Couldn't create document", e );
88 /**
89 * Document disposed here.
91 @Override
92 protected void cleanup( TestParameters tParam, PrintWriter log ) {
93 log.println( " disposing xImpressDoc " );
94 xImpressDoc.dispose();
97 /**
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.comp.Impress.XMLExporter</code> with
101 * argument which is an implementation of <code>XDocumentHandler</code>
102 * and which can check if required tags and character data is
103 * exported. <p>
104 * The impress document is set as a source document for exporter
105 * created. A new draw page with specific name created. This made
106 * for checking if this draw page is successfully exported within
107 * the document.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'MediaDescriptor'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'XFilter.Checker'</code> for
113 * {@link ifc.document._XFilter} interface </li>
114 * <li> <code>'SourceDocument'</code> for
115 * {@link ifc.document._XExporter} interface </li>
116 * </ul>
118 @Override
119 protected synchronized TestEnvironment createTestEnvironment
120 (TestParameters tParam, PrintWriter log) {
122 XMultiServiceFactory xMSF = tParam.getMSF() ;
123 XInterface oObj = null;
125 FilterChecker Filter = new FilterChecker(log);
126 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
128 final String NAME = "XMLExporter";
130 try {
131 oObj = (XInterface) xMSF.createInstanceWithArguments(
132 "com.sun.star.comp.Impress.XMLExporter", new Object[] {arg});
134 //get draw pages
135 XDrawPagesSupplier drawPagesSupplier = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
136 XDrawPages drawPages = drawPagesSupplier.getDrawPages();
137 //insert new draw page
138 XDrawPage newDrawPage = drawPages.insertNewByIndex(0);
139 //set specific test name
140 XNamed newPageNamed = UnoRuntime.queryInterface(XNamed.class, newDrawPage);
141 newPageNamed.setName(NAME);
142 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
143 xEx.setSourceDocument(xImpressDoc);
145 } catch (com.sun.star.uno.Exception e) {
146 e.printStackTrace(log) ;
147 throw new StatusException("Can't create component.", e) ;
150 // adding tags which must be contained in XML output
151 Filter.addTag( new XMLTools.Tag("office:document") );
152 Filter.addTagEnclosed(
153 new XMLTools.Tag("office:body"),
154 new XMLTools.Tag("office:document") );
155 Filter.addTagEnclosed(
156 new XMLTools.Tag("draw:page", "draw:name", NAME),
157 new XMLTools.Tag("office:body") );
160 // create testobject here
161 log.println( "creating a new environment" );
162 TestEnvironment tEnv = new TestEnvironment( oObj );
164 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
165 new String[] {"FilterName"},
166 new Object[] {"simpress: StarOffice XML (Impress)"}));
167 tEnv.addObjRelation("SourceDocument",xImpressDoc);
168 tEnv.addObjRelation("XFilter.Checker", Filter) ;
170 return tEnv;
174 * This class checks the XML for tags and data required and returns
175 * checking result to <code>XFilter</code> interface test. All
176 * the information about errors occurred in XML data is written
177 * to log specified.
178 * @see ifc.document._XFilter
180 private class FilterChecker extends XMLTools.XMLChecker
181 implements ifc.document._XFilter.FilterChecker {
184 * Creates a class which will write information
185 * into log specified.
187 private FilterChecker(PrintWriter log) {
188 super(log, true) ;
191 * <code>_XFilter.FilterChecker</code> interface method
192 * which returns the result of XML checking.
193 * @return <code>true</code> if the XML data exported was
194 * valid (i.e. all necessary tags and character data exists),
195 * <code>false</code> if some errors occurred.
197 public boolean checkFilter() {
198 return check();