tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLSettingsImporter.java
blobfc83d3e3b4f2c68cc575a5b7d9189577a2d47344
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;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.document.XImporter;
30 import com.sun.star.frame.XController;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li><code>com::sun::star::lang::XInitialization</code></li>
44 * <li><code>com::sun::star::document::XImporter</code></li>
45 * <li><code>com::sun::star::document::XFilter</code></li>
46 * <li><code>com::sun::star::document::ImportFilter</code></li>
47 * <li><code>com::sun::star::beans::XPropertySet</code></li>
48 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
50 * </ul>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.XImporter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.ImportFilter
55 * @see com.sun.star.beans.XPropertySet
56 * @see com.sun.star.xml.sax.XDocumentHandler
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._XImporter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
62 * @see ifc.xml.sax._XDocumentHandler
64 public class XMLSettingsImporter extends TestCase {
65 private XSpreadsheetDocument xSheetDoc;
66 static XComponent comp ;
68 /**
69 * New spreadsheet document created.
71 @Override
72 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
75 log.println( "creating a Spreadsheet document" );
76 xSheetDoc = SOF.createCalcDoc( null );
77 comp = UnoRuntime.queryInterface
78 (XComponent.class, xSheetDoc) ;
81 /**
82 * Spreadsheet document destroyed.
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing document " );
87 util.DesktopTools.closeDoc(comp);
90 /**
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code><p>
95 * The calc document is set as a target document for importer.
96 * Imported XML-data contains only settings tags including tag
97 * with new number of iteration steps.
98 * After import 'IterationCount' property getting from
99 * target document is checked.
100 * Object relations created :
101 * <ul>
102 * <li> <code>'XDocumentHandler.XMLData'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'TargetDocument'</code> for
107 * {@link ifc.document._XImporter} interface </li>
108 * </ul>
110 @Override
111 public TestEnvironment createTestEnvironment( TestParameters tParam,
112 PrintWriter log )
113 throws Exception {
115 XInterface oObj = null;
116 Object oInt = null ;
118 // creation of testobject here
119 // first we write what we are intend to do to log file
120 log.println( "creating a test environment" );
122 XMultiServiceFactory xMSF = tParam.getMSF() ;
123 final XPropertySet xPropSet ;
125 oInt = xMSF.createInstance
126 ("com.sun.star.comp.Calc.XMLSettingsImporter") ;
127 XImporter imp = UnoRuntime.queryInterface
128 (XImporter.class, oInt) ;
129 imp.setTargetDocument(comp) ;
131 XModel xSheetModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
132 XController xController = xSheetModel.getCurrentController();
133 xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
135 oObj = (XInterface) oInt ;
137 // create testobject here
138 log.println( "creating a new environment for Paragraph object" );
139 TestEnvironment tEnv = new TestEnvironment( oObj );
141 // adding relation
142 tEnv.addObjRelation("TargetDocument", comp) ;
144 // adding relation for XDocumentHandler
145 String[][] xml = new String[][] {
146 {"start", "office:document-settings",
147 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
148 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
149 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"},
150 {"start", "office:settings"},
151 {"start", "config:config-item-set",
152 "config:name", "CDATA", "view-settings"},
153 {"start", "config:config-item-map-indexed",
154 "config:name", "CDATA", "Views"},
155 {"start", "config:config-item-map-entry"},
156 {"start", "config:config-item",
157 "config:name", "CDATA", "ShowGrid",
158 "config:type", "CDATA", "boolean"},
159 {"chars", "false"},
160 {"end", "config:config-item"},
161 {"start", "config:config-item",
162 "config:name", "CDATA", "ZoomType",
163 "config:type", "CDATA", "short"},
164 {"chars", "0"},
165 {"start", "config:config-item",
166 "config:name", "CDATA", "ZoomValue",
167 "config:type", "CDATA", "int"},
168 {"chars", "124"},
169 {"end", "config:config-item"},
170 {"end", "config:config-item"},
171 {"end", "config:config-item-map-entry"},
172 {"end", "config:config-item-map-indexed"},
173 {"end", "config:config-item-set"},
174 {"end", "office:settings"},
175 {"end", "office:document-settings"}} ;
177 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
179 final PrintWriter logF = log ;
181 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
182 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
183 public boolean checkImport() {
184 try {
185 Object gVal = xPropSet.getPropertyValue("ShowGrid") ;
186 logF.println("ShowGrid = " + gVal ) ;
187 return "false".equals(gVal) ;
188 } catch (com.sun.star.uno.Exception e) {
189 logF.println("Exception occurred while checking filter :") ;
190 e.printStackTrace(logF) ;
191 return false ;
194 }) ;
196 return tEnv;
197 } // finish method getTestEnvironment