bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Draw / XMLContentExporter.java
blob2e6bd3bfca2e8cd4f345abc8fd982c3e4d2f4cca
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._xmloff.Draw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
28 import util.XMLTools;
30 import com.sun.star.container.XNamed;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.Any;
38 import com.sun.star.uno.Exception;
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.Draw.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 {
67 XComponent xDrawDoc = null;
69 /**
70 * New text document created.
72 @Override
73 protected void initialize( TestParameters tParam, PrintWriter log ) {
74 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
76 try {
77 log.println( "creating a drawdocument" );
78 xDrawDoc = SOF.createDrawDoc(null);
79 } catch ( Exception e ) {
80 // Some exception occurs.FAILED
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Document disposed here.
89 @Override
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( " disposing xDrawDoc " );
92 xDrawDoc.dispose();
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Draw.XMLContentExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
101 * exported. <p>
102 * The draw document is set as a source document for exporter
103 * created. Then a new page (Slide) created in this document and
104 * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this
105 * filter checks that new tags exist in the XML output.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
114 * </ul>
116 @Override
117 protected synchronized TestEnvironment createTestEnvironment
118 (TestParameters tParam, PrintWriter log) {
120 XMultiServiceFactory xMSF = tParam.getMSF() ;
121 XInterface oObj = null;
122 FilterChecker filter = new FilterChecker(log);
123 Any arg = new Any(new Type(XDocumentHandler.class),filter);
125 // Adding tags for checking existence of head tag and other tags
126 filter.addTag(new XMLTools.Tag("office:document-content"));
127 filter.addTag(new XMLTools.Tag("office:body"));
128 filter.addTagEnclosed(
129 new XMLTools.Tag("draw:page"),
130 new XMLTools.Tag("office:body"));
131 filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1"));
132 filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2"));
134 try {
135 oObj = (XInterface) xMSF.createInstanceWithArguments(
136 "com.sun.star.comp.Draw.XMLContentExporter",
137 new Object[] {arg});
138 XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj);
140 XDrawPagesSupplier supp = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
141 XDrawPages set = supp.getDrawPages();
143 // This is an XML-export BUG (new slide named "NewSlide2"
144 // can not be exported to XML)
145 set.insertNewByIndex(1);
147 XDrawPage page1 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0));
148 XNamed NPage1 = UnoRuntime.queryInterface(XNamed.class,page1);
149 NPage1.setName("NewSlide1");
150 XDrawPage page2 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1));
151 XNamed NPage2 = UnoRuntime.queryInterface(XNamed.class,page2);
152 NPage2.setName("NewSlide2");
153 xEx.setSourceDocument(xDrawDoc);
154 } catch (com.sun.star.uno.Exception e) {
155 e.printStackTrace(log) ;
156 throw new StatusException("Can't create component.", e) ;
159 // create testobject here
160 log.println( "creating a new environment" );
161 TestEnvironment tEnv = new TestEnvironment( oObj );
163 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
164 new String[] {"FilterName"},
165 new Object[] {"sdraw: StarOffice XML (Draw)"}));
166 tEnv.addObjRelation("SourceDocument",xDrawDoc);
167 tEnv.addObjRelation("XFilter.Checker", filter);
168 return tEnv;
173 * This class checks the XML for tags and data required and returns
174 * checking result to <code>XFilter</code> interface test. All
175 * the information about errors occurred in XML data is written
176 * to log specified.
177 * @see ifc.document._XFilter
179 private class FilterChecker extends XMLTools.XMLChecker
180 implements ifc.document._XFilter.FilterChecker {
183 * Creates a class which will write information
184 * into log specified.
186 private FilterChecker(PrintWriter log) {
187 super(log,true) ;
190 * <code>_XFilter.FilterChecker</code> interface method
191 * which returns the result of XML checking.
192 * @return <code>true</code> if the XML data exported was
193 * valid (i.e. all necessary tags and character data exists),
194 * <code>false</code> if some errors occurred.
196 public boolean checkFilter() {
197 return check();