tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLSettingsExporter.java
blobf52ef2b2ae79bd1149e0fc0893aee4d859ecd1c3
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
27 import util.XMLTools;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.document.XExporter;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.Any;
34 import com.sun.star.uno.Type;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.xml.sax.XDocumentHandler;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.comp.Math.XMLSettingsExporter</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 * <li><code>com::sun::star::lang::XInitialization</code></li>
45 * <li><code>com::sun::star::document::ExportFilter</code></li>
46 * <li><code>com::sun::star::document::XFilter</code></li>
47 * <li><code>com::sun::star::document::XExporter</code></li>
48 * <li><code>com::sun::star::beans::XPropertySet</code></li>
49 * </ul>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.ExportFilter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.XExporter
54 * @see com.sun.star.beans.XPropertySet
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._ExportFilter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
61 public class XMLSettingsExporter extends TestCase {
62 XComponent xMathDoc;
64 /**
65 * New math document created.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
71 log.println( "creating a math document" );
72 xMathDoc = SOF.createMathDoc(null);
75 /**
76 * Document disposed here.
78 @Override
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xMathDoc " );
81 xMathDoc.dispose();
84 /**
85 * Creating a TestEnvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.comp.Math.XMLSettingsExporter</code> with
88 * argument which is an implementation of <code>XDocumentHandler</code>
89 * and which can check if required tags and character data is
90 * exported. <p>
91 * The math document is set as a source document for exporter
92 * created. A new value for TopMargin property is set for document.
93 * This made
94 * for checking if this property is successfully exported within
95 * the document settings.
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) throws Exception {
109 XMultiServiceFactory xMSF = tParam.getMSF() ;
110 XInterface oObj = null;
111 final short expMargin = 67 ;
113 FilterChecker filter = new FilterChecker(log);
114 Any arg = new Any(new Type(XDocumentHandler.class), filter);
116 oObj = (XInterface) xMSF.createInstanceWithArguments(
117 "com.sun.star.comp.Math.XMLSettingsExporter",
118 new Object[] {arg});
119 XExporter xEx = UnoRuntime.queryInterface
120 (XExporter.class,oObj);
121 xEx.setSourceDocument(xMathDoc);
123 // setting a formula in document
124 XPropertySet xPS = UnoRuntime.queryInterface
125 (XPropertySet.class, xMathDoc) ;
127 xPS.setPropertyValue("TopMargin", Short.valueOf(expMargin)) ;
129 // checking tags required
131 filter.addTag(new XMLTools.Tag("office:document-settings")) ;
132 filter.addCharactersEnclosed(String.valueOf(expMargin),
133 new XMLTools.Tag("config:config-item", "config:name", "TopMargin")) ;
135 // create testobject here
136 log.println( "creating a new environment" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
140 new String[] {"FilterName"},
141 new Object[] {"smath: StarOffice XML (Math)"}));
142 tEnv.addObjRelation("SourceDocument",xMathDoc);
143 tEnv.addObjRelation("XFilter.Checker", filter) ;
145 log.println("Implementation Name: "+util.utils.getImplName(oObj));
147 return tEnv;
151 * This class checks the XML for tags and data required and returns
152 * checking result to <code>XFilter</code> interface test. All
153 * the information about errors occurred in XML data is written
154 * to log specified.
155 * @see ifc.document._XFilter
157 private class FilterChecker extends XMLTools.XMLChecker
158 implements ifc.document._XFilter.FilterChecker {
161 * Creates a class which will write information
162 * into log specified.
164 private FilterChecker(PrintWriter log) {
165 super(log, true) ;
168 * <code>_XFilter.FilterChecker</code> interface method
169 * which returns the result of XML checking.
170 * @return <code>true</code> if the XML data exported was
171 * valid (i.e. all necessary tags and character data exists),
172 * <code>false</code> if some errors occurred.
174 public boolean checkFilter() {
175 return check();
179 } // finish class TestCase