bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLImporter.java
blobcb4fd3f2d8ec2087bd3e46829215909cf20deed8
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.document.XImporter;
30 import com.sun.star.lang.XMultiServiceFactory;
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.XMLImporter</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 XMLImporter extends TestCase {
62 XTextDocument xTextDoc;
64 /**
65 * New text document created.
67 protected void initialize( TestParameters tParam, PrintWriter log ) {
68 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70 try {
71 log.println( "creating a textdocument" );
72 xTextDoc = SOF.createTextDoc( null );
73 } catch ( com.sun.star.uno.Exception e ) {
74 // Some exception occurs.FAILED
75 e.printStackTrace( log );
76 throw new StatusException( "Couldn't create document", e );
80 /**
81 * Text document destroyed.
83 protected void cleanup( TestParameters tParam, PrintWriter log ) {
84 log.println( " disposing xTextDoc " );
85 util.DesktopTools.closeDoc(xTextDoc);
88 /**
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Writer.XMLImporter</code><p>
93 * The text document is set as a target document for importer.
94 * Imported tags contain tag including tag with test text.
95 * After import text getting from target document 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 public synchronized TestEnvironment createTestEnvironment
107 ( TestParameters tParam, PrintWriter log) {
109 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
110 XInterface oObj = null;
112 try {
113 oObj = (XInterface) xMSF.createInstance
114 ("com.sun.star.comp.Writer.XMLImporter");
115 XImporter xIm = UnoRuntime.queryInterface
116 (XImporter.class,oObj);
117 xIm.setTargetDocument(xTextDoc);
118 } catch (com.sun.star.uno.Exception e) {
119 e.printStackTrace(log) ;
120 throw new StatusException("Can't create component.", e) ;
123 // create testobject here
124 log.println( "creating a new environment" );
125 TestEnvironment tEnv = new TestEnvironment( oObj );
127 final String impText = "XMLImporter test." ;
128 String[][] xml = new String[][] {
129 {"start", "office:document" ,
130 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
131 "office:class", "CDATA", "text",
132 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"},
133 {"start", "office:body" },
134 {"start", "text:p" },
135 {"chars", impText},
136 {"end", "text:p"},
137 {"end", "office:body"},
138 {"end", "office:document"}} ;
140 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
142 tEnv.addObjRelation("TargetDocument",xTextDoc);
143 log.println("Implementation Name: "+util.utils.getImplName(oObj));
145 final XTextDocument textDoc = UnoRuntime.queryInterface
146 (XTextDocument.class, xTextDoc) ;
147 final PrintWriter fLog = log ;
148 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
149 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
150 public boolean checkImport() {
151 String docText = textDoc.getText().getString() ;
152 fLog.println("Document text returned = '" + docText + "'") ;
153 return impText.equals(docText) ;
155 }) ;
157 return tEnv;