bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLStylesExporter.java
blobc9ad9930c328b1b39d2f871760148336eb17555d
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.Chart;
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.chart.XChartDocument;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.Any;
34 import com.sun.star.uno.Exception;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.xml.sax.XDocumentHandler;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.comp.Chart.XMLStylesExporter</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li><code>com::sun::star::lang::XInitialization</code></li>
46 * <li><code>com::sun::star::document::ExportFilter</code></li>
47 * <li><code>com::sun::star::document::XFilter</code></li>
48 * <li><code>com::sun::star::document::XExporter</code></li>
49 * <li><code>com::sun::star::beans::XPropertySet</code></li>
50 * </ul>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.ExportFilter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.XExporter
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._ExportFilter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
62 public class XMLStylesExporter extends TestCase {
63 XChartDocument xChartDoc = null;
65 /**
66 * New text document created.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 // get a soffice factory object
71 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
73 try {
74 log.println( "creating a chartdocument" );
75 xChartDoc = SOF.createChartDoc(null);
76 } catch ( Exception e ) {
77 // Some exception occurs.FAILED
78 e.printStackTrace( log );
79 throw new StatusException( "Couldn't create document", e );
83 /**
84 * Close document
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 if( xChartDoc!=null ) {
88 log.println( " closing xChartDoc" );
89 util.DesktopTools.closeDoc(xChartDoc);
90 xChartDoc = null;
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Chart.XMLStylesExporter</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 * Existing of some tags checked in XML data exported.
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;
118 FilterChecker filter = new FilterChecker(log);
119 Any arg = new Any(new Type(XDocumentHandler.class),filter);
121 try {
122 oObj = (XInterface) xMSF.createInstanceWithArguments(
123 "com.sun.star.comp.Chart.XMLStylesExporter",
124 new Object[] {arg});
125 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
126 xEx.setSourceDocument(xChartDoc);
128 } catch (com.sun.star.uno.Exception e) {
129 e.printStackTrace(log) ;
130 throw new StatusException("Can't create component.", e) ;
134 filter.addTag(new XMLTools.Tag("office:document-styles")) ;
135 filter.addTagEnclosed(new XMLTools.Tag("office:styles"),
136 new XMLTools.Tag("office:document-styles"));
138 // create testobject here
139 log.println( "creating a new environment" );
140 TestEnvironment tEnv = new TestEnvironment( oObj );
142 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
143 new String[] {"FilterName"},
144 new Object[] {"schart: StarOffice XML (Chart)"}));
145 tEnv.addObjRelation("SourceDocument",xChartDoc);
146 tEnv.addObjRelation("XFilter.Checker", filter) ;
147 log.println("Implementation Name: "+util.utils.getImplName(oObj));
149 return tEnv;
154 * This class checks the XML for tags and data required and returns
155 * checking result to <code>XFilter</code> interface test. All
156 * the information about errors occurred in XML data is written
157 * to log specified.
158 * @see ifc.document._XFilter
160 protected class FilterChecker extends XMLTools.XMLChecker
161 implements ifc.document._XFilter.FilterChecker {
164 * Creates a class which will write information
165 * into log specified.
167 public FilterChecker(PrintWriter log) {
168 super(log, true) ;
171 * <code>_XFilter.FilterChecker</code> interface method
172 * which returns the result of XML checking.
173 * @return <code>true</code> if the XML data exported was
174 * valid (i.e. all necessary tags and character data exists),
175 * <code>false</code> if some errors occurred.
177 public boolean checkFilter() {
178 return check() ;