Java-WebSocket: upgrade to 1.6.0
[LibreOffice.git] / qadevOOo / tests / java / mod / _xmloff / Impress / XMLContentImporter.java
blob23ed91b475dd0e16fc212007711c3148ae004b1d
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.container.XNamed;
29 import com.sun.star.drawing.XDrawPages;
30 import com.sun.star.drawing.XDrawPagesSupplier;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Impress.XMLContentImporter</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <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 XMLContentImporter extends TestCase {
62 XComponent xImpressDoc = null;
64 /**
65 * New chart document created.
67 @Override
68 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
70 // get a soffice factory object
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
73 log.println( "creating an impress document" );
74 xImpressDoc = SOF.createImpressDoc(null);
77 /**
78 * Disposes document.
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing document " );
83 xImpressDoc.dispose();
86 /**
87 * Creating a TestEnvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.comp.Impress.XMLContentImporter</code><p>
91 * The chart document is set as a target document for importer.
92 * Imported XML-data contains the tag with a new page which has
93 * some name.
94 * After import page name getting from target document is checked.
95 * Object relations created :
96 * <ul>
97 * <li> <code>'XDocumentHandler.XMLData'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'TargetDocument'</code> for
102 * {@link ifc.document._XImporter} interface </li>
103 * </ul>
105 @Override
106 public TestEnvironment createTestEnvironment
107 (TestParameters tParam,PrintWriter log) throws Exception {
109 XInterface oObj = null;
110 Object oInt = null ;
111 final String impPageName = "XMLImporterPage" ;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log.println( "creating a test environment" );
117 XMultiServiceFactory xMSF = tParam.getMSF() ;
119 oInt = xMSF.createInstance
120 ("com.sun.star.comp.Impress.XMLContentImporter") ;
122 oObj = (XInterface) oInt ;
124 // create testobject here
125 log.println( "creating a new environment for Paragraph object" );
126 TestEnvironment tEnv = new TestEnvironment( oObj );
128 // adding relation
129 tEnv.addObjRelation("TargetDocument", xImpressDoc) ;
131 // adding relation for XDocumentHandler
132 String[][] xml = new String[][] {
133 {"start", "office:document",
134 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
135 "xmlns:presentation", "CDATA", "http://openoffice.org/2000/presentation",
136 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
137 "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing",
138 "office:class", "CDATA", "presentation"
139 ,"office:version", "CDATA", "1.0"
141 {"start", "office:body"},
142 {"start", "draw:page",
143 "draw:name", "CDATA", impPageName,
144 "draw:master-page-name", "CDATA", "Default"
146 {"start", "presentation:notes"},
147 {"start", "draw:page-thumbnail",
148 "draw:style-name", "CDATA", "gr1",
149 "draw:layer", "CDATA", "layout",
150 "svg:width", "CDATA", "12.768cm",
151 "svg:height", "CDATA", "9.576cm",
152 "svg:x", "CDATA", "4.411cm",
153 "svg:y", "CDATA", "2.794cm",
154 "presentation:class", "CDATA", "page",
155 "draw:page-number", "CDATA", "1"
157 {"end", "draw:page-thumbnail"},
158 {"start", "draw:text-box",
159 "presentation:style-name", "CDATA", "Default-notes",
160 "draw:layer", "CDATA", "layout",
161 "svg:width", "CDATA", "15.021cm",
162 "svg:height", "CDATA", "10.63cm",
163 "svg:x", "CDATA", "3.292cm",
164 "svg:y", "CDATA", "13.299cm",
165 "presentation:class", "CDATA", "notes",
166 "presentation:placeholder", "CDATA", "true"
168 {"end", "draw:text-box"},
169 {"end", "presentation:notes"},
170 {"end", "draw:page"},
171 {"end", "office:body"},
172 {"end", "office:document"}} ;
174 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
176 final PrintWriter logF = log ;
178 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
179 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
180 public boolean checkImport() {
181 try {
182 XDrawPagesSupplier xPagesSup = UnoRuntime.queryInterface
183 (XDrawPagesSupplier.class, xImpressDoc) ;
184 XDrawPages xPages = xPagesSup.getDrawPages() ;
185 XNamed xPageName = UnoRuntime.queryInterface
186 (XNamed.class, xPages.getByIndex(0)) ;
187 String gName = xPageName.getName() ;
188 logF.println("Page name returned = '" + gName + "'") ;
189 return impPageName.equals(gName) ;
190 } catch (com.sun.star.uno.Exception e) {
191 logF.println("Exception occurred while checking filter :") ;
192 e.printStackTrace(logF) ;
193 return false ;
196 }) ;
198 return tEnv;
199 } // finish method getTestEnvironment