bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLSettingsImporter.java
blobc8fa3c31dc8314bd14eb749fc531f158b27f288d
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;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.frame.XController;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.view.XViewSettingsSupplier;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * </ul>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLSettingsImporter extends TestCase {
64 XTextDocument xTextDoc;
66 /**
67 * New text document created.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
73 try {
74 log.println( "creating a textdocument" );
75 xTextDoc = SOF.createTextDoc( null );
76 } catch ( com.sun.star.uno.Exception e ) {
77 // Some exception occurs.FAILED
78 e.printStackTrace( log );
79 throw new StatusException( "Couldn't create document", e );
83 /**
84 * Text document destroyed.
86 @Override
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xTextDoc " );
89 util.DesktopTools.closeDoc(xTextDoc);
92 /**
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code><p>
97 * The text document is set as a target document for importer.
98 * Imported XML-data contains only settings tags including
99 * title tag with test zoom factor.
100 * After import zoom factor getting from target document is checked.
101 * Object relations created :
102 * <ul>
103 * <li> <code>'XDocumentHandler.XMLData'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
106 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
107 * <li> <code>'TargetDocument'</code> for
108 * {@link ifc.document._XImporter} interface </li>
109 * </ul>
111 @Override
112 public synchronized TestEnvironment createTestEnvironment
113 (TestParameters tParam, PrintWriter log ) throws StatusException {
115 XInterface oObj = null;
116 Object oInt = null ;
117 final short impZoom = 50 ;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log.println( "creating a test environment" );
123 XMultiServiceFactory xMSF = tParam.getMSF() ;
125 try {
126 oInt = xMSF.createInstance
127 ("com.sun.star.comp.Writer.XMLSettingsImporter") ;
129 } catch (com.sun.star.uno.Exception e) {
130 e.printStackTrace(log) ;
131 throw new StatusException("Can't create component.", e) ;
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", xTextDoc) ;
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:config", "CDATA", "http://openoffice.org/2001/config",
149 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
151 {"start", "office:settings"},
152 {"start", "config:config-item-set",
153 "config:name", "CDATA", "view-settings"
155 {"start", "config:config-item-map-indexed",
156 "config:name", "CDATA", "Views"},
157 {"start", "config:config-item-map-entry"},
158 {"start", "config:config-item",
159 "config:name", "CDATA", "ZoomFactor",
160 "config:type", "CDATA", "short"
162 {"chars", String.valueOf(impZoom)},
163 {"end", "config:config-item"},
164 {"start", "config:config-item",
165 "config:name", "CDATA", "ZoomType",
166 "config:type", "CDATA", "short"
168 {"chars", "0"},
169 {"end", "config:config-item"},
170 {"end", "config:config-item-map-entry"},
171 {"end", "config:config-item-map-indexed"},
172 {"end", "config:config-item-set"},
173 {"end", "office:settings"},
174 {"end", "office:document-settings"}} ;
176 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
178 final PrintWriter logF = log ;
179 XController xController = xTextDoc.getCurrentController();
180 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class, xController);
181 final XPropertySet xPropSet = xViewSetSup.getViewSettings();
182 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
183 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
184 public boolean checkImport() {
185 try {
186 Short gValue = (Short)
187 xPropSet.getPropertyValue("ZoomValue");
188 logF.println("ZoomValue property value = " + gValue) ;
189 return impZoom == gValue.shortValue() ;
190 } catch (com.sun.star.uno.Exception e) {
191 logF.println("Exception while checking import :") ;
192 e.printStackTrace(logF) ;
193 return false ;
196 }) ;
198 return tEnv;
199 } // finish method getTestEnvironment