diff options
Diffstat (limited to 'qadevOOo/tests/java/mod/_xmloff/Draw')
10 files changed, 1845 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java new file mode 100644 index 000000000..e0e26b710 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentExporter.java @@ -0,0 +1,190 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XExporter; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLOasisContentExporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::ExportFilter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::XExporter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLContentExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New text document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Document disposed here. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLOasisContentExporter</code> with + * argument which is an implementation of <code>XDocumentHandler</code> + * and which can check if required tags and character data is + * exported. <p> + * The draw document is set as a source document for exporter + * created. Then a new page (Slide) created in this document and + * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this + * filter checks that new tags exist in the XML output. + * Object relations created : + * <ul> + * <li> <code>'MediaDescriptor'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'XFilter.Checker'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'SourceDocument'</code> for + * {@link ifc.document._XExporter} interface </li> + * </ul> + */ + @Override + protected TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) throws Exception { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log); + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + // Adding tags for checking existence of head tag and other tags + filter.addTag(new XMLTools.Tag("office:document-content")); + filter.addTag(new XMLTools.Tag("office:body")); + filter.addTagEnclosed( + new XMLTools.Tag("draw:page"), + new XMLTools.Tag("office:body")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2")); + + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLOasisContentExporter", + new Object[] {arg}); + XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj); + + XDrawPagesSupplier supp = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); + XDrawPages set = supp.getDrawPages(); + + // This is an XML-export BUG (new slide named "NewSlide2" + // can not be exported to XML) + set.insertNewByIndex(1); + + XDrawPage page1 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0)); + XNamed NPage1 = UnoRuntime.queryInterface(XNamed.class,page1); + NPage1.setName("NewSlide1"); + XDrawPage page2 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1)); + XNamed NPage2 = UnoRuntime.queryInterface(XNamed.class,page2); + NPage2.setName("NewSlide2"); + xEx.setSourceDocument(xDrawDoc); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to <code>XFilter</code> interface test. All + * the information about errors occurred in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + private class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + private FilterChecker(PrintWriter log) { + super(log,true) ; + } + /** + * <code>_XFilter.FilterChecker</code> interface method + * which returns the result of XML checking. + * @return <code>true</code> if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * <code>false</code> if some errors occurred. + */ + public boolean checkFilter() { + return check(); + } + } +} + + diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java new file mode 100644 index 000000000..7225b192b --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLContentImporter.java @@ -0,0 +1,192 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +import com.sun.star.container.XNamed; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLContentImporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::XImporter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::ImportFilter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLContentImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New spreadsheet document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Spreadsheet document destroyed. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLContentImporter</code><p> + * + * The Draw document is set as a target document for importer. + * Imported XML-data contains only content tags including pages + * named 'NewSlide1' and 'NewSlide2'. + * Pages getting from target document is checked after import + * Object relations created : + * <ul> + * <li> <code>'XDocumentHandler.XMLData'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'XDocumentHandler.ImportChecker'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'TargetDocument'</code> for + * {@link ifc.document._XImporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws Exception { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLContentImporter") ; + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // New XML document generated to be imported to Draw document + String[][] xml = new String[][] { + {"start", "office:document", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing", + "office:class", "CDATA", "drawing" + ,"office:version", "CDATA", "1.0" + }, + {"start", "office:body"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide1", + "draw:master-page-name", "CDATA", "Default"}, + {"end", "draw:page"}, + {"start", "draw:page", "draw:name", "CDATA", "NewSlide2", + "draw:master-page-name", "CDATA", "Default"}, + {"end","draw:page"}, + {"end", "draw:page"}, + {"end", "office:body"}, + {"end", "office:document"}}; + + // adding relation for XDocumentHandler + tEnv.addObjRelation("XDocumentHandler.XMLData", xml); + + //save to log content before import + final PrintWriter fLog = log; + + // Checking target document after import + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + XDrawPagesSupplier supp = UnoRuntime.queryInterface + (XDrawPagesSupplier.class, xDrawDoc); + final XDrawPages xPages = supp.getDrawPages(); + XNamed[] pageArray = new XNamed[ xPages.getCount() ]; + for (int i=0; i < xPages.getCount(); i++) { + try { + pageArray[i] = UnoRuntime.queryInterface + (XNamed.class, xPages.getByIndex(i)); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(fLog) ; + throw new StatusException + ("Can't get page name by index.", e) ; + } + } + fLog.println("Slide names after import:"); + for ( int i = 0; i < xPages.getCount(); i++ ) { + if ((pageArray[i].getName().equals("NewSlide1")) + || (pageArray[i].getName().equals("NewSlide2"))) { + fLog.println(" " + pageArray[i].getName()); + } + else { + fLog.println("Error: some imported values are not exist in target document!"); + return false; + } + } + return true; + } + }); + + return tEnv; + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java new file mode 100644 index 000000000..5bf74b1cb --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLExporter.java @@ -0,0 +1,190 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +import com.sun.star.container.XNamed; +import com.sun.star.document.XExporter; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLExporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::ExportFilter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::XExporter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New text document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Document disposed here. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLExporter</code> with + * argument which is an implementation of <code>XDocumentHandler</code> + * and which can check if required tags and character data is + * exported. <p> + * The draw document is set as a source document for exporter + * created. Then a new page (Slide) created in this document and + * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this + * filter checks that new tags exist in the XML output. + * Object relations created : + * <ul> + * <li> <code>'MediaDescriptor'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'XFilter.Checker'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'SourceDocument'</code> for + * {@link ifc.document._XExporter} interface </li> + * </ul> + */ + @Override + protected TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) throws Exception { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log); + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + // Adding tags for checking existence of head tag and other tags + filter.addTag(new XMLTools.Tag("office:document")); + filter.addTag(new XMLTools.Tag("office:body")); + filter.addTagEnclosed( + new XMLTools.Tag("draw:page"), + new XMLTools.Tag("office:body")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1")); + filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2")); + + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLExporter", new Object[] {arg}); + + + XDrawPagesSupplier supp = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); + XDrawPages set = supp.getDrawPages(); + + // This is an XML-export BUG (new slide named "NewSlide2" can not be exported to XML) + set.insertNewByIndex(1); + + XDrawPage page1 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0)); + XNamed NPage1 = UnoRuntime.queryInterface(XNamed.class,page1); + NPage1.setName("NewSlide1"); + XDrawPage page2 = UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1)); + XNamed NPage2 = UnoRuntime.queryInterface(XNamed.class,page2); + NPage2.setName("NewSlide2"); + + XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj); + xEx.setSourceDocument(xDrawDoc); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to <code>XFilter</code> interface test. All + * the information about errors occurred in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + private class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + private FilterChecker(PrintWriter log) { + super(log,true) ; + } + /** + * <code>_XFilter.FilterChecker</code> interface method + * which returns the result of XML checking. + * @return <code>true</code> if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * <code>false</code> if some errors occurred. + */ + public boolean checkFilter() { + return check(); + } + } + +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java new file mode 100644 index 000000000..b550ffea6 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLImporter.java @@ -0,0 +1,192 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.StatusException; +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +import com.sun.star.container.XNamed; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLImporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::XImporter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::ImportFilter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New spreadsheet document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Spreadsheet document destroyed. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLImporter</code><p> + * + * The Draw document is set as a target document for importer. + * Imported XML-data contains only content tags including pages + * named 'NewSlide1' and 'NewSlide2'. + * Pages getting from target document are checked after import. + * Object relations created : + * <ul> + * <li> <code>'XDocumentHandler.XMLData'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'XDocumentHandler.ImportChecker'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'TargetDocument'</code> for + * {@link ifc.document._XImporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws Exception { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + oInt = xMSF.createInstance("com.sun.star.comp.Draw.XMLImporter") ; + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing", + "office:class", "CDATA", "drawing" + ,"office:version", "CDATA", "1.0" + }, + {"start", "office:body"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide1", + "draw:master-page-name", "CDATA", "Default"}, + {"end", "draw:page"}, + {"start", "draw:page", + "draw:name", "CDATA", "NewSlide2", + "draw:master-page-name", "CDATA", "Default"}, + {"end","draw:page"}, + {"end", "draw:page"}, + {"end", "office:body"}, + {"end", "office:document"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + //save to log content before import + final PrintWriter fLog = log; + + // Checking target document after import + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + XDrawPagesSupplier supp = UnoRuntime.queryInterface + (XDrawPagesSupplier.class, xDrawDoc); + final XDrawPages xPages = supp.getDrawPages(); + XNamed[] pageArray = new XNamed[ xPages.getCount() ]; + for (int i=0; i < xPages.getCount(); i++) { + try { + pageArray[i] = UnoRuntime.queryInterface + (XNamed.class, xPages.getByIndex(i)); + } catch (com.sun.star.uno.Exception e) { + e.printStackTrace(fLog) ; + throw new StatusException + ("Can't get page name by index.", e) ; + } + } + fLog.println("Slide names after import:"); + for ( int i = 0; i < xPages.getCount(); i++ ) { + if ((pageArray[i].getName().equals("NewSlide1")) + || (pageArray[i].getName().equals("NewSlide2"))) { + fLog.println(" " + pageArray[i].getName()); + } + else { + fLog.println("Error: some imported values are not exist in target document!"); + return false; + } + } + return true; + } + }); + + return tEnv; + } // end of getTestEnvironment + +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java new file mode 100644 index 000000000..0e2835d41 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaExporter.java @@ -0,0 +1,183 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +import com.sun.star.document.XDocumentPropertiesSupplier; +import com.sun.star.document.XDocumentProperties; +import com.sun.star.document.XExporter; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLOasisMetaExporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::ExportFilter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::XExporter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLMetaExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Document disposed here. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLOasisMetaExporter</code> with + * argument which is an implementation of <code>XDocumentHandler</code> + * and which can check if required tags and character data is + * exported. <p> + * The draw document is set as a source document for exporter + * created. Set title of document to 'XMLMetaExporter'. + * This made for checking if this title is successfully exported within + * the document meta information. + * Object relations created : + * <ul> + * <li> <code>'MediaDescriptor'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'XFilter.Checker'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'SourceDocument'</code> for + * {@link ifc.document._XExporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws Exception { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + final String TITLE = "XMLMetaExporter"; + + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLOasisMetaExporter", new Object[] {arg}); + XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj); + xEx.setSourceDocument(xDrawDoc); + + //set some meta data + XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface + (XDocumentPropertiesSupplier.class, xDrawDoc); + final XDocumentProperties xDocProps = xPropSup.getDocumentProperties(); + xDocProps.setTitle(TITLE); + + // Checking Head Tag existence and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-meta")); + filter.addTagEnclosed( + new XMLTools.Tag("office:meta"), + new XMLTools.Tag("office:document-meta") ); + filter.addTagEnclosed( + new XMLTools.Tag("dc:title"), + new XMLTools.Tag("office:meta") ); + filter.addCharactersEnclosed( TITLE, + new XMLTools.Tag("dc:title") ); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument", xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to <code>XFilter</code> interface test. All + * the information about errors occurred in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + private class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + private FilterChecker(PrintWriter log) { + super(log, true) ; + } + + /** + * <code>_XFilter.FilterChecker</code> interface method + * which returns the result of XML checking. + * @return <code>true</code> if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * <code>false</code> if some errors occurred. + */ + public boolean checkFilter() { + return check(); + } + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java new file mode 100644 index 000000000..8bcf5b355 --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLMetaImporter.java @@ -0,0 +1,162 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +import com.sun.star.document.XDocumentPropertiesSupplier; +import com.sun.star.document.XDocumentProperties; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLMetaImporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::XImporter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::ImportFilter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLMetaImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Draw document destroyed. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLMetaImporter</code><p> + * + * The draw document is set as a target document for importer. + * Imported XML-data contains only meta tags including + * title tag with test name. + * After import title name getting from target document is checked. + * Object relations created : + * <ul> + * <li> <code>'XDocumentHandler.XMLData'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'XDocumentHandler.ImportChecker'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'TargetDocument'</code> for + * {@link ifc.document._XImporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam,PrintWriter log ) throws Exception { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + oInt = xMSF.createInstance("com.sun.star.comp.Draw.XMLMetaImporter") ; + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + final String impTitle = "XMLMetaImporter" ; + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-meta", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta", + "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/" + }, + {"start", "office:meta"}, + {"start", "dc:title"}, + {"chars", impTitle}, + {"end", "dc:title"}, + {"end", "office:meta"}, + {"end", "office:document-meta"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + //set some meta data + XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface + (XDocumentPropertiesSupplier.class, xDrawDoc); + final XDocumentProperties xDocProps = xPropSup.getDocumentProperties(); + final PrintWriter logF = log ; + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + String title = xDocProps.getTitle(); + logF.println("Title returned = '" + title + "'") ; + return impTitle.equals(title) ; + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java new file mode 100644 index 000000000..261852b8e --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsExporter.java @@ -0,0 +1,189 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.document.XExporter; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLOasisSettingsExporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::ExportFilter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::XExporter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLSettingsExporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Document disposed here. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>om.sun.star.comp.Draw.XMLSettingsExporter</code> with + * argument which is an implementation of <code>XDocumentHandler</code> + * and which can check if required tags and character data is + * exported. <p> + * The draw document is set as a source document for exporter + * created. Property 'IsLayerMode' set to true. + * This made for checking if this property is successfully exported within + * the document styles information. + * Object relations created : + * <ul> + * <li> <code>'MediaDescriptor'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'XFilter.Checker'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'SourceDocument'</code> for + * {@link ifc.document._XExporter} interface </li> + * </ul> + */ + @Override + protected TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) throws Exception { + + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLOasisSettingsExporter", + new Object[] {arg}); + XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj); + xEx.setSourceDocument(xDrawDoc); + + //set some settings + XModel xDrawModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc); + XController xController = xDrawModel.getCurrentController(); + XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController); + xPropSet.setPropertyValue("IsLayerMode", Boolean.TRUE); + + // Checking Head Tag existence and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-settings")); + filter.addTagEnclosed( + new XMLTools.Tag ("office:settings"), + new XMLTools.Tag ("office:document-settings") ); + filter.addTagEnclosed( + new XMLTools.Tag ("config:config-item-set"), + new XMLTools.Tag ("office:settings") ); + filter.addTagEnclosed( + new XMLTools.Tag ("config:config-item-map-indexed"), + new XMLTools.Tag ("config:config-item-set") ); + filter.addCharactersEnclosed( "true", + new XMLTools.Tag( "config:config-item", + "config:name", + "IsLayerMode" )); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument", xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to <code>XFilter</code> interface test. All + * the information about errors occurred in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + private class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + private FilterChecker(PrintWriter log) { + super(log, false) ; + } + + /** + * <code>_XFilter.FilterChecker</code> interface method + * which returns the result of XML checking. + * @return <code>true</code> if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * <code>false</code> if some errors occurred. + */ + public boolean checkFilter() { + return check(); + } + } +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java new file mode 100644 index 000000000..ec6d5625d --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java @@ -0,0 +1,178 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.frame.XController; +import com.sun.star.frame.XModel; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::XImporter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::ImportFilter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLSettingsImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Text draw destroyed. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code><p> + * + * The draw document is set as a target document for importer. + * Imported XML-data contains only settings tags including + * tag with property 'IsLayerMode'. + * After import property 'IsLayerMode' getting from target + * document is checked. + * Object relations created : + * <ul> + * <li> <code>'XDocumentHandler.XMLData'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'XDocumentHandler.ImportChecker'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'TargetDocument'</code> for + * {@link ifc.document._XImporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log) throws Exception { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLSettingsImporter") ; + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-settings", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:config", "CDATA", "http://openoffice.org/2001/config"}, + {"start", "office:settings"}, + {"start", "config:config-item-set", + "config:name", "CDATA", "view-settings"}, + {"start", "config:config-item-map-indexed", + "config:name", "CDATA", "Views"}, + {"start", "config:config-item-map-entry"}, + {"start", "config:config-item", + "config:name", "CDATA", "IsLayerMode", + "config:type", "CDATA", "boolean"}, + {"chars", "true"}, + {"end", "config:config-item"}, + {"end", "config:config-item-map-entry"}, + {"end", "config:config-item-map-indexed"}, + {"end", "config:config-item-set"}, + {"end", "office:settings"}, + {"end", "office:document-settings"} }; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml); + final PrintWriter logF = log; + XModel xDrawModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc); + XController xController = xDrawModel.getCurrentController(); + final XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController); + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + try { + Boolean value = (Boolean) + xPropSet.getPropertyValue("IsLayerMode"); + logF.println("'IsLayerMode' property value is '" + + value + "'"); + return value.booleanValue(); + } catch (com.sun.star.uno.Exception e) { + logF.println("Exception while checking import :") ; + e.printStackTrace(logF) ; + return false ; + } + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java new file mode 100644 index 000000000..2fbf238ca --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesExporter.java @@ -0,0 +1,193 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; +import util.XMLTools; + +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.document.XExporter; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyle; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.uno.Any; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.xml.sax.XDocumentHandler; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLOasisStylesExporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::ExportFilter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::XExporter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.ExportFilter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.XExporter + * @see com.sun.star.beans.XPropertySet + * @see ifc.lang._XInitialization + * @see ifc.document._ExportFilter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + */ +public class XMLStylesExporter extends TestCase { + XComponent xDrawDoc = null; + protected static int counter = 0; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Document disposed here. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing xDrawDoc " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLOasisStylesExporter</code> with + * argument which is an implementation of <code>XDocumentHandler</code> + * and which can check if required tags and character data is + * exported. <p> + * The draw document is set as a source document for exporter + * created. New style is added to the style family 'graphics' with unique name + * every time. This made for checking if this style is successfully exported + * within the document styles information. + * Object relations created : + * <ul> + * <li> <code>'MediaDescriptor'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'XFilter.Checker'</code> for + * {@link ifc.document._XFilter} interface </li> + * <li> <code>'SourceDocument'</code> for + * {@link ifc.document._XExporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment( + TestParameters tParam, PrintWriter log) throws Exception { + + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() ); + XMultiServiceFactory xMSF = tParam.getMSF() ; + XInterface oObj = null; + FilterChecker filter = new FilterChecker(log) ; + Any arg = new Any(new Type(XDocumentHandler.class),filter); + final String STYLE_NAME = "New style" + counter++ ; + + oObj = (XInterface) xMSF.createInstanceWithArguments( + "com.sun.star.comp.Draw.XMLOasisStylesExporter", new Object[] {arg}); + XExporter xEx = UnoRuntime.queryInterface(XExporter.class,oObj); + xEx.setSourceDocument(xDrawDoc); + + //obtain style families + XStyleFamiliesSupplier styleSup = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xDrawDoc); + XNameAccess StyleFamilies = styleSup.getStyleFamilies(); + //obtain all style family names + String[] styleFamiliesNames = StyleFamilies.getElementNames(); + String styleFamilyName = styleFamiliesNames[0]; + //obtain style family with name[0] + Object objectStyle = StyleFamilies.getByName(styleFamilyName); + XNameContainer xStyleFamilyName = UnoRuntime.queryInterface(XNameContainer.class, objectStyle); + //create new style + Object SC = SOF.createInstance(xDrawDoc, "com.sun.star.style.Style"); + XStyle Style = UnoRuntime.queryInterface(XStyle.class,SC); + //add new style to style family with name[0] + xStyleFamilyName.insertByName(STYLE_NAME,Style); + + // Checking Head Tag existence and that property has changed + filter.addTag(new XMLTools.Tag ("office:document-styles")); + filter.addTag(new XMLTools.Tag ("office:styles")); + filter.addTagEnclosed( + new XMLTools.Tag("style:style"), + new XMLTools.Tag("office:styles") ); + filter.addTag(new XMLTools.Tag("style:style", "style:name", STYLE_NAME)); + + // create testobject here + log.println( "creating a new environment" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( + new String[] {"FilterName"}, + new Object[] {"sdraw: StarOffice XML (Draw)"})); + tEnv.addObjRelation("SourceDocument",xDrawDoc); + tEnv.addObjRelation("XFilter.Checker", filter); + return tEnv; + } + + /** + * This class checks the XML for tags and data required and returns + * checking result to <code>XFilter</code> interface test. All + * the information about errors occurred in XML data is written + * to log specified. + * @see ifc.document._XFilter + */ + private class FilterChecker extends XMLTools.XMLChecker + implements ifc.document._XFilter.FilterChecker { + + /** + * Creates a class which will write information + * into log specified. + */ + private FilterChecker(PrintWriter log) { + super(log, false) ; + } + + /** + * <code>_XFilter.FilterChecker</code> interface method + * which returns the result of XML checking. + * @return <code>true</code> if the XML data exported was + * valid (i.e. all necessary tags and character data exists), + * <code>false</code> if some errors occurred. + */ + public boolean checkFilter() { + return check(); + } + } +} + diff --git a/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java new file mode 100644 index 000000000..63dae1c1b --- /dev/null +++ b/qadevOOo/tests/java/mod/_xmloff/Draw/XMLStylesImporter.java @@ -0,0 +1,176 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package mod._xmloff.Draw; + +import java.io.PrintWriter; + +import lib.TestCase; +import lib.TestEnvironment; +import lib.TestParameters; +import util.SOfficeFactory; + +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +/** + * Test for object which is represented by service + * <code>com.sun.star.comp.Draw.XMLStylesImporter</code>. <p> + * Object implements the following interfaces : + * <ul> + * <li><code>com::sun::star::lang::XInitialization</code></li> + * <li><code>com::sun::star::document::XImporter</code></li> + * <li><code>com::sun::star::document::XFilter</code></li> + * <li><code>com::sun::star::document::ImportFilter</code></li> + * <li><code>com::sun::star::beans::XPropertySet</code></li> + * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> + * </ul> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.document.XImporter + * @see com.sun.star.document.XFilter + * @see com.sun.star.document.ImportFilter + * @see com.sun.star.beans.XPropertySet + * @see com.sun.star.xml.sax.XDocumentHandler + * @see ifc.lang._XInitialization + * @see ifc.document._XImporter + * @see ifc.document._XFilter + * @see ifc.document._XExporter + * @see ifc.beans._XPropertySet + * @see ifc.xml.sax._XDocumentHandler + */ +public class XMLStylesImporter extends TestCase { + XComponent xDrawDoc = null; + + /** + * New draw document created. + */ + @Override + protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception { + + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF()); + + log.println( "creating a drawdocument" ); + xDrawDoc = SOF.createDrawDoc(null); + } + + /** + * Text draw destroyed. + */ + @Override + protected void cleanup( TestParameters tParam, PrintWriter log ) { + log.println( " disposing document " ); + xDrawDoc.dispose(); + } + + /** + * Creating a TestEnvironment for the interfaces to be tested. + * Creates an instance of the service + * <code>com.sun.star.comp.Draw.XMLStylesImporter</code><p> + * + * The draw document is set as a target document for importer. + * Imported XML-data contains only styles tags including + * tag with new style. + * After import checked existing of this new style in style + * collection obtained from target document. + * Object relations created : + * <ul> + * <li> <code>'XDocumentHandler.XMLData'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'XDocumentHandler.ImportChecker'</code> for + * {@link ifc.xml.sax._XDocumentHandler} interface </li> + * <li> <code>'TargetDocument'</code> for + * {@link ifc.document._XImporter} interface </li> + * </ul> + */ + @Override + public TestEnvironment createTestEnvironment + (TestParameters tParam, PrintWriter log ) throws Exception { + + XInterface oObj = null; + Object oInt = null ; + + // creation of testobject here + // first we write what we are intend to do to log file + log.println( "creating a test environment" ); + + XMultiServiceFactory xMSF = tParam.getMSF() ; + + oInt = xMSF.createInstance + ("com.sun.star.comp.Draw.XMLStylesImporter") ; + + oObj = (XInterface) oInt ; + + // create testobject here + log.println( "creating a new environment for Paragraph object" ); + TestEnvironment tEnv = new TestEnvironment( oObj ); + + // adding relation + tEnv.addObjRelation("TargetDocument", xDrawDoc) ; + + final String impStyleName = "New style for test XMLStylesImporter"; + final String impFamilyName = "graphics"; + // adding relation for XDocumentHandler + String[][] xml = new String[][] { + {"start", "office:document-styles", + "xmlns:office", "CDATA", "http://openoffice.org/2000/office", + "xmlns:style", "CDATA", "http://openoffice.org/2000/style"}, + {"start", "office:styles"}, + {"start", "style:style", + "style:name", "CDATA", impStyleName, + "style:family", "CDATA", impFamilyName}, + {"end", "style:style"}, + {"end", "office:styles"}, + {"end", "office:document"}} ; + + tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; + + final PrintWriter logF = log; + //obtain style families + XStyleFamiliesSupplier styleSup = UnoRuntime.queryInterface (XStyleFamiliesSupplier.class, xDrawDoc) ; + final XNameAccess StyleFamilies = styleSup.getStyleFamilies(); + + tEnv.addObjRelation("XDocumentHandler.ImportChecker", + new ifc.xml.sax._XDocumentHandler.ImportChecker() { + public boolean checkImport() { + try { + Object objectStyle = + StyleFamilies.getByName(impFamilyName); + XNameContainer StyleFamilyName = UnoRuntime.queryInterface + (XNameContainer.class, objectStyle); + boolean hasStyle = + StyleFamilyName.hasByName(impStyleName); + logF.println("Does style with name '" + impStyleName + + "' exist? " + hasStyle ); + return hasStyle; + } catch (com.sun.star.uno.Exception e) { + logF.println("Exception while checking import :") ; + e.printStackTrace(logF) ; + return false ; + } + } + }) ; + + return tEnv; + } // finish method getTestEnvironment +} |