bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLImporter.java
blob20781cc72868cd8612785d0c100d64b53a1021b3
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.XMLImporter</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 XMLImporter extends TestCase {
62 XComponent comp ;
63 XChartDocument xChartDoc = null;
65 /**
66 * New chart document created.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
72 try {
73 log.println( "creating a chartdocument" );
74 xChartDoc = SOF.createChartDoc(null);
75 } catch ( Exception e ) {
76 // Some exception occurs.FAILED
77 e.printStackTrace( log );
78 throw new StatusException( "Couldn't create document", e );
81 comp = xChartDoc;
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;
92 comp = null;
96 /**
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Chart.XMLImporter</code><p>
101 * The chart document is set as a target document for importer.
102 * Imported XML-data contains the tag which specifies the title
103 * of a chart.
104 * After import title name getting from target document is checked.
105 * Object relations created :
106 * <ul>
107 * <li> <code>'XDocumentHandler.XMLData'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'TargetDocument'</code> for
112 * {@link ifc.document._XImporter} interface </li>
113 * </ul>
115 public synchronized TestEnvironment createTestEnvironment
116 (TestParameters tParam, PrintWriter log) {
118 XInterface oObj = null;
119 Object oInt = null ;
120 final String impValue = "XMLImporter_test" ;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log.println( "creating a test environment" );
126 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
128 final XPropertySet xTitleProp ;
129 try {
130 oInt = xMSF.createInstance("com.sun.star.comp.Chart.XMLImporter") ;
132 Object oTitle = xChartDoc.getTitle() ;
133 xTitleProp = UnoRuntime.queryInterface
134 (XPropertySet.class, oTitle) ;
135 } catch (com.sun.star.uno.Exception e) {
136 e.printStackTrace(log) ;
137 throw new StatusException("Can't create component.", e) ;
140 oObj = (XInterface) oInt ;
142 // create testobject here
143 log.println( "creating a new environment for Paragraph object" );
144 TestEnvironment tEnv = new TestEnvironment( oObj );
146 // adding relation
147 tEnv.addObjRelation("TargetDocument", comp) ;
149 // adding relation for XDocumentHandler
150 String[][] xml = new String[][] {
151 {"start", "office:document",
152 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
153 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
154 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
155 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
156 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
157 "office:class", "CDATA", "chart"
158 ,"office:version", "CDATA", "1.0"
160 {"start", "office:body"},
161 {"start", "chart:chart"},
162 {"start", "chart:title"},
163 {"start", "text:p"},
164 {"chars", impValue},
165 {"end", "text:p"},
166 {"end", "chart:title"},
167 {"end", "chart:chart"},
168 {"end", "office:body"},
169 {"end", "office:document-content"}} ;
171 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
173 final PrintWriter logF = log ;
175 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
176 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
177 public boolean checkImport() {
178 try {
179 String title = (String)
180 xTitleProp.getPropertyValue("String") ;
181 logF.println("Title returned = '" + title + "'") ;
182 return impValue.equals(title) ;
183 } catch (com.sun.star.uno.Exception e) {
184 logF.println
185 ("Exception occurred while checking filter :") ;
186 e.printStackTrace(logF) ;
187 return false ;
190 }) ;
193 return tEnv;
194 } // finish method getTestEnvironment