bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLContentImporter.java
blob47ec935175ee6964e292929880782aed78787ca8
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;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.chart.XChartDocument;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Chart.XMLContentImporter</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
47 * </ul>
48 * @see com.sun.star.lang.XInitialization
49 * @see com.sun.star.document.XImporter
50 * @see com.sun.star.document.XFilter
51 * @see com.sun.star.document.ImportFilter
52 * @see com.sun.star.beans.XPropertySet
53 * @see com.sun.star.xml.sax.XDocumentHandler
54 * @see ifc.lang._XInitialization
55 * @see ifc.document._XImporter
56 * @see ifc.document._XFilter
57 * @see ifc.document._XExporter
58 * @see ifc.beans._XPropertySet
59 * @see ifc.xml.sax._XDocumentHandler
61 public class XMLContentImporter extends TestCase {
62 XComponent comp ;
63 XChartDocument xChartDoc = null;
65 /**
66 * New chart document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 // get a soffice factory object
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
73 try {
74 log.println( "creating a chartdocument" );
75 xChartDoc = SOF.createChartDoc();
76 } catch ( Exception e ) {
77 // Some exception occurs.FAILED
78 e.printStackTrace( log );
79 throw new StatusException( "Couldn't create document", e );
82 comp = xChartDoc;
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;
94 comp = null;
98 /**
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.comp.Chart.XMLContentImporter</code><p>
103 * The chart document is set as a target document for importer.
104 * Imported XML-data contains the tag which specifies the title
105 * of a chart.
106 * After import title name getting from target document is checked.
107 * Object relations created :
108 * <ul>
109 * <li> <code>'XDocumentHandler.XMLData'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'TargetDocument'</code> for
114 * {@link ifc.document._XImporter} interface </li>
115 * </ul>
117 @Override
118 public synchronized TestEnvironment createTestEnvironment
119 (TestParameters tParam, PrintWriter log ) {
121 XInterface oObj = null;
122 Object oInt = null ;
123 final String impValue = "XMLContentImporter_test" ;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log.println( "creating a test environment" );
129 XMultiServiceFactory xMSF = tParam.getMSF() ;
131 final XPropertySet xTitleProp ;
132 try {
133 oInt = xMSF.createInstance
134 ("com.sun.star.comp.Chart.XMLContentImporter") ;
137 Object oTitle = xChartDoc.getTitle() ;
138 xTitleProp = UnoRuntime.queryInterface
139 (XPropertySet.class, oTitle) ;
140 } catch (com.sun.star.uno.Exception e) {
141 e.printStackTrace(log) ;
142 throw new StatusException("Can't create component.", e) ;
145 oObj = (XInterface) oInt ;
147 // create testobject here
148 log.println( "creating a new environment for Paragraph object" );
149 TestEnvironment tEnv = new TestEnvironment( oObj );
151 // adding relation
152 tEnv.addObjRelation("TargetDocument", comp) ;
154 // adding relation for XDocumentHandler
155 String[][] xml = new String[][] {
156 {"start", "office:document-content",
157 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
158 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
159 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
160 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
161 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
162 "office:class", "CDATA", "chart"
163 ,"office:version", "CDATA", "1.0"
165 {"start", "office:body"},
166 {"start", "chart:chart"},
167 {"start", "chart:title"},
168 {"start", "text:p"},
169 {"chars", impValue},
170 {"end", "text:p"},
171 {"end", "chart:title"},
172 {"end", "chart:chart"},
173 {"end", "office:body"},
174 {"end", "office:document-content"}} ;
176 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
178 final PrintWriter logF = log ;
180 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
181 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
182 public boolean checkImport() {
183 try {
184 String title = (String)
185 xTitleProp.getPropertyValue("String") ;
186 logF.println("Title returned = '" + title + "'") ;
187 return impValue.equals(title) ;
188 } catch (com.sun.star.uno.Exception e) {
189 logF.println
190 ("Exception occurred while checking filter :") ;
191 e.printStackTrace(logF) ;
192 return false ;
195 }) ;
198 return tEnv;
199 } // finish method getTestEnvironment