Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLSettingsExporter.java
blobb3a5205e90004a9e2d585ea8f84f6cc0091053f6
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.Impress;
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.Impress.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 xImpressDoc = null;
68 /**
69 * New text document created.
71 @Override
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
75 try {
76 log.println( "creating an impress document" );
77 xImpressDoc = SOF.createImpressDoc(null);
78 } catch ( Exception e ) {
79 // Some exception occurs.FAILED
80 e.printStackTrace( log );
81 throw new StatusException( "Couldn't create document", e );
85 /**
86 * Document disposed here.
88 @Override
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xImpressDoc " );
91 xImpressDoc.dispose();
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Impress.XMLSettingsExporter</code> with
98 * argument which is an implementation of <code>XDocumentHandler</code>
99 * and which can check if required tags and character data is
100 * exported. <p>
101 * The Impress document is set as a source document for exporter
102 * created. Then setting 'IsLayerMode' is changed to a new value.
103 * After this filter checks that value has changed in the XML output.
104 * Object relations created :
105 * <ul>
106 * <li> <code>'MediaDescriptor'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'XFilter.Checker'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'SourceDocument'</code> for
111 * {@link ifc.document._XExporter} interface </li>
112 * </ul>
114 @Override
115 public synchronized TestEnvironment createTestEnvironment
116 (TestParameters tParam, PrintWriter log ) throws StatusException {
118 XMultiServiceFactory xMSF = tParam.getMSF();
119 XInterface oObj = null;
120 FilterChecker filter = new FilterChecker(log);
121 Any arg = new Any(new Type(XDocumentHandler.class),filter);
122 final boolean NewDataValue;
124 try {
125 oObj = (XInterface) xMSF.createInstanceWithArguments(
126 "com.sun.star.comp.Impress.XMLSettingsExporter",
127 new Object[] {arg});
128 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
129 xEx.setSourceDocument(xImpressDoc);
131 //set some settings
132 XModel xImpressModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
133 XController xController = xImpressModel.getCurrentController();
134 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
135 NewDataValue = ! ((Boolean) xPropSet.getPropertyValue
136 ("IsLayerMode")).booleanValue();
137 xPropSet.setPropertyValue("IsLayerMode",
138 Boolean.valueOf(NewDataValue));
141 } catch (com.sun.star.uno.Exception e) {
142 e.printStackTrace(log) ;
143 throw new StatusException("Can't create component.", e) ;
146 // Adding tags for checking existence of head tag and other tags
147 filter.addTagEnclosed(new XMLTools.Tag("office:settings"),
148 new XMLTools.Tag("office:document-settings"));
149 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-set"),
150 new XMLTools.Tag("office:settings"));
151 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-indexed"),
152 new XMLTools.Tag("config:config-item-set"));
153 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-entry"),
154 new XMLTools.Tag("config:config-item-map-indexed"));
155 filter.addTagEnclosed(new XMLTools.Tag("config:config-item"),
156 new XMLTools.Tag("config:config-item-map-entry"));
157 filter.addCharactersEnclosed(String.valueOf(NewDataValue),
158 new XMLTools.Tag("config:config-item","config:name","IsLayerMode"));
160 // create testobject here
161 log.println( "creating a new environment" );
162 TestEnvironment tEnv = new TestEnvironment( oObj );
164 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
165 new String[] {"FilterName"},
166 new Object[] {"simpress: StarOffice XML (Impress)"}));
167 tEnv.addObjRelation("SourceDocument",xImpressDoc);
168 tEnv.addObjRelation("XFilter.Checker", filter);
169 return tEnv;
173 * This class checks the XML for tags and data required and returns
174 * checking result to <code>XFilter</code> interface test. All
175 * the information about errors occurred in XML data is written
176 * to log specified.
177 * @see ifc.document._XFilter
179 private class FilterChecker extends XMLTools.XMLChecker
180 implements ifc.document._XFilter.FilterChecker {
183 * Creates a class which will write information
184 * into log specified.
186 private FilterChecker(PrintWriter log) {
187 super(log,false) ;
190 * <code>_XFilter.FilterChecker</code> interface method
191 * which returns the result of XML checking.
192 * @return <code>true</code> if the XML data exported was
193 * valid (i.e. all necessary tags and character data exists),
194 * <code>false</code> if some errors occurred.
196 public boolean checkFilter() {
197 return check();