bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLExporter.java
blobfe0d31000906c95046112805512fe9e8a118f2e3
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.XPropertySet;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.Any;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.xml.sax.XDocumentHandler;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.comp.Math.XMLExporter</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li><code>com::sun::star::lang::XInitialization</code></li>
46 * <li><code>com::sun::star::document::ExportFilter</code></li>
47 * <li><code>com::sun::star::document::XFilter</code></li>
48 * <li><code>com::sun::star::document::XExporter</code></li>
49 * <li><code>com::sun::star::beans::XPropertySet</code></li>
50 * </ul>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.ExportFilter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.XExporter
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._ExportFilter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
62 public class XMLExporter extends TestCase {
63 XComponent xMathDoc;
65 /**
66 * New math document created.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
71 try {
72 log.println( "creating a math document" );
73 xMathDoc = SOF.createMathDoc(null);
74 } catch ( com.sun.star.uno.Exception e ) {
75 // Some exception occurs.FAILED
76 e.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", e );
81 /**
82 * Document disposed here.
84 protected void cleanup( TestParameters tParam, PrintWriter log ) {
85 log.println( " disposing xMathDoc " );
86 xMathDoc.dispose();
89 /**
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Math.XMLExporter</code> with
93 * argument which is an implementation of <code>XDocumentHandler</code>
94 * and which can check if required tags and character data is
95 * exported. <p>
96 * The math document is set as a source document for exporter
97 * created. A new formula inserted into document. This made
98 * for checking if this formula is successfully exported within
99 * the document content.
100 * Object relations created :
101 * <ul>
102 * <li> <code>'MediaDescriptor'</code> for
103 * {@link ifc.document._XFilter} interface </li>
104 * <li> <code>'XFilter.Checker'</code> for
105 * {@link ifc.document._XFilter} interface </li>
106 * <li> <code>'SourceDocument'</code> for
107 * {@link ifc.document._XExporter} interface </li>
108 * </ul>
110 protected TestEnvironment createTestEnvironment
111 (TestParameters tParam, PrintWriter log) {
113 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
114 XInterface oObj = null;
115 final String expFormula = "a - b" ;
117 FilterChecker filter = new FilterChecker(log);
118 Any arg = new Any(new Type(XDocumentHandler.class), filter);
120 try {
121 oObj = (XInterface) xMSF.createInstanceWithArguments(
122 "com.sun.star.comp.Math.XMLExporter", new Object[] {arg});
123 XExporter xEx = UnoRuntime.queryInterface
124 (XExporter.class,oObj);
125 xEx.setSourceDocument(xMathDoc);
127 // setting a formula in document
128 XPropertySet xPS = UnoRuntime.queryInterface
129 (XPropertySet.class, xMathDoc) ;
130 xPS.setPropertyValue("Formula", expFormula) ;
131 } catch (com.sun.star.uno.Exception e) {
132 e.printStackTrace(log) ;
133 throw new StatusException("Can't create component.", e) ;
136 // checking tags required
137 filter.addTag(new XMLTools.Tag("math:math")) ;
138 filter.addTagEnclosed(new XMLTools.Tag("math:annotation"),
139 new XMLTools.Tag("math:semantics")) ;
140 filter.addCharactersEnclosed(expFormula,
141 new XMLTools.Tag("math:annotation")) ;
143 // create testobject here
144 log.println( "creating a new environment" );
145 TestEnvironment tEnv = new TestEnvironment( oObj );
147 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
148 new String[] {"FilterName"},
149 new Object[] {"smath: StarOffice XML (Math)"}));
150 tEnv.addObjRelation("SourceDocument",xMathDoc);
151 tEnv.addObjRelation("XFilter.Checker", filter) ;
153 log.println("Implementation Name: "+util.utils.getImplName(oObj));
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 FilterChecker extends XMLTools.XMLChecker
166 implements ifc.document._XFilter.FilterChecker {
169 * Creates a class which will write information
170 * into log specified.
172 public FilterChecker(PrintWriter log) {
173 super(log, true) ;
176 * <code>_XFilter.FilterChecker</code> interface method
177 * which returns the result of XML checking.
178 * @return <code>true</code> if the XML data exported was
179 * valid (i.e. all necessary tags and character data exists),
180 * <code>false</code> if some errors occurred.
182 public boolean checkFilter() {
183 return check();
187 } // finish class TestCase