svx: prefix members of SdrUnoObj
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLContentImporter.java
blob1481e01346c9023d3ae9b61274b4637f79865415
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.chart.XChartDocument;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Chart.XMLContentImporter</code>. <p>
38 * Object implements the following interfaces :
39 * <ul>
40 * <li><code>com::sun::star::lang::XInitialization</code></li>
41 * <li><code>com::sun::star::document::XImporter</code></li>
42 * <li><code>com::sun::star::document::XFilter</code></li>
43 * <li><code>com::sun::star::document::ImportFilter</code></li>
44 * <li><code>com::sun::star::beans::XPropertySet</code></li>
45 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
46 * </ul>
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.document.XImporter
49 * @see com.sun.star.document.XFilter
50 * @see com.sun.star.document.ImportFilter
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.xml.sax.XDocumentHandler
53 * @see ifc.lang._XInitialization
54 * @see ifc.document._XImporter
55 * @see ifc.document._XFilter
56 * @see ifc.document._XExporter
57 * @see ifc.beans._XPropertySet
58 * @see ifc.xml.sax._XDocumentHandler
60 public class XMLContentImporter extends TestCase {
61 XComponent comp ;
62 XChartDocument xChartDoc = null;
64 /**
65 * New chart document created.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
72 log.println( "creating a chartdocument" );
73 xChartDoc = SOF.createChartDoc();
75 comp = xChartDoc;
78 /**
79 * Close document
81 @Override
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 if( xChartDoc!=null ) {
84 log.println( " closing xChartDoc" );
85 util.DesktopTools.closeDoc(xChartDoc);
86 xChartDoc = null;
87 comp = null;
91 /**
92 * Creating a TestEnvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Chart.XMLContentImporter</code><p>
96 * The chart document is set as a target document for importer.
97 * Imported XML-data contains the tag which specifies the title
98 * of a chart.
99 * After import title name getting from target document is checked.
100 * Object relations created :
101 * <ul>
102 * <li> <code>'XDocumentHandler.XMLData'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'TargetDocument'</code> for
107 * {@link ifc.document._XImporter} interface </li>
108 * </ul>
110 @Override
111 public TestEnvironment createTestEnvironment
112 (TestParameters tParam, PrintWriter log ) throws Exception {
114 XInterface oObj = null;
115 Object oInt = null ;
116 final String impValue = "XMLContentImporter_test" ;
118 // creation of testobject here
119 // first we write what we are intend to do to log file
120 log.println( "creating a test environment" );
122 XMultiServiceFactory xMSF = tParam.getMSF() ;
124 final XPropertySet xTitleProp ;
125 oInt = xMSF.createInstance
126 ("com.sun.star.comp.Chart.XMLContentImporter") ;
129 Object oTitle = xChartDoc.getTitle() ;
130 xTitleProp = UnoRuntime.queryInterface
131 (XPropertySet.class, oTitle) ;
133 oObj = (XInterface) oInt ;
135 // create testobject here
136 log.println( "creating a new environment for Paragraph object" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 // adding relation
140 tEnv.addObjRelation("TargetDocument", comp) ;
142 // adding relation for XDocumentHandler
143 String[][] xml = new String[][] {
144 {"start", "office:document-content",
145 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
146 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
147 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
148 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
149 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
150 "office:class", "CDATA", "chart"
151 ,"office:version", "CDATA", "1.0"
153 {"start", "office:body"},
154 {"start", "chart:chart"},
155 {"start", "chart:title"},
156 {"start", "text:p"},
157 {"chars", impValue},
158 {"end", "text:p"},
159 {"end", "chart:title"},
160 {"end", "chart:chart"},
161 {"end", "office:body"},
162 {"end", "office:document-content"}} ;
164 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
166 final PrintWriter logF = log ;
168 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
169 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
170 public boolean checkImport() {
171 try {
172 String title = (String)
173 xTitleProp.getPropertyValue("String") ;
174 logF.println("Title returned = '" + title + "'") ;
175 return impValue.equals(title) ;
176 } catch (com.sun.star.uno.Exception e) {
177 logF.println
178 ("Exception occurred while checking filter :") ;
179 e.printStackTrace(logF) ;
180 return false ;
183 }) ;
186 return tEnv;
187 } // finish method getTestEnvironment