Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLMetaExporter.java
bloba9894f5f6068f6c88c399201325a140a3bf23c6a
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.document.XDocumentPropertiesSupplier;
31 import com.sun.star.document.XDocumentProperties;
32 import com.sun.star.document.XExporter;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Exception;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import com.sun.star.xml.sax.XDocumentHandler;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Impress.XMLMetaExporter</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li><code>com::sun::star::lang::XInitialization</code></li>
48 * <li><code>com::sun::star::document::ExportFilter</code></li>
49 * <li><code>com::sun::star::document::XFilter</code></li>
50 * <li><code>com::sun::star::document::XExporter</code></li>
51 * <li><code>com::sun::star::beans::XPropertySet</code></li>
52 * </ul>
53 * @see com.sun.star.lang.XInitialization
54 * @see com.sun.star.document.ExportFilter
55 * @see com.sun.star.document.XFilter
56 * @see com.sun.star.document.XExporter
57 * @see com.sun.star.beans.XPropertySet
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._ExportFilter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
64 public class XMLMetaExporter extends TestCase {
65 XComponent xImpressDoc = null;
67 /**
68 * New impress document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 // get a soffice factory object
74 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
76 try {
77 log.println( "creating an impress document" );
78 xImpressDoc = SOF.createImpressDoc(null);
79 } catch ( Exception e ) {
80 // Some exception occurs.FAILED
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Impress document disposed
89 @Override
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( "disposing xImpressDoc " );
92 xImpressDoc.dispose();
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Impress.XMLMetaExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
101 * exported. <p>
102 * The impress document is set as a source document for exporter
103 * created. A meta property 'Title' is set to specific value. This made
104 * for checking if this value is successfully exported within
105 * the document meta information.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
114 * </ul>
116 @Override
117 public synchronized TestEnvironment createTestEnvironment
118 (TestParameters tParam, PrintWriter log) throws StatusException {
120 XMultiServiceFactory xMSF = tParam.getMSF() ;
121 XInterface oObj = null;
123 FilterChecker filter = new FilterChecker(log);
124 Any arg = new Any(new Type(XDocumentHandler.class), filter);
125 final String NAME = "XMLMetaExporter";
127 try {
128 oObj = (XInterface) xMSF.createInstanceWithArguments(
129 "com.sun.star.comp.Impress.XMLMetaExporter",
130 new Object[]{arg});
131 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
132 xEx.setSourceDocument(xImpressDoc);
134 // change title name
135 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
136 (XDocumentPropertiesSupplier.class, xImpressDoc);
137 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
138 xDocProps.setTitle(NAME);
140 } catch (com.sun.star.uno.Exception e) {
141 e.printStackTrace(log) ;
142 throw new StatusException("Can't create component.", e) ;
145 // Checking tags existence and changed property value
146 filter.addTag(new XMLTools.Tag ("office:document-meta"));
147 filter.addTagEnclosed(
148 new XMLTools.Tag("office:meta"),
149 new XMLTools.Tag("office:document-meta") );
150 filter.addTagEnclosed(
151 new XMLTools.Tag("dc:title"),
152 new XMLTools.Tag("office:meta") );
153 filter.addCharactersEnclosed(
154 NAME,
155 new XMLTools.Tag ("dc:title") );
157 // create testobject here
158 log.println( "creating a new environment" );
159 TestEnvironment tEnv = new TestEnvironment( oObj );
161 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
162 new String[] {"FilterName"},
163 new Object[] {"simpress: StarOffice XML (Impress)"}));
164 tEnv.addObjRelation("SourceDocument", xImpressDoc);
165 tEnv.addObjRelation("XFilter.Checker", filter) ;
166 return tEnv;
170 * This class checks the XML for tags and data required and returns
171 * checking result to <code>XFilter</code> interface test. All
172 * the information about errors occurred in XML data is written
173 * to log specified.
174 * @see ifc.document._XFilter
176 private class FilterChecker extends XMLTools.XMLChecker
177 implements ifc.document._XFilter.FilterChecker {
180 * Creates a class which will write information
181 * into log specified.
183 private FilterChecker(PrintWriter log) {
184 super(log, true);
187 * <code>_XFilter.FilterChecker</code> interface method
188 * which returns the result of XML checking.
189 * @return <code>true</code> if the XML data exported was
190 * valid (i.e. all necessary tags and character data exists),
191 * <code>false</code> if some errors occurred.
193 public boolean checkFilter() {
194 return check();