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