bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLImporter.java
blob6a5e38a3a1da8781df0c97d34097a593dfee1d75
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;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Math.XMLImporter</code>. <p>
38 * Object implements the following interfaces :
39 * <ul>
40 * <li><code>com::sun::star::lang::XInitialization</code></li>
41 * <li><code>com::sun::star::document::XImporter</code></li>
42 * <li><code>com::sun::star::document::XFilter</code></li>
43 * <li><code>com::sun::star::document::ImportFilter</code></li>
44 * <li><code>com::sun::star::beans::XPropertySet</code></li>
45 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
46 * </ul>
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.document.XImporter
49 * @see com.sun.star.document.XFilter
50 * @see com.sun.star.document.ImportFilter
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.xml.sax.XDocumentHandler
53 * @see ifc.lang._XInitialization
54 * @see ifc.document._XImporter
55 * @see ifc.document._XFilter
56 * @see ifc.document._XExporter
57 * @see ifc.beans._XPropertySet
58 * @see ifc.xml.sax._XDocumentHandler
60 public class XMLImporter extends TestCase {
61 XComponent xMathDoc;
64 /**
65 * New math document created.
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 xMathDoc = SOF.openDoc("smath","_blank");
72 } catch (com.sun.star.uno.Exception ex) {
73 ex.printStackTrace( log );
74 throw new StatusException( "Couldn't create document", ex );
78 /**
79 * Disposes document.
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xMathDoc " );
83 xMathDoc.dispose();
86 /**
87 * Creating a Testenvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.comp.Math.XMLImporter</code><p>
91 * The chart document is set as a target document for importer.
92 * Imported XML-data contains the tag which specifies a formula
93 * in the document.
94 * After import the formula getting from target document is checked.
95 * Object relations created :
96 * <ul>
97 * <li> <code>'XDocumentHandler.XMLData'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'TargetDocument'</code> for
102 * {@link ifc.document._XImporter} interface </li>
103 * </ul>
105 public synchronized TestEnvironment createTestEnvironment
106 ( TestParameters Param, PrintWriter log )
107 throws StatusException {
109 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
110 XInterface oObj = null;
111 final String impFormula = "a - b" ;
113 try {
114 oObj = (XInterface)xMSF.createInstance(
115 "com.sun.star.comp.Math.XMLImporter");
116 } catch (com.sun.star.uno.Exception e) {
117 e.printStackTrace(log);
118 throw new StatusException("Unexpected exception", e);
121 TestEnvironment tEnv = new TestEnvironment(oObj);
123 tEnv.addObjRelation("TargetDocument",xMathDoc);
125 String[][] xml = new String[][] {
126 {"start", "math:math",
127 "xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"},
128 {"start", "math:semantics"},
129 {"start", "math:annotation",
130 "math:encoding", "CDATA", "StarMath 5.0"},
131 {"chars", impFormula},
132 {"end", "math:annotation"},
133 {"end", "math:semantics"},
134 {"end", "math:math"}} ;
136 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
138 final PrintWriter logF = log ;
139 final XPropertySet xPS = UnoRuntime.queryInterface
140 (XPropertySet.class, xMathDoc) ;
142 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
143 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
144 public boolean checkImport() {
145 try {
146 String gFormula = (String) xPS.getPropertyValue
147 ("Formula") ;
148 logF.println("Formula returned = '" + gFormula + "'") ;
149 return impFormula.equals(gFormula) ;
150 } catch (com.sun.star.uno.Exception e) {
151 logF.println("Exception occurred while checking filter :") ;
152 e.printStackTrace(logF) ;
153 return false ;
156 }) ;
158 return tEnv;