merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sm / XMLImporter.java
blob42037ce0379e8637938c856d1e9708f97bf2e794
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: XMLImporter.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;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.comp.Math.XMLImporter</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li><code>com::sun::star::lang::XInitialization</code></li>
53 * <li><code>com::sun::star::document::XImporter</code></li>
54 * <li><code>com::sun::star::document::XFilter</code></li>
55 * <li><code>com::sun::star::document::ImportFilter</code></li>
56 * <li><code>com::sun::star::beans::XPropertySet</code></li>
57 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
58 * </ul>
59 * @see com.sun.star.lang.XInitialization
60 * @see com.sun.star.document.XImporter
61 * @see com.sun.star.document.XFilter
62 * @see com.sun.star.document.ImportFilter
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.xml.sax.XDocumentHandler
65 * @see ifc.lang._XInitialization
66 * @see ifc.document._XImporter
67 * @see ifc.document._XFilter
68 * @see ifc.document._XExporter
69 * @see ifc.beans._XPropertySet
70 * @see ifc.xml.sax._XDocumentHandler
72 public class XMLImporter extends TestCase {
73 XComponent xMathDoc;
76 /**
77 * New math document created.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
82 try {
83 xMathDoc = SOF.openDoc("smath","_blank");
84 } catch (com.sun.star.uno.Exception ex) {
85 ex.printStackTrace( log );
86 throw new StatusException( "Couldn't create document", ex );
90 /**
91 * Disposes document.
93 protected void cleanup( TestParameters tParam, PrintWriter log ) {
94 log.println( " disposing xMathDoc " );
95 xMathDoc.dispose();
98 /**
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.comp.Math.XMLImporter</code><p>
103 * The chart document is set as a target document for importer.
104 * Imported XML-data contains the tag which specifies a formula
105 * in the document.
106 * After import the formula getting from target document is checked.
107 * Object relations created :
108 * <ul>
109 * <li> <code>'XDocumentHandler.XMLData'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'TargetDocument'</code> for
114 * {@link ifc.document._XImporter} interface </li>
115 * </ul>
117 public synchronized TestEnvironment createTestEnvironment
118 ( TestParameters Param, PrintWriter log )
119 throws StatusException {
121 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
122 XInterface oObj = null;
123 final String impFormula = "a - b" ;
125 try {
126 oObj = (XInterface)xMSF.createInstance(
127 "com.sun.star.comp.Math.XMLImporter");
128 } catch (com.sun.star.uno.Exception e) {
129 e.printStackTrace(log);
130 throw new StatusException("Unexpected exception", e);
133 TestEnvironment tEnv = new TestEnvironment(oObj);
135 tEnv.addObjRelation("TargetDocument",xMathDoc);
137 String[][] xml = new String[][] {
138 {"start", "math:math",
139 "xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"},
140 {"start", "math:semantics"},
141 {"start", "math:annotation",
142 "math:encoding", "CDATA", "StarMath 5.0"},
143 {"chars", impFormula},
144 {"end", "math:annotation"},
145 {"end", "math:semantics"},
146 {"end", "math:math"}} ;
148 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
150 final PrintWriter logF = log ;
151 final XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface
152 (XPropertySet.class, xMathDoc) ;
154 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
155 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
156 public boolean checkImport() {
157 try {
158 String gFormula = (String) xPS.getPropertyValue
159 ("Formula") ;
160 logF.println("Formula returned = '" + gFormula + "'") ;
161 return impFormula.equals(gFormula) ;
162 } catch (com.sun.star.uno.Exception e) {
163 logF.println("Exception occured while checking filter :") ;
164 e.printStackTrace(logF) ;
165 return false ;
168 }) ;
170 return tEnv;