tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLExporter.java
blobf13275f00442199ca398ad94f26c4cd49b96d84c
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 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
72 log.println( "creating a math document" );
73 xMathDoc = SOF.createMathDoc(null);
76 /**
77 * Document disposed here.
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xMathDoc " );
82 xMathDoc.dispose();
85 /**
86 * Creating a TestEnvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.comp.Math.XMLExporter</code> with
89 * argument which is an implementation of <code>XDocumentHandler</code>
90 * and which can check if required tags and character data is
91 * exported. <p>
92 * The math document is set as a source document for exporter
93 * created. A new formula inserted into document. This made
94 * for checking if this formula is successfully exported within
95 * the document content.
96 * Object relations created :
97 * <ul>
98 * <li> <code>'MediaDescriptor'</code> for
99 * {@link ifc.document._XFilter} interface </li>
100 * <li> <code>'XFilter.Checker'</code> for
101 * {@link ifc.document._XFilter} interface </li>
102 * <li> <code>'SourceDocument'</code> for
103 * {@link ifc.document._XExporter} interface </li>
104 * </ul>
106 @Override
107 protected TestEnvironment createTestEnvironment
108 (TestParameters tParam, PrintWriter log) {
110 XMultiServiceFactory xMSF = tParam.getMSF() ;
111 XInterface oObj = null;
112 final String expFormula = "a - b" ;
114 FilterChecker filter = new FilterChecker(log);
115 Any arg = new Any(new Type(XDocumentHandler.class), filter);
117 try {
118 oObj = (XInterface) xMSF.createInstanceWithArguments(
119 "com.sun.star.comp.Math.XMLExporter", new Object[] {arg});
120 XExporter xEx = UnoRuntime.queryInterface
121 (XExporter.class,oObj);
122 xEx.setSourceDocument(xMathDoc);
124 // setting a formula in document
125 XPropertySet xPS = UnoRuntime.queryInterface
126 (XPropertySet.class, xMathDoc) ;
127 xPS.setPropertyValue("Formula", expFormula) ;
128 } catch (com.sun.star.uno.Exception e) {
129 e.printStackTrace(log) ;
130 throw new StatusException("Can't create component.", e) ;
133 // checking tags required
134 filter.addTag(new XMLTools.Tag("math:math")) ;
135 filter.addTagEnclosed(new XMLTools.Tag("math:annotation"),
136 new XMLTools.Tag("math:semantics")) ;
137 filter.addCharactersEnclosed(expFormula,
138 new XMLTools.Tag("math:annotation")) ;
140 // create testobject here
141 log.println( "creating a new environment" );
142 TestEnvironment tEnv = new TestEnvironment( oObj );
144 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
145 new String[] {"FilterName"},
146 new Object[] {"smath: StarOffice XML (Math)"}));
147 tEnv.addObjRelation("SourceDocument",xMathDoc);
148 tEnv.addObjRelation("XFilter.Checker", filter) ;
150 log.println("Implementation Name: "+util.utils.getImplName(oObj));
152 return tEnv;
156 * This class checks the XML for tags and data required and returns
157 * checking result to <code>XFilter</code> interface test. All
158 * the information about errors occurred in XML data is written
159 * to log specified.
160 * @see ifc.document._XFilter
162 private class FilterChecker extends XMLTools.XMLChecker
163 implements ifc.document._XFilter.FilterChecker {
166 * Creates a class which will write information
167 * into log specified.
169 private FilterChecker(PrintWriter log) {
170 super(log, true) ;
173 * <code>_XFilter.FilterChecker</code> interface method
174 * which returns the result of XML checking.
175 * @return <code>true</code> if the XML data exported was
176 * valid (i.e. all necessary tags and character data exists),
177 * <code>false</code> if some errors occurred.
179 public boolean checkFilter() {
180 return check();
184 } // finish class TestCase