bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFooterContentObj.java
blob9cab5f527ca146387c614e890554a487bb673f83
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XHeaderFooterContent;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.style.XStyle;
36 import com.sun.star.style.XStyleFamiliesSupplier;
37 import com.sun.star.text.XText;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.sheet.HeaderFooterContent</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::sheet::XHeaderFooterContent</code></li>
49 * </ul>
50 * @see com.sun.star.sheet.HeaderFooterContent
51 * @see com.sun.star.sheet.XHeaderFooterContent
52 * @see ifc.sheet._XHeaderFooterContent
54 public class ScHeaderFooterContentObj extends TestCase {
55 private XSpreadsheetDocument xSpreadsheetDoc;
57 /**
58 * Creates Spreadsheet document.
60 protected void initialize( TestParameters tParam, PrintWriter log ) {
61 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
63 try {
64 log.println( "creating a Spreadsheet document" );
65 xSpreadsheetDoc = SOF.createCalcDoc(null);
66 } catch ( com.sun.star.uno.Exception e ) {
67 // Some exception occurs.FAILED
68 e.printStackTrace( log );
69 throw new StatusException( "Couldn't create document", e );
74 /**
75 * Disposes Spreadsheet document.
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xSheetDoc " );
79 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
80 util.DesktopTools.closeDoc(oComp);
83 /**
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Retrieves the collection of style families available in the document
86 * using the interface <code>XStyleFamiliesSupplier</code>.
87 * Obtains default style from the style family <code>'PageStyles'</code>.
88 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
89 * Sets some text for every part of header or footer using the interface
90 * <code>XHeaderFooterContent</code> and sets new value of the property
91 * <code>'RightPageHeaderContent'</code>. The value of this property is the
92 * instance of the service <code>com.sun.star.sheet.HeaderFooterContent</code>.
93 * @see com.sun.star.style.XStyleFamiliesSupplier
94 * @see com.sun.star.sheet.XHeaderFooterContent
95 * @see com.sun.star.sheet.HeaderFooterContent
97 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
99 XInterface oObj = null;
100 XPropertySet PropSet;
101 XNameAccess PageStyles = null;
102 XStyle StdStyle = null;
104 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(
105 XStyleFamiliesSupplier.class,
106 xSpreadsheetDoc );
107 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
108 try{
109 PageStyles = (XNameAccess) AnyConverter.toObject(
110 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
111 StdStyle = (XStyle) AnyConverter.toObject(
112 new Type(XStyle.class),PageStyles.getByName("Default"));
113 } catch(com.sun.star.lang.WrappedTargetException e){
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't get by name", e);
116 } catch(com.sun.star.container.NoSuchElementException e){
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't get by name", e);
119 } catch(com.sun.star.lang.IllegalArgumentException e){
120 e.printStackTrace(log);
121 throw new StatusException("Couldn't get by name", e);
124 //get the property-set
125 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
127 XHeaderFooterContent RPHC = null;
128 // creation of testobject here
129 // first we write what we are intend to do to log file
130 log.println( "creating a test environment" );
131 try {
132 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
133 new Type(XHeaderFooterContent.class),
134 PropSet.getPropertyValue("RightPageHeaderContent"));
135 } catch(com.sun.star.lang.WrappedTargetException e){
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't get HeaderContent", e);
138 } catch(com.sun.star.beans.UnknownPropertyException e){
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't get HeaderContent", e);
141 } catch(com.sun.star.lang.IllegalArgumentException e){
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't get HeaderContent", e);
146 XText center = RPHC.getCenterText();
147 XText left = RPHC.getLeftText();
148 XText right = RPHC.getRightText();
150 center.setString("CENTER");
151 left.setString("LEFT");
152 right.setString("RIGHT");
154 try {
155 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
156 } catch (com.sun.star.lang.WrappedTargetException e) {
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't set HeaderContent", e);
159 } catch (com.sun.star.lang.IllegalArgumentException e) {
160 e.printStackTrace(log);
161 throw new StatusException("Couldn't set HeaderContent", e);
162 } catch (com.sun.star.beans.PropertyVetoException e) {
163 e.printStackTrace(log);
164 throw new StatusException("Couldn't set HeaderContent", e);
165 } catch (com.sun.star.beans.UnknownPropertyException e) {
166 e.printStackTrace(log);
167 throw new StatusException("Couldn't set HeaderContent", e);
170 // create testobject here
171 oObj = RPHC;
172 TestEnvironment tEnv = new TestEnvironment(oObj);
174 return tEnv;
176 } // finish method getTestEnvironment
178 } // finish class ScHeaderFooterContentObj