115ab5183SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 315ab5183SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 415ab5183SAndrew Rist * or more contributor license agreements. See the NOTICE file 515ab5183SAndrew Rist * distributed with this work for additional information 615ab5183SAndrew Rist * regarding copyright ownership. The ASF licenses this file 715ab5183SAndrew Rist * to you under the Apache License, Version 2.0 (the 815ab5183SAndrew Rist * "License"); you may not use this file except in compliance 915ab5183SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1115ab5183SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1315ab5183SAndrew Rist * Unless required by applicable law or agreed to in writing, 1415ab5183SAndrew Rist * software distributed under the License is distributed on an 1515ab5183SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1615ab5183SAndrew Rist * KIND, either express or implied. See the License for the 1715ab5183SAndrew Rist * specific language governing permissions and limitations 1815ab5183SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2015ab5183SAndrew Rist *************************************************************/ 2115ab5183SAndrew Rist 2215ab5183SAndrew Rist 23cdf0e10cSrcweir package complex.sc; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.Property; 26cdf0e10cSrcweir import com.sun.star.beans.PropertyAttribute; 27cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 28cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 29cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 30cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo; 31cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 32cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 33cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages; 34cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 35cdf0e10cSrcweir import com.sun.star.drawing.XShape; 36cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 37cdf0e10cSrcweir import com.sun.star.lang.XComponent; 38cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 39cdf0e10cSrcweir import com.sun.star.sheet.XCellRangeAddressable; 40cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 41cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 42cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 43cdf0e10cSrcweir // import com.sun.star.table.XCell; 44cdf0e10cSrcweir import com.sun.star.uno.Any; 45cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 46cdf0e10cSrcweir import com.sun.star.uno.Type; 47cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 48cdf0e10cSrcweir import com.sun.star.util.XCloseable; 49cdf0e10cSrcweir 50cdf0e10cSrcweir // import complexlib.ComplexTestCase; 51cdf0e10cSrcweir 52cdf0e10cSrcweir // import java.io.PrintWriter; 53cdf0e10cSrcweir 54cdf0e10cSrcweir import util.DrawTools; 55cdf0e10cSrcweir import util.SOfficeFactory; 56cdf0e10cSrcweir import util.ValueComparer; 57cdf0e10cSrcweir 58cdf0e10cSrcweir // import org.junit.After; 59cdf0e10cSrcweir import org.junit.AfterClass; 60cdf0e10cSrcweir // import org.junit.Before; 61cdf0e10cSrcweir import org.junit.BeforeClass; 62cdf0e10cSrcweir import org.junit.Test; 63cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 64cdf0e10cSrcweir import static org.junit.Assert.*; 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir public class CalcRTL /* extends ComplexTestCase */ 68cdf0e10cSrcweir { 69cdf0e10cSrcweir XSpreadsheetDocument xSheetDoc = null; 70cdf0e10cSrcweir 71cdf0e10cSrcweir /* 72cdf0e10cSrcweir * This testcase checks the calcrtl feature added to cws_calcrtl in three steps 73cdf0e10cSrcweir * <br> 74cdf0e10cSrcweir * (<b>REMARK: </b> the testcases expects the TableLayout to be LR_TB) 75cdf0e10cSrcweir * <br> 76cdf0e10cSrcweir * 1. A calc document is opened and the properties in css.sheet.Spreadsheet are checked 77cdf0e10cSrcweir * <br> 78cdf0e10cSrcweir * 2. A calc document is opened and a shape inserted, afterwards the properties in css.sheet.Shape are checked 79cdf0e10cSrcweir * <br> 80cdf0e10cSrcweir * 3. A calc document is opened and a shape inserted, afterwards the effect of changing the TableLayout to the shape is checked 81cdf0e10cSrcweir */ 82cdf0e10cSrcweir // public String[] getTestMethodNames() { 83cdf0e10cSrcweir // return new String[] { 84cdf0e10cSrcweir // "checkSpreadsheetProperties", "checkShapeProperties", 85cdf0e10cSrcweir // "checkInfluenceOfSpreadsheetChange" 86cdf0e10cSrcweir // }; 87cdf0e10cSrcweir // } 88cdf0e10cSrcweir 89cdf0e10cSrcweir /* 90cdf0e10cSrcweir * In this method a spreadsheet document is opened<br> 91cdf0e10cSrcweir * afterwards all properties of the Spreadsheet are checked.<br> 92cdf0e10cSrcweir * <p> 93cdf0e10cSrcweir * These are 94cdf0e10cSrcweir * <ul> 95cdf0e10cSrcweir *<li> IsVisible 96cdf0e10cSrcweir *<li> PageStyle 97cdf0e10cSrcweir *<li> TableLayout 98cdf0e10cSrcweir *</ul> 99cdf0e10cSrcweir */ checkSpreadsheetProperties()100cdf0e10cSrcweir @Test public void checkSpreadsheetProperties() { 101cdf0e10cSrcweir assertTrue("Couldn't open document", openSpreadsheetDocument()); 102cdf0e10cSrcweir 103cdf0e10cSrcweir XPropertySet set = UnoRuntime.queryInterface( 104cdf0e10cSrcweir XPropertySet.class, getSpreadsheet()); 105cdf0e10cSrcweir assertTrue("Problems when setting property 'IsVisible'", 106cdf0e10cSrcweir changeProperty(set, "IsVisible", Boolean.FALSE)); 107cdf0e10cSrcweir assertTrue("Problems when setting property 'IsVisible'", 108cdf0e10cSrcweir changeProperty(set, "IsVisible", Boolean.TRUE)); 109cdf0e10cSrcweir assertTrue("Problems when setting property 'PageStyle'", 110cdf0e10cSrcweir changeProperty(set, "PageStyle", "Report")); 111cdf0e10cSrcweir assertTrue("Problems when setting property 'PageStyle'", 112cdf0e10cSrcweir changeProperty(set, "PageStyle", "Default")); 113cdf0e10cSrcweir assertTrue("Problems when setting property 'TableLayout'", 114cdf0e10cSrcweir changeProperty(set, "TableLayout", 115cdf0e10cSrcweir new Short(com.sun.star.text.WritingMode2.RL_TB))); 116cdf0e10cSrcweir assertTrue("Problems when setting property 'TableLayout'", 117cdf0e10cSrcweir changeProperty(set, "TableLayout", 118cdf0e10cSrcweir new Short(com.sun.star.text.WritingMode2.LR_TB))); 119cdf0e10cSrcweir assertTrue("Couldn't close document", closeSpreadsheetDocument()); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir /* 123cdf0e10cSrcweir * In this method a spreadsheet document is opened and a shape inserted<br> 124cdf0e10cSrcweir * afterwards all calc specific properties of the Shape are checked.<br> 125cdf0e10cSrcweir * <p> 126cdf0e10cSrcweir * These are 127cdf0e10cSrcweir * <ul> 128cdf0e10cSrcweir *<li> Anchor 129cdf0e10cSrcweir *<li> HoriOrientPosition 130cdf0e10cSrcweir *<li> VertOrientPosition 131cdf0e10cSrcweir *</ul> 132cdf0e10cSrcweir */ checkShapeProperties()133cdf0e10cSrcweir @Test public void checkShapeProperties() { 134cdf0e10cSrcweir assertTrue("Couldn't open document", openSpreadsheetDocument()); 135cdf0e10cSrcweir 136cdf0e10cSrcweir XPropertySet set = UnoRuntime.queryInterface( 137cdf0e10cSrcweir XPropertySet.class, getInsertedShape()); 138cdf0e10cSrcweir 139cdf0e10cSrcweir try { 140cdf0e10cSrcweir assertTrue("Problems when setting property 'Anchor'", 141cdf0e10cSrcweir changeProperty(set, "Anchor", 142cdf0e10cSrcweir getSpreadsheet().getCellByPosition(5, 5))); 143cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 144cdf0e10cSrcweir // assure("Problems when setting property 'Anchor'", false); 145cdf0e10cSrcweir fail("Problems when setting property 'Anchor'"); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir assertTrue("Problems when setting property 'HoriOrientPosition'", 149cdf0e10cSrcweir changeProperty(set, "HoriOrientPosition", new Integer(1000))); 150cdf0e10cSrcweir 151cdf0e10cSrcweir assertTrue("Problems when setting property 'VertOrientPosition'", 152cdf0e10cSrcweir changeProperty(set, "VertOrientPosition", new Integer(1000))); 153cdf0e10cSrcweir 154cdf0e10cSrcweir assertTrue("Couldn't close document", closeSpreadsheetDocument()); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir checkInfluenceOfSpreadsheetChange()157cdf0e10cSrcweir @Test public void checkInfluenceOfSpreadsheetChange() { 158cdf0e10cSrcweir assertTrue("Couldn't open document", openSpreadsheetDocument()); 159cdf0e10cSrcweir 160cdf0e10cSrcweir XShape oShape = getInsertedShape(); 161cdf0e10cSrcweir XPropertySet sheetProps = UnoRuntime.queryInterface( 162cdf0e10cSrcweir XPropertySet.class, getSpreadsheet()); 163cdf0e10cSrcweir XPropertySet shapeProps = UnoRuntime.queryInterface( 164cdf0e10cSrcweir XPropertySet.class, oShape); 165cdf0e10cSrcweir 166cdf0e10cSrcweir String[] previous = getShapeProps(shapeProps, oShape); 167cdf0e10cSrcweir assertTrue("Problems when setting property 'TableLayout'", 168cdf0e10cSrcweir changeProperty(sheetProps, "TableLayout", 169cdf0e10cSrcweir new Short(com.sun.star.text.WritingMode2.RL_TB))); 170cdf0e10cSrcweir 171cdf0e10cSrcweir String[] RL_TB = getShapeProps(shapeProps, oShape); 172cdf0e10cSrcweir assertTrue("Problems when setting property 'TableLayout'", 173cdf0e10cSrcweir changeProperty(sheetProps, "TableLayout", 174cdf0e10cSrcweir new Short(com.sun.star.text.WritingMode2.LR_TB))); 175cdf0e10cSrcweir 176cdf0e10cSrcweir String[] LR_TB = getShapeProps(shapeProps, oShape); 177cdf0e10cSrcweir assertTrue("Anchor has changed", 178cdf0e10cSrcweir (previous[0].equals(RL_TB[0]) && previous[0].equals(LR_TB[0]))); 179cdf0e10cSrcweir assertEquals("HoriOrientPosition has changed", 180cdf0e10cSrcweir 2100, (Integer.valueOf(previous[1]).intValue() + Integer.valueOf( 181cdf0e10cSrcweir RL_TB[1]) 182cdf0e10cSrcweir .intValue() + 183cdf0e10cSrcweir Integer.valueOf(LR_TB[1]).intValue())); 184cdf0e10cSrcweir assertEquals("VertOrientPosition has changed", 185cdf0e10cSrcweir 3*Integer.valueOf(previous[2]).intValue(), 186cdf0e10cSrcweir (Integer.valueOf(previous[2]).intValue() + Integer.valueOf( 187cdf0e10cSrcweir RL_TB[2]) 188cdf0e10cSrcweir .intValue() + 189cdf0e10cSrcweir Integer.valueOf(LR_TB[2]).intValue())); 190cdf0e10cSrcweir assertTrue("x-position hasn't changed", 191cdf0e10cSrcweir (previous[3].equals(LR_TB[3]) && 192cdf0e10cSrcweir ((Integer.valueOf(previous[3]).intValue() * (-1)) - 193cdf0e10cSrcweir oShape.getSize().Width != Integer.valueOf(LR_TB[2]) 194cdf0e10cSrcweir .intValue()))); 195cdf0e10cSrcweir assertTrue("Couldn't close document", closeSpreadsheetDocument()); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir getShapeProps(XPropertySet set, XShape oShape)198cdf0e10cSrcweir protected String[] getShapeProps(XPropertySet set, XShape oShape) { 199cdf0e10cSrcweir String[] reValue = new String[4]; 200cdf0e10cSrcweir 201cdf0e10cSrcweir try { 202cdf0e10cSrcweir reValue[0] = toString(getRealValue(set.getPropertyValue("Anchor"))); 203cdf0e10cSrcweir reValue[1] = toString(set.getPropertyValue("HoriOrientPosition")); 204cdf0e10cSrcweir reValue[2] = toString(set.getPropertyValue("VertOrientPosition")); 205cdf0e10cSrcweir reValue[3] = toString(new Integer(oShape.getPosition().X)); 206cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 207cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir System.out.println("\t Anchor :" + reValue[0]); 211cdf0e10cSrcweir System.out.println("\t HoriOrientPosition :" + reValue[1]); 212cdf0e10cSrcweir System.out.println("\t VertOrientPosition :" + reValue[2]); 213cdf0e10cSrcweir System.out.println("\t Shape Position (x,y) : (" + oShape.getPosition().X + 214cdf0e10cSrcweir "," + oShape.getPosition().Y + ")"); 215cdf0e10cSrcweir 216cdf0e10cSrcweir return reValue; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir /* 220cdf0e10cSrcweir * this method opens a calc document and sets the corresponding class variable xSheetDoc 221cdf0e10cSrcweir */ openSpreadsheetDocument()222cdf0e10cSrcweir protected boolean openSpreadsheetDocument() { 223cdf0e10cSrcweir // SOfficeFactory SOF = SOfficeFactory.getFactory( 224cdf0e10cSrcweir // (XMultiServiceFactory) param.getMSF()); 225cdf0e10cSrcweir 226cdf0e10cSrcweir final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 227cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf); 228cdf0e10cSrcweir 229cdf0e10cSrcweir boolean worked = true; 230cdf0e10cSrcweir 231cdf0e10cSrcweir try { 232cdf0e10cSrcweir System.out.println("creating a sheetdocument"); 233cdf0e10cSrcweir xSheetDoc = SOF.createCalcDoc(null); 234cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 235f0a78d43SJohn Bampton // Some exception occurred. FAILED 236cdf0e10cSrcweir worked = false; 237cdf0e10cSrcweir e.printStackTrace(/*(PrintWriter) log*/ System.out); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir return worked; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir /* 244cdf0e10cSrcweir * this method closes a calc document and resets the corresponding class variable xSheetDoc 245cdf0e10cSrcweir */ closeSpreadsheetDocument()246cdf0e10cSrcweir protected boolean closeSpreadsheetDocument() { 247cdf0e10cSrcweir boolean worked = true; 248cdf0e10cSrcweir 249cdf0e10cSrcweir System.out.println(" disposing xSheetDoc "); 250cdf0e10cSrcweir 251cdf0e10cSrcweir try { 252cdf0e10cSrcweir XCloseable oCloser = UnoRuntime.queryInterface( 253cdf0e10cSrcweir XCloseable.class, xSheetDoc); 254cdf0e10cSrcweir oCloser.close(true); 255cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 256cdf0e10cSrcweir worked = false; 257cdf0e10cSrcweir System.out.println("Couldn't close document"); 258cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 259cdf0e10cSrcweir worked = false; 260cdf0e10cSrcweir System.out.println("Document already disposed"); 261cdf0e10cSrcweir } catch (java.lang.NullPointerException e) { 262cdf0e10cSrcweir worked = false; 263cdf0e10cSrcweir System.out.println("Couldn't get XCloseable"); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir xSheetDoc = null; 267cdf0e10cSrcweir 268cdf0e10cSrcweir return worked; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir /* 272cdf0e10cSrcweir * This method gets the first Sheet of the SpreadsheetDocument 273cdf0e10cSrcweir * 274cdf0e10cSrcweir */ getSpreadsheet()275cdf0e10cSrcweir protected XSpreadsheet getSpreadsheet() { 276cdf0e10cSrcweir XSpreadsheet oSheet = null; 277cdf0e10cSrcweir 278cdf0e10cSrcweir System.out.println("getting sheets"); 279cdf0e10cSrcweir 280cdf0e10cSrcweir XSpreadsheets xSpreadsheets = xSheetDoc.getSheets(); 281cdf0e10cSrcweir 282cdf0e10cSrcweir System.out.println("getting a sheet"); 283cdf0e10cSrcweir 284cdf0e10cSrcweir XIndexAccess oIndexAccess = UnoRuntime.queryInterface( 285cdf0e10cSrcweir XIndexAccess.class, xSpreadsheets); 286cdf0e10cSrcweir 287cdf0e10cSrcweir try { 288cdf0e10cSrcweir oSheet = UnoRuntime.queryInterface( 289cdf0e10cSrcweir XSpreadsheet.class, oIndexAccess.getByIndex(0)); 290cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 291cdf0e10cSrcweir e.printStackTrace(System.out); 292cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 293cdf0e10cSrcweir e.printStackTrace(System.out); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir return oSheet; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir /* 300cdf0e10cSrcweir * This method changes a given property to a given value 301cdf0e10cSrcweir * Parameters: 302cdf0e10cSrcweir * @param set : The XPropertySet that contains the properties 303cdf0e10cSrcweir * @param pName : The name of the Property that has to be changed 304cdf0e10cSrcweir * @param pValue : The value, the property should be changed too. 305cdf0e10cSrcweir */ changeProperty(XPropertySet set, String pName, Object pValue)306cdf0e10cSrcweir protected boolean changeProperty(XPropertySet set, String pName, 307cdf0e10cSrcweir Object pValue) { 308cdf0e10cSrcweir boolean worked = true; 309cdf0e10cSrcweir 310cdf0e10cSrcweir try { 311cdf0e10cSrcweir Object oldValue = set.getPropertyValue(pName); 312cdf0e10cSrcweir 313cdf0e10cSrcweir // for an exception thrown during setting new value 314cdf0e10cSrcweir // to pass it to checkResult method 315cdf0e10cSrcweir Exception exception = null; 316cdf0e10cSrcweir 317cdf0e10cSrcweir try { 318cdf0e10cSrcweir set.setPropertyValue(pName, pValue); 319cdf0e10cSrcweir } catch (IllegalArgumentException e) { 320cdf0e10cSrcweir exception = e; 321cdf0e10cSrcweir } catch (PropertyVetoException e) { 322cdf0e10cSrcweir exception = e; 323cdf0e10cSrcweir } catch (WrappedTargetException e) { 324cdf0e10cSrcweir exception = e; 325cdf0e10cSrcweir } catch (UnknownPropertyException e) { 326cdf0e10cSrcweir exception = e; 327cdf0e10cSrcweir } catch (RuntimeException e) { 328cdf0e10cSrcweir exception = e; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir // getting result value 332cdf0e10cSrcweir Object resValue = set.getPropertyValue(pName); 333cdf0e10cSrcweir 334cdf0e10cSrcweir 335cdf0e10cSrcweir // checking results 336cdf0e10cSrcweir worked = checkResult(set, pName, oldValue, pValue, resValue, 337cdf0e10cSrcweir exception); 338cdf0e10cSrcweir } catch (Exception e) { 33986e1cf34SPedro Giffuni System.out.println("Exception occurred while testing property '" + 340cdf0e10cSrcweir pName + "'"); 341cdf0e10cSrcweir e.printStackTrace(); 342cdf0e10cSrcweir worked = false; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir return worked; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir /* 349cdf0e10cSrcweir * This methods checks if a property has changed as expected 350cdf0e10cSrcweir * Parameters: 351cdf0e10cSrcweir * @param set : the given XPropertySet 352cdf0e10cSrcweir * @param propName : the name of the property that has been changed 353cdf0e10cSrcweir * @param oldValue : the value of the property before it has been changed 354cdf0e10cSrcweir * @param newValue : the value the property has been set to 355cdf0e10cSrcweir * @param resValue : the value getPropertyValue returned for the property 356*af228fbfSJohn Bampton * @param exception : the exception thrown during the change of the property 357cdf0e10cSrcweir */ checkResult(XPropertySet set, String propName, Object oldValue, Object newValue, Object resValue, Exception exception)358cdf0e10cSrcweir protected boolean checkResult(XPropertySet set, String propName, 359cdf0e10cSrcweir Object oldValue, Object newValue, 360cdf0e10cSrcweir Object resValue, Exception exception) 361cdf0e10cSrcweir throws Exception { 362cdf0e10cSrcweir XPropertySetInfo info = set.getPropertySetInfo(); 363cdf0e10cSrcweir Property prop = info.getPropertyByName(propName); 364cdf0e10cSrcweir 365cdf0e10cSrcweir oldValue = getRealValue(oldValue); 366cdf0e10cSrcweir newValue = getRealValue(newValue); 367cdf0e10cSrcweir resValue = getRealValue(resValue); 368cdf0e10cSrcweir 369cdf0e10cSrcweir short attr = prop.Attributes; 370cdf0e10cSrcweir boolean readOnly = (prop.Attributes & PropertyAttribute.READONLY) != 0; 371cdf0e10cSrcweir boolean maybeVoid = (prop.Attributes & PropertyAttribute.MAYBEVOID) != 0; 372cdf0e10cSrcweir 373cdf0e10cSrcweir //check get-set methods 374cdf0e10cSrcweir if (maybeVoid) { 375cdf0e10cSrcweir System.out.println("Property " + propName + " is void"); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir 378cdf0e10cSrcweir if (readOnly) { 379cdf0e10cSrcweir System.out.println("Property " + propName + " is readOnly"); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir if (util.utils.isVoid(oldValue) && !maybeVoid) { 383cdf0e10cSrcweir System.out.println(propName + " is void, but it's not MAYBEVOID"); 384cdf0e10cSrcweir 385cdf0e10cSrcweir return false; 386cdf0e10cSrcweir } else if (oldValue == null) { 387cdf0e10cSrcweir System.out.println(propName + 388cdf0e10cSrcweir " has null value, and therefore can't be changed"); 389cdf0e10cSrcweir 390cdf0e10cSrcweir return true; 391cdf0e10cSrcweir } else if (readOnly) { 392cdf0e10cSrcweir // check if exception was thrown 393cdf0e10cSrcweir if (exception != null) { 394cdf0e10cSrcweir if (exception instanceof PropertyVetoException) { 395cdf0e10cSrcweir // the change of read only prohibited - OK 396cdf0e10cSrcweir System.out.println("Property is ReadOnly and wasn't changed"); 397cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 398cdf0e10cSrcweir 399cdf0e10cSrcweir return true; 400cdf0e10cSrcweir } else if (exception instanceof IllegalArgumentException) { 401cdf0e10cSrcweir // the change of read only prohibited - OK 402cdf0e10cSrcweir System.out.println("Property is ReadOnly and wasn't changed"); 403cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 404cdf0e10cSrcweir 405cdf0e10cSrcweir return true; 406cdf0e10cSrcweir } else if (exception instanceof UnknownPropertyException) { 407cdf0e10cSrcweir // the change of read only prohibited - OK 408cdf0e10cSrcweir System.out.println("Property is ReadOnly and wasn't changed"); 409cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 410cdf0e10cSrcweir 411cdf0e10cSrcweir return true; 412cdf0e10cSrcweir } else if (exception instanceof RuntimeException) { 413cdf0e10cSrcweir // the change of read only prohibited - OK 414cdf0e10cSrcweir System.out.println("Property is ReadOnly and wasn't changed"); 415cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 416cdf0e10cSrcweir 417cdf0e10cSrcweir return true; 418cdf0e10cSrcweir } else { 419cdf0e10cSrcweir throw exception; 420cdf0e10cSrcweir } 421cdf0e10cSrcweir } else { 422cdf0e10cSrcweir // if no exception - check that value 423cdf0e10cSrcweir // has not changed 424cdf0e10cSrcweir if (!ValueComparer.equalValue(resValue, oldValue)) { 425cdf0e10cSrcweir System.out.println("Read only property '" + propName + 426cdf0e10cSrcweir "' has changed"); 427cdf0e10cSrcweir 428cdf0e10cSrcweir try { 429cdf0e10cSrcweir if (!util.utils.isVoid(oldValue) && 430cdf0e10cSrcweir oldValue instanceof Any) { 431cdf0e10cSrcweir oldValue = AnyConverter.toObject( 432cdf0e10cSrcweir new Type(((Any) oldValue).getClass()), 433cdf0e10cSrcweir oldValue); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir System.out.println("old = " + toString(oldValue)); 437cdf0e10cSrcweir System.out.println("new = " + toString(newValue)); 438cdf0e10cSrcweir System.out.println("result = " + toString(resValue)); 439cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir return false; 443cdf0e10cSrcweir } else { 444cdf0e10cSrcweir System.out.println("Read only property '" + propName + 445cdf0e10cSrcweir "' hasn't changed"); 446cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 447cdf0e10cSrcweir 448cdf0e10cSrcweir return true; 449cdf0e10cSrcweir } 450cdf0e10cSrcweir } 451cdf0e10cSrcweir } else { 452cdf0e10cSrcweir if (exception == null) { 453cdf0e10cSrcweir // if no exception thrown 454cdf0e10cSrcweir // check that the new value is set 455cdf0e10cSrcweir if ((!ValueComparer.equalValue(resValue, newValue)) || 456cdf0e10cSrcweir (ValueComparer.equalValue(resValue, oldValue))) { 457cdf0e10cSrcweir System.out.println("Value for '" + propName + 458cdf0e10cSrcweir "' hasn't changed as expected"); 459cdf0e10cSrcweir 460cdf0e10cSrcweir try { 461cdf0e10cSrcweir if (!util.utils.isVoid(oldValue) && 462cdf0e10cSrcweir oldValue instanceof Any) { 463cdf0e10cSrcweir oldValue = AnyConverter.toObject( 464cdf0e10cSrcweir new Type(((Any) oldValue).getClass()), 465cdf0e10cSrcweir oldValue); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir System.out.println("old = " + toString(oldValue)); 469cdf0e10cSrcweir System.out.println("new = " + toString(newValue)); 470cdf0e10cSrcweir System.out.println("result = " + toString(resValue)); 471cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 472cdf0e10cSrcweir } 473cdf0e10cSrcweir 474cdf0e10cSrcweir if (resValue != null) { 475cdf0e10cSrcweir if ((!ValueComparer.equalValue(resValue, oldValue)) || 476cdf0e10cSrcweir (!resValue.equals(oldValue))) { 477cdf0e10cSrcweir System.out.println("But it has changed."); 478cdf0e10cSrcweir 479cdf0e10cSrcweir return true; 480cdf0e10cSrcweir } else { 481cdf0e10cSrcweir return false; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } else { 484cdf0e10cSrcweir return false; 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir //tRes.tested(propName, false); 488cdf0e10cSrcweir } else { 489cdf0e10cSrcweir System.out.println("Property '" + propName + "' OK"); 490cdf0e10cSrcweir 491cdf0e10cSrcweir try { 492cdf0e10cSrcweir if (!util.utils.isVoid(oldValue) && 493cdf0e10cSrcweir oldValue instanceof Any) { 494cdf0e10cSrcweir oldValue = AnyConverter.toObject( 495cdf0e10cSrcweir new Type(((Any) oldValue).getClass()), 496cdf0e10cSrcweir oldValue); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir 499cdf0e10cSrcweir System.out.println("old = " + toString(oldValue)); 500cdf0e10cSrcweir System.out.println("new = " + toString(newValue)); 501cdf0e10cSrcweir System.out.println("result = " + toString(resValue)); 502cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir return true; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir } else { 508cdf0e10cSrcweir throw exception; 509cdf0e10cSrcweir } 510cdf0e10cSrcweir } 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir /* 514cdf0e10cSrcweir * Returns a String representation of a given object, returns "null" in case of a NullObject 515cdf0e10cSrcweir * @param obj : the given object 516cdf0e10cSrcweir */ toString(Object obj)517cdf0e10cSrcweir protected String toString(Object obj) { 518cdf0e10cSrcweir return (obj == null) ? "null" : obj.toString(); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir /* 522cdf0e10cSrcweir * Returns a human readable String representation for CellRangeAddressable 523cdf0e10cSrcweir */ getRealValue(Object obj)524cdf0e10cSrcweir protected Object getRealValue(Object obj) { 525cdf0e10cSrcweir Object value = null; 526cdf0e10cSrcweir 527cdf0e10cSrcweir if (UnoRuntime.queryInterface(XCellRangeAddressable.class, obj) != null) { 528cdf0e10cSrcweir XCellRangeAddressable aCell = UnoRuntime.queryInterface( 529cdf0e10cSrcweir XCellRangeAddressable.class, 530cdf0e10cSrcweir obj); 531cdf0e10cSrcweir value = "Cell in Column " + aCell.getRangeAddress().StartColumn + 532cdf0e10cSrcweir " and Row " + aCell.getRangeAddress().StartRow; 533cdf0e10cSrcweir } else { 534cdf0e10cSrcweir return obj; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir return value; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir /* 541d4fdf834SJohn Bampton * This method inserts a RectangleShape into the calc document xSheetDoc and returns the resulting XShape-object 542cdf0e10cSrcweir */ getInsertedShape()543cdf0e10cSrcweir protected XShape getInsertedShape() { 544cdf0e10cSrcweir XShape insertedShape = null; 545cdf0e10cSrcweir 546cdf0e10cSrcweir try { 547cdf0e10cSrcweir System.out.println("getting Drawpages"); 548cdf0e10cSrcweir 549cdf0e10cSrcweir XDrawPagesSupplier oDPS = UnoRuntime.queryInterface( 550cdf0e10cSrcweir XDrawPagesSupplier.class, 551cdf0e10cSrcweir xSheetDoc); 552cdf0e10cSrcweir XDrawPages oDP = oDPS.getDrawPages(); 553cdf0e10cSrcweir XDrawPage firstDrawPage = UnoRuntime.queryInterface( 554cdf0e10cSrcweir XDrawPage.class, 555cdf0e10cSrcweir oDP.getByIndex(0)); 556cdf0e10cSrcweir 557cdf0e10cSrcweir final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 558cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf); 559cdf0e10cSrcweir 560cdf0e10cSrcweir // SOfficeFactory SOF = SOfficeFactory.getFactory( 561cdf0e10cSrcweir // (XMultiServiceFactory) param.getMSF()); 562cdf0e10cSrcweir XComponent xComp = UnoRuntime.queryInterface( 563cdf0e10cSrcweir XComponent.class, xSheetDoc); 564cdf0e10cSrcweir insertedShape = SOF.createShape(xComp, 5000, 3500, 700, 500, 565cdf0e10cSrcweir "Rectangle"); 566cdf0e10cSrcweir DrawTools.getShapes(firstDrawPage).add(insertedShape); 567cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 568cdf0e10cSrcweir System.out.println("Couldn't create instance"); 569cdf0e10cSrcweir e.printStackTrace(); 570cdf0e10cSrcweir 571cdf0e10cSrcweir return null; 572cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 573cdf0e10cSrcweir System.out.println("Couldn't create instance"); 574cdf0e10cSrcweir e.printStackTrace(); 575cdf0e10cSrcweir 576cdf0e10cSrcweir return null; 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir return insertedShape; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582cdf0e10cSrcweir 583cdf0e10cSrcweir 584cdf0e10cSrcweir setUpConnection()585cdf0e10cSrcweir @BeforeClass public static void setUpConnection() throws Exception { 586cdf0e10cSrcweir connection.setUp(); 587cdf0e10cSrcweir } 588cdf0e10cSrcweir tearDownConnection()589cdf0e10cSrcweir @AfterClass public static void tearDownConnection() 590cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 591cdf0e10cSrcweir { 592cdf0e10cSrcweir connection.tearDown(); 593cdf0e10cSrcweir } 594cdf0e10cSrcweir 595cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 596cdf0e10cSrcweir 597cdf0e10cSrcweir } 598