bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLExporter.java
blobcc9d5dbb7a60bd99f76391f17adea9f4c1793d87
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.beans.XPropertySet;
31 import com.sun.star.chart.XChartDocument;
32 import com.sun.star.document.XExporter;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.Any;
35 import com.sun.star.uno.Exception;
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.Chart.XMLExporter</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 XMLExporter extends TestCase {
64 XChartDocument xChartDoc = null;
66 /**
67 * New text document created.
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
74 try {
75 log.println( "creating a chartdocument" );
76 xChartDoc = SOF.createChartDoc(null);
77 } catch ( Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Close document
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 if( xChartDoc!=null ) {
89 log.println( " closing xChartDoc" );
90 util.DesktopTools.closeDoc(xChartDoc);
91 xChartDoc = null;
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Chart.XMLExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
101 * exported. <p>
102 * The chart document is set as a source document for exporter
103 * created. A new 'main title' is set for chart. This made
104 * for checking if this title is successfully exported within
105 * the document content.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
114 * </ul>
116 public synchronized TestEnvironment createTestEnvironment
117 (TestParameters tParam, PrintWriter log ) {
119 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
120 XInterface oObj = null;
121 final String exportStr = "XMLExporter test." ;
123 FilterChecker filter = new FilterChecker(log);
124 Any arg = new Any(new Type(XDocumentHandler.class),filter);
126 try {
127 oObj = (XInterface) xMSF.createInstanceWithArguments(
128 "com.sun.star.comp.Chart.XMLExporter", new Object[] {arg});
129 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
130 xEx.setSourceDocument(xChartDoc);
132 Object oTitle = xChartDoc.getTitle() ;
133 XPropertySet xTitleProp = UnoRuntime.queryInterface
134 (XPropertySet.class, oTitle) ;
135 xTitleProp.setPropertyValue("String", exportStr) ;
136 } catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace(log) ;
138 throw new StatusException("Can't create component.", e) ;
141 filter.addTag(new XMLTools.Tag("office:document")) ;
142 filter.addTagEnclosed(new XMLTools.Tag("office:meta"),
143 new XMLTools.Tag("office:document"));
144 filter.addTagEnclosed(new XMLTools.Tag("office:body"),
145 new XMLTools.Tag("office:document"));
146 filter.addCharactersEnclosed(exportStr,
147 new XMLTools.Tag("chart:title")) ;
150 // create testobject here
151 log.println( "creating a new environment" );
152 TestEnvironment tEnv = new TestEnvironment( oObj );
154 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
155 new String[] {"FilterName"},
156 new Object[] {"schart: StarOffice XML (Chart)"}));
157 tEnv.addObjRelation("SourceDocument",xChartDoc);
158 tEnv.addObjRelation("XFilter.Checker", filter) ;
159 log.println("Implementation Name: "+util.utils.getImplName(oObj));
161 return tEnv;
166 * This class checks the XML for tags and data required and returns
167 * checking result to <code>XFilter</code> interface test. All
168 * the information about errors occurred in XML data is written
169 * to log specified.
170 * @see ifc.document._XFilter
172 protected class FilterChecker extends XMLTools.XMLChecker
173 implements ifc.document._XFilter.FilterChecker {
176 * Creates a class which will write information
177 * into log specified.
179 public FilterChecker(PrintWriter log) {
180 super(log, true) ;
183 * <code>_XFilter.FilterChecker</code> interface method
184 * which returns the result of XML checking.
185 * @return <code>true</code> if the XML data exported was
186 * valid (i.e. all necessary tags and character data exists),
187 * <code>false</code> if some errors occurred.
189 public boolean checkFilter() {
190 return check() ;