Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFieldsObj.java
blob945b607cde79607b2aed9519583182dc40e71cc2
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._sc;
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.beans.XPropertySet;
29 import com.sun.star.container.XNameAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XHeaderFooterContent;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.style.XStyle;
35 import com.sun.star.style.XStyleFamiliesSupplier;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextFieldsSupplier;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by collection of
47 * text fields contained in the text of a page header. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
52 * <li> <code>com::sun::star::util::XRefreshable</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * </ul> <p>
56 * @see com.sun.star.container.XEnumerationAccess
57 * @see com.sun.star.util.XRefreshable
58 * @see com.sun.star.container.XElementAccess
59 * @see ifc.container._XEnumerationAccess
60 * @see ifc.util._XRefreshable
61 * @see ifc.container._XElementAccess
63 public class ScHeaderFieldsObj extends TestCase {
64 private XSpreadsheetDocument xSpreadsheetDoc;
66 /**
67 * Creates Spreadsheet document.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
72 log.println( "creating a Spreadsheet document" );
73 xSpreadsheetDoc = SOF.createCalcDoc(null);
76 /**
77 * Disposes Spreadsheet document.
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xSheetDoc " );
82 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
83 util.DesktopTools.closeDoc(oComp);
86 /**
87 * Creating a TestEnvironment for the interfaces to be tested.
88 * Retrieves the collection of style families available in the document
89 * using the interface <code>XStyleFamiliesSupplier</code>.
90 * Obtains default style from the style family <code>'PageStyles'</code>.
91 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
92 * using the property <code>'RightPageHeaderContent'</code>. Creates the
93 * instance of the service <code>com.sun.star.text.TextField.Time</code> .
94 * Obtains the text (the interface <code>XText</code>) which is printed in
95 * the left part of the header or footer and inserts in its content
96 * the created field instance. Then the tested component is obtained
97 * through <code>XTextFieldsSupplier</code> interface of a text.
99 * @see com.sun.star.style.XStyleFamiliesSupplier
100 * @see com.sun.star.sheet.XHeaderFooterContent
101 * @see com.sun.star.text.XText
102 * @see com.sun.star.text.XTextContent
104 @Override
105 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
107 XInterface oObj = null;
108 XPropertySet PropSet;
109 XNameAccess PageStyles = null;
110 XStyle StdStyle = null;
112 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
113 xSpreadsheetDoc );
115 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
116 PageStyles = (XNameAccess) AnyConverter.toObject(
117 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
118 StdStyle = (XStyle) AnyConverter.toObject(
119 new Type(XStyle.class),PageStyles.getByName("Default"));
121 //get the property-set
122 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
124 XHeaderFooterContent RPHC = null;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log.println( "creating a test environment" );
128 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
129 new Type(XHeaderFooterContent.class),
130 PropSet.getPropertyValue("RightPageHeaderContent"));
132 XText left = RPHC.getLeftText();
134 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(
135 XMultiServiceFactory.class,
136 xSpreadsheetDoc );
138 XTextContent the_Field = null;
139 oObj = (XInterface)
140 oDocMSF.createInstance( "com.sun.star.text.TextField.Time" );
142 the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
144 XTextCursor the_Cursor = left.createTextCursor();
146 left.insertTextContent(the_Cursor,the_Field, false);
147 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
149 XTextFieldsSupplier xTFSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, left);
151 oObj = xTFSupp.getTextFields();
153 TestEnvironment tEnv = new TestEnvironment(oObj);
155 return tEnv;
156 } // finish method getTestEnvironment