tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLImporter.java
blob92291cde6431acabf85dbe5c530f6533463f40f3
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.document.XImporter;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
34 /**
35 * Test for object which is represented by service
36 * <code>com.sun.star.comp.Writer.XMLImporter</code>. <p>
37 * Object implements the following interfaces :
38 * <ul>
39 * <li><code>com::sun::star::lang::XInitialization</code></li>
40 * <li><code>com::sun::star::document::XImporter</code></li>
41 * <li><code>com::sun::star::document::XFilter</code></li>
42 * <li><code>com::sun::star::document::ImportFilter</code></li>
43 * <li><code>com::sun::star::beans::XPropertySet</code></li>
44 * <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 XMLImporter extends TestCase {
61 XTextDocument xTextDoc;
63 /**
64 * New text document created.
66 @Override
67 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
68 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
70 log.println( "creating a textdocument" );
71 xTextDoc = SOF.createTextDoc( null );
74 /**
75 * Text document destroyed.
77 @Override
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
79 log.println( " disposing xTextDoc " );
80 util.DesktopTools.closeDoc(xTextDoc);
83 /**
84 * Creating a TestEnvironment for the interfaces to be tested.
85 * Creates an instance of the service
86 * <code>com.sun.star.comp.Writer.XMLImporter</code><p>
88 * The text document is set as a target document for importer.
89 * Imported tags contain tag including tag with test text.
90 * After import text getting from target document is checked.
91 * Object relations created :
92 * <ul>
93 * <li> <code>'XDocumentHandler.XMLData'</code> for
94 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
95 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
96 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
97 * <li> <code>'TargetDocument'</code> for
98 * {@link ifc.document._XImporter} interface </li>
99 * </ul>
101 @Override
102 public TestEnvironment createTestEnvironment
103 ( TestParameters tParam, PrintWriter log) throws Exception {
105 XMultiServiceFactory xMSF = tParam.getMSF() ;
106 XInterface oObj = null;
108 oObj = (XInterface) xMSF.createInstance
109 ("com.sun.star.comp.Writer.XMLImporter");
110 XImporter xIm = UnoRuntime.queryInterface
111 (XImporter.class,oObj);
112 xIm.setTargetDocument(xTextDoc);
114 // create testobject here
115 log.println( "creating a new environment" );
116 TestEnvironment tEnv = new TestEnvironment( oObj );
118 final String impText = "XMLImporter test." ;
119 String[][] xml = new String[][] {
120 {"start", "office:document" ,
121 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
122 "office:class", "CDATA", "text",
123 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"},
124 {"start", "office:body" },
125 {"start", "text:p" },
126 {"chars", impText},
127 {"end", "text:p"},
128 {"end", "office:body"},
129 {"end", "office:document"}} ;
131 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
133 tEnv.addObjRelation("TargetDocument",xTextDoc);
134 log.println("Implementation Name: "+util.utils.getImplName(oObj));
136 final XTextDocument textDoc = UnoRuntime.queryInterface
137 (XTextDocument.class, xTextDoc) ;
138 final PrintWriter fLog = log ;
139 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
140 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
141 public boolean checkImport() {
142 String docText = textDoc.getText().getString() ;
143 fLog.println("Document text returned = '" + docText + "'") ;
144 return impText.equals(docText) ;
146 }) ;
148 return tEnv;