bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Draw / XMLSettingsImporter.java
blob0a7159a8426f82eed007df66ce530df5137ca414
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._xmloff.Draw;
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.frame.XModel;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Draw.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>
48 * </ul>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLSettingsImporter extends TestCase {
63 XComponent xDrawDoc = null;
65 /**
66 * New draw document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
74 try {
75 log.println( "creating a drawdocument" );
76 xDrawDoc = SOF.createDrawDoc(null);
77 } catch ( Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Text draw destroyed.
87 @Override
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing document " );
90 xDrawDoc.dispose();
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code><p>
98 * The draw document is set as a target document for importer.
99 * Imported XML-data contains only settings tags including
100 * tag with property 'IsLayerMode'.
101 * After import property 'IsLayerMode' getting from target
102 * document is checked.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'XDocumentHandler.XMLData'</code> for
106 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
107 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'TargetDocument'</code> for
110 * {@link ifc.document._XImporter} interface </li>
111 * </ul>
113 @Override
114 public synchronized TestEnvironment createTestEnvironment
115 (TestParameters tParam, PrintWriter log) throws StatusException {
117 XInterface oObj = null;
118 Object oInt = null ;
120 // creation of testobject here
121 // first we write what we are intend to do to log file
122 log.println( "creating a test environment" );
124 XMultiServiceFactory xMSF = tParam.getMSF() ;
126 try {
127 oInt = xMSF.createInstance
128 ("com.sun.star.comp.Draw.XMLSettingsImporter") ;
130 } catch (com.sun.star.uno.Exception e) {
131 e.printStackTrace(log) ;
132 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", xDrawDoc) ;
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 {"start", "office:settings"},
150 {"start", "config:config-item-set",
151 "config:name", "CDATA", "view-settings"},
152 {"start", "config:config-item-map-indexed",
153 "config:name", "CDATA", "Views"},
154 {"start", "config:config-item-map-entry"},
155 {"start", "config:config-item",
156 "config:name", "CDATA", "IsLayerMode",
157 "config:type", "CDATA", "boolean"},
158 {"chars", "true"},
159 {"end", "config:config-item"},
160 {"end", "config:config-item-map-entry"},
161 {"end", "config:config-item-map-indexed"},
162 {"end", "config:config-item-set"},
163 {"end", "office:settings"},
164 {"end", "office:document-settings"} };
166 tEnv.addObjRelation("XDocumentHandler.XMLData", xml);
167 final PrintWriter logF = log;
168 XModel xDrawModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
169 XController xController = xDrawModel.getCurrentController();
170 final XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
172 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
173 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
174 public boolean checkImport() {
175 try {
176 Boolean value = (Boolean)
177 xPropSet.getPropertyValue("IsLayerMode");
178 logF.println("'IsLayerMode' property value is '"
179 + value + "'");
180 return value.booleanValue();
181 } catch (com.sun.star.uno.Exception e) {
182 logF.println("Exception while checking import :") ;
183 e.printStackTrace(logF) ;
184 return false ;
187 }) ;
189 return tEnv;
190 } // finish method getTestEnvironment