tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLStylesImporter.java
blobc51f1d2e01ffee243fd8b977acc0df6a7aa1fade
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._sw;
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.lang.XMultiServiceFactory;
30 import com.sun.star.text.XFootnotesSupplier;
31 import com.sun.star.text.XTextDocument;
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.Writer.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 XTextDocument xTextDoc;
64 /**
65 * New text document created.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
71 log.println( "creating a textdocument" );
72 xTextDoc = SOF.createTextDoc( null );
75 /**
76 * Text document destroyed.
78 @Override
79 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 log.println( " disposing xTextDoc " );
81 util.DesktopTools.closeDoc(xTextDoc);
84 /**
85 * Creating a TestEnvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code><p>
89 * The text document is set as a target document for importer.
90 * Imported XML-data contains only style tags including
91 * title tag with test prefix.
92 * After import prefixes 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( TestParameters tParam,
105 PrintWriter log )
106 throws Exception {
108 XInterface oObj = null;
109 Object oInt = null ;
110 final String impPrefix = "Prefix" ;
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log.println( "creating a test environment" );
116 XMultiServiceFactory xMSF = tParam.getMSF() ;
118 oInt = xMSF.createInstance
119 ("com.sun.star.comp.Writer.XMLStylesImporter") ;
121 oObj = (XInterface) oInt ;
123 // create testobject here
124 log.println( "creating a new environment for Paragraph object" );
125 TestEnvironment tEnv = new TestEnvironment( oObj );
127 // adding relation
128 tEnv.addObjRelation("TargetDocument", xTextDoc) ;
130 // adding relation for XDocumentHandler
131 String[][] xml = new String[][] {
132 {"start", "office:document-styles",
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
135 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"
137 {"start", "office:styles"},
138 {"start", "text:footnotes-configuration",
139 "style:num-prefix", "CDATA", impPrefix},
140 {"end", "text:footnotes-configuration"},
141 {"end", "office:styles"},
142 {"end", "office:document-styles"}} ;
144 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
146 XFootnotesSupplier supp = UnoRuntime.queryInterface
147 (XFootnotesSupplier.class, xTextDoc);
148 final XPropertySet set = supp.getFootnoteSettings();
149 final PrintWriter logF = log ;
151 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
152 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
153 public boolean checkImport() {
154 try {
155 String prefix = (String) set.getPropertyValue("Prefix");
156 logF.println("Prefix returned = '" + prefix + "'") ;
157 return impPrefix.equals(prefix) ;
158 } catch (com.sun.star.uno.Exception e) {
159 logF.println("Exception occurred while checking filter :") ;
160 e.printStackTrace(logF) ;
161 return false ;
164 }) ;
166 return tEnv;
167 } // finish method getTestEnvironment