Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFooterContentObj.java
blob2fdb2b20ba5650a255eabd7b44bd144ec7da8ed2
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.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.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.sheet.HeaderFooterContent</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::sheet::XHeaderFooterContent</code></li>
48 * </ul>
49 * @see com.sun.star.sheet.HeaderFooterContent
50 * @see com.sun.star.sheet.XHeaderFooterContent
51 * @see ifc.sheet._XHeaderFooterContent
53 public class ScHeaderFooterContentObj extends TestCase {
54 private XSpreadsheetDocument xSpreadsheetDoc;
56 /**
57 * Creates Spreadsheet document.
59 @Override
60 protected void initialize( TestParameters tParam, PrintWriter log ) {
61 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
79 log.println( " disposing xSheetDoc " );
80 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
81 util.DesktopTools.closeDoc(oComp);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Retrieves the collection of style families available in the document
87 * using the interface <code>XStyleFamiliesSupplier</code>.
88 * Obtains default style from the style family <code>'PageStyles'</code>.
89 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
90 * Sets some text for every part of header or footer using the interface
91 * <code>XHeaderFooterContent</code> and sets new value of the property
92 * <code>'RightPageHeaderContent'</code>. The value of this property is the
93 * instance of the service <code>com.sun.star.sheet.HeaderFooterContent</code>.
94 * @see com.sun.star.style.XStyleFamiliesSupplier
95 * @see com.sun.star.sheet.XHeaderFooterContent
96 * @see com.sun.star.sheet.HeaderFooterContent
98 @Override
99 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
101 XInterface oObj = null;
102 XPropertySet PropSet;
103 XNameAccess PageStyles = null;
104 XStyle StdStyle = null;
106 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(
107 XStyleFamiliesSupplier.class,
108 xSpreadsheetDoc );
109 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
110 try{
111 PageStyles = (XNameAccess) AnyConverter.toObject(
112 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
113 StdStyle = (XStyle) AnyConverter.toObject(
114 new Type(XStyle.class),PageStyles.getByName("Default"));
115 } catch(com.sun.star.lang.WrappedTargetException e){
116 e.printStackTrace(log);
117 throw new StatusException("Couldn't get by name", e);
118 } catch(com.sun.star.container.NoSuchElementException e){
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't get by name", e);
121 } catch(com.sun.star.lang.IllegalArgumentException e){
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't get by name", e);
126 //get the property-set
127 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
129 XHeaderFooterContent RPHC = null;
130 // creation of testobject here
131 // first we write what we are intend to do to log file
132 log.println( "creating a test environment" );
133 try {
134 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
135 new Type(XHeaderFooterContent.class),
136 PropSet.getPropertyValue("RightPageHeaderContent"));
137 } catch(com.sun.star.lang.WrappedTargetException e){
138 e.printStackTrace(log);
139 throw new StatusException("Couldn't get HeaderContent", e);
140 } catch(com.sun.star.beans.UnknownPropertyException e){
141 e.printStackTrace(log);
142 throw new StatusException("Couldn't get HeaderContent", e);
143 } catch(com.sun.star.lang.IllegalArgumentException e){
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't get HeaderContent", e);
148 XText center = RPHC.getCenterText();
149 XText left = RPHC.getLeftText();
150 XText right = RPHC.getRightText();
152 center.setString("CENTER");
153 left.setString("LEFT");
154 right.setString("RIGHT");
156 try {
157 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
158 } catch (com.sun.star.lang.WrappedTargetException e) {
159 e.printStackTrace(log);
160 throw new StatusException("Couldn't set HeaderContent", e);
161 } catch (com.sun.star.lang.IllegalArgumentException e) {
162 e.printStackTrace(log);
163 throw new StatusException("Couldn't set HeaderContent", e);
164 } catch (com.sun.star.beans.PropertyVetoException e) {
165 e.printStackTrace(log);
166 throw new StatusException("Couldn't set HeaderContent", e);
167 } catch (com.sun.star.beans.UnknownPropertyException e) {
168 e.printStackTrace(log);
169 throw new StatusException("Couldn't set HeaderContent", e);
172 // create testobject here
173 oObj = RPHC;
174 TestEnvironment tEnv = new TestEnvironment(oObj);
176 return tEnv;
178 } // finish method getTestEnvironment
180 } // finish class ScHeaderFooterContentObj