Set that a non-modal Popover don't auto-grab focus on popup
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLContentExporter.java
blob9edbe3aa3f3b3371cd13cc2b9de4703ab656483a
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;
27 import util.XMLTools;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.chart.XChartDocument;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.Any;
34 import com.sun.star.uno.Exception;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.xml.sax.XDocumentHandler;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.comp.Chart.XMLContentExporter</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li><code>com::sun::star::lang::XInitialization</code></li>
46 * <li><code>com::sun::star::document::ExportFilter</code></li>
47 * <li><code>com::sun::star::document::XFilter</code></li>
48 * <li><code>com::sun::star::document::XExporter</code></li>
49 * <li><code>com::sun::star::beans::XPropertySet</code></li>
50 * </ul>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.ExportFilter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.XExporter
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._ExportFilter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
62 public class XMLContentExporter extends TestCase {
63 XChartDocument xChartDoc = null;
65 /**
66 * New text document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
74 log.println( "creating a chartdocument" );
75 xChartDoc = SOF.createChartDoc();
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;
90 /**
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Chart.XMLContentExporter</code> with
94 * argument which is an implementation of <code>XDocumentHandler</code>
95 * and which can check if required tags and character data is
96 * exported. <p>
97 * The chart document is set as a source document for exporter
98 * created. A new 'main title' is set for chart. This made
99 * for checking if this title is successfully exported within
100 * the document content.
101 * Object relations created :
102 * <ul>
103 * <li> <code>'MediaDescriptor'</code> for
104 * {@link ifc.document._XFilter} interface </li>
105 * <li> <code>'XFilter.Checker'</code> for
106 * {@link ifc.document._XFilter} interface </li>
107 * <li> <code>'SourceDocument'</code> for
108 * {@link ifc.document._XExporter} interface </li>
109 * </ul>
111 @Override
112 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
114 XMultiServiceFactory xMSF = tParam.getMSF() ;
115 XInterface oObj = null;
116 final String exportStr = "XMLContentExporter" ;
118 FilterChecker filter = new FilterChecker(log);
119 Any arg = new Any(new Type(XDocumentHandler.class),filter);
121 oObj = (XInterface) xMSF.createInstanceWithArguments(
122 "com.sun.star.comp.Chart.XMLContentExporter",
123 new Object[] {arg});
124 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
125 xEx.setSourceDocument(xChartDoc);
127 Object oTitle = xChartDoc.getTitle() ;
128 XPropertySet xTitleProp = UnoRuntime.queryInterface
129 (XPropertySet.class, oTitle) ;
130 xTitleProp.setPropertyValue("String", exportStr) ;
132 filter.addTag(new XMLTools.Tag("office:document-content")) ;
133 filter.addTagEnclosed(new XMLTools.Tag("office:body"),
134 new XMLTools.Tag("office:document-content"));
135 filter.addCharactersEnclosed(exportStr,
136 new XMLTools.Tag("chart:title")) ;
139 // create testobject here
140 log.println( "creating a new environment" );
141 TestEnvironment tEnv = new TestEnvironment( oObj );
143 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
144 new String[] {"FilterName"},
145 new Object[] {"schart: StarOffice XML (Chart)"}));
146 tEnv.addObjRelation("SourceDocument",xChartDoc);
147 tEnv.addObjRelation("XFilter.Checker", filter) ;
148 log.println("Implementation Name: "+util.utils.getImplName(oObj));
150 return tEnv;
155 * This class checks the XML for tags and data required and returns
156 * checking result to <code>XFilter</code> interface test. All
157 * the information about errors occurred in XML data is written
158 * to log specified.
159 * @see ifc.document._XFilter
161 private class FilterChecker extends XMLTools.XMLChecker
162 implements ifc.document._XFilter.FilterChecker {
165 * Creates a class which will write information
166 * into log specified.
168 private FilterChecker(PrintWriter log) {
169 super(log, true) ;
172 * <code>_XFilter.FilterChecker</code> interface method
173 * which returns the result of XML checking.
174 * @return <code>true</code> if the XML data exported was
175 * valid (i.e. all necessary tags and character data exists),
176 * <code>false</code> if some errors occurred.
178 public boolean checkFilter() {
179 return check() ;