tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLImporter.java
blobff5e940631005e064d73e0346d4cc60e0934f354
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.XImporter;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.sheet.XSpreadsheetDocument;
32 import com.sun.star.sheet.XSpreadsheets;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Calc.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 {
63 static XComponent xSheetDoc;
65 /**
66 * New spreadsheet document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
72 log.println( "creating a Spreadsheet document" );
73 XSpreadsheetDocument xSpreadsheetDoc = SOF.createCalcDoc( null );
74 xSheetDoc = UnoRuntime.queryInterface
75 (XComponent.class, xSpreadsheetDoc);
78 /**
79 * Spreadsheet document destroyed.
81 @Override
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing document " );
84 util.DesktopTools.closeDoc(xSheetDoc);
87 /**
88 * Creating a TestEnvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Calc.XMLImporter</code><p>
92 * The calc document is set as a target document for importer.
93 * Imported tags contain new value for table name.
94 * After import table name getting from
95 * 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 @Override
107 public TestEnvironment createTestEnvironment( TestParameters tParam,
108 PrintWriter log )
109 throws Exception {
111 XInterface oObj = null;
112 Object oInt = null ;
113 final String impValue = "XMLImporter_test" ;
115 // creation of testobject here
116 // first we write what we are intend to do to log file
117 log.println( "creating a test environment" );
119 XMultiServiceFactory xMSF = tParam.getMSF() ;
121 oInt = xMSF.createInstance("com.sun.star.comp.Calc.XMLImporter") ;
122 XImporter imp = UnoRuntime.queryInterface
123 (XImporter.class, oInt) ;
124 imp.setTargetDocument(xSheetDoc);
126 oObj = (XInterface) oInt ;
128 // create testobject here
129 log.println( "creating a new environment for Paragraph object" );
130 TestEnvironment tEnv = new TestEnvironment( oObj );
132 // adding relation
133 tEnv.addObjRelation("TargetDocument", xSheetDoc) ;
135 // adding relation for XDocumentHandler
136 String[][] xml = new String[][] {
137 {"start", "office:document",
138 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
139 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
140 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
141 "office:class", "CDATA", "spreadsheet"
143 {"start", "office:body"},
144 {"start", "table:table",
145 "table:name", "CDATA", impValue},
146 {"end", "table:table"},
147 {"end", "office:body"},
148 {"end", "office:document"}} ;
150 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
152 final PrintWriter fLog = log ;
153 XSpreadsheetDocument xSpreadsheetDoc = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
154 final XSpreadsheets sheets = xSpreadsheetDoc.getSheets() ;
155 log.println("Sheets before importing :") ;
156 String[] names = sheets.getElementNames() ;
157 for (int i = 0; i < names.length; i++) {
158 log.println(" " + names[i]) ;
160 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
161 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
162 public boolean checkImport() {
163 fLog.println("Sheet names :") ;
164 String[] snames = sheets.getElementNames() ;
165 for (int i = 0; i < snames.length; i++) {
166 fLog.println(" " + snames[i]) ;
169 return sheets.hasByName(impValue) ;
171 }) ;
173 return tEnv;
174 } // finish method getTestEnvironment