tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLMetaImporter.java
blob72ba25ccdd79358db945b34977263231e7192de0
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._sm;
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.beans.XPropertySetInfo;
30 import com.sun.star.beans.Property;
31 import com.sun.star.document.XDocumentPropertiesSupplier;
32 import com.sun.star.document.XDocumentProperties;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.comp.Math.XMLMetaImporter</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li><code>com::sun::star::lang::XInitialization</code></li>
44 * <li><code>com::sun::star::document::XImporter</code></li>
45 * <li><code>com::sun::star::document::XFilter</code></li>
46 * <li><code>com::sun::star::document::ImportFilter</code></li>
47 * <li><code>com::sun::star::beans::XPropertySet</code></li>
48 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * </ul>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLMetaImporter extends TestCase {
64 XComponent xMathDoc;
66 /**
67 * New math document created.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
73 xMathDoc = SOF.openDoc("smath","_blank");
76 /**
77 * Disposes document.
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xMathDoc " );
82 xMathDoc.dispose();
85 /**
86 * Creating a TestEnvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.comp.Math.XMLMetaImporter</code><p>
90 * The math document is set as a target document for importer.
91 * Imported XML-data contains the tag which specifies new user info
92 * field and a title of document.
93 * After import user fields info and the title of target document
94 * is checked.
95 * Object relations created :
96 * <ul>
97 * <li> <code>'XDocumentHandler.XMLData'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'TargetDocument'</code> for
102 * {@link ifc.document._XImporter} interface </li>
103 * </ul>
105 @Override
106 public TestEnvironment createTestEnvironment
107 ( TestParameters Param, PrintWriter log )
108 throws Exception {
110 XMultiServiceFactory xMSF = Param.getMSF();
111 XInterface oObj = null;
112 final String impName = "XMLMetaImporter" ;
113 final String impValue = "XMLMetaImporter_Value" ;
114 final String impTitle = "XMLMetaImporter Title" ;
116 oObj = (XInterface)xMSF.createInstance(
117 "com.sun.star.comp.Math.XMLMetaImporter");
119 TestEnvironment tEnv = new TestEnvironment(oObj);
121 tEnv.addObjRelation("TargetDocument",xMathDoc);
123 String[][] xml = new String[][] {
124 {"start", "office:document-meta",
125 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
126 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
127 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
128 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"
130 {"start", "office:meta"},
131 {"start", "dc:title"},
132 {"chars", impTitle},
133 {"end", "dc:title"},
134 {"start", "meta:user-defined",
135 "meta:name", "CDATA", impName},
136 {"chars", impValue},
137 {"end", "meta:user-defined"},
138 {"end", "office:meta"},
139 {"end", "office:document-meta"}} ;
141 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
143 final PrintWriter logF = log ;
145 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
146 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
147 public boolean checkImport() {
148 try {
149 XDocumentPropertiesSupplier xPropSup =
150 UnoRuntime.queryInterface
151 (XDocumentPropertiesSupplier.class, xMathDoc);
152 final XDocumentProperties xDocProps =
153 xPropSup.getDocumentProperties();
155 XPropertySet xUDProps = UnoRuntime.queryInterface(
156 XPropertySet.class,
157 xDocProps.getUserDefinedProperties());
158 XPropertySetInfo xInfo =
159 xUDProps.getPropertySetInfo();
160 Property[] props = xInfo.getProperties();
161 boolean result = false;
162 for (int i = 0; i < props.length; i++) {
163 String gName = props[i].Name;
164 String gValue = (String)
165 xUDProps.getPropertyValue(gName);
166 logF.println("Field '" + gName + "' = '"
167 + gValue + "'") ;
168 if (impName.equals(gName) && impValue.equals(gValue))
169 result = true ;
171 String gTitle = xDocProps.getTitle();
172 logF.println("Title returned : '" + gTitle + "'");
173 result &= impTitle.equals(gTitle) ;
175 return result ;
176 } catch (com.sun.star.uno.Exception e) {
177 logF.println("Exception occurred while checking filter :") ;
178 e.printStackTrace(logF) ;
179 return false ;
182 }) ;
184 return tEnv;