bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLMetaExporter.java
blob6446afde67d036e507232eaaff6b20f1c54b9dbc
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._sc;
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.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.xml.sax.XDocumentHandler;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Calc.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 {
66 static XComponent xSheetDoc;
68 /**
69 * New spreadsheet document created.
71 @Override
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
75 try {
76 log.println( "creating a calc document" );
77 xSheetDoc = SOF.openDoc("scalc","_blank");
78 } catch ( com.sun.star.uno.Exception e ) {
79 // Some exception occurs.FAILED
80 e.printStackTrace( log );
81 throw new StatusException( "Couldn't create document", e );
85 /**
86 * Spreadsheet document disposed
88 @Override
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xCalcDoc " );
91 util.DesktopTools.closeDoc(xSheetDoc);
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
98 * argument which is an implementation of <code>XDocumentHandler</code>
99 * and which can check if required tags and character data is
100 * exported. <p>
101 * The calc document is set as a source document for exporter
102 * created. A meta property 'Title' is set to some value. This made
103 * for checking if this value is successfully exported within
104 * the document meta information.
105 * Object relations created :
106 * <ul>
107 * <li> <code>'MediaDescriptor'</code> for
108 * {@link ifc.document._XFilter} interface </li>
109 * <li> <code>'XFilter.Checker'</code> for
110 * {@link ifc.document._XFilter} interface </li>
111 * <li> <code>'SourceDocument'</code> for
112 * {@link ifc.document._XExporter} interface </li>
113 * </ul>
115 @Override
116 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
117 PrintWriter log )
118 throws StatusException {
120 XMultiServiceFactory xMSF = tParam.getMSF() ;
121 XInterface oObj = null;
122 FilterChecker filter = new FilterChecker(log);
123 Any arg = new Any(new Type(XDocumentHandler.class),filter);
125 // Checking tags existence and changed property value
126 filter.addTag(new XMLTools.Tag ("office:document-meta"));
127 filter.addTag(new XMLTools.Tag ("office:meta"));
128 filter.addCharactersEnclosed("TestDocument",
129 new XMLTools.Tag ("dc:title"));
131 try {
132 oObj = (XInterface) xMSF.createInstanceWithArguments(
133 "com.sun.star.comp.Calc.XMLMetaExporter", new Object[] {arg});
134 XExporter xEx = UnoRuntime.queryInterface
135 (XExporter.class,oObj);
136 xEx.setSourceDocument(xSheetDoc);
138 // Obtaining and changing property values
139 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
140 (XDocumentPropertiesSupplier.class, xSheetDoc);
141 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
142 xDocProps.setTitle("TestDocument");
144 log.println("fill sheet 1 with contnet...");
145 util.CalcTools.fillCalcSheetWithContent(xSheetDoc,1, 3, 3, 50, 50);
147 } catch (com.sun.star.uno.Exception e) {
148 e.printStackTrace(log) ;
149 throw new StatusException("Can't create environment.", e) ;
150 } catch (java.lang.Exception e) {
151 e.printStackTrace(log);
152 throw new StatusException("Can't create environment.", e);
155 // create testobject here
156 log.println( "creating a new environment" );
157 TestEnvironment tEnv = new TestEnvironment( oObj );
159 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
160 new String[] {"FilterName"},
161 new Object[] {"scalc: StarOffice XML (Calc)"}));
162 tEnv.addObjRelation("SourceDocument",xSheetDoc);
163 tEnv.addObjRelation("XFilter.Checker", filter) ;
164 return tEnv;
169 * This class checks the XML for tags and data required and returns
170 * checking result to <code>XFilter</code> interface test. All
171 * the information about errors occurred in XML data is written
172 * to log specified.
173 * @see ifc.document._XFilter
175 private class FilterChecker extends XMLTools.XMLChecker
176 implements ifc.document._XFilter.FilterChecker {
179 * Creates a class which will write information
180 * into log specified.
182 private FilterChecker(PrintWriter log) {
183 super(log,false) ;
186 * <code>_XFilter.FilterChecker</code> interface method
187 * which returns the result of XML checking.
188 * @return <code>true</code> if the XML data exported was
189 * valid (i.e. all necessary tags and character data exists),
190 * <code>false</code> if some errors occurred.
192 public boolean checkFilter() {
193 return check();