bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLSettingsExporter.java
blobb2fc797e717b5a2d00068333f293dbae4829c647
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._sw;
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.frame.XController;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.view.XViewSettingsSupplier;
40 import com.sun.star.xml.sax.XDocumentHandler;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li><code>com::sun::star::lang::XInitialization</code></li>
48 * <li><code>com::sun::star::document::ExportFilter</code></li>
49 * <li><code>com::sun::star::document::XFilter</code></li>
50 * <li><code>com::sun::star::document::XExporter</code></li>
51 * <li><code>com::sun::star::beans::XPropertySet</code></li>
52 * </ul>
53 * @see com.sun.star.lang.XInitialization
54 * @see com.sun.star.document.ExportFilter
55 * @see com.sun.star.document.XFilter
56 * @see com.sun.star.document.XExporter
57 * @see com.sun.star.beans.XPropertySet
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._ExportFilter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
64 public class XMLSettingsExporter extends TestCase {
66 XTextDocument xTextDoc;
67 SettingsFilterChecker Filter;
69 /**
70 * New text document created.
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
75 try {
76 log.println( "creating a textdocument" );
77 xTextDoc = SOF.createTextDoc( null );
79 } catch ( com.sun.star.uno.Exception e ) {
80 // Some exception occurs.FAILED
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
87 /**
88 * Document disposed here.
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( " disposing xTextDoc " );
92 util.DesktopTools.closeDoc(xTextDoc);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
101 * exported. <p>
102 * The text document is set as a source document for exporter
103 * created. New document zoom is set as one of the 'View' settings. This made
104 * for checking if this setting is successfully exported within
105 * the document settings.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
114 * </ul>
116 public synchronized TestEnvironment createTestEnvironment
117 (TestParameters tParam, PrintWriter log) {
119 final short ZOOM = 50;
121 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
122 XInterface oObj = null;
124 Filter = new SettingsFilterChecker(log);
125 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
126 try {
127 oObj = (XInterface) xMSF.createInstanceWithArguments(
128 "com.sun.star.comp.Writer.XMLSettingsExporter",
129 new Object[] {arg});
130 XExporter xEx = UnoRuntime.queryInterface
131 (XExporter.class,oObj);
132 xEx.setSourceDocument(xTextDoc);
134 //set some settings
135 XController xController = xTextDoc.getCurrentController();
136 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
137 xController);
138 XPropertySet xPropSet = xViewSetSup.getViewSettings();
139 xPropSet.setPropertyValue("ZoomValue", new Short(ZOOM));
141 } catch (com.sun.star.uno.Exception e) {
142 e.printStackTrace(log) ;
143 throw new StatusException("Can't create component.", e) ;
146 // adding tags which must be contained in XML output
147 Filter.addTag( new XMLTools.Tag("office:document-settings") );
148 Filter.addTagEnclosed(
149 new XMLTools.Tag("office:settings"),
150 new XMLTools.Tag("office:document-settings") );
151 Filter.addCharactersEnclosed(
152 String.valueOf(ZOOM),
153 new XMLTools.Tag("config:config-item",
154 "config:name", "ZoomFactor") );
156 // create testobject here
157 log.println( "creating a new environment" );
158 TestEnvironment tEnv = new TestEnvironment( oObj );
160 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
161 new String[] {"FilterName"},
162 new Object[] {"swriter: StarOffice XML (Writer)"}));
163 tEnv.addObjRelation("SourceDocument",xTextDoc);
164 tEnv.addObjRelation("XFilter.Checker", Filter);
165 return tEnv;
170 * This class checks the XML for tags and data required and returns
171 * checking result to <code>XFilter</code> interface test. All
172 * the information about errors occurred in XML data is written
173 * to log specified.
174 * @see ifc.document._XFilter
176 protected class SettingsFilterChecker extends XMLTools.XMLChecker
177 implements ifc.document._XFilter.FilterChecker {
180 * Creates a class which will write information
181 * into log specified.
183 public SettingsFilterChecker(PrintWriter log) {
184 super(log, false) ;
188 * <code>_XFilter.FilterChecker</code> interface method
189 * which returns the result of XML checking.
190 * @return <code>true</code> if the XML data exported was
191 * valid (i.e. all necessary tags and character data exists),
192 * <code>false</code> if some errors occurred.
194 public boolean checkFilter() {
195 return check();