1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sc; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.SOfficeFactory; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 35cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 36cdf0e10cSrcweir import com.sun.star.lang.XComponent; 37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 38cdf0e10cSrcweir import com.sun.star.sheet.XHeaderFooterContent; 39cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 40cdf0e10cSrcweir import com.sun.star.style.XStyle; 41cdf0e10cSrcweir import com.sun.star.style.XStyleFamiliesSupplier; 42cdf0e10cSrcweir import com.sun.star.text.XText; 43cdf0e10cSrcweir import com.sun.star.text.XTextContent; 44cdf0e10cSrcweir import com.sun.star.text.XTextCursor; 45cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 46cdf0e10cSrcweir import com.sun.star.uno.Type; 47cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 48cdf0e10cSrcweir import com.sun.star.uno.XInterface; 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** 51cdf0e10cSrcweir * Test for object which is represented by service 52cdf0e10cSrcweir * <code>com.sun.star.text.TextField</code>. <p> 53cdf0e10cSrcweir * Object implements the following interfaces : 54cdf0e10cSrcweir * <ul> 55cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextField</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::text::XTextContent</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::text::TextContent</code></li> 60cdf0e10cSrcweir * </ul> 61cdf0e10cSrcweir * @see com.sun.star.text.TextField 62cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 63cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 64cdf0e10cSrcweir * @see com.sun.star.text.XTextField 65cdf0e10cSrcweir * @see com.sun.star.text.XTextContent 66cdf0e10cSrcweir * @see com.sun.star.text.TextContent 67cdf0e10cSrcweir * @see ifc.lang._XComponent 68cdf0e10cSrcweir * @see ifc.beans._XPropertySet 69cdf0e10cSrcweir * @see ifc.text._XTextField 70cdf0e10cSrcweir * @see ifc.text._XTextContent 71cdf0e10cSrcweir * @see ifc.text._TextContent 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir public class ScHeaderFieldObj extends TestCase { 74cdf0e10cSrcweir static XSpreadsheetDocument xSpreadsheetDoc; 75cdf0e10cSrcweir 76cdf0e10cSrcweir /** 77cdf0e10cSrcweir * Creates Spreadsheet document. 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 80cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir try { 83cdf0e10cSrcweir log.println( "creating a Spreadsheet document" ); 84cdf0e10cSrcweir xSpreadsheetDoc = SOF.createCalcDoc(null); 85cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 86*30acf5e8Spfg // Some exception occured.FAILED 87cdf0e10cSrcweir e.printStackTrace( log ); 88cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** 94cdf0e10cSrcweir * Disposes Spreadsheet document. 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 97cdf0e10cSrcweir log.println( " disposing xSheetDoc " ); 98cdf0e10cSrcweir XComponent oComp = (XComponent) 99cdf0e10cSrcweir UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc); 100cdf0e10cSrcweir util.DesktopTools.closeDoc(oComp); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** 104cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 105cdf0e10cSrcweir * Retrieves the collection of style families available in the document 106cdf0e10cSrcweir * using the interface <code>XStyleFamiliesSupplier</code>. 107cdf0e10cSrcweir * Obtains default style from the style family <code>'PageStyles'</code>. 108cdf0e10cSrcweir * Retrieves the interface <code>XHeaderFooterContent</code> from the style 109cdf0e10cSrcweir * using the property <code>'RightPageHeaderContent'</code>. Creates the 110cdf0e10cSrcweir * instance of the service <code>com.sun.star.text.TextField.Time</code> and 111cdf0e10cSrcweir * the instance of the service <code>com.sun.star.text.TextField.Date</code> 112cdf0e10cSrcweir * Obtains the text (the interface <code>XText</code>) which is printed in 113cdf0e10cSrcweir * the left part of the header or footer and inserts in it's content 114cdf0e10cSrcweir * the second created instance. 115cdf0e10cSrcweir * Object relations created : 116cdf0e10cSrcweir * <ul> 117cdf0e10cSrcweir * <li> <code>'CONTENT'</code> for 118cdf0e10cSrcweir * {@link ifc.text._XTextContent}(the interface <code>XTextContent</code> 119cdf0e10cSrcweir * that was queried from the second created instance) </li> 120cdf0e10cSrcweir * <li> <code>'TEXT'</code> for 121cdf0e10cSrcweir * {@link ifc.text._XTextContent}(the the text which is printed in the 122cdf0e10cSrcweir * right part of the header or footer) </li> 123cdf0e10cSrcweir * </ul> 124cdf0e10cSrcweir * @see com.sun.star.style.XStyleFamiliesSupplier 125cdf0e10cSrcweir * @see com.sun.star.sheet.XHeaderFooterContent 126cdf0e10cSrcweir * @see com.sun.star.text.XText 127cdf0e10cSrcweir * @see com.sun.star.text.XTextContent 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 130cdf0e10cSrcweir 131cdf0e10cSrcweir XInterface oObj = null; 132cdf0e10cSrcweir XPropertySet PropSet; 133cdf0e10cSrcweir XNameAccess PageStyles = null; 134cdf0e10cSrcweir XStyle StdStyle = null; 135cdf0e10cSrcweir XTextContent oContent = null; 136cdf0e10cSrcweir XInterface aField = null; 137cdf0e10cSrcweir 138cdf0e10cSrcweir XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier) 139cdf0e10cSrcweir UnoRuntime.queryInterface( 140cdf0e10cSrcweir XStyleFamiliesSupplier.class, 141cdf0e10cSrcweir xSpreadsheetDoc ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); 144cdf0e10cSrcweir try{ 145cdf0e10cSrcweir PageStyles = (XNameAccess) AnyConverter.toObject( 146cdf0e10cSrcweir new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles")); 147cdf0e10cSrcweir StdStyle = (XStyle) AnyConverter.toObject( 148cdf0e10cSrcweir new Type(XStyle.class),PageStyles.getByName("Default")); 149cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e){ 150cdf0e10cSrcweir e.printStackTrace(log); 151cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 152cdf0e10cSrcweir } catch(com.sun.star.container.NoSuchElementException e){ 153cdf0e10cSrcweir e.printStackTrace(log); 154cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 155cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e){ 156cdf0e10cSrcweir e.printStackTrace(log); 157cdf0e10cSrcweir throw new StatusException("Couldn't get by name", e); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //get the property-set 161cdf0e10cSrcweir PropSet = (XPropertySet) 162cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, StdStyle); 163cdf0e10cSrcweir 164cdf0e10cSrcweir XHeaderFooterContent RPHC = null; 165cdf0e10cSrcweir // creation of testobject here 166cdf0e10cSrcweir // first we write what we are intend to do to log file 167cdf0e10cSrcweir log.println( "creating a test environment" ); 168cdf0e10cSrcweir try { 169cdf0e10cSrcweir RPHC = (XHeaderFooterContent) AnyConverter.toObject( 170cdf0e10cSrcweir new Type(XHeaderFooterContent.class), 171cdf0e10cSrcweir PropSet.getPropertyValue("RightPageHeaderContent")); 172cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 173cdf0e10cSrcweir e.printStackTrace(log); 174cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 175cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 176cdf0e10cSrcweir e.printStackTrace(log); 177cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 178cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 179cdf0e10cSrcweir e.printStackTrace(log); 180cdf0e10cSrcweir throw new StatusException("Couldn't get HeaderContent", e); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir XText left = RPHC.getLeftText(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 186cdf0e10cSrcweir UnoRuntime.queryInterface( 187cdf0e10cSrcweir XMultiServiceFactory.class, 188cdf0e10cSrcweir xSpreadsheetDoc ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir XTextContent the_Field = null; 191cdf0e10cSrcweir try { 192cdf0e10cSrcweir oObj = (XInterface) 193cdf0e10cSrcweir oDocMSF.createInstance( "com.sun.star.text.TextField.Time" ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir the_Field = (XTextContent) 196cdf0e10cSrcweir UnoRuntime.queryInterface(XTextContent.class,oObj); 197cdf0e10cSrcweir 198cdf0e10cSrcweir aField = (XInterface) 199cdf0e10cSrcweir oDocMSF.createInstance("com.sun.star.text.TextField.Date"); 200cdf0e10cSrcweir } catch(com.sun.star.uno.Exception e) { 201cdf0e10cSrcweir e.printStackTrace(log); 202cdf0e10cSrcweir throw new StatusException("Couldn't create instance", e); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir oContent = (XTextContent) 206cdf0e10cSrcweir UnoRuntime.queryInterface(XTextContent.class, aField); 207cdf0e10cSrcweir 208cdf0e10cSrcweir XTextCursor the_Cursor = left.createTextCursor(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir try { 211cdf0e10cSrcweir left.insertTextContent(the_Cursor,the_Field, false); 212cdf0e10cSrcweir PropSet.setPropertyValue("RightPageHeaderContent", RPHC); 213cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 214cdf0e10cSrcweir e.printStackTrace(log); 215cdf0e10cSrcweir throw new StatusException("Couldn't create a test environment", e); 216cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 217cdf0e10cSrcweir e.printStackTrace(log); 218cdf0e10cSrcweir throw new StatusException("Couldn't create a test environment", e); 219cdf0e10cSrcweir } catch(com.sun.star.beans.PropertyVetoException e) { 220cdf0e10cSrcweir e.printStackTrace(log); 221cdf0e10cSrcweir throw new StatusException("Couldn't create a test environment", e); 222cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 223cdf0e10cSrcweir e.printStackTrace(log); 224cdf0e10cSrcweir throw new StatusException("Couldn't create a test environment", e); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 228cdf0e10cSrcweir 229cdf0e10cSrcweir tEnv.addObjRelation("CONTENT",oContent); 230cdf0e10cSrcweir tEnv.addObjRelation("TEXT", RPHC.getRightText()); 231cdf0e10cSrcweir 232cdf0e10cSrcweir return tEnv; 233cdf0e10cSrcweir 234cdf0e10cSrcweir } // finish method getTestEnvironment 235cdf0e10cSrcweir 236cdf0e10cSrcweir } // finish class ScHeaderFieldObj 237cdf0e10cSrcweir 238