merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLStylesExporter.java
blobe9db678d0e227c0cd311ca229d61e5680914eb0f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLStylesExporter.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._xmloff.Chart;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
40 import util.XMLTools;
42 import com.sun.star.chart.XChartDocument;
43 import com.sun.star.document.XExporter;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.Any;
46 import com.sun.star.uno.Exception;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.xml.sax.XDocumentHandler;
52 /**
53 * Test for object which is represented by service
54 * <code>com.sun.star.comp.Chart.XMLStylesExporter</code>. <p>
55 * Object implements the following interfaces :
56 * <ul>
57 * <li><code>com::sun::star::lang::XInitialization</code></li>
58 * <li><code>com::sun::star::document::ExportFilter</code></li>
59 * <li><code>com::sun::star::document::XFilter</code></li>
60 * <li><code>com::sun::star::document::XExporter</code></li>
61 * <li><code>com::sun::star::beans::XPropertySet</code></li>
62 * </ul>
63 * @see com.sun.star.lang.XInitialization
64 * @see com.sun.star.document.ExportFilter
65 * @see com.sun.star.document.XFilter
66 * @see com.sun.star.document.XExporter
67 * @see com.sun.star.beans.XPropertySet
68 * @see ifc.lang._XInitialization
69 * @see ifc.document._ExportFilter
70 * @see ifc.document._XFilter
71 * @see ifc.document._XExporter
72 * @see ifc.beans._XPropertySet
74 public class XMLStylesExporter extends TestCase {
75 XChartDocument xChartDoc = null;
77 /**
78 * New text document created.
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
82 // get a soffice factory object
83 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
85 try {
86 log.println( "creating a chartdocument" );
87 xChartDoc = SOF.createChartDoc(null);;
88 } catch ( Exception e ) {
89 // Some exception occures.FAILED
90 e.printStackTrace( log );
91 throw new StatusException( "Couldn't create document", e );
95 /**
96 * Document disposed here.
98 protected void cleanup( TestParameters tParam, PrintWriter log ) {
99 log.println( " disposing xChartDoc " );
100 xChartDoc.dispose();
104 * Creating a Testenvironment for the interfaces to be tested.
105 * Creates an instance of the service
106 * <code>com.sun.star.comp.Chart.XMLStylesExporter</code> with
107 * argument which is an implementation of <code>XDocumentHandler</code>
108 * and which can check if required tags and character data is
109 * exported. <p>
110 * Existing of some tags checked in XML data exported.
111 * Object relations created :
112 * <ul>
113 * <li> <code>'MediaDescriptor'</code> for
114 * {@link ifc.document._XFilter} interface </li>
115 * <li> <code>'XFilter.Checker'</code> for
116 * {@link ifc.document._XFilter} interface </li>
117 * <li> <code>'SourceDocument'</code> for
118 * {@link ifc.document._XExporter} interface </li>
119 * </ul>
121 public synchronized TestEnvironment createTestEnvironment
122 (TestParameters tParam, PrintWriter log) {
124 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
125 XInterface oObj = null;
127 FilterChecker filter = new FilterChecker(log);
128 Any arg = new Any(new Type(XDocumentHandler.class),filter);
130 try {
131 oObj = (XInterface) xMSF.createInstanceWithArguments(
132 "com.sun.star.comp.Chart.XMLStylesExporter",
133 new Object[] {arg});
134 XExporter xEx = (XExporter)
135 UnoRuntime.queryInterface(XExporter.class,oObj);
136 xEx.setSourceDocument(xChartDoc);
138 } catch (com.sun.star.uno.Exception e) {
139 e.printStackTrace(log) ;
140 throw new StatusException("Can't create component.", e) ;
144 filter.addTag(new XMLTools.Tag("office:document-styles")) ;
145 filter.addTagEnclosed(new XMLTools.Tag("office:styles"),
146 new XMLTools.Tag("office:document-styles"));
148 // create testobject here
149 log.println( "creating a new environment" );
150 TestEnvironment tEnv = new TestEnvironment( oObj );
152 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
153 new String[] {"FilterName"},
154 new Object[] {"schart: StarOffice XML (Chart)"}));
155 tEnv.addObjRelation("SourceDocument",xChartDoc);
156 tEnv.addObjRelation("XFilter.Checker", filter) ;
157 log.println("Implementation Name: "+util.utils.getImplName(oObj));
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 occured 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, true) ;
181 * <code>_XFilter.FilterChecker</code> interface method
182 * which returns the result of XML checking.
183 * @return <code>true</code> if the XML data exported was
184 * valid (i.e. all necessary tags and character data exists),
185 * <code>false</code> if some errors occured.
187 public boolean checkFilter() {
188 return check() ;