tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLExporter.java
blobc9edb37ab54e176efb0ed9e38770599ed51990f9
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;
27 import util.XMLTools;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XNamed;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.XSpreadsheet;
35 import com.sun.star.sheet.XSpreadsheetDocument;
36 import com.sun.star.sheet.XSpreadsheets;
37 import com.sun.star.uno.Any;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.xml.sax.XDocumentHandler;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.comp.Calc.XMLExporter</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li><code>com::sun::star::lang::XInitialization</code></li>
50 * <li><code>com::sun::star::document::ExportFilter</code></li>
51 * <li><code>com::sun::star::document::XFilter</code></li>
52 * <li><code>com::sun::star::document::XExporter</code></li>
53 * <li><code>com::sun::star::beans::XPropertySet</code></li>
54 * </ul>
55 * @see com.sun.star.lang.XInitialization
56 * @see com.sun.star.document.ExportFilter
57 * @see com.sun.star.document.XFilter
58 * @see com.sun.star.document.XExporter
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.lang._XInitialization
61 * @see ifc.document._ExportFilter
62 * @see ifc.document._XFilter
63 * @see ifc.document._XExporter
64 * @see ifc.beans._XPropertySet
66 public class XMLExporter extends TestCase {
67 static XComponent xSheetDoc;
69 /**
70 * New spreadsheet document created.
72 @Override
73 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
74 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
75 log.println( "creating a calc document" );
76 xSheetDoc = SOF.openDoc("scalc","_blank");
79 /**
80 * Spreadsheet document disposed
82 @Override
83 protected void cleanup( TestParameters tParam, PrintWriter log ) {
84 log.println( " disposing xCalcDoc " );
85 util.DesktopTools.closeDoc(xSheetDoc);
88 /**
89 * Creating a TestEnvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Calc.XMLExporter</code> with
92 * argument which is an implementation of <code>XDocumentHandler</code>
93 * and which can check if required tags and character data is
94 * exported. <p>
95 * The calc document is set as a source document for exporter
96 * created. Checking whether tags for table corresponding to some sheet
97 * is exported.<p>
98 * Object relations created :
99 * <ul>
100 * <li> <code>'MediaDescriptor'</code> for
101 * {@link ifc.document._XFilter} interface </li>
102 * <li> <code>'XFilter.Checker'</code> for
103 * {@link ifc.document._XFilter} interface </li>
104 * <li> <code>'SourceDocument'</code> for
105 * {@link ifc.document._XExporter} interface </li>
106 * </ul>
108 @Override
109 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
111 XMultiServiceFactory xMSF = tParam.getMSF() ;
112 XInterface oObj = null;
113 FilterChecker Filter = new FilterChecker(log);
114 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
115 final String SHEET_NAME = "XMLExporter_SheetTestName";
117 oObj = (XInterface) xMSF.createInstanceWithArguments(
118 "com.sun.star.comp.Calc.XMLExporter", new Object[] {arg} );
119 XExporter xEx = UnoRuntime.queryInterface
120 (XExporter.class,oObj);
121 xEx.setSourceDocument(xSheetDoc);
123 //set name of sheet
124 XSpreadsheetDocument xSpreadsheetDoc = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
125 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
126 XIndexAccess xSheetsIndexArray = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
127 XSpreadsheet xSheet = (XSpreadsheet) AnyConverter.toObject(
128 new Type(XSpreadsheet.class),xSheetsIndexArray.getByIndex(0));
129 XNamed xSheetNamed = UnoRuntime.queryInterface(XNamed.class, xSheet);
130 xSheetNamed.setName(SHEET_NAME);
132 log.println("fill sheet with content...");
133 util.CalcTools.fillCalcSheetWithContent(xSheet, 3, 3, 50, 50);
135 // adding tags which must be contained in XML output
136 Filter.addTag( new XMLTools.Tag("office:document") );
137 Filter.addTagEnclosed(
138 new XMLTools.Tag("office:meta"),
139 new XMLTools.Tag("office:document") );
140 Filter.addTagEnclosed(
141 new XMLTools.Tag("office:settings"),
142 new XMLTools.Tag("office:document") );
143 Filter.addTagEnclosed(
144 new XMLTools.Tag("office:script"),
145 new XMLTools.Tag("office:document") );
146 Filter.addTagEnclosed(
147 new XMLTools.Tag("office:styles"),
148 new XMLTools.Tag("office:document") );
149 Filter.addTagEnclosed(
150 new XMLTools.Tag("office:body"),
151 new XMLTools.Tag("office:document") );
152 Filter.addTagEnclosed(
153 new XMLTools.Tag("table:table"),
154 new XMLTools.Tag("office:body") );
155 Filter.addTag(
156 new XMLTools.Tag("table:table", "table:name", SHEET_NAME) );
158 // create testobject here
159 log.println( "creating a new environment" );
160 TestEnvironment tEnv = new TestEnvironment( oObj );
162 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
163 new String[] {"FilterName"},
164 new Object[] {"scalc: StarOffice XML (Calc)"}));
165 tEnv.addObjRelation("SourceDocument",xSheetDoc);
166 tEnv.addObjRelation("XFilter.Checker", Filter) ;
167 return tEnv;
171 * This class checks the XML for tags and data required and returns
172 * checking result to <code>XFilter</code> interface test. All
173 * the information about errors occurred in XML data is written
174 * to log specified.
175 * @see ifc.document._XFilter
177 private class FilterChecker extends XMLTools.XMLChecker
178 implements ifc.document._XFilter.FilterChecker {
181 * Creates a class which will write information
182 * into log specified.
184 private FilterChecker(PrintWriter log) {
185 super(log, false) ;
188 * <code>_XFilter.FilterChecker</code> interface method
189 * which returns the result of XML checking.
190 * @return <code>true</code> if the XML data exported was
191 * valid (i.e. all necessary tags and character data exists),
192 * <code>false</code> if some errors occurred.
194 public boolean checkFilter() {
195 return check();