bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLMetaExporter.java
blobc2c1e0584af9e765160b5d6f3f46ee275603a1ed
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._sm;
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.beans.XPropertyContainer;
31 import com.sun.star.document.XDocumentPropertiesSupplier;
32 import com.sun.star.document.XDocumentProperties;
33 import com.sun.star.document.XExporter;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.Any;
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.Math.XMLExporter</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 xMathDoc;
67 /**
68 * New math document created.
70 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
73 try {
74 log.println( "creating a math document" );
75 xMathDoc = SOF.createMathDoc(null);
76 } catch ( com.sun.star.uno.Exception e ) {
77 // Some exception occurs.FAILED
78 e.printStackTrace( log );
79 throw new StatusException( "Couldn't create document", e );
83 /**
84 * Document disposed here.
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xMathDoc " );
88 xMathDoc.dispose();
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Math.XMLExporter</code> with
95 * argument which is an implementation of <code>XDocumentHandler</code>
96 * and which can check if required tags and character data is
97 * exported. <p>
98 * The math document is set as a source document for exporter
99 * created. A new user info field inserted into document. This made
100 * for checking if this info field is successfully exported within
101 * the document content.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'MediaDescriptor'</code> for
105 * {@link ifc.document._XFilter} interface </li>
106 * <li> <code>'XFilter.Checker'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'SourceDocument'</code> for
109 * {@link ifc.document._XExporter} interface </li>
110 * </ul>
112 protected TestEnvironment createTestEnvironment
113 (TestParameters tParam, PrintWriter log) {
114 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
115 XInterface oObj = null;
116 final String expName = "XMLMetaExporterName" ;
117 final String expValue = "XMLMetaExporterValue" ;
119 FilterChecker filter = new FilterChecker(log);
120 Any arg = new Any(new Type(XDocumentHandler.class), filter);
122 try {
123 oObj = (XInterface) xMSF.createInstanceWithArguments(
124 "com.sun.star.comp.Math.XMLMetaExporter", new Object[] {arg});
125 XExporter xEx = UnoRuntime.queryInterface
126 (XExporter.class,oObj);
127 xEx.setSourceDocument(xMathDoc);
129 // setting a new name and value for user info field
130 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
131 (XDocumentPropertiesSupplier.class, xMathDoc);
132 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
133 XPropertyContainer xProps = xDocProps.getUserDefinedProperties();
134 xProps.addProperty(expName, (short)0, expValue);
135 } catch (com.sun.star.uno.Exception e) {
136 e.printStackTrace(log) ;
137 throw new StatusException("Can't create component.", e) ;
140 // checking tags required
141 filter.addTag(new XMLTools.Tag("office:document-meta")) ;
142 filter.addCharactersEnclosed(expValue,
143 new XMLTools.Tag("meta:user-defined", "meta:name", expName)) ;
145 // create testobject here
146 log.println( "creating a new environment" );
147 TestEnvironment tEnv = new TestEnvironment( oObj );
150 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
151 new String[] {"FilterName"},
152 new Object[] {"smath: StarOffice XML (Math)"}));
153 tEnv.addObjRelation("SourceDocument",xMathDoc);
154 tEnv.addObjRelation("XFilter.Checker", filter) ;
156 log.println("Implementation Name: "+util.utils.getImplName(oObj));
158 return tEnv;
162 * This class checks the XML for tags and data required and returns
163 * checking result to <code>XFilter</code> interface test. All
164 * the information about errors occurred in XML data is written
165 * to log specified.
166 * @see ifc.document._XFilter
168 protected class FilterChecker extends XMLTools.XMLChecker
169 implements ifc.document._XFilter.FilterChecker {
172 * Creates a class which will write information
173 * into log specified.
175 public FilterChecker(PrintWriter log) {
176 super(log, true) ;
179 * <code>_XFilter.FilterChecker</code> interface method
180 * which returns the result of XML checking.
181 * @return <code>true</code> if the XML data exported was
182 * valid (i.e. all necessary tags and character data exists),
183 * <code>false</code> if some errors occurred.
185 public boolean checkFilter() {
186 return check();
189 } // finish class TestCase