bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLStylesExporter.java
blob8ef291b31943319d8d698117872421f32083e3fd
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;
28 import util.XMLTools;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XFootnotesSupplier;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.xml.sax.XDocumentHandler;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLStylesExporter</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLStylesExporter extends TestCase {
65 XTextDocument xTextDoc;
67 /**
68 * New text document created.
70 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)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 * Document disposed here.
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xTextDoc " );
88 util.DesktopTools.closeDoc(xTextDoc);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Calc.XMLStylesExporter</code> with
95 * argument which is an implementation of <code>XDocumentHandler</code>
96 * and which can check if required tags and character data is
97 * exported. <p>
98 * The text document is set as a source document for exporter
99 * created. Footnote property 'Prefix' is set to a new value. This made
100 * for checking if this property value is successfully exported within
101 * the document styles.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'MediaDescriptor'</code> for
105 * {@link ifc.document._XFilter} interface </li>
106 * <li> <code>'XFilter.Checker'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'SourceDocument'</code> for
109 * {@link ifc.document._XExporter} interface </li>
110 * </ul>
112 public synchronized TestEnvironment createTestEnvironment
113 ( TestParameters tParam, PrintWriter log ) {
115 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
116 XInterface oObj = null;
117 FilterChecker filter = new FilterChecker(log) ;
118 Any arg = new Any(new Type(XDocumentHandler.class),filter);
120 try {
121 oObj = (XInterface) xMSF.createInstanceWithArguments(
122 "com.sun.star.comp.Writer.XMLStylesExporter",
123 new Object[] {arg});
124 XExporter xEx = UnoRuntime.queryInterface
125 (XExporter.class,oObj);
126 xEx.setSourceDocument(xTextDoc);
127 } catch (com.sun.star.uno.Exception e) {
128 e.printStackTrace(log) ;
129 throw new StatusException("Can't create component.", e) ;
132 // Cheching Head Tag existance and that property has changed
133 filter.addTag(new XMLTools.Tag ("office:document-styles"));
134 filter.addTag(new XMLTools.Tag ("text:footnotes-configuration",
135 "style:num-prefix","New Property")) ;
137 // create testobject here
138 log.println( "creating a new environment" );
139 TestEnvironment tEnv = new TestEnvironment( oObj );
141 // Obtain Footnotes properties
142 XFootnotesSupplier supp = UnoRuntime.queryInterface
143 (XFootnotesSupplier.class, xTextDoc);
144 XPropertySet set = supp.getFootnoteSettings();
146 // Change property "Prefix"
147 try {
148 set.setPropertyValue("Prefix","New Property");
149 } catch (com.sun.star.uno.Exception e) {
150 e.printStackTrace( log );
151 throw new StatusException( "Couldn't change property value", e );
154 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
155 new String[] {"FilterName"},
156 new Object[] {"swriter: StarOffice XML (Writer)"}));
157 tEnv.addObjRelation("SourceDocument",xTextDoc);
158 tEnv.addObjRelation("XFilter.Checker", filter) ;
159 return tEnv;
164 * This class checks the XML for tags and data required and returns
165 * checking result to <code>XFilter</code> interface test. All
166 * the information about errors occurred in XML data is written
167 * to log specified.
168 * @see ifc.document._XFilter
170 protected class FilterChecker extends XMLTools.XMLChecker
171 implements ifc.document._XFilter.FilterChecker {
174 * Creates a class which will write information
175 * into log specified.
177 public FilterChecker(PrintWriter log) {
178 super(log,false) ;
182 * <code>_XFilter.FilterChecker</code> interface method
183 * which returns the result of XML checking.
184 * @return <code>true</code> if the XML data exported was
185 * valid (i.e. all necessary tags and character data exists),
186 * <code>false</code> if some errors occurred.
188 public boolean checkFilter() {
189 return check();