bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLMetaExporter.java
blob8cea6256add17d0a974c08a9dceb83f487ce4816
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._sw;
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.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.xml.sax.XDocumentHandler;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLMetaExporter extends TestCase {
65 XTextDocument xTextDoc;
66 MetaFilterChecker Filter;
68 /**
69 * New text document created.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
73 try {
74 log.println( "creating a textdocument" );
75 xTextDoc = SOF.createTextDoc( null );
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Document disposed here.
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xTextDoc " );
89 util.DesktopTools.closeDoc(xTextDoc);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
96 * argument which is an implementation of <code>XDocumentHandler</code>
97 * and which can check if required tags and character data is
98 * exported. <p>
99 * The text document is set as a source document for exporter
100 * created. The 'Title' metadata property is set to a value. This made
101 * for checking if this property is successfully exported within
102 * the document metadata.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'MediaDescriptor'</code> for
106 * {@link ifc.document._XFilter} interface </li>
107 * <li> <code>'XFilter.Checker'</code> for
108 * {@link ifc.document._XFilter} interface </li>
109 * <li> <code>'SourceDocument'</code> for
110 * {@link ifc.document._XExporter} interface </li>
111 * </ul>
113 public synchronized TestEnvironment createTestEnvironment
114 ( TestParameters tParam, PrintWriter log ) throws StatusException {
115 final String TITLE = "Title for testing of XMLMetaExporter";
117 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
118 XInterface oObj = null;
120 Filter = new MetaFilterChecker(log);
121 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
123 try {
124 oObj = (XInterface) xMSF.createInstanceWithArguments(
125 "com.sun.star.comp.Writer.XMLMetaExporter",
126 new Object[] {arg});
127 XExporter xEx = UnoRuntime.queryInterface
128 (XExporter.class,oObj);
129 xEx.setSourceDocument(xTextDoc);
131 //set some meta data
132 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
133 (XDocumentPropertiesSupplier.class, xTextDoc);
134 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
135 xDocProps.setTitle(TITLE);
136 } catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace(log) ;
138 throw new StatusException("Can't create component.", e) ;
141 // adding tags which must be contained in XML output
142 Filter.addTag("office:document-meta");
143 Filter.addTagEnclosed("office:meta", "office:document-meta");
144 Filter.addCharactersEnclosed(TITLE, "dc:title");
146 // create testobject here
147 log.println( "creating a new environment" );
148 TestEnvironment tEnv = new TestEnvironment( oObj );
150 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
151 new String[] {"FilterName"},
152 new Object[] {"swriter: StarOffice XML (Writer)"}));
153 tEnv.addObjRelation("SourceDocument", xTextDoc);
154 tEnv.addObjRelation("XFilter.Checker", Filter);
155 return tEnv;
159 * This class checks the XML for tags and data required and returns
160 * checking result to <code>XFilter</code> interface test. All
161 * the information about errors occurred in XML data is written
162 * to log specified.
163 * @see ifc.document._XFilter
165 protected class MetaFilterChecker extends XMLTools.XMLTagsChecker
166 implements ifc.document._XFilter.FilterChecker {
169 * Creates a class which will write information
170 * into log specified.
172 public MetaFilterChecker(PrintWriter log) {
173 super(log) ;
177 * <code>_XFilter.FilterChecker</code> interface method
178 * which returns the result of XML checking.
179 * @return <code>true</code> if the XML data exported was
180 * valid (i.e. all necessary tags and character data exists),
181 * <code>false</code> if some errors occurred.
183 public boolean checkFilter() {
184 return checkTags();