bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Draw / XMLSettingsExporter.java
blob34a162fe067d487c591ac33f21fda5c092fc732c
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;
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.Exception;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.xml.sax.XDocumentHandler;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.comp.Draw.XMLSettingsExporter</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li><code>com::sun::star::lang::XInitialization</code></li>
49 * <li><code>com::sun::star::document::ExportFilter</code></li>
50 * <li><code>com::sun::star::document::XFilter</code></li>
51 * <li><code>com::sun::star::document::XExporter</code></li>
52 * <li><code>com::sun::star::beans::XPropertySet</code></li>
53 * </ul>
54 * @see com.sun.star.lang.XInitialization
55 * @see com.sun.star.document.ExportFilter
56 * @see com.sun.star.document.XFilter
57 * @see com.sun.star.document.XExporter
58 * @see com.sun.star.beans.XPropertySet
59 * @see ifc.lang._XInitialization
60 * @see ifc.document._ExportFilter
61 * @see ifc.document._XFilter
62 * @see ifc.document._XExporter
63 * @see ifc.beans._XPropertySet
65 public class XMLSettingsExporter extends TestCase {
66 XComponent xDrawDoc = null;
68 /**
69 * New draw document created.
71 @Override
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
74 // get a soffice factory object
75 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
77 try {
78 log.println( "creating a drawdocument" );
79 xDrawDoc = SOF.createDrawDoc(null);
80 } catch ( Exception e ) {
81 // Some exception occurs.FAILED
82 e.printStackTrace( log );
83 throw new StatusException( "Couldn't create document", e );
87 /**
88 * Document disposed here.
90 @Override
91 protected void cleanup( TestParameters tParam, PrintWriter log ) {
92 log.println( " disposing xDrawDoc " );
93 xDrawDoc.dispose();
96 /**
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>om.sun.star.comp.Draw.XMLSettingsExporter</code> with
100 * argument which is an implementation of <code>XDocumentHandler</code>
101 * and which can check if required tags and character data is
102 * exported. <p>
103 * The draw document is set as a source document for exporter
104 * created. Property 'IsLayerMode' set to true.
105 * This made for checking if this property is successfully exported within
106 * the document styles information.
107 * Object relations created :
108 * <ul>
109 * <li> <code>'MediaDescriptor'</code> for
110 * {@link ifc.document._XFilter} interface </li>
111 * <li> <code>'XFilter.Checker'</code> for
112 * {@link ifc.document._XFilter} interface </li>
113 * <li> <code>'SourceDocument'</code> for
114 * {@link ifc.document._XExporter} interface </li>
115 * </ul>
117 @Override
118 protected synchronized TestEnvironment createTestEnvironment
119 (TestParameters tParam, PrintWriter log) {
121 XMultiServiceFactory xMSF = tParam.getMSF() ;
122 XInterface oObj = null;
124 FilterChecker filter = new FilterChecker(log) ;
125 Any arg = new Any(new Type(XDocumentHandler.class),filter);
127 try {
128 oObj = (XInterface) xMSF.createInstanceWithArguments(
129 "com.sun.star.comp.Draw.XMLSettingsExporter",
130 new Object[] {arg});
131 XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj);
132 xEx.setSourceDocument(xDrawDoc);
134 //set some settings
135 XModel xDrawModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
136 XController xController = xDrawModel.getCurrentController();
137 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
138 xPropSet.setPropertyValue("IsLayerMode", Boolean.TRUE);
140 } catch (com.sun.star.uno.Exception e) {
141 e.printStackTrace(log) ;
142 throw new StatusException("Can't create component.", e) ;
145 // Checking Head Tag existence and that property has changed
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.addTagEnclosed(
151 new XMLTools.Tag ("config:config-item-set"),
152 new XMLTools.Tag ("office:settings") );
153 filter.addTagEnclosed(
154 new XMLTools.Tag ("config:config-item-map-indexed"),
155 new XMLTools.Tag ("config:config-item-set") );
156 filter.addCharactersEnclosed( "true",
157 new XMLTools.Tag( "config:config-item",
158 "config:name",
159 "IsLayerMode" ));
161 // create testobject here
162 log.println( "creating a new environment" );
163 TestEnvironment tEnv = new TestEnvironment( oObj );
165 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
166 new String[] {"FilterName"},
167 new Object[] {"sdraw: StarOffice XML (Draw)"}));
168 tEnv.addObjRelation("SourceDocument", xDrawDoc);
169 tEnv.addObjRelation("XFilter.Checker", filter);
170 return tEnv;
174 * This class checks the XML for tags and data required and returns
175 * checking result to <code>XFilter</code> interface test. All
176 * the information about errors occurred in XML data is written
177 * to log specified.
178 * @see ifc.document._XFilter
180 private class FilterChecker extends XMLTools.XMLChecker
181 implements ifc.document._XFilter.FilterChecker {
184 * Creates a class which will write information
185 * into log specified.
187 private FilterChecker(PrintWriter log) {
188 super(log, false) ;
192 * <code>_XFilter.FilterChecker</code> interface method
193 * which returns the result of XML checking.
194 * @return <code>true</code> if the XML data exported was
195 * valid (i.e. all necessary tags and character data exists),
196 * <code>false</code> if some errors occurred.
198 public boolean checkFilter() {
199 return check();