Java-WebSocket: upgrade to 1.6.0
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLStylesImporter.java
blob4b0823b446743c4c6d61a8050f015011f5c00f4f
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;
28 import com.sun.star.container.XNameAccess;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.style.XStyleFamiliesSupplier;
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.Impress.XMLStylesImporter</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>
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 XMLStylesImporter extends TestCase {
62 XComponent xImpressDoc = null;
64 /**
65 * New spreadsheet 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());
71 log.println( "creating an impress document" );
72 xImpressDoc = SOF.createImpressDoc(null);
75 /**
76 * Spreadsheet document destroyed.
78 @Override
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing document " );
81 xImpressDoc.dispose();
84 /**
85 * Creating a TestEnvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
89 * The Impress document is set as a target document for importer.
90 * Imported XML-data contains only style tags including tag
91 * with new style name.
92 * After import style names getting from target document is checked.
93 * Object relations created :
94 * <ul>
95 * <li> <code>'XDocumentHandler.XMLData'</code> for
96 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
97 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'TargetDocument'</code> for
100 * {@link ifc.document._XImporter} interface </li>
101 * </ul>
103 @Override
104 public TestEnvironment createTestEnvironment
105 (TestParameters tParam, PrintWriter log ) throws Exception {
107 XInterface oObj = null;
108 Object oInt = null ;
109 final String impValue = "XMLImporter_test" ;
111 // creation of testobject here
112 // first we write what we are intend to do to log file
113 log.println( "creating a test environment" );
115 XMultiServiceFactory xMSF = tParam.getMSF() ;
117 oInt = xMSF.createInstance
118 ("com.sun.star.comp.Impress.XMLStylesImporter") ;
120 oObj = (XInterface) oInt ;
122 // create testobject here
123 log.println( "creating a new environment for Paragraph object" );
124 TestEnvironment tEnv = new TestEnvironment( oObj );
126 // adding relation
127 tEnv.addObjRelation("TargetDocument", xImpressDoc) ;
129 String[][] xml = new String[][] {
130 {"start", "office:document-styles",
131 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
132 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
133 "xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format",
134 "xmlns:table", "CDATA", "http://openoffice.org/2000/table"},
135 {"start", "office:styles"},
136 {"start", "style:style",
137 "style:name", "CDATA", impValue,
138 "style:family", "CDATA", "graphics",
139 "style:parent-style-name", "CDATA", "standard"},
140 {"end", "style:style"},
141 {"end", "office:styles"},
142 {"end", "office:document-styles"}} ;
144 // adding relation for XDocumentHandler
145 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
146 XNameAccess styles = null ;
147 try {
148 XStyleFamiliesSupplier sup = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
149 xImpressDoc);
150 XNameAccess oStyleFamilies = sup.getStyleFamilies();
151 Object family = oStyleFamilies.getByName("graphics") ;
152 styles = UnoRuntime.queryInterface
153 (XNameAccess.class, family) ;
154 log.println("Styles before:") ;
155 String[] names = styles.getElementNames() ;
156 for (int i = 0; i < names.length; i++) {
157 log.println(" " + names[i]) ;
159 } catch (com.sun.star.uno.Exception e) {
160 e.printStackTrace(log) ;
162 final XNameAccess stylesF = styles ;
163 final PrintWriter logF = log ;
164 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
165 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
166 public boolean checkImport() {
167 logF.println("Styles after:") ;
168 String[] names = stylesF.getElementNames() ;
169 for (int i = 0; i < names.length; i++) {
170 logF.println(" " + names[i]) ;
172 return stylesF.hasByName(impValue) ;
174 }) ;
176 return tEnv;
177 } // end of getTestEnvironment