tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLMetaImporter.java
blobb7e26d0bb1381d2008474308dd7421ae99141861
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._sc;
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.XDocumentPropertiesSupplier;
29 import com.sun.star.document.XDocumentProperties;
30 import com.sun.star.document.XImporter;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * </ul>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLMetaImporter extends TestCase {
64 private XSpreadsheetDocument xSheetDoc;
65 static XComponent comp ;
67 /**
68 * New spreadsheet document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
74 log.println( "creating a Spreadsheet document" );
75 xSheetDoc = SOF.createCalcDoc( null );
76 comp = UnoRuntime.queryInterface
77 (XComponent.class, xSheetDoc) ;
80 /**
81 * Spreadsheet document destroyed.
83 @Override
84 protected void cleanup( TestParameters tParam, PrintWriter log ) {
85 log.println( " disposing document " );
86 util.DesktopTools.closeDoc(comp);
89 /**
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code><p>
94 * The calc document is set as a target document for importer.
95 * Imported XML-data contains only meta tags including title tag
96 * with test title name.
97 * 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 @Override
110 public TestEnvironment createTestEnvironment( TestParameters tParam,
111 PrintWriter log )
112 throws Exception {
114 XInterface oObj = null;
115 Object oInt = null ;
116 final String impTitle = "XMLMetaImporter" ;
118 // creation of testobject here
119 // first we write what we are intend to do to log file
120 log.println( "creating a test environment" );
122 XMultiServiceFactory xMSF = tParam.getMSF() ;
124 oInt = xMSF.createInstance
125 ("com.sun.star.comp.Calc.XMLMetaImporter") ;
126 XImporter imp = UnoRuntime.queryInterface
127 (XImporter.class, oInt) ;
128 imp.setTargetDocument(comp) ;
130 oObj = (XInterface) oInt ;
132 // create testobject here
133 log.println( "creating a new environment for Paragraph object" );
134 TestEnvironment tEnv = new TestEnvironment( oObj );
136 // adding relation
137 tEnv.addObjRelation("TargetDocument", comp) ;
139 // adding relation for XDocumentHandler
140 String[][] xml = new String[][] {
141 {"start", "office:document-meta" ,
142 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
143 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
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, xSheetDoc);
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