1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.table; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.util.Random; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 30cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32cdf0e10cSrcweir import com.sun.star.table.XAutoFormattable; 33cdf0e10cSrcweir import com.sun.star.table.XCell; 34cdf0e10cSrcweir import com.sun.star.table.XCellRange; 35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36cdf0e10cSrcweir import com.sun.star.uno.XInterface; 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir /** 40cdf0e10cSrcweir * Testing <code>com.sun.star.table.XAutoFormattable</code> 41cdf0e10cSrcweir * interface methods : 42cdf0e10cSrcweir * <ul> 43cdf0e10cSrcweir * <li><code> autoFormat()</code></li> 44cdf0e10cSrcweir * </ul> <p> 45cdf0e10cSrcweir * The component tested <b>must implement</b> interface 46cdf0e10cSrcweir * <code>com.sun.star.table.XCellRange</code>. <p> 47cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 48cdf0e10cSrcweir * @see com.sun.star.table.XAutoFormattable 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir public class _XAutoFormattable extends MultiMethodTest { 51cdf0e10cSrcweir public XAutoFormattable oObj = null; 52cdf0e10cSrcweir 53cdf0e10cSrcweir /** 54cdf0e10cSrcweir * First 'Default' autoformat is set and a background of a cell 55cdf0e10cSrcweir * is obtained. Then any other autoformat is set and background 56cdf0e10cSrcweir * of a cell is obtained again.<p> 57cdf0e10cSrcweir * Has <b> OK </b> status if backgrounds with different autoformat 58cdf0e10cSrcweir * settings are differ. <p> 59cdf0e10cSrcweir */ _autoFormat()60cdf0e10cSrcweir public void _autoFormat() { 61cdf0e10cSrcweir boolean bResult = true; 62cdf0e10cSrcweir XMultiServiceFactory oMSF = (XMultiServiceFactory) tParam.getMSF(); 63cdf0e10cSrcweir String name = "Default"; 64cdf0e10cSrcweir 65cdf0e10cSrcweir try { 66cdf0e10cSrcweir oObj.autoFormat(name); // applying default format 67cdf0e10cSrcweir 68cdf0e10cSrcweir // getting current background of the cell 69cdf0e10cSrcweir XCellRange cellRange = (XCellRange) UnoRuntime.queryInterface( 70cdf0e10cSrcweir XCellRange.class, oObj); 71cdf0e10cSrcweir XCell oCell = cellRange.getCellByPosition(0, 0); 72cdf0e10cSrcweir XPropertySet PS = (XPropertySet) UnoRuntime.queryInterface( 73cdf0e10cSrcweir XPropertySet.class, oCell); 74cdf0e10cSrcweir 75cdf0e10cSrcweir Integer bkgrnd1; 76cdf0e10cSrcweir try { 77cdf0e10cSrcweir bkgrnd1 = (Integer) PS.getPropertyValue("CellBackColor"); 78cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 79cdf0e10cSrcweir bkgrnd1 = (Integer) PS.getPropertyValue("BackColor"); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir // getting formats names. 83cdf0e10cSrcweir XInterface iFormats = (XInterface) oMSF.createInstance( 84cdf0e10cSrcweir "com.sun.star.sheet.TableAutoFormats"); 85cdf0e10cSrcweir XNameAccess formats = (XNameAccess) UnoRuntime.queryInterface( 86cdf0e10cSrcweir XNameAccess.class, iFormats); 87cdf0e10cSrcweir String[] names = formats.getElementNames(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir // getting one random not default style name 90cdf0e10cSrcweir Random rnd = new Random(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir if (names.length > 1) { 93cdf0e10cSrcweir while (name.equals("Default")) { 94cdf0e10cSrcweir name = names[rnd.nextInt(names.length)]; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } else { 97cdf0e10cSrcweir name = names[0]; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir log.println("Applying style " + name); 101cdf0e10cSrcweir 102cdf0e10cSrcweir 103cdf0e10cSrcweir // applying style 104cdf0e10cSrcweir oObj.autoFormat(name); 105cdf0e10cSrcweir 106cdf0e10cSrcweir // getting new cell's backround. 107cdf0e10cSrcweir Integer bkgrnd2; 108cdf0e10cSrcweir try { 109cdf0e10cSrcweir bkgrnd2 = (Integer) PS.getPropertyValue("CellBackColor"); 110cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 111cdf0e10cSrcweir bkgrnd2 = (Integer) PS.getPropertyValue("BackColor"); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir bResult &= !bkgrnd1.equals(bkgrnd2); 115cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 116cdf0e10cSrcweir log.println("Exception occured :"); 117cdf0e10cSrcweir e.printStackTrace(log); 118cdf0e10cSrcweir bResult = false; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir tRes.tested("autoFormat()", bResult); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** 125cdf0e10cSrcweir * Forces environment recreation. 126cdf0e10cSrcweir */ after()127cdf0e10cSrcweir protected void after() { 128cdf0e10cSrcweir disposeEnvironment(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir }