Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / table / _XAutoFormattable.java
blob6473f17b738012645261eda891598b5a06f8b545
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 .
18 package ifc.table;
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;
34 /**
35 * Testing <code>com.sun.star.table.XAutoFormattable</code>
36 * interface methods :
37 * <ul>
38 * <li><code> autoFormat()</code></li>
39 * </ul> <p>
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;
48 /**
49 * First 'Default' autoformat is set and a background of a cell
50 * is obtained. Then any other autoformat is set and background
51 * of a cell is obtained again.<p>
52 * Has <b> OK </b> status if backgrounds with different autoformat
53 * settings are differ. <p>
55 public void _autoFormat() {
56 boolean bResult = true;
57 XMultiServiceFactory oMSF = tParam.getMSF();
58 String name = "Default";
60 try {
61 oObj.autoFormat(name); // applying default format
63 // getting current background of the cell
64 XCellRange cellRange = UnoRuntime.queryInterface(
65 XCellRange.class, oObj);
66 XCell oCell = cellRange.getCellByPosition(0, 0);
67 XPropertySet PS = UnoRuntime.queryInterface(
68 XPropertySet.class, oCell);
70 Integer bkgrnd1;
71 try {
72 bkgrnd1 = (Integer) PS.getPropertyValue("CellBackColor");
73 } catch (com.sun.star.beans.UnknownPropertyException e) {
74 bkgrnd1 = (Integer) PS.getPropertyValue("BackColor");
77 // getting formats names.
78 XInterface iFormats = (XInterface) oMSF.createInstance(
79 "com.sun.star.sheet.TableAutoFormats");
80 XNameAccess formats = UnoRuntime.queryInterface(
81 XNameAccess.class, iFormats);
82 String[] names = formats.getElementNames();
84 // getting one random not default style name
85 Random rnd = new Random();
87 if (names.length > 1) {
88 while (name.equals("Default")) {
89 name = names[rnd.nextInt(names.length)];
91 } else {
92 name = names[0];
95 log.println("Applying style " + name);
98 // applying style
99 oObj.autoFormat(name);
101 // getting new cell's background.
102 Integer bkgrnd2;
103 try {
104 bkgrnd2 = (Integer) PS.getPropertyValue("CellBackColor");
105 } catch (com.sun.star.beans.UnknownPropertyException e) {
106 bkgrnd2 = (Integer) PS.getPropertyValue("BackColor");
109 bResult &= !bkgrnd1.equals(bkgrnd2);
110 } catch (com.sun.star.uno.Exception e) {
111 log.println("Exception occurred :");
112 e.printStackTrace(log);
113 bResult = false;
116 tRes.tested("autoFormat()", bResult);
120 * Forces environment recreation.
122 @Override
123 protected void after() {
124 disposeEnvironment();