tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLSettingsExporter.java
blob9386a233d7deae19b33444dd941a327f4b045be5
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.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.frame.XController;
32 import com.sun.star.frame.XModel;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.lang.XMultiServiceFactory;
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.xml.sax.XDocumentHandler;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLSettingsExporter extends TestCase {
65 static XComponent xSheetDoc;
67 /**
68 * New spreadsheet document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
74 log.println( "creating a calc document" );
75 xSheetDoc = SOF.openDoc("scalc","_blank");
78 /**
79 * Spreadsheet document disposed
81 @Override
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xCalcDoc " );
84 util.DesktopTools.closeDoc(xSheetDoc);
87 /**
88 * Creating a TestEnvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
91 * argument which is an implementation of <code>XDocumentHandler</code>
92 * and which can check if required tags and character data is
93 * exported. <p>
94 * The calc document is set as a source document for exporter
95 * created. Sets settings' property 'ShowGrid' to 'false', then checks
96 * it in the exported xml document.<p>
97 * Object relations created :
98 * <ul>
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} interface </li>
101 * <li> <code>'XFilter.Checker'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'SourceDocument'</code> for
104 * {@link ifc.document._XExporter} interface </li>
105 * </ul>
107 @Override
108 public TestEnvironment createTestEnvironment( TestParameters tParam,
109 PrintWriter log )
110 throws Exception {
112 XMultiServiceFactory xMSF = tParam.getMSF() ;
113 XInterface oObj = null;
114 SettingsFilterChecker filter = new SettingsFilterChecker(log);
115 Any arg = new Any(new Type(XDocumentHandler.class), filter);
116 oObj = (XInterface) xMSF.createInstanceWithArguments(
117 "com.sun.star.comp.Calc.XMLSettingsExporter",
118 new Object[] {arg} );
119 XExporter xEx = UnoRuntime.queryInterface
120 (XExporter.class,oObj);
121 xEx.setSourceDocument(xSheetDoc);
123 //set some settings
124 XModel xSheetModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
125 XController xController = xSheetModel.getCurrentController();
126 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
127 xPropSet.setPropertyValue("ShowGrid", "false");
129 util.CalcTools.fillCalcSheetWithContent(xSheetDoc, 0, 3, 3, 50, 50);
131 //Create and prepare filter
132 // adding tags which must be contained in XML output
133 filter.addTag(new XMLTools.Tag("office:document-settings") );
134 filter.addTagEnclosed(
135 new XMLTools.Tag("office:settings"),
136 new XMLTools.Tag("office:document-settings") );
137 filter.addCharactersEnclosed(
138 "false",
139 new XMLTools.Tag("config:config-item", "config:name", "ShowGrid") );
141 // create testobject here
142 log.println( "creating a new environment" );
143 TestEnvironment tEnv = new TestEnvironment( oObj );
145 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
146 new String[] {"FilterName"},
147 new Object[] {"scalc: StarOffice XML (Calc)"}));
148 tEnv.addObjRelation("SourceDocument",xSheetDoc);
149 tEnv.addObjRelation("XFilter.Checker", filter) ;
150 return tEnv;
154 * This class checks the XML for tags and data required and returns
155 * checking result to <code>XFilter</code> interface test. All
156 * the information about errors occurred in XML data is written
157 * to log specified.
158 * @see ifc.document._XFilter
160 private class SettingsFilterChecker extends XMLTools.XMLChecker
161 implements ifc.document._XFilter.FilterChecker {
164 * Creates a class which will write information
165 * into log specified.
167 private SettingsFilterChecker(PrintWriter log) {
168 super(log, false) ;
171 * <code>_XFilter.FilterChecker</code> interface method
172 * which returns the result of XML checking.
173 * @return <code>true</code> if the XML data exported was
174 * valid (i.e. all necessary tags and character data exists),
175 * <code>false</code> if some errors occurred.
177 public boolean checkFilter() {
178 return check();