xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScHeaderFooterContentObj.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.container.XNameAccess;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sheet.XHeaderFooterContent;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.style.XStyle;
45 import com.sun.star.style.XStyleFamiliesSupplier;
46 import com.sun.star.text.XText;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 
52 /**
53 * Test for object which is represented by service
54 * <code>com.sun.star.sheet.HeaderFooterContent</code>. <p>
55 * Object implements the following interfaces :
56 * <ul>
57 *  <li> <code>com::sun::star::sheet::XHeaderFooterContent</code></li>
58 * </ul>
59 * @see com.sun.star.sheet.HeaderFooterContent
60 * @see com.sun.star.sheet.XHeaderFooterContent
61 * @see ifc.sheet._XHeaderFooterContent
62 */
63 public class ScHeaderFooterContentObj extends TestCase {
64     static XSpreadsheetDocument xSpreadsheetDoc;
65 
66     /**
67     * Creates Spreadsheet document.
68     */
69     protected void initialize( TestParameters tParam, PrintWriter log ) {
70         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
71 
72         try {
73             log.println( "creating a Spreadsheet document" );
74             xSpreadsheetDoc = SOF.createCalcDoc(null);
75         } catch ( com.sun.star.uno.Exception e ) {
76             // Some exception occures.FAILED
77             e.printStackTrace( log );
78             throw new StatusException( "Couldn't create document", e );
79         }
80 
81     }
82 
83     /**
84     * Disposes Spreadsheet document.
85     */
86     protected void cleanup( TestParameters tParam, PrintWriter log ) {
87         log.println( "    disposing xSheetDoc " );
88         XComponent oComp = (XComponent)
89             UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
90         util.DesktopTools.closeDoc(oComp);
91     }
92 
93     /**
94     * Creating a Testenvironment for the interfaces to be tested.
95     * Retrieves the collection of style families available in the document
96     * using the interface <code>XStyleFamiliesSupplier</code>.
97     * Obtains default style from the style family <code>'PageStyles'</code>.
98     * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
99     * Sets some text for every part of header or footer using the interface
100     * <code>XHeaderFooterContent</code> and sets new value of the property
101     * <code>'RightPageHeaderContent'</code>. The value of this property is the
102     * instance of the service <code>com.sun.star.sheet.HeaderFooterContent</code>.
103     * @see com.sun.star.style.XStyleFamiliesSupplier
104     * @see com.sun.star.sheet.XHeaderFooterContent
105     * @see com.sun.star.sheet.HeaderFooterContent
106     */
107     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
108 
109         XInterface oObj = null;
110         XPropertySet PropSet;
111         XNameAccess PageStyles = null;
112         XStyle StdStyle = null;
113 
114         XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
115             UnoRuntime.queryInterface(
116                 XStyleFamiliesSupplier.class,
117                 xSpreadsheetDoc );
118         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
119         try{
120             PageStyles = (XNameAccess) AnyConverter.toObject(
121                 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
122             StdStyle = (XStyle) AnyConverter.toObject(
123                         new Type(XStyle.class),PageStyles.getByName("Default"));
124         } catch(com.sun.star.lang.WrappedTargetException e){
125             e.printStackTrace(log);
126             throw new StatusException("Couldn't get by name", e);
127         } catch(com.sun.star.container.NoSuchElementException e){
128             e.printStackTrace(log);
129             throw new StatusException("Couldn't get by name", e);
130         } catch(com.sun.star.lang.IllegalArgumentException e){
131             e.printStackTrace(log);
132             throw new StatusException("Couldn't get by name", e);
133         }
134 
135         //get the property-set
136         PropSet = (XPropertySet)
137             UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
138 
139         XHeaderFooterContent RPHC = null;
140         // creation of testobject here
141         // first we write what we are intend to do to log file
142         log.println( "creating a test environment" );
143         try {
144             RPHC = (XHeaderFooterContent) AnyConverter.toObject(
145                 new Type(XHeaderFooterContent.class),
146                     PropSet.getPropertyValue("RightPageHeaderContent"));
147         } catch(com.sun.star.lang.WrappedTargetException e){
148             e.printStackTrace(log);
149             throw new StatusException("Couldn't get HeaderContent", e);
150         } catch(com.sun.star.beans.UnknownPropertyException e){
151             e.printStackTrace(log);
152             throw new StatusException("Couldn't get HeaderContent", e);
153         } catch(com.sun.star.lang.IllegalArgumentException e){
154             e.printStackTrace(log);
155             throw new StatusException("Couldn't get HeaderContent", e);
156         }
157 
158         XText center = RPHC.getCenterText();
159         XText left = RPHC.getLeftText();
160         XText right = RPHC.getRightText();
161 
162         center.setString("CENTER");
163         left.setString("LEFT");
164         right.setString("RIGHT");
165 
166         try {
167             PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
168         } catch (com.sun.star.lang.WrappedTargetException e) {
169             e.printStackTrace(log);
170             throw new StatusException("Couldn't set HeaderContent", e);
171         } catch (com.sun.star.lang.IllegalArgumentException e) {
172             e.printStackTrace(log);
173             throw new StatusException("Couldn't set HeaderContent", e);
174         } catch (com.sun.star.beans.PropertyVetoException e) {
175             e.printStackTrace(log);
176             throw new StatusException("Couldn't set HeaderContent", e);
177         } catch (com.sun.star.beans.UnknownPropertyException e) {
178             e.printStackTrace(log);
179             throw new StatusException("Couldn't set HeaderContent", e);
180         }
181 
182         // create testobject here
183         oObj = RPHC;
184         TestEnvironment tEnv = new TestEnvironment(oObj);
185 
186         return tEnv;
187 
188     } // finish method getTestEnvironment
189 
190 }    // finish class ScHeaderFooterContentObj
191