Set that a non-modal Popover don't auto-grab focus on popup
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLImporter.java
blobeb60684b80046c9375e0574dfa41d1b7b7a391fc
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.XMLImporter</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 XMLImporter 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.XMLImporter</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 = "XMLImporter_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("com.sun.star.comp.Chart.XMLImporter") ;
127 Object oTitle = xChartDoc.getTitle() ;
128 xTitleProp = UnoRuntime.queryInterface
129 (XPropertySet.class, oTitle) ;
131 oObj = (XInterface) oInt ;
133 // create testobject here
134 log.println( "creating a new environment for Paragraph object" );
135 TestEnvironment tEnv = new TestEnvironment( oObj );
137 // adding relation
138 tEnv.addObjRelation("TargetDocument", comp) ;
140 // adding relation for XDocumentHandler
141 String[][] xml = new String[][] {
142 {"start", "office:document",
143 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
144 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
145 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
146 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
147 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
148 "office:class", "CDATA", "chart"
149 ,"office:version", "CDATA", "1.0"
151 {"start", "office:body"},
152 {"start", "chart:chart"},
153 {"start", "chart:title"},
154 {"start", "text:p"},
155 {"chars", impValue},
156 {"end", "text:p"},
157 {"end", "chart:title"},
158 {"end", "chart:chart"},
159 {"end", "office:body"},
160 {"end", "office:document-content"}} ;
162 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
164 final PrintWriter logF = log ;
166 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
167 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
168 public boolean checkImport() {
169 try {
170 String title = (String)
171 xTitleProp.getPropertyValue("String") ;
172 logF.println("Title returned = '" + title + "'") ;
173 return impValue.equals(title) ;
174 } catch (com.sun.star.uno.Exception e) {
175 logF.println
176 ("Exception occurred while checking filter :") ;
177 e.printStackTrace(logF) ;
178 return false ;
181 }) ;
184 return tEnv;
185 } // finish method getTestEnvironment