merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sm / XMLExporter.java
blobea4e7888d201f8c6b1fb889a9bb820ec1af386b1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLExporter.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sm;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
40 import util.XMLTools;
42 import com.sun.star.beans.XPropertySet;
43 import com.sun.star.document.XExporter;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.Any;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.xml.sax.XDocumentHandler;
52 /**
53 * Test for object which is represented by service
54 * <code>com.sun.star.comp.Math.XMLExporter</code>. <p>
55 * Object implements the following interfaces :
56 * <ul>
57 * <li><code>com::sun::star::lang::XInitialization</code></li>
58 * <li><code>com::sun::star::document::ExportFilter</code></li>
59 * <li><code>com::sun::star::document::XFilter</code></li>
60 * <li><code>com::sun::star::document::XExporter</code></li>
61 * <li><code>com::sun::star::beans::XPropertySet</code></li>
62 * </ul>
63 * @see com.sun.star.lang.XInitialization
64 * @see com.sun.star.document.ExportFilter
65 * @see com.sun.star.document.XFilter
66 * @see com.sun.star.document.XExporter
67 * @see com.sun.star.beans.XPropertySet
68 * @see ifc.lang._XInitialization
69 * @see ifc.document._ExportFilter
70 * @see ifc.document._XFilter
71 * @see ifc.document._XExporter
72 * @see ifc.beans._XPropertySet
74 public class XMLExporter extends TestCase {
75 XComponent xMathDoc;
77 /**
78 * New math document created.
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
83 try {
84 log.println( "creating a math document" );
85 xMathDoc = SOF.createMathDoc(null);
86 } catch ( com.sun.star.uno.Exception e ) {
87 // Some exception occures.FAILED
88 e.printStackTrace( log );
89 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Document disposed here.
96 protected void cleanup( TestParameters tParam, PrintWriter log ) {
97 log.println( " disposing xMathDoc " );
98 xMathDoc.dispose();
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Creates an instance of the service
104 * <code>com.sun.star.comp.Math.XMLExporter</code> with
105 * argument which is an implementation of <code>XDocumentHandler</code>
106 * and which can check if required tags and character data is
107 * exported. <p>
108 * The math document is set as a source document for exporter
109 * created. A new formula inserted into document. This made
110 * for checking if this formula is successfully exported within
111 * the document content.
112 * Object relations created :
113 * <ul>
114 * <li> <code>'MediaDescriptor'</code> for
115 * {@link ifc.document._XFilter} interface </li>
116 * <li> <code>'XFilter.Checker'</code> for
117 * {@link ifc.document._XFilter} interface </li>
118 * <li> <code>'SourceDocument'</code> for
119 * {@link ifc.document._XExporter} interface </li>
120 * </ul>
122 protected TestEnvironment createTestEnvironment
123 (TestParameters tParam, PrintWriter log) {
125 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
126 XInterface oObj = null;
127 final String expFormula = "a - b" ;
129 FilterChecker filter = new FilterChecker(log);
130 Any arg = new Any(new Type(XDocumentHandler.class), filter);
132 try {
133 oObj = (XInterface) xMSF.createInstanceWithArguments(
134 "com.sun.star.comp.Math.XMLExporter", new Object[] {arg});
135 XExporter xEx = (XExporter) UnoRuntime.queryInterface
136 (XExporter.class,oObj);
137 xEx.setSourceDocument(xMathDoc);
139 // setting a formula in document
140 XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface
141 (XPropertySet.class, xMathDoc) ;
142 xPS.setPropertyValue("Formula", expFormula) ;
143 } catch (com.sun.star.uno.Exception e) {
144 e.printStackTrace(log) ;
145 throw new StatusException("Can't create component.", e) ;
148 // checking tags required
149 filter.addTag(new XMLTools.Tag("math:math")) ;
150 filter.addTagEnclosed(new XMLTools.Tag("math:annotation"),
151 new XMLTools.Tag("math:semantics")) ;
152 filter.addCharactersEnclosed(expFormula,
153 new XMLTools.Tag("math:annotation")) ;
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[] {"smath: StarOffice XML (Math)"}));
162 tEnv.addObjRelation("SourceDocument",xMathDoc);
163 tEnv.addObjRelation("XFilter.Checker", filter) ;
165 log.println("Implementation Name: "+util.utils.getImplName(oObj));
167 return tEnv;
171 * This class checks the XML for tags and data required and returns
172 * checking result to <code>XFilter</code> interface test. All
173 * the information about errors occured in XML data is written
174 * to log specified.
175 * @see ifc.document._XFilter
177 protected class FilterChecker extends XMLTools.XMLChecker
178 implements ifc.document._XFilter.FilterChecker {
181 * Creates a class which will write information
182 * into log specified.
184 public FilterChecker(PrintWriter log) {
185 super(log, true) ;
188 * <code>_XFilter.FilterChecker</code> interface method
189 * which returns the result of XML checking.
190 * @return <code>true</code> if the XML data exported was
191 * valid (i.e. all necessary tags and character data exists),
192 * <code>false</code> if some errors occured.
194 public boolean checkFilter() {
195 return check();
199 } // finish class TestCase