tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLContentExporter.java
blob098866ff058da5a90a0581309e876a748352903a
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.document.XExporter;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.table.XCell;
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.XMLContentExporter</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 XMLContentExporter extends TestCase {
68 static XComponent xSheetDoc;
70 /**
71 * New spreadsheet document created.
73 @Override
74 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
75 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
76 log.println( "creating a calc document" );
77 xSheetDoc = SOF.openDoc("scalc","_blank");
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xCalcDoc " );
83 util.DesktopTools.closeDoc(xSheetDoc);
86 /**
87 * Creating a TestEnvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.comp.Calc.XMLContentExporter</code> with
90 * argument which is an implementation of <code>XDocumentHandler</code>
91 * and which can check if required tags and character data is
92 * exported. <p>
93 * The calc document is set as a source document for exporter
94 * created. A cell in the sheet is set to some value. This made
95 * for checking if this value is successfully exported within
96 * the document content.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} interface </li>
101 * <li> <code>'XFilter.Checker'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'SourceDocument'</code> for
104 * {@link ifc.document._XExporter} interface </li>
105 * </ul>
107 @Override
108 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
110 XMultiServiceFactory xMSF = tParam.getMSF() ;
111 XInterface oObj = null;
112 final String CELL_TEXT = "XMLContentExporter";
114 ContentFilterChecker Filter = new ContentFilterChecker(log);
116 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
117 oObj = (XInterface) xMSF.createInstanceWithArguments(
118 "com.sun.star.comp.Calc.XMLContentExporter",
119 new Object[] {arg} );
120 XExporter xEx = UnoRuntime.queryInterface
121 (XExporter.class,oObj);
122 xEx.setSourceDocument(xSheetDoc);
124 // Setting some string to a cell
125 XSpreadsheetDocument xSpreadsheetDoc = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
126 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
127 XIndexAccess xSheetsIndexArray = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
128 XSpreadsheet xSheet = (XSpreadsheet) AnyConverter.toObject(
129 new Type(XSpreadsheet.class),xSheetsIndexArray.getByIndex(0));
130 XCell xCell = xSheet.getCellByPosition(0, 0);
131 xCell.setFormula(CELL_TEXT);
133 log.println("fill sheet 1 with content...");
134 util.CalcTools.fillCalcSheetWithContent(xSheetDoc, 1, 1, 1, 5, 5);
136 // adding tags which must be contained in XML output
137 Filter.addTag("office:document-content");
138 Filter.addTagEnclosed("office:body", "office:document-content");
139 Filter.addTagEnclosed("office:script", "office:document-content");
140 Filter.addTagEnclosed("table:table", "office:body");
141 Filter.addTagEnclosed("table:table-column", "table:table");
142 Filter.addTagEnclosed("table:table-row", "table:table");
143 Filter.addTagEnclosed("table:table-cell", "table:table-row");
144 Filter.addTagEnclosed("text:p", "table:table-cell");
145 Filter.addCharactersEnclosed(CELL_TEXT, "text:p");
147 // create testobject here
148 log.println( "creating a new environment" );
149 TestEnvironment tEnv = new TestEnvironment( oObj );
151 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
152 new String[] {"FilterName"},
153 new Object[] {"scalc: StarOffice XML (Calc)"}));
154 tEnv.addObjRelation("SourceDocument",xSheetDoc);
155 tEnv.addObjRelation("XFilter.Checker", Filter);
156 return tEnv;
161 * This class checks the XML for tags and data required and returns
162 * checking result to <code>XFilter</code> interface test. All
163 * the information about errors occurred in XML data is written
164 * to log specified.
165 * @see ifc.document._XFilter
167 private class ContentFilterChecker extends XMLTools.XMLTagsChecker
168 implements ifc.document._XFilter.FilterChecker {
171 * Creates a class which will write information
172 * into log specified.
174 private ContentFilterChecker(PrintWriter log) {
175 super(log) ;
179 * <code>_XFilter.FilterChecker</code> interface method
180 * which returns the result of XML checking.
181 * @return <code>true</code> if the XML data exported was
182 * valid (i.e. all necessary tags and character data exists),
183 * <code>false</code> if some errors occurred.
185 public boolean checkFilter() {
186 return checkTags();