bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLSettingsExporter.java
blobd82986a7f424bf42587d6f4f1d717e1491ae4921
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._sc;
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.frame.XModel;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.Any;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
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 static XComponent xSheetDoc;
68 /**
69 * New spreadsheet document created.
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
74 try {
75 log.println( "creating a calc document" );
76 xSheetDoc = SOF.openDoc("scalc","_blank");
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Spreadsheet document disposed
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xCalcDoc " );
89 util.DesktopTools.closeDoc(xSheetDoc);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
96 * argument which is an implementation of <code>XDocumentHandler</code>
97 * and which can check if required tags and character data is
98 * exported. <p>
99 * The calc document is set as a source document for exporter
100 * created. Sets settings' property 'ShowGrid' to 'false', then checks
101 * it in the exported xml document.<p>
102 * Object relations created :
103 * <ul>
104 * <li> <code>'MediaDescriptor'</code> for
105 * {@link ifc.document._XFilter} interface </li>
106 * <li> <code>'XFilter.Checker'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'SourceDocument'</code> for
109 * {@link ifc.document._XExporter} interface </li>
110 * </ul>
112 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
113 PrintWriter log )
114 throws StatusException {
116 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
117 XInterface oObj = null;
118 SettingsFilterChecker filter = new SettingsFilterChecker(log);
119 Any arg = new Any(new Type(XDocumentHandler.class), filter);
120 try {
121 oObj = (XInterface) xMSF.createInstanceWithArguments(
122 "com.sun.star.comp.Calc.XMLSettingsExporter",
123 new Object[] {arg} );
124 XExporter xEx = UnoRuntime.queryInterface
125 (XExporter.class,oObj);
126 xEx.setSourceDocument(xSheetDoc);
128 //set some settings
129 XModel xSheetModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
130 XController xController = xSheetModel.getCurrentController();
131 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
132 xPropSet.setPropertyValue("ShowGrid", "false");
134 util.CalcTools.fillCalcSheetWithContent(xSheetDoc, 0, 3, 3, 50, 50);
136 } catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace(log) ;
138 throw new StatusException("Can't create component.", e) ;
139 } catch (java.lang.Exception e) {
140 e.printStackTrace(log);
141 throw new StatusException("Can't create environment.", e);
144 //Create and prepare filter
145 // adding tags which must be contained in XML output
146 filter.addTag(new XMLTools.Tag("office:document-settings") );
147 filter.addTagEnclosed(
148 new XMLTools.Tag("office:settings"),
149 new XMLTools.Tag("office:document-settings") );
150 filter.addCharactersEnclosed(
151 "false",
152 new XMLTools.Tag("config:config-item", "config:name", "ShowGrid") );
154 // create testobject here
155 log.println( "creating a new environment" );
156 TestEnvironment tEnv = new TestEnvironment( oObj );
158 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
159 new String[] {"FilterName"},
160 new Object[] {"scalc: StarOffice XML (Calc)"}));
161 tEnv.addObjRelation("SourceDocument",xSheetDoc);
162 tEnv.addObjRelation("XFilter.Checker", filter) ;
163 return tEnv;
167 * This class checks the XML for tags and data required and returns
168 * checking result to <code>XFilter</code> interface test. All
169 * the information about errors occurred in XML data is written
170 * to log specified.
171 * @see ifc.document._XFilter
173 protected class SettingsFilterChecker extends XMLTools.XMLChecker
174 implements ifc.document._XFilter.FilterChecker {
177 * Creates a class which will write information
178 * into log specified.
180 public SettingsFilterChecker(PrintWriter log) {
181 super(log, false) ;
184 * <code>_XFilter.FilterChecker</code> interface method
185 * which returns the result of XML checking.
186 * @return <code>true</code> if the XML data exported was
187 * valid (i.e. all necessary tags and character data exists),
188 * <code>false</code> if some errors occurred.
190 public boolean checkFilter() {
191 return check();