bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLMetaImporter.java
blobccbbb4c27ec6f89f6c5c6604a9f65b39ed8d66de
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.document.XDocumentPropertiesSupplier;
30 import com.sun.star.document.XDocumentProperties;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Impress.XMLMetaImporter</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <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 XMLMetaImporter extends TestCase {
62 XComponent xImpressDoc = null;
64 /**
65 * New impress document created.
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 // get a soffice factory object
70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
72 try {
73 log.println( "creating an impress document" );
74 xImpressDoc = SOF.createImpressDoc(null);
75 } catch ( Exception e ) {
76 // Some exception occurs.FAILED
77 e.printStackTrace( log );
78 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Impress document destroyed.
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing document " );
87 xImpressDoc.dispose();
90 /**
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Impress.XMLMetaImporter</code><p>
95 * The impress document is set as a target document for importer.
96 * Imported XML-data contains only meta tags including title tag
97 * with test title name. After import title name getting from
98 * target document is checked.
99 * Object relations created :
100 * <ul>
101 * <li> <code>'XDocumentHandler.XMLData'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'TargetDocument'</code> for
106 * {@link ifc.document._XImporter} interface </li>
107 * </ul>
109 public synchronized TestEnvironment createTestEnvironment
110 (TestParameters tParam,PrintWriter log ) throws StatusException {
112 XInterface oObj = null;
113 Object oInt = null ;
114 final String impTitle = "XMLImporter_test" ;
116 // creation of testobject here
117 // first we write what we are intend to do to log file
118 log.println( "creating a test environment" );
120 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
122 try {
123 oInt = xMSF.createInstance
124 ("com.sun.star.comp.Impress.XMLMetaImporter") ;
126 } catch (com.sun.star.uno.Exception e) {
127 e.printStackTrace(log) ;
128 throw new StatusException("Can't create component.", e) ;
131 oObj = (XInterface) oInt ;
133 // create testobject here
134 log.println( "creating a new environment for Paragraph object" );
135 TestEnvironment tEnv = new TestEnvironment( oObj );
137 // adding relation
138 tEnv.addObjRelation("TargetDocument", xImpressDoc) ;
140 // adding relation for XDocumentHandler
141 String[][] xml = new String[][] {
142 {"start", "office:document-meta" ,
143 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
144 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
145 {"start", "office:meta"} ,
146 {"start", "dc:title"},
147 {"chars", impTitle},
148 {"end", "dc:title"},
149 {"end", "office:meta"},
150 {"end", "office:document-meta"}} ;
152 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
154 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
155 (XDocumentPropertiesSupplier.class, xImpressDoc);
156 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
157 final PrintWriter logF = log ;
159 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
160 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
161 public boolean checkImport() {
162 String title = xDocProps.getTitle();
163 logF.println("Title returned = '" + title + "'") ;
164 return impTitle.equals(title) ;
166 } );
168 return tEnv;
169 } // finish method getTestEnvironment