bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sm / XMLSettingsImporter.java
blob9860a8609fab77d68820e044b75acdd3a183d068
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
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.Math.XMLSettingsImporter</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>
46 * </ul>
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.document.XImporter
49 * @see com.sun.star.document.XFilter
50 * @see com.sun.star.document.ImportFilter
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.xml.sax.XDocumentHandler
53 * @see ifc.lang._XInitialization
54 * @see ifc.document._XImporter
55 * @see ifc.document._XFilter
56 * @see ifc.document._XExporter
57 * @see ifc.beans._XPropertySet
58 * @see ifc.xml.sax._XDocumentHandler
60 public class XMLSettingsImporter extends TestCase {
61 XComponent xMathDoc;
63 /**
64 * New math document created.
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
69 try {
70 xMathDoc = SOF.openDoc("smath","_blank");
71 } catch (com.sun.star.uno.Exception ex) {
72 ex.printStackTrace( log );
73 throw new StatusException( "Couldn't create document", ex );
77 /**
78 * Disposes document.
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.XMLSettingsImporter</code><p>
90 * The math document is set as a target document for importer.
91 * Imported XML-data contains the tag which specifies new
92 * 'TopMargin' property value.
93 * After import 'TopMargin' property value 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 public synchronized TestEnvironment createTestEnvironment
106 ( TestParameters Param, PrintWriter log )
107 throws StatusException {
109 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
110 XInterface oObj = null;
111 final short impMargin = 67 ;
113 try {
114 oObj = (XInterface)xMSF.createInstance(
115 "com.sun.star.comp.Math.XMLSettingsImporter");
117 } catch (com.sun.star.uno.Exception e) {
118 e.printStackTrace(log);
119 throw new StatusException("Unexpected exception", e);
122 TestEnvironment tEnv = new TestEnvironment(oObj);
124 tEnv.addObjRelation("TargetDocument",xMathDoc);
126 String[][] xml = new String[][] {
127 {"start", "office:document-settings",
128 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
129 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
130 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
131 "office:version", "CDATA", "1.0"
133 {"start", "office:settings"},
134 {"start", "config:config-item-set",
135 "config:name", "CDATA", "configuration-settings"},
137 {"start", "config:config-item",
138 "config:name", "CDATA", "TopMargin",
139 "config:type", "CDATA", "short"},
140 {"chars", String.valueOf(impMargin)},
141 {"end", "config:config-item"},
142 {"end", "config:config-item-set"},
143 {"end", "office:settings"},
144 {"end", "office:document-settings"}} ;
146 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
148 final PrintWriter logF = log ;
149 final XPropertySet xPS = UnoRuntime.queryInterface
150 (XPropertySet.class, xMathDoc) ;
152 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
153 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
154 public boolean checkImport() {
155 try {
156 Short gMargin = (Short) xPS.getPropertyValue
157 ("TopMargin") ;
158 logF.println("Margin returned: " + gMargin);
159 return impMargin == gMargin.shortValue() ;
160 } catch (com.sun.star.uno.Exception e) {
161 logF.println("Exception occurred while checking filter :") ;
162 e.printStackTrace(logF) ;
163 return false ;
166 }) ;
168 return tEnv;