tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLContentImporter.java
blobe10549ced72cd9b9be436c60c1dc0f55cf5edd47
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.lang.XMultiServiceFactory;
29 import com.sun.star.text.XTextDocument;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
33 /**
34 * Test for object which is represented by service
35 * <code>com.sun.star.comp.Writer.XMLContentImporter</code>. <p>
36 * Object implements the following interfaces :
37 * <ul>
38 * <li><code>com::sun::star::lang::XInitialization</code></li>
39 * <li><code>com::sun::star::document::XImporter</code></li>
40 * <li><code>com::sun::star::document::XFilter</code></li>
41 * <li><code>com::sun::star::document::ImportFilter</code></li>
42 * <li><code>com::sun::star::beans::XPropertySet</code></li>
43 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
45 * </ul>
46 * @see com.sun.star.lang.XInitialization
47 * @see com.sun.star.document.XImporter
48 * @see com.sun.star.document.XFilter
49 * @see com.sun.star.document.ImportFilter
50 * @see com.sun.star.beans.XPropertySet
51 * @see com.sun.star.xml.sax.XDocumentHandler
52 * @see ifc.lang._XInitialization
53 * @see ifc.document._XImporter
54 * @see ifc.document._XFilter
55 * @see ifc.document._XExporter
56 * @see ifc.beans._XPropertySet
57 * @see ifc.xml.sax._XDocumentHandler
59 public class XMLContentImporter extends TestCase {
60 XTextDocument xTextDoc;
62 /**
63 * New text document created.
65 @Override
66 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
67 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
69 log.println( "creating a textdocument" );
70 xTextDoc = SOF.createTextDoc( null );
73 /**
74 * Text document destroyed.
76 @Override
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xTextDoc " );
79 util.DesktopTools.closeDoc(xTextDoc);
82 /**
83 * Creating a TestEnvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.comp.Writer.XMLContentImporter</code><p>
87 * The text document is set as a target document for importer.
88 * Imported XML-data contains only content tags including test text.
89 * After import text getting from target document is checked.
90 * Object relations created :
91 * <ul>
92 * <li> <code>'XDocumentHandler.XMLData'</code> for
93 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
94 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
95 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
96 * <li> <code>'TargetDocument'</code> for
97 * {@link ifc.document._XImporter} interface </li>
98 * </ul>
100 @Override
101 public TestEnvironment createTestEnvironment( TestParameters tParam,
102 PrintWriter log )
103 throws Exception {
105 XInterface oObj = null;
106 Object oInt = null ;
107 final String impText = "XMLContentImporter test." ;
109 // creation of testobject here
110 // first we write what we are intend to do to log file
111 log.println( "creating a test environment" );
113 XMultiServiceFactory xMSF = tParam.getMSF() ;
115 oInt = xMSF.createInstance
116 ("com.sun.star.comp.Writer.XMLContentImporter") ;
118 oObj = (XInterface) oInt ;
120 // create testobject here
121 log.println( "creating a new environment for Paragraph object" );
122 TestEnvironment tEnv = new TestEnvironment( oObj );
124 // adding relation
125 tEnv.addObjRelation("TargetDocument", xTextDoc) ;
127 // adding relation for XDocumentHandler
128 String[][] xml = new String[][] {
129 {"start", "office:document-content",
130 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
131 "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-content"}} ;
140 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
142 final XTextDocument textDoc = UnoRuntime.queryInterface
143 (XTextDocument.class, xTextDoc) ;
144 final PrintWriter fLog = log ;
145 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
146 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
147 public boolean checkImport() {
148 String docText = textDoc.getText().getString() ;
149 fLog.println("Document text returned = '" + docText + "'") ;
150 return impText.equals(docText) ;
152 }) ;
154 return tEnv;
155 } // finish method getTestEnvironment