merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sm / XMLMetaExporter.java
blob3e73f91ab77c1469c07e260022999af46159fbf8
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: XMLMetaExporter.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.document.XDocumentInfo;
43 import com.sun.star.document.XDocumentInfoSupplier;
44 import com.sun.star.document.XExporter;
45 import com.sun.star.lang.XComponent;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.Any;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.xml.sax.XDocumentHandler;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.comp.Math.XMLExporter</code>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li><code>com::sun::star::lang::XInitialization</code></li>
59 * <li><code>com::sun::star::document::ExportFilter</code></li>
60 * <li><code>com::sun::star::document::XFilter</code></li>
61 * <li><code>com::sun::star::document::XExporter</code></li>
62 * <li><code>com::sun::star::beans::XPropertySet</code></li>
63 * </ul>
64 * @see com.sun.star.lang.XInitialization
65 * @see com.sun.star.document.ExportFilter
66 * @see com.sun.star.document.XFilter
67 * @see com.sun.star.document.XExporter
68 * @see com.sun.star.beans.XPropertySet
69 * @see ifc.lang._XInitialization
70 * @see ifc.document._ExportFilter
71 * @see ifc.document._XFilter
72 * @see ifc.document._XExporter
73 * @see ifc.beans._XPropertySet
75 public class XMLMetaExporter extends TestCase {
76 XComponent xMathDoc;
78 /**
79 * New math document created.
81 protected void initialize( TestParameters tParam, PrintWriter log ) {
82 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
84 try {
85 log.println( "creating a math document" );
86 xMathDoc = SOF.createMathDoc(null);
87 } catch ( com.sun.star.uno.Exception e ) {
88 // Some exception occures.FAILED
89 e.printStackTrace( log );
90 throw new StatusException( "Couldn't create document", e );
94 /**
95 * Document disposed here.
97 protected void cleanup( TestParameters tParam, PrintWriter log ) {
98 log.println( " disposing xMathDoc " );
99 xMathDoc.dispose();
103 * Creating a Testenvironment for the interfaces to be tested.
104 * Creates an instance of the service
105 * <code>com.sun.star.comp.Math.XMLExporter</code> with
106 * argument which is an implementation of <code>XDocumentHandler</code>
107 * and which can check if required tags and character data is
108 * exported. <p>
109 * The math document is set as a source document for exporter
110 * created. A new user info field inserted into document. This made
111 * for checking if this info field is successfully exported within
112 * the document content.
113 * Object relations created :
114 * <ul>
115 * <li> <code>'MediaDescriptor'</code> for
116 * {@link ifc.document._XFilter} interface </li>
117 * <li> <code>'XFilter.Checker'</code> for
118 * {@link ifc.document._XFilter} interface </li>
119 * <li> <code>'SourceDocument'</code> for
120 * {@link ifc.document._XExporter} interface </li>
121 * </ul>
123 protected TestEnvironment createTestEnvironment
124 (TestParameters tParam, PrintWriter log) {
125 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
126 XInterface oObj = null;
127 final String expName = "XMLMetaExporterName" ;
128 final String expValue = "XMLMetaExporterValue" ;
130 FilterChecker filter = new FilterChecker(log);
131 Any arg = new Any(new Type(XDocumentHandler.class), filter);
133 try {
134 oObj = (XInterface) xMSF.createInstanceWithArguments(
135 "com.sun.star.comp.Math.XMLMetaExporter", new Object[] {arg});
136 XExporter xEx = (XExporter) UnoRuntime.queryInterface
137 (XExporter.class,oObj);
138 xEx.setSourceDocument(xMathDoc);
140 // setting a new name and value for user info field
141 XDocumentInfoSupplier xDocInfoSup = (XDocumentInfoSupplier)
142 UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xMathDoc) ;
143 XDocumentInfo xDocInfo = xDocInfoSup.getDocumentInfo() ;
144 xDocInfo.setUserFieldName((short) 0, expName) ;
145 xDocInfo.setUserFieldValue((short) 0, expValue) ;
146 } catch (com.sun.star.uno.Exception e) {
147 e.printStackTrace(log) ;
148 throw new StatusException("Can't create component.", e) ;
151 // checking tags required
152 filter.addTag(new XMLTools.Tag("office:document-meta")) ;
153 filter.addCharactersEnclosed(expValue,
154 new XMLTools.Tag("meta:user-defined", "meta:name", expName)) ;
156 // create testobject here
157 log.println( "creating a new environment" );
158 TestEnvironment tEnv = new TestEnvironment( oObj );
161 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
162 new String[] {"FilterName"},
163 new Object[] {"smath: StarOffice XML (Math)"}));
164 tEnv.addObjRelation("SourceDocument",xMathDoc);
165 tEnv.addObjRelation("XFilter.Checker", filter) ;
167 log.println("Implementation Name: "+util.utils.getImplName(oObj));
169 return tEnv;
173 * This class checks the XML for tags and data required and returns
174 * checking result to <code>XFilter</code> interface test. All
175 * the information about errors occured in XML data is written
176 * to log specified.
177 * @see ifc.document._XFilter
179 protected class FilterChecker extends XMLTools.XMLChecker
180 implements ifc.document._XFilter.FilterChecker {
183 * Creates a class which will write information
184 * into log specified.
186 public FilterChecker(PrintWriter log) {
187 super(log, true) ;
190 * <code>_XFilter.FilterChecker</code> interface method
191 * which returns the result of XML checking.
192 * @return <code>true</code> if the XML data exported was
193 * valid (i.e. all necessary tags and character data exists),
194 * <code>false</code> if some errors occured.
196 public boolean checkFilter() {
197 return check();
200 } // finish class TestCase