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 .
20 import java
.util
.Random
;
22 import lib
.MultiMethodTest
;
24 import com
.sun
.star
.beans
.XPropertySet
;
25 import com
.sun
.star
.container
.XNameAccess
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.table
.XAutoFormattable
;
28 import com
.sun
.star
.table
.XCell
;
29 import com
.sun
.star
.table
.XCellRange
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
31 import com
.sun
.star
.uno
.XInterface
;
35 * Testing <code>com.sun.star.table.XAutoFormattable</code>
38 * <li><code> autoFormat()</code></li>
40 * The component tested <b>must implement</b> interface
41 * <code>com.sun.star.table.XCellRange</code>. <p>
42 * Test is <b> NOT </b> multithread compliant. <p>
43 * @see com.sun.star.table.XAutoFormattable
45 public class _XAutoFormattable
extends MultiMethodTest
{
46 public XAutoFormattable oObj
= null;
47 public Random rnd
= new Random();
50 * First 'Default' autoformat is set and a background of a cell
51 * is obtained. Then any other autoformat is set and background
52 * of a cell is obtained again.<p>
53 * Has <b> OK </b> status if backgrounds with different autoformat
54 * settings are differ. <p>
56 public void _autoFormat() {
57 boolean bResult
= true;
58 XMultiServiceFactory oMSF
= tParam
.getMSF();
59 String name
= "Default";
62 oObj
.autoFormat(name
); // applying default format
64 // getting current background of the cell
65 XCellRange cellRange
= UnoRuntime
.queryInterface(
66 XCellRange
.class, oObj
);
67 XCell oCell
= cellRange
.getCellByPosition(0, 0);
68 XPropertySet PS
= UnoRuntime
.queryInterface(
69 XPropertySet
.class, oCell
);
73 bkgrnd1
= (Integer
) PS
.getPropertyValue("CellBackColor");
74 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
75 bkgrnd1
= (Integer
) PS
.getPropertyValue("BackColor");
78 // getting formats names.
79 XInterface iFormats
= (XInterface
) oMSF
.createInstance(
80 "com.sun.star.sheet.TableAutoFormats");
81 XNameAccess formats
= UnoRuntime
.queryInterface(
82 XNameAccess
.class, iFormats
);
83 String
[] names
= formats
.getElementNames();
85 // getting one random not default style name
86 if (names
.length
> 1) {
87 while (name
.equals("Default")) {
88 name
= names
[rnd
.nextInt(names
.length
)];
94 log
.println("Applying style " + name
);
98 oObj
.autoFormat(name
);
100 // getting new cell's background.
103 bkgrnd2
= (Integer
) PS
.getPropertyValue("CellBackColor");
104 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
105 bkgrnd2
= (Integer
) PS
.getPropertyValue("BackColor");
108 bResult
&= !bkgrnd1
.equals(bkgrnd2
);
109 } catch (com
.sun
.star
.uno
.Exception e
) {
110 log
.println("Exception occurred :");
111 e
.printStackTrace(log
);
115 tRes
.tested("autoFormat()", bResult
);
119 * Forces environment recreation.
122 protected void after() {
123 disposeEnvironment();