Java-WebSocket: upgrade to 1.6.0
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLSettingsExporter.java
blobb733d67fd983775707565ea391ab98974c66f2d6
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
27 import util.XMLTools;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.document.XExporter;
31 import com.sun.star.frame.XController;
32 import com.sun.star.frame.XModel;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Exception;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import com.sun.star.xml.sax.XDocumentHandler;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Impress.XMLOasisSettingsExporter</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li><code>com::sun::star::lang::XInitialization</code></li>
48 * <li><code>com::sun::star::document::ExportFilter</code></li>
49 * <li><code>com::sun::star::document::XFilter</code></li>
50 * <li><code>com::sun::star::document::XExporter</code></li>
51 * <li><code>com::sun::star::beans::XPropertySet</code></li>
52 * </ul>
53 * @see com.sun.star.lang.XInitialization
54 * @see com.sun.star.document.ExportFilter
55 * @see com.sun.star.document.XFilter
56 * @see com.sun.star.document.XExporter
57 * @see com.sun.star.beans.XPropertySet
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._ExportFilter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
64 public class XMLSettingsExporter extends TestCase {
65 XComponent xImpressDoc = null;
67 /**
68 * New text document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
74 log.println( "creating an impress document" );
75 xImpressDoc = SOF.createImpressDoc(null);
78 /**
79 * Document disposed here.
81 @Override
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xImpressDoc " );
84 xImpressDoc.dispose();
87 /**
88 * Creating a TestEnvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Impress.XMLOasisSettingsExporter</code> with
91 * argument which is an implementation of <code>XDocumentHandler</code>
92 * and which can check if required tags and character data is
93 * exported. <p>
94 * The Impress document is set as a source document for exporter
95 * created. Then setting 'IsLayerMode' is changed to a new value.
96 * After this filter checks that value has changed in the XML output.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} interface </li>
101 * <li> <code>'XFilter.Checker'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'SourceDocument'</code> for
104 * {@link ifc.document._XExporter} interface </li>
105 * </ul>
107 @Override
108 public TestEnvironment createTestEnvironment
109 (TestParameters tParam, PrintWriter log ) throws Exception {
111 XMultiServiceFactory xMSF = tParam.getMSF();
112 XInterface oObj = null;
113 FilterChecker filter = new FilterChecker(log);
114 Any arg = new Any(new Type(XDocumentHandler.class),filter);
115 final boolean NewDataValue;
117 oObj = (XInterface) xMSF.createInstanceWithArguments(
118 "com.sun.star.comp.Impress.XMLOasisSettingsExporter",
119 new Object[] {arg});
120 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
121 xEx.setSourceDocument(xImpressDoc);
123 //set some settings
124 XModel xImpressModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
125 XController xController = xImpressModel.getCurrentController();
126 XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
127 NewDataValue = ! ((Boolean) xPropSet.getPropertyValue
128 ("IsLayerMode")).booleanValue();
129 xPropSet.setPropertyValue("IsLayerMode",
130 Boolean.valueOf(NewDataValue));
133 // Adding tags for checking existence of head tag and other tags
134 filter.addTagEnclosed(new XMLTools.Tag("office:settings"),
135 new XMLTools.Tag("office:document-settings"));
136 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-set"),
137 new XMLTools.Tag("office:settings"));
138 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-indexed"),
139 new XMLTools.Tag("config:config-item-set"));
140 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-entry"),
141 new XMLTools.Tag("config:config-item-map-indexed"));
142 filter.addTagEnclosed(new XMLTools.Tag("config:config-item"),
143 new XMLTools.Tag("config:config-item-map-entry"));
144 filter.addCharactersEnclosed(String.valueOf(NewDataValue),
145 new XMLTools.Tag("config:config-item","config:name","IsLayerMode"));
147 // create testobject here
148 log.println( "creating a new environment" );
149 TestEnvironment tEnv = new TestEnvironment( oObj );
151 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
152 new String[] {"FilterName"},
153 new Object[] {"simpress: StarOffice XML (Impress)"}));
154 tEnv.addObjRelation("SourceDocument",xImpressDoc);
155 tEnv.addObjRelation("XFilter.Checker", filter);
156 return tEnv;
160 * This class checks the XML for tags and data required and returns
161 * checking result to <code>XFilter</code> interface test. All
162 * the information about errors occurred in XML data is written
163 * to log specified.
164 * @see ifc.document._XFilter
166 private class FilterChecker extends XMLTools.XMLChecker
167 implements ifc.document._XFilter.FilterChecker {
170 * Creates a class which will write information
171 * into log specified.
173 private FilterChecker(PrintWriter log) {
174 super(log,false) ;
177 * <code>_XFilter.FilterChecker</code> interface method
178 * which returns the result of XML checking.
179 * @return <code>true</code> if the XML data exported was
180 * valid (i.e. all necessary tags and character data exists),
181 * <code>false</code> if some errors occurred.
183 public boolean checkFilter() {
184 return check();