Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLImporter.java
blobe3016f20219c990cc43a8f90cf370569ad6d3e30
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 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
71 try {
72 log.println( "creating a textdocument" );
73 xTextDoc = SOF.createTextDoc( null );
74 } catch ( com.sun.star.uno.Exception e ) {
75 // Some exception occurs.FAILED
76 e.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", e );
81 /**
82 * Text document destroyed.
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xTextDoc " );
87 util.DesktopTools.closeDoc(xTextDoc);
90 /**
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Writer.XMLImporter</code><p>
95 * The text document is set as a target document for importer.
96 * Imported tags contain tag including tag with test text.
97 * After import text getting from target document is checked.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'XDocumentHandler.XMLData'</code> for
101 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
102 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'TargetDocument'</code> for
105 * {@link ifc.document._XImporter} interface </li>
106 * </ul>
108 @Override
109 public synchronized TestEnvironment createTestEnvironment
110 ( TestParameters tParam, PrintWriter log) {
112 XMultiServiceFactory xMSF = tParam.getMSF() ;
113 XInterface oObj = null;
115 try {
116 oObj = (XInterface) xMSF.createInstance
117 ("com.sun.star.comp.Writer.XMLImporter");
118 XImporter xIm = UnoRuntime.queryInterface
119 (XImporter.class,oObj);
120 xIm.setTargetDocument(xTextDoc);
121 } catch (com.sun.star.uno.Exception e) {
122 e.printStackTrace(log) ;
123 throw new StatusException("Can't create component.", e) ;
126 // create testobject here
127 log.println( "creating a new environment" );
128 TestEnvironment tEnv = new TestEnvironment( oObj );
130 final String impText = "XMLImporter test." ;
131 String[][] xml = new String[][] {
132 {"start", "office:document" ,
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "office:class", "CDATA", "text",
135 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"},
136 {"start", "office:body" },
137 {"start", "text:p" },
138 {"chars", impText},
139 {"end", "text:p"},
140 {"end", "office:body"},
141 {"end", "office:document"}} ;
143 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
145 tEnv.addObjRelation("TargetDocument",xTextDoc);
146 log.println("Implementation Name: "+util.utils.getImplName(oObj));
148 final XTextDocument textDoc = UnoRuntime.queryInterface
149 (XTextDocument.class, xTextDoc) ;
150 final PrintWriter fLog = log ;
151 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
152 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
153 public boolean checkImport() {
154 String docText = textDoc.getText().getString() ;
155 fLog.println("Document text returned = '" + docText + "'") ;
156 return impText.equals(docText) ;
158 }) ;
160 return tEnv;