Java-WebSocket: upgrade to 1.6.0
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLSettingsImporter.java
blob32860a675d4efeb55d003ea2507a2bda21545c3d
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.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.frame.XController;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Impress.XMLSettingsImporter</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <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 XMLSettingsImporter extends TestCase {
64 XComponent xImpressDoc = null;
66 /**
67 * New impress document created.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
74 log.println( "creating an impress document" );
75 xImpressDoc = SOF.createImpressDoc(null);
78 /**
79 * Impress document destroyed.
81 @Override
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing document " );
84 xImpressDoc.dispose();
87 /**
88 * Creating a TestEnvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
92 * The Impress document is set as a target document for importer.
93 * Value of a property "IsLayerMode" has imported as 'true' to a target
94 * document. After import property value getting from target document
95 * is checked.
96 * Object relations created :
97 * <ul>
98 * <li> <code>'XDocumentHandler.XMLData'</code> for
99 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
100 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
101 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
102 * <li> <code>'TargetDocument'</code> for
103 * {@link ifc.document._XImporter} interface </li>
104 * </ul>
106 @Override
107 public TestEnvironment createTestEnvironment
108 (TestParameters tParam, PrintWriter log ) throws Exception {
110 XInterface oObj = null;
111 Object oInt = null ;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log.println( "creating a test environment" );
117 XMultiServiceFactory xMSF = tParam.getMSF() ;
119 oInt = xMSF.createInstance
120 ("com.sun.star.comp.Impress.XMLSettingsImporter") ;
122 oObj = (XInterface) oInt ;
124 // create testobject here
125 log.println( "creating a new environment for Paragraph object" );
126 TestEnvironment tEnv = new TestEnvironment( oObj );
128 // adding relation
129 tEnv.addObjRelation("TargetDocument", xImpressDoc) ;
131 // adding relation for XDocumentHandler
132 String[][] xml = new String[][] {
133 {"start", "office:document-settings",
134 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
135 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
136 "xmlns:presentation", "CDATA",
137 "http://openoffice.org/2000/presentation",
138 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
139 "office:version", "CDATA", "1.0"},
140 {"start", "office:settings"},
141 {"start", "config:config-item-map-indexed", "config:name",
142 "CDATA", "Views"},
143 {"start", "config:config-item-map-entry"},
144 {"start","config:config-item", "config:name", "CDATA",
145 "IsLayerMode"},
146 {"chars", "true"},
147 {"end", "config:config-item"},
148 {"end", "config:config-item-map-entry"},
149 {"end", "config:config-item-map-indexed"},
150 {"end", "office:settings"},
151 {"end", "office:document-settings"}} ;
153 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
155 // get property before import
156 XModel xImpressModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
157 XController xController = xImpressModel.getCurrentController();
158 final XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
159 log.println("Property \"IsLayerMode\" before import is " +
160 xPropSet.getPropertyValue("IsLayerMode"));
161 final PrintWriter logF = log;
162 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
163 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
164 public boolean checkImport() {
165 Boolean propValue;
166 try {
167 propValue = (Boolean) xPropSet.getPropertyValue
168 ("IsLayerMode");
169 } catch (com.sun.star.uno.Exception e) {
170 e.printStackTrace(logF);
171 throw new StatusException
172 ("Can't get property value.", e);
174 logF.println("Property \"IsLayerMode\" after import is "
175 + propValue);
176 return propValue.booleanValue();
180 return tEnv;
181 } // end of getTestEnvironment