Set that a non-modal Popover don't auto-grab focus on popup
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLStylesExporter.java
blob2a44f8a8ed6b33293adfbdb387e7601ab4a58e13
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.Impress;
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.container.XNameAccess;
30 import com.sun.star.container.XNameContainer;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.style.XStyle;
35 import com.sun.star.style.XStyleFamiliesSupplier;
36 import com.sun.star.uno.Any;
37 import com.sun.star.uno.Exception;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.xml.sax.XDocumentHandler;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.comp.Impress.XMLOasisStylesExporter</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li><code>com::sun::star::lang::XInitialization</code></li>
49 * <li><code>com::sun::star::document::ExportFilter</code></li>
50 * <li><code>com::sun::star::document::XFilter</code></li>
51 * <li><code>com::sun::star::document::XExporter</code></li>
52 * <li><code>com::sun::star::beans::XPropertySet</code></li>
53 * </ul>
54 * @see com.sun.star.lang.XInitialization
55 * @see com.sun.star.document.ExportFilter
56 * @see com.sun.star.document.XFilter
57 * @see com.sun.star.document.XExporter
58 * @see com.sun.star.beans.XPropertySet
59 * @see ifc.lang._XInitialization
60 * @see ifc.document._ExportFilter
61 * @see ifc.document._XFilter
62 * @see ifc.document._XExporter
63 * @see ifc.beans._XPropertySet
65 public class XMLStylesExporter extends TestCase {
66 XComponent xImpressDoc = null;
67 protected static int counter = 0;
69 /**
70 * New spreadsheet document created.
72 @Override
73 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
74 // get a soffice factory object
75 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
77 log.println( "creating an impress document" );
78 xImpressDoc = SOF.createImpressDoc(null);
81 /**
82 * Spreadsheet document disposed
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xImpressDoc " );
87 xImpressDoc.dispose();
90 /**
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Impress.XMLOasisStylesExporter</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 Impress document is set as a source document for exporter
98 * created. New style 'NewStyle' added to style family "Graphics".
99 * This made for checking if this style is successfully exported within
100 * the document styles information.
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 public TestEnvironment createTestEnvironment
113 (TestParameters tParam, PrintWriter log) throws Exception {
115 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
116 XMultiServiceFactory xMSF = tParam.getMSF() ;
117 XInterface oObj = null;
118 FilterChecker filter = new FilterChecker(log);
119 Any arg = new Any(new Type(XDocumentHandler.class),filter);
121 String newName = "NewGraphicsStyle" + counter++;
122 // Adding tags for checking existence of head tag and property value
123 filter.addTag(new XMLTools.Tag("office:document-styles"));
124 filter.addTag(new XMLTools.Tag("office:styles"));
125 filter.addTag(new XMLTools.Tag("style:style","style:name", newName));
127 oObj = (XInterface) xMSF.createInstanceWithArguments(
128 "com.sun.star.comp.Impress.XMLOasisStylesExporter",
129 new Object[] {arg});
130 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
131 xEx.setSourceDocument(xImpressDoc);
133 // Obtaining and changing property values
134 XStyleFamiliesSupplier styleSup = UnoRuntime.queryInterface
135 (XStyleFamiliesSupplier.class, xImpressDoc) ;
136 XNameAccess styleFamilies = styleSup.getStyleFamilies();
137 String[] styleFamiliesNames = styleFamilies.getElementNames();
138 XNameContainer StyleFamilyName = UnoRuntime.queryInterface(XNameContainer.class,
139 styleFamilies.getByName(styleFamiliesNames[0]));
140 Object SC = SOF.createInstance
141 (xImpressDoc, "com.sun.star.style.Style");
142 XStyle StylePage = UnoRuntime.queryInterface(XStyle.class,SC);
143 StyleFamilyName.insertByName(newName, StylePage);
145 // create testobject here
146 log.println( "creating a new environment" );
147 TestEnvironment tEnv = new TestEnvironment( oObj );
149 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
150 new String[] {"FilterName"},
151 new Object[] {"simpress: StarOffice XML (Impress)"}));
152 tEnv.addObjRelation("SourceDocument",xImpressDoc);
153 tEnv.addObjRelation("XFilter.Checker", filter);
154 return tEnv;
158 * This class checks the XML for tags and data required and returns
159 * checking result to <code>XFilter</code> interface test. All
160 * the information about errors occurred in XML data is written
161 * to log specified.
162 * @see ifc.document._XFilter
164 private class FilterChecker extends XMLTools.XMLChecker
165 implements ifc.document._XFilter.FilterChecker {
168 * Creates a class which will write information
169 * into log specified.
171 private FilterChecker(PrintWriter log) {
172 super(log, false) ;
175 * <code>_XFilter.FilterChecker</code> interface method
176 * which returns the result of XML checking.
177 * @return <code>true</code> if the XML data exported was
178 * valid (i.e. all necessary tags and character data exists),
179 * <code>false</code> if some errors occurred.
181 public boolean checkFilter() {
182 return check();