merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / table / _XAutoFormattable.java
blob3250d28c912c10a6559f1a3acd6754c53855e84d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAutoFormattable.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.table;
32 import java.util.Random;
34 import lib.MultiMethodTest;
36 import com.sun.star.beans.XPropertySet;
37 import com.sun.star.container.XNameAccess;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.table.XAutoFormattable;
40 import com.sun.star.table.XCell;
41 import com.sun.star.table.XCellRange;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
46 /**
47 * Testing <code>com.sun.star.table.XAutoFormattable</code>
48 * interface methods :
49 * <ul>
50 * <li><code> autoFormat()</code></li>
51 * </ul> <p>
52 * The component tested <b>must implement</b> interface
53 * <code>com.sun.star.table.XCellRange</code>. <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.table.XAutoFormattable
57 public class _XAutoFormattable extends MultiMethodTest {
58 public XAutoFormattable oObj = null;
60 /**
61 * First 'Default' autoformat is set and a background of a cell
62 * is obtained. Then any other autoformat is set and background
63 * of a cell is obtained again.<p>
64 * Has <b> OK </b> status if backgrounds with different autoformat
65 * settings are differ. <p>
67 public void _autoFormat() {
68 boolean bResult = true;
69 XMultiServiceFactory oMSF = (XMultiServiceFactory) tParam.getMSF();
70 String name = "Default";
72 try {
73 oObj.autoFormat(name); // applying default format
75 // getting current background of the cell
76 XCellRange cellRange = (XCellRange) UnoRuntime.queryInterface(
77 XCellRange.class, oObj);
78 XCell oCell = cellRange.getCellByPosition(0, 0);
79 XPropertySet PS = (XPropertySet) UnoRuntime.queryInterface(
80 XPropertySet.class, oCell);
82 Integer bkgrnd1;
83 try {
84 bkgrnd1 = (Integer) PS.getPropertyValue("CellBackColor");
85 } catch (com.sun.star.beans.UnknownPropertyException e) {
86 bkgrnd1 = (Integer) PS.getPropertyValue("BackColor");
89 // getting formats names.
90 XInterface iFormats = (XInterface) oMSF.createInstance(
91 "com.sun.star.sheet.TableAutoFormats");
92 XNameAccess formats = (XNameAccess) UnoRuntime.queryInterface(
93 XNameAccess.class, iFormats);
94 String[] names = formats.getElementNames();
96 // getting one random not default style name
97 Random rnd = new Random();
99 if (names.length > 1) {
100 while (name.equals("Default")) {
101 name = names[rnd.nextInt(names.length)];
103 } else {
104 name = names[0];
107 log.println("Applying style " + name);
110 // applying style
111 oObj.autoFormat(name);
113 // getting new cell's backround.
114 Integer bkgrnd2;
115 try {
116 bkgrnd2 = (Integer) PS.getPropertyValue("CellBackColor");
117 } catch (com.sun.star.beans.UnknownPropertyException e) {
118 bkgrnd2 = (Integer) PS.getPropertyValue("BackColor");
121 bResult &= !bkgrnd1.equals(bkgrnd2);
122 } catch (com.sun.star.uno.Exception e) {
123 log.println("Exception occured :");
124 e.printStackTrace(log);
125 bResult = false;
128 tRes.tested("autoFormat()", bResult);
132 * Forces environment recreation.
134 protected void after() {
135 disposeEnvironment();