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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
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
;
41 * Test for object which is represented by service
42 * <code>com.sun.star.comp.Math.XMLSettingsExporter</code>. <p>
43 * Object implements the following interfaces :
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>
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 XMLSettingsExporter
extends TestCase
{
66 * New math document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
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
);
82 * Document disposed here.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xMathDoc " );
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Math.XMLSettingsExporter</code> with
93 * argument which is an implementation of <code>XDocumentHandler</code>
94 * and which can check if required tags and character data is
96 * The math document is set as a source document for exporter
97 * created. A new value for TopMargin property is set for document.
99 * for checking if this property is successfully exported within
100 * the document settings.
101 * Object relations created :
103 * <li> <code>'MediaDescriptor'</code> for
104 * {@link ifc.document._XFilter} interface </li>
105 * <li> <code>'XFilter.Checker'</code> for
106 * {@link ifc.document._XFilter} interface </li>
107 * <li> <code>'SourceDocument'</code> for
108 * {@link ifc.document._XExporter} interface </li>
111 protected TestEnvironment createTestEnvironment
112 (TestParameters tParam
, PrintWriter log
) {
113 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
114 XInterface oObj
= null;
115 final short expMargin
= 67 ;
117 FilterChecker filter
= new FilterChecker(log
);
118 Any arg
= new Any(new Type(XDocumentHandler
.class), filter
);
121 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
122 "com.sun.star.comp.Math.XMLSettingsExporter",
124 XExporter xEx
= UnoRuntime
.queryInterface
125 (XExporter
.class,oObj
);
126 xEx
.setSourceDocument(xMathDoc
);
128 // setting a formula in document
129 XPropertySet xPS
= UnoRuntime
.queryInterface
130 (XPropertySet
.class, xMathDoc
) ;
132 xPS
.setPropertyValue("TopMargin", new Short(expMargin
)) ;
133 } catch (com
.sun
.star
.uno
.Exception e
) {
134 e
.printStackTrace(log
) ;
135 throw new StatusException("Can't create component.", e
) ;
138 // checking tags required
140 filter
.addTag(new XMLTools
.Tag("office:document-settings")) ;
141 filter
.addCharactersEnclosed(String
.valueOf(expMargin
),
142 new XMLTools
.Tag("config:config-item", "config:name", "TopMargin")) ;
144 // create testobject here
145 log
.println( "creating a new environment" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
149 new String
[] {"FilterName"},
150 new Object
[] {"smath: StarOffice XML (Math)"}));
151 tEnv
.addObjRelation("SourceDocument",xMathDoc
);
152 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
154 log
.println("Implementation Name: "+util
.utils
.getImplName(oObj
));
160 * This class checks the XML for tags and data required and returns
161 * checking result to <code>XFilter</code> interface test. All
162 * the information about errors occurred in XML data is written
164 * @see ifc.document._XFilter
166 protected class FilterChecker
extends XMLTools
.XMLChecker
167 implements ifc
.document
._XFilter
.FilterChecker
{
170 * Creates a class which will write information
171 * into log specified.
173 public FilterChecker(PrintWriter log
) {
177 * <code>_XFilter.FilterChecker</code> interface method
178 * which returns the result of XML checking.
179 * @return <code>true</code> if the XML data exported was
180 * valid (i.e. all necessary tags and character data exists),
181 * <code>false</code> if some errors occurred.
183 public boolean checkFilter() {
188 } // finish class TestCase