Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLContentImporter.java
blob5129138c984151df14e48a30d449476d4189f267
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.Impress;
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;
29 import com.sun.star.container.XNamed;
30 import com.sun.star.drawing.XDrawPages;
31 import com.sun.star.drawing.XDrawPagesSupplier;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
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.Impress.XMLContentImporter</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>
48 * </ul>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLContentImporter extends TestCase {
63 XComponent xImpressDoc = null;
65 /**
66 * New chart document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
74 try {
75 log.println( "creating an impress document" );
76 xImpressDoc = SOF.createImpressDoc(null);
77 } catch ( Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Disposes document.
87 @Override
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing document " );
90 xImpressDoc.dispose();
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.comp.Impress.XMLContentImporter</code><p>
98 * The chart document is set as a target document for importer.
99 * Imported XML-data contains the tag with a new page which has
100 * some name.
101 * After import page name getting from target document is checked.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'XDocumentHandler.XMLData'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
107 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
108 * <li> <code>'TargetDocument'</code> for
109 * {@link ifc.document._XImporter} interface </li>
110 * </ul>
112 @Override
113 public synchronized TestEnvironment createTestEnvironment
114 (TestParameters tParam,PrintWriter log) throws StatusException {
116 XInterface oObj = null;
117 Object oInt = null ;
118 final String impPageName = "XMLImporterPage" ;
120 // creation of testobject here
121 // first we write what we are intend to do to log file
122 log.println( "creating a test environment" );
124 XMultiServiceFactory xMSF = tParam.getMSF() ;
126 try {
127 oInt = xMSF.createInstance
128 ("com.sun.star.comp.Impress.XMLContentImporter") ;
130 } catch (com.sun.star.uno.Exception e) {
131 e.printStackTrace(log) ;
132 throw new StatusException("Can't create component.", e) ;
135 oObj = (XInterface) oInt ;
137 // create testobject here
138 log.println( "creating a new environment for Paragraph object" );
139 TestEnvironment tEnv = new TestEnvironment( oObj );
141 // adding relation
142 tEnv.addObjRelation("TargetDocument", xImpressDoc) ;
144 // adding relation for XDocumentHandler
145 String[][] xml = new String[][] {
146 {"start", "office:document",
147 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
148 "xmlns:presentation", "CDATA", "http://openoffice.org/2000/presentation",
149 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
150 "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing",
151 "office:class", "CDATA", "presentation"
152 ,"office:version", "CDATA", "1.0"
154 {"start", "office:body"},
155 {"start", "draw:page",
156 "draw:name", "CDATA", impPageName,
157 "draw:master-page-name", "CDATA", "Default"
159 {"start", "presentation:notes"},
160 {"start", "draw:page-thumbnail",
161 "draw:style-name", "CDATA", "gr1",
162 "draw:layer", "CDATA", "layout",
163 "svg:width", "CDATA", "12.768cm",
164 "svg:height", "CDATA", "9.576cm",
165 "svg:x", "CDATA", "4.411cm",
166 "svg:y", "CDATA", "2.794cm",
167 "presentation:class", "CDATA", "page",
168 "draw:page-number", "CDATA", "1"
170 {"end", "draw:page-thumbnail"},
171 {"start", "draw:text-box",
172 "presentation:style-name", "CDATA", "Default-notes",
173 "draw:layer", "CDATA", "layout",
174 "svg:width", "CDATA", "15.021cm",
175 "svg:height", "CDATA", "10.63cm",
176 "svg:x", "CDATA", "3.292cm",
177 "svg:y", "CDATA", "13.299cm",
178 "presentation:class", "CDATA", "notes",
179 "presentation:placeholder", "CDATA", "true"
181 {"end", "draw:text-box"},
182 {"end", "presentation:notes"},
183 {"end", "draw:page"},
184 {"end", "office:body"},
185 {"end", "office:document"}} ;
187 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
189 final PrintWriter logF = log ;
191 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
192 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
193 public boolean checkImport() {
194 try {
195 XDrawPagesSupplier xPagesSup = UnoRuntime.queryInterface
196 (XDrawPagesSupplier.class, xImpressDoc) ;
197 XDrawPages xPages = xPagesSup.getDrawPages() ;
198 XNamed xPageName = UnoRuntime.queryInterface
199 (XNamed.class, xPages.getByIndex(0)) ;
200 String gName = xPageName.getName() ;
201 logF.println("Page name returned = '" + gName + "'") ;
202 return impPageName.equals(gName) ;
203 } catch (com.sun.star.uno.Exception e) {
204 logF.println("Exception occurred while checking filter :") ;
205 e.printStackTrace(logF) ;
206 return false ;
209 }) ;
211 return tEnv;
212 } // finish method getTestEnvironment