1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sw.table; 23 24 import static org.junit.Assert.*; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.openoffice.test.common.FileUtil; 30 import org.openoffice.test.common.Testspace; 31 import org.openoffice.test.uno.UnoApp; 32 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.text.*; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.beans.PropertyValue; 37 import com.sun.star.beans.XPropertySet; 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.table.*; 40 import com.sun.star.frame.XStorable; 41 42 43 public class TableBasic { 44 45 private static final UnoApp app = new UnoApp(); 46 private XTextDocument xTextDocument=null; 47 private XMultiServiceFactory xWriterFactory=null; 48 private XText xText=null; 49 @Before setUp()50 public void setUp() throws Exception { 51 app.start(); 52 } 53 54 @After tearDown()55 public void tearDown() throws Exception { 56 app.close(); 57 } 58 /* 59 * test create table 60 * 1.new a text document and create a table,5 rows,4 columns 61 * 2.save to odt,close it and reopen new saved document 62 * 3.check the table column count and row count 63 */ 64 @Test testCreateTable()65 public void testCreateTable() throws Exception { 66 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 67 xText=xTextDocument.getText(); 68 XTextCursor xTextCursor = xText.createTextCursor(); 69 // get internal service factory of the document 70 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 71 // Create a new table from the document's factory 72 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 73 xTable.initialize(5, 4); 74 xText.insertTextContent(xTextCursor,xTable,false); 75 76 //save and reload text document 77 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 78 PropertyValue[] aStoreProperties = new PropertyValue[2]; 79 aStoreProperties[0] = new PropertyValue(); 80 aStoreProperties[1] = new PropertyValue(); 81 aStoreProperties[0].Name = "Override"; 82 aStoreProperties[0].Value = true; 83 aStoreProperties[1].Name = "FilterName"; 84 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 85 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 86 app.closeDocument(xTextDocument); 87 88 //reopen the document and assert create table successfully 89 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 90 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 91 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 92 Object xTable_obj=xIndexedTables.getByIndex(0); 93 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj); 94 XTableRows xRows=xTable_Assert.getRows(); 95 assertEquals("assert inserted table has 5 rows",5, xRows.getCount()); 96 XTableColumns xColumns=xTable_Assert.getColumns(); 97 assertEquals("assert inserted table has 4 columns",4, xColumns.getCount()); 98 } 99 /* 100 * test insert/delete row/column 101 * 1.new a text document and new a table 5x4 102 * 2.insert 2 rows,4 columns 103 * 3.check the total row count and column count 104 * 4.delete 3 row,2 column 105 * 5.check the total row count and column count 106 */ 107 @Test testInsert_Delete_Rows_Columns()108 public void testInsert_Delete_Rows_Columns() throws Exception { 109 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 110 xText=xTextDocument.getText(); 111 XTextCursor xTextCursor = xText.createTextCursor(); 112 // get internal service factory of the document 113 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 114 // Create a new table from the document's factory 115 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 116 xTable.initialize(5, 4); 117 xText.insertTextContent(xTextCursor,xTable,false); 118 XTableRows xRows=xTable.getRows(); 119 XTableColumns xColumns=xTable.getColumns(); 120 xRows.insertByIndex(0, 2); 121 xColumns.insertByIndex(3, 4); 122 assertEquals("assert inserted 2 rows",7, xRows.getCount()); 123 assertEquals("assert inserted 2 columns",8, xColumns.getCount()); 124 xRows.removeByIndex(0, 3); 125 xColumns.removeByIndex(3, 2); 126 assertEquals("assert delete 3 rows",4, xRows.getCount()); 127 assertEquals("assert delete 2 columns",6, xColumns.getCount()); 128 app.closeDocument(xTextDocument); 129 } 130 /* 131 * test table tow height 132 * 1.new a text document and new a table 133 * 2.set the first row height and not auto fit 134 * 3.save to odt,close it and reopen new saved document 135 * 4.check the table first row height setting 136 */ 137 @Test testSetRowHeight()138 public void testSetRowHeight() throws Exception { 139 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 140 xText=xTextDocument.getText(); 141 XTextCursor xTextCursor = xText.createTextCursor(); 142 // get internal service factory of the document 143 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 144 // Create a new table from the document's factory 145 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 146 xText.insertTextContent(xTextCursor,xTable,false); 147 XTableRows xRows=xTable.getRows(); 148 //set first row not auto fit and user-defined height 149 XPropertySet xRowsProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xRows.getByIndex(0)); 150 xRowsProps.setPropertyValue("IsAutoHeight",false); 151 xRowsProps.setPropertyValue("Height",5001); 152 //save and reload text document 153 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 154 PropertyValue[] aStoreProperties = new PropertyValue[2]; 155 aStoreProperties[0] = new PropertyValue(); 156 aStoreProperties[1] = new PropertyValue(); 157 aStoreProperties[0].Name = "Override"; 158 aStoreProperties[0].Value = true; 159 aStoreProperties[1].Name = "FilterName"; 160 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 161 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 162 app.closeDocument(xTextDocument); 163 164 //reopen the document and assert row height setting 165 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 166 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 167 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 168 Object xTable_obj=xIndexedTables.getByIndex(0); 169 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj); 170 XTableRows xRows_Assert=xTable_Assert.getRows(); 171 XPropertySet xRowsProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRows_Assert.getByIndex(0)); 172 assertEquals("assert the second row height is 5001",5001,xRowsProps_assert.getPropertyValue("Height")); 173 assertEquals("assert the second row height is not autofitable",false, xRowsProps_assert.getPropertyValue("IsAutoHeight")); 174 } 175 /* 176 * test table border setting 177 * 1.new a text document and create a table 178 * 2.set table border line color and style 179 * 3.save to odt,close it and reopen new saved document 180 * 4.check the table border setting 181 */ 182 @Test testSetTableBorder()183 public void testSetTableBorder() throws Exception { 184 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 185 xText=xTextDocument.getText(); 186 XTextCursor xTextCursor = xText.createTextCursor(); 187 // get internal service factory of the document 188 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 189 // Create a new table from the document's factory 190 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 191 xText.insertTextContent(xTextCursor,xTable,false); 192 XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable); 193 //set table border 194 TableBorder tableBorder = new TableBorder(); 195 BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()}; 196 borderLine[0].Color=0x00FF0000; 197 borderLine[0].InnerLineWidth=101; 198 borderLine[0].OuterLineWidth=19; 199 borderLine[0].LineDistance=100; 200 borderLine[1].Color =0x00FFFF00; 201 borderLine[1].InnerLineWidth=101; 202 borderLine[1].OuterLineWidth=19; 203 borderLine[1].LineDistance=101; 204 borderLine[2].Color =0x0000FF00; 205 borderLine[2].InnerLineWidth=150; 206 borderLine[2].OuterLineWidth=19; 207 borderLine[2].LineDistance=101; 208 borderLine[3].Color =0x0000FF00; 209 borderLine[3].InnerLineWidth=150; 210 borderLine[3].OuterLineWidth=19; 211 borderLine[3].LineDistance=101; 212 borderLine[4].Color =0x0000FF00; 213 borderLine[4].InnerLineWidth=150; 214 borderLine[4].OuterLineWidth=19; 215 borderLine[4].LineDistance=101; 216 borderLine[5].Color =0x0000FF00; 217 borderLine[5].InnerLineWidth=150; 218 borderLine[5].OuterLineWidth=19; 219 borderLine[5].LineDistance=101; 220 tableBorder.TopLine =borderLine[0]; 221 tableBorder.BottomLine =borderLine[1]; 222 tableBorder.LeftLine =borderLine[2]; 223 tableBorder.RightLine =borderLine[3]; 224 tableBorder.HorizontalLine =borderLine[4]; 225 tableBorder.VerticalLine =borderLine[5]; 226 tableBorder.IsBottomLineValid = true; 227 tableBorder.IsLeftLineValid = true; 228 tableBorder.IsRightLineValid = true; 229 tableBorder.IsTopLineValid = true; 230 tableBorder.IsHorizontalLineValid = true; 231 tableBorder.IsVerticalLineValid = true; 232 xTableProps.setPropertyValue("TableBorder", tableBorder); 233 //save and reload text document 234 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 235 PropertyValue[] aStoreProperties = new PropertyValue[2]; 236 aStoreProperties[0] = new PropertyValue(); 237 aStoreProperties[1] = new PropertyValue(); 238 aStoreProperties[0].Name = "Override"; 239 aStoreProperties[0].Value = true; 240 aStoreProperties[1].Name = "FilterName"; 241 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 242 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 243 app.closeDocument(xTextDocument); 244 245 //reopen the document and assert table border setting 246 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 247 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 248 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 249 Object xTable_obj=xIndexedTables.getByIndex(0); 250 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj); 251 XPropertySet xTableProps_Assert = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert); 252 TableBorder tableBorder_Assert=(TableBorder) UnoRuntime.queryInterface(TableBorder.class, xTableProps_Assert.getPropertyValue("TableBorder")); 253 assertEquals("assert topline color as setting",0x00FF0000,tableBorder_Assert.TopLine.Color); 254 assertEquals("assert topline innerline width as setting",101,tableBorder_Assert.TopLine.InnerLineWidth); 255 assertEquals("assert topline outerlinewidth as setting",19,tableBorder_Assert.TopLine.OuterLineWidth); 256 assertEquals("assert topline linedistance as setting",101,tableBorder_Assert.TopLine.LineDistance); 257 assertEquals("assert bottomline color as setting",0x00FFFF00,tableBorder_Assert.BottomLine.Color); 258 assertEquals("assert bottomline innerline width as setting",101,tableBorder_Assert.BottomLine.InnerLineWidth); 259 assertEquals("assert bottomline outerlinewidth as setting",19,tableBorder_Assert.BottomLine.OuterLineWidth); 260 assertEquals("assert bottomline linedistance as setting",101,tableBorder_Assert.BottomLine.LineDistance); 261 assertEquals("assert leftline color as setting",0x0000FF00,tableBorder_Assert.LeftLine.Color); 262 assertEquals("assert leftline innerline width as setting",150,tableBorder_Assert.LeftLine.InnerLineWidth); 263 assertEquals("assert leftline outerlinewidth as setting",19,tableBorder_Assert.LeftLine.OuterLineWidth); 264 assertEquals("assert leftline linedistance as setting",101,tableBorder_Assert.LeftLine.LineDistance); 265 assertEquals("assert rightline color as setting",0x0000FF00,tableBorder_Assert.RightLine.Color); 266 assertEquals("assert rightline linedistance as setting",101,tableBorder_Assert.RightLine.LineDistance); 267 assertEquals("assert rightline innerline width as setting",150,tableBorder_Assert.RightLine.InnerLineWidth); 268 assertEquals("assert rightline outerlinewidth as setting",19,tableBorder_Assert.RightLine.OuterLineWidth); 269 assertEquals("assert HorizontalLine color as setting",0x0000FF00,tableBorder_Assert.HorizontalLine.Color); 270 assertEquals("assert HorizontalLine innerline width as setting",150,tableBorder_Assert.HorizontalLine.InnerLineWidth); 271 assertEquals("assert HorizontalLine outerlinewidth as setting",19,tableBorder_Assert.HorizontalLine.OuterLineWidth); 272 assertEquals("assert HorizontalLine linedistance as setting",101,tableBorder_Assert.HorizontalLine.LineDistance); 273 assertEquals("assert VerticalLine color as setting",0x0000FF00,tableBorder_Assert.VerticalLine.Color); 274 assertEquals("assert VerticalLine innerline width as setting",150,tableBorder_Assert.VerticalLine.InnerLineWidth); 275 assertEquals("assert VerticalLine outerlinewidth as setting",19,tableBorder_Assert.VerticalLine.OuterLineWidth); 276 assertEquals("assert VerticalLine linedistance as setting",101,tableBorder_Assert.VerticalLine.LineDistance); 277 } 278 /* 279 * test table spacing to page and alignment 280 * 1.new a text document 281 * 2.create a table 282 * 3.set the table alignment to automatic,and spacing to margin 283 * 4.repeat step2 5 times,and set second table alignment to manual/center/left/from left/right,and spacing to margin 284 * 5.save to odt,close it and reopen the new saved document 285 * 6.reopen and check the every table alignment and spacing to margin 286 */ 287 @Test testSetTable_AlignmentAndMarginToPage()288 public void testSetTable_AlignmentAndMarginToPage() throws Exception { 289 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 290 xText=xTextDocument.getText(); 291 XTextCursor xTextCursor = xText.createTextCursor(); 292 // get internal service factory of the document 293 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 294 // Create new table from the document's factory 295 XTextTable xTable1 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 296 xText.insertTextContent(xTextCursor,xTable1,false); 297 XPropertySet xTableProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable1); 298 xTableProps1.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.FULL); 299 xTableProps1.setPropertyValue("LeftMargin",2591); 300 xTableProps1.setPropertyValue("RightMargin",3000); 301 xTableProps1.setPropertyValue("TopMargin",2000); 302 xTableProps1.setPropertyValue("BottomMargin",2000); 303 XTextTable xTable2 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 304 xText.insertTextContent(xTextCursor,xTable2,false); 305 XPropertySet xTableProps2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable2); 306 xTableProps2.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.NONE); 307 xTableProps2.setPropertyValue("LeftMargin",2591); 308 xTableProps2.setPropertyValue("RightMargin",3000); 309 xTableProps2.setPropertyValue("TopMargin",2000); 310 xTableProps2.setPropertyValue("BottomMargin",2000); 311 XTextTable xTable3 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 312 xText.insertTextContent(xTextCursor,xTable3,false); 313 XPropertySet xTableProps3 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable3); 314 xTableProps3.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.CENTER); 315 xTableProps3.setPropertyValue("LeftMargin",2000); 316 xTableProps3.setPropertyValue("RightMargin",3000); 317 xTableProps3.setPropertyValue("TopMargin",2000); 318 xTableProps3.setPropertyValue("BottomMargin",2000); 319 XTextTable xTable4 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 320 xText.insertTextContent(xTextCursor,xTable4,false); 321 XPropertySet xTableProps4 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable4); 322 xTableProps4.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.LEFT); 323 xTableProps4.setPropertyValue("KeepTogether",true); 324 xTableProps4.setPropertyValue("RightMargin",2000); 325 xTableProps4.setPropertyValue("TopMargin",2000); 326 xTableProps4.setPropertyValue("BottomMargin",2000); 327 XTextTable xTable5 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 328 xText.insertTextContent(xTextCursor,xTable5,false); 329 XPropertySet xTableProps5 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable5); 330 xTableProps5.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.LEFT_AND_WIDTH); 331 xTableProps5.setPropertyValue("TopMargin",2000); 332 xTableProps5.setPropertyValue("BottomMargin",2000); 333 XTextTable xTable6 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 334 xText.insertTextContent(xTextCursor,xTable6,false); 335 XPropertySet xTableProps6 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable6); 336 xTableProps6.setPropertyValue("HoriOrient",com.sun.star.text.HoriOrientation.RIGHT); 337 xTableProps6.setPropertyValue("TopMargin",2000); 338 xTableProps6.setPropertyValue("BottomMargin",2000); 339 //save and reload text document 340 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 341 PropertyValue[] aStoreProperties = new PropertyValue[2]; 342 aStoreProperties[0] = new PropertyValue(); 343 aStoreProperties[1] = new PropertyValue(); 344 aStoreProperties[0].Name = "Override"; 345 aStoreProperties[0].Value = true; 346 aStoreProperties[1].Name = "FilterName"; 347 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 348 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 349 app.closeDocument(xTextDocument); 350 351 //reopen the document and assert table margin to page setting 352 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 353 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 354 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 355 Object xTable_obj1=xIndexedTables.getByIndex(0); 356 XTextTable xTable_Assert1=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj1); 357 XPropertySet xTableProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert1); 358 assertEquals("assert table alignment as automatic",com.sun.star.text.HoriOrientation.FULL,xTableProps_assert1.getPropertyValue("HoriOrient")); 359 assertEquals("assert left margin to page",0,xTableProps_assert1.getPropertyValue("LeftMargin")); 360 assertEquals("assert right margin to page",0,xTableProps_assert1.getPropertyValue("RightMargin")); 361 assertEquals("assert top margin to page",2000,xTableProps_assert1.getPropertyValue("TopMargin")); 362 assertEquals("assert bottom margin to page",2000,xTableProps_assert1.getPropertyValue("BottomMargin")); 363 Object xTable_obj2=xIndexedTables.getByIndex(1); 364 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj2); 365 XPropertySet xTableProps_assert2 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert); 366 assertEquals("assert table alignment as manual",com.sun.star.text.HoriOrientation.NONE,xTableProps_assert2.getPropertyValue("HoriOrient")); 367 assertEquals("assert left margin to page",2591,xTableProps_assert2.getPropertyValue("LeftMargin")); 368 assertEquals("assert right margin to page",3000,xTableProps_assert2.getPropertyValue("RightMargin")); 369 assertEquals("assert top margin to page",2000,xTableProps_assert2.getPropertyValue("TopMargin")); 370 assertEquals("assert bottom margin to page",2000,xTableProps_assert2.getPropertyValue("BottomMargin")); 371 Object xTable_obj3=xIndexedTables.getByIndex(2); 372 XTextTable xTable_Assert3=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj3); 373 XPropertySet xTableProps_assert3 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert3); 374 assertEquals("assert table alignment as center",com.sun.star.text.HoriOrientation.CENTER,xTableProps_assert3.getPropertyValue("HoriOrient")); 375 assertEquals("assert top margin to page",2000,xTableProps_assert3.getPropertyValue("TopMargin")); 376 assertEquals("assert bottom margin to page",2000,xTableProps_assert3.getPropertyValue("BottomMargin")); 377 Object xTable_obj4=xIndexedTables.getByIndex(3); 378 XTextTable xTable_Assert4=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj4); 379 XPropertySet xTableProps_assert4 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert4); 380 assertEquals("assert table alignment as left",com.sun.star.text.HoriOrientation.LEFT,xTableProps_assert4.getPropertyValue("HoriOrient")); 381 assertEquals("assert top margin to page",2000,xTableProps_assert4.getPropertyValue("TopMargin")); 382 assertEquals("assert bottom margin to page",2000,xTableProps_assert4.getPropertyValue("BottomMargin")); 383 Object xTable_obj5=xIndexedTables.getByIndex(4); 384 XTextTable xTable_Assert5=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj5); 385 XPropertySet xTableProps_assert5 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert5); 386 assertEquals("assert table alignment as from left",com.sun.star.text.HoriOrientation.LEFT,xTableProps_assert5.getPropertyValue("HoriOrient")); 387 assertEquals("assert top margin to page",2000,xTableProps_assert5.getPropertyValue("TopMargin")); 388 assertEquals("assert bottom margin to page",2000,xTableProps_assert5.getPropertyValue("BottomMargin")); 389 Object xTable_obj6=xIndexedTables.getByIndex(5); 390 XTextTable xTable_Assert6=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj6); 391 XPropertySet xTableProps_assert6 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert6); 392 assertEquals("assert table alignment as right",com.sun.star.text.HoriOrientation.RIGHT,xTableProps_assert6.getPropertyValue("HoriOrient")); 393 assertEquals("assert top margin to page",2000,xTableProps_assert5.getPropertyValue("TopMargin")); 394 assertEquals("assert bottom margin to page",2000,xTableProps_assert5.getPropertyValue("BottomMargin")); 395 } 396 /* 397 * test set table background with color 398 * 1.new a text document and new a table 399 * 2.set table background with color 400 * 3.save to odt and close it,then reopen the new saved document 401 * 4.check the table background color 402 */ 403 @Test testSetTableBackColor()404 public void testSetTableBackColor() throws Exception { 405 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 406 xText=xTextDocument.getText(); 407 XTextCursor xTextCursor = xText.createTextCursor(); 408 // get internal service factory of the document 409 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 410 // Create a new table from the document's factory 411 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 412 xText.insertTextContent(xTextCursor,xTable,false); 413 XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable); 414 xTableProps.setPropertyValue("BackColor",0x0000FF00); 415 416 //save and reload text document 417 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 418 PropertyValue[] aStoreProperties = new PropertyValue[2]; 419 aStoreProperties[0] = new PropertyValue(); 420 aStoreProperties[1] = new PropertyValue(); 421 aStoreProperties[0].Name = "Override"; 422 aStoreProperties[0].Value = true; 423 aStoreProperties[1].Name = "FilterName"; 424 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 425 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 426 app.closeDocument(xTextDocument); 427 428 //reopen the document and assert table margin to page setting 429 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 430 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 431 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 432 Object xTable_obj=xIndexedTables.getByIndex(0); 433 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj); 434 XPropertySet xTableProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert); 435 assertEquals("verify table background color",0x0000FF00,xTableProps_assert.getPropertyValue("BackColor")); 436 } 437 /*test table repeat heading setting 438 * 1.new a text document and create a table 439 * 2.set table first row as repeat heading 440 * 3.save to odt and close it,then reopen the document 441 * 4.check the table first row as repeat heading 442 */ 443 444 @Test testSetTableRepeatHeading()445 public void testSetTableRepeatHeading() throws Exception { 446 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 447 xText=xTextDocument.getText(); 448 XTextCursor xTextCursor = xText.createTextCursor(); 449 // get internal service factory of the document 450 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 451 // Create a new table from the document's factory 452 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 453 xText.insertTextContent(xTextCursor,xTable,false); 454 XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable); 455 //set table first one row as table heading 456 xTableProps.setPropertyValue("RepeatHeadline",true); 457 xTableProps.setPropertyValue("HeaderRowCount",1); 458 459 //save and reload text document 460 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 461 PropertyValue[] aStoreProperties = new PropertyValue[2]; 462 aStoreProperties[0] = new PropertyValue(); 463 aStoreProperties[1] = new PropertyValue(); 464 aStoreProperties[0].Name = "Override"; 465 aStoreProperties[0].Value = true; 466 aStoreProperties[1].Name = "FilterName"; 467 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 468 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 469 app.closeDocument(xTextDocument); 470 471 //reopen the document and assert table repeat heading setting 472 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 473 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 474 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 475 Object xTable_obj=xIndexedTables.getByIndex(0); 476 XTextTable xTable_Assert=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj); 477 XPropertySet xTableProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert); 478 assertEquals("verify table heading row number",1,xTableProps_assert.getPropertyValue("HeaderRowCount")); 479 assertEquals("verify table heading repeat",true,xTableProps_assert.getPropertyValue("RepeatHeadline")); 480 } 481 /* 482 * test table shadow setting 483 * 1.new a text document 484 * 2.create 5 tables 485 * 3.set the 5 table shadow location to bottom_right,bottom_left,none,top_left,top_right,and shadow width 486 * 4.save to odt and close it,then reopen the new saved document 487 * 5.check the 5 table shadow location and width 488 */ 489 @Test testSetTableShadow()490 public void testSetTableShadow() throws Exception { 491 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 492 xText=xTextDocument.getText(); 493 XTextCursor xTextCursor = xText.createTextCursor(); 494 // get internal service factory of the document 495 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 496 // Create new table from the document's factory 497 XTextTable xTable1 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 498 xText.insertTextContent(xTextCursor,xTable1,false); 499 XPropertySet xTableProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable1); 500 XTextTable xTable2 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 501 xText.insertTextContent(xTextCursor,xTable2,false); 502 XPropertySet xTableProps2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable2); 503 XTextTable xTable3 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 504 xText.insertTextContent(xTextCursor,xTable3,false); 505 XPropertySet xTableProps3 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable3); 506 XTextTable xTable4 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 507 xText.insertTextContent(xTextCursor,xTable4,false); 508 XPropertySet xTableProps4 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable4); 509 XTextTable xTable5 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 510 xText.insertTextContent(xTextCursor,xTable5,false); 511 XPropertySet xTableProps5 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable5); 512 //set table shadow 513 ShadowFormat[] shadowFormat=new ShadowFormat[] {new ShadowFormat(),new ShadowFormat(),new ShadowFormat(),new ShadowFormat(),new ShadowFormat()}; 514 shadowFormat[0].Location=ShadowLocation.BOTTOM_RIGHT; 515 shadowFormat[0].ShadowWidth=100; 516 shadowFormat[0].Color=0x00FF00FF; 517 shadowFormat[1].Location=ShadowLocation.BOTTOM_LEFT; 518 shadowFormat[1].ShadowWidth=100; 519 shadowFormat[1].Color=0x00FF00FF; 520 shadowFormat[2].Location=ShadowLocation.NONE; 521 shadowFormat[3].Location=ShadowLocation.TOP_LEFT; 522 shadowFormat[3].ShadowWidth=100; 523 shadowFormat[3].Color=0x00FF00FF; 524 shadowFormat[4].Location=ShadowLocation.TOP_RIGHT; 525 shadowFormat[4].ShadowWidth=100; 526 shadowFormat[4].Color=0x00FF00FF; 527 xTableProps1.setPropertyValue("ShadowFormat",shadowFormat[0]); 528 xTableProps2.setPropertyValue("ShadowFormat",shadowFormat[1]); 529 xTableProps3.setPropertyValue("ShadowFormat",shadowFormat[2]); 530 xTableProps4.setPropertyValue("ShadowFormat",shadowFormat[3]); 531 xTableProps5.setPropertyValue("ShadowFormat",shadowFormat[4]); 532 533 //save and reload text document 534 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 535 PropertyValue[] aStoreProperties = new PropertyValue[2]; 536 aStoreProperties[0] = new PropertyValue(); 537 aStoreProperties[1] = new PropertyValue(); 538 aStoreProperties[0].Name = "Override"; 539 aStoreProperties[0].Value = true; 540 aStoreProperties[1].Name = "FilterName"; 541 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 542 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 543 app.closeDocument(xTextDocument); 544 545 //reopen the document and assert table shadow setting 546 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 547 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 548 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 549 Object xTable_obj1=xIndexedTables.getByIndex(0); 550 XTextTable xTable_Assert1=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj1); 551 XPropertySet xTableProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert1); 552 ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTableProps_assert1.getPropertyValue("ShadowFormat")); 553 assertEquals("assert shadow location",ShadowLocation.BOTTOM_RIGHT,shadowFormat_Assert1.Location); 554 assertEquals("assert shadow width",100,shadowFormat_Assert1.ShadowWidth); 555 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert1.Color); 556 557 Object xTable_obj2=xIndexedTables.getByIndex(1); 558 XTextTable xTable_Assert2=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj2); 559 XPropertySet xTableProps_assert2 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert2); 560 ShadowFormat shadowFormat_Assert2=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTableProps_assert2.getPropertyValue("ShadowFormat")); 561 assertEquals("assert shadow location",ShadowLocation.BOTTOM_LEFT,shadowFormat_Assert2.Location); 562 assertEquals("assert shadow width",100,shadowFormat_Assert2.ShadowWidth); 563 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert2.Color); 564 565 Object xTable_obj3=xIndexedTables.getByIndex(2); 566 XTextTable xTable_Assert3=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj3); 567 XPropertySet xTableProps_assert3 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert3); 568 ShadowFormat shadowFormat_Assert3=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTableProps_assert3.getPropertyValue("ShadowFormat")); 569 assertEquals("assert shadow location",ShadowLocation.NONE,shadowFormat_Assert3.Location); 570 571 Object xTable_obj4=xIndexedTables.getByIndex(3); 572 XTextTable xTable_Assert4=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj4); 573 XPropertySet xTableProps_assert4 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert4); 574 ShadowFormat shadowFormat_Assert4=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTableProps_assert4.getPropertyValue("ShadowFormat")); 575 assertEquals("assert shadow location",ShadowLocation.TOP_LEFT,shadowFormat_Assert4.Location); 576 assertEquals("assert shadow width",100,shadowFormat_Assert4.ShadowWidth); 577 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert4.Color); 578 579 Object xTable_obj5=xIndexedTables.getByIndex(4); 580 XTextTable xTable_Assert5=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj5); 581 XPropertySet xTableProps_assert5 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert5); 582 ShadowFormat shadowFormat_Assert5=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTableProps_assert5.getPropertyValue("ShadowFormat")); 583 assertEquals("assert shadow location",ShadowLocation.TOP_RIGHT,shadowFormat_Assert5.Location); 584 assertEquals("assert shadow width",100,shadowFormat_Assert5.ShadowWidth); 585 assertEquals("assert shadow color",0x00FF00FF,shadowFormat_Assert5.Color); 586 } 587 /* 588 * test set table background with graphic 589 * 1.new a text document and create a table 590 * 2.set table background with a picture 591 * 3.save to odt and closet it,then reopen the new saved document 592 * 4.check the table background 593 */ 594 @Test testSetTableBackGraphic()595 public void testSetTableBackGraphic() throws Exception { 596 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 597 xText=xTextDocument.getText(); 598 XTextCursor xTextCursor = xText.createTextCursor(); 599 // get internal service factory of the document 600 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 601 // Create a new table from the document's factory 602 XTextTable xTable1 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 603 xText.insertTextContent(xTextCursor,xTable1,false); 604 XPropertySet xTableProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable1); 605 xTableProps1.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 606 xTableProps1.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 607 xTableProps1.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.LEFT_BOTTOM); 608 609 XTextTable xTable2 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 610 xText.insertTextContent(xTextCursor,xTable2,false); 611 XPropertySet xTableProps2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable2); 612 xTableProps2.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 613 xTableProps2.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 614 xTableProps2.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.LEFT_MIDDLE); 615 616 XTextTable xTable3 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 617 xText.insertTextContent(xTextCursor,xTable3,false); 618 XPropertySet xTableProps3 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable3); 619 xTableProps3.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 620 xTableProps3.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 621 xTableProps3.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.LEFT_TOP); 622 623 XTextTable xTable4 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 624 xText.insertTextContent(xTextCursor,xTable4,false); 625 XPropertySet xTableProps4 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable4); 626 xTableProps4.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 627 xTableProps4.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 628 xTableProps4.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.MIDDLE_BOTTOM); 629 630 XTextTable xTable5 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 631 xText.insertTextContent(xTextCursor,xTable5,false); 632 XPropertySet xTableProps5 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable5); 633 xTableProps5.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 634 xTableProps5.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 635 xTableProps5.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.MIDDLE_MIDDLE); 636 637 XTextTable xTable6 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 638 xText.insertTextContent(xTextCursor,xTable6,false); 639 XPropertySet xTableProps6 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable6); 640 xTableProps6.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 641 xTableProps6.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 642 xTableProps6.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.MIDDLE_TOP); 643 644 XTextTable xTable7 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 645 xText.insertTextContent(xTextCursor,xTable7,false); 646 XPropertySet xTableProps7 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable7); 647 xTableProps7.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 648 xTableProps7.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 649 xTableProps7.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.NONE); 650 651 XTextTable xTable8 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 652 xText.insertTextContent(xTextCursor,xTable8,false); 653 XPropertySet xTableProps8 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable8); 654 xTableProps8.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 655 xTableProps8.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 656 xTableProps8.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.RIGHT_BOTTOM); 657 658 XTextTable xTable9 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 659 xText.insertTextContent(xTextCursor,xTable9,false); 660 XPropertySet xTableProps9 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable9); 661 xTableProps9.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 662 xTableProps9.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 663 xTableProps9.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.RIGHT_MIDDLE); 664 665 XTextTable xTable10 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 666 xText.insertTextContent(xTextCursor,xTable10,false); 667 XPropertySet xTableProps10 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable10); 668 xTableProps10.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 669 xTableProps10.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 670 xTableProps10.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.RIGHT_TOP); 671 672 XTextTable xTable11 = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 673 xText.insertTextContent(xTextCursor,xTable11,false); 674 XPropertySet xTableProps11 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTable11); 675 xTableProps11.setPropertyValue("BackGraphicURL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg"))); 676 xTableProps11.setPropertyValue("BackGraphicFilter","draw_jpg_Export"); 677 xTableProps11.setPropertyValue("BackGraphicLocation",com.sun.star.style.GraphicLocation.AREA); 678 //save and reload text document 679 XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 680 PropertyValue[] aStoreProperties = new PropertyValue[2]; 681 aStoreProperties[0] = new PropertyValue(); 682 aStoreProperties[1] = new PropertyValue(); 683 aStoreProperties[0].Name = "Override"; 684 aStoreProperties[0].Value = true; 685 aStoreProperties[1].Name = "FilterName"; 686 aStoreProperties[1].Value = "StarOffice XML (Writer)"; 687 xStorable.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties); 688 app.closeDocument(xTextDocument); 689 690 //reopen the document and assert table margin to page setting 691 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 692 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument ); 693 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier.getTextTables()); 694 Object xTable_obj1=xIndexedTables.getByIndex(0); 695 XTextTable xTable_Assert1=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj1); 696 XPropertySet xTableProps1_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert1); 697 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.LEFT_BOTTOM,xTableProps1_assert.getPropertyValue("BackGraphicLocation")); 698 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps1_assert.getPropertyValue("BackGraphicFilter")); 699 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps1_assert.getPropertyValue("BackGraphicURL")); 700 701 Object xTable_obj2=xIndexedTables.getByIndex(1); 702 XTextTable xTable_Assert2=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj2); 703 XPropertySet xTableProps2_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert2); 704 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.LEFT_MIDDLE,xTableProps2_assert.getPropertyValue("BackGraphicLocation")); 705 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps2_assert.getPropertyValue("BackGraphicFilter")); 706 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps2_assert.getPropertyValue("BackGraphicURL")); 707 708 Object xTable_obj3=xIndexedTables.getByIndex(2); 709 XTextTable xTable_Assert3=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj3); 710 XPropertySet xTableProps3_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert3); 711 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.LEFT_TOP,xTableProps3_assert.getPropertyValue("BackGraphicLocation")); 712 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps3_assert.getPropertyValue("BackGraphicFilter")); 713 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps3_assert.getPropertyValue("BackGraphicURL")); 714 715 Object xTable_obj4=xIndexedTables.getByIndex(3); 716 XTextTable xTable_Assert4=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj4); 717 XPropertySet xTableProps4_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert4); 718 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.MIDDLE_BOTTOM,xTableProps4_assert.getPropertyValue("BackGraphicLocation")); 719 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps4_assert.getPropertyValue("BackGraphicFilter")); 720 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps4_assert.getPropertyValue("BackGraphicURL")); 721 722 Object xTable_obj5=xIndexedTables.getByIndex(4); 723 XTextTable xTable_Assert5=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj5); 724 XPropertySet xTableProps5_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert5); 725 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.MIDDLE_MIDDLE,xTableProps5_assert.getPropertyValue("BackGraphicLocation")); 726 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps5_assert.getPropertyValue("BackGraphicFilter")); 727 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps5_assert.getPropertyValue("BackGraphicURL")); 728 729 Object xTable_obj6=xIndexedTables.getByIndex(5); 730 XTextTable xTable_Assert6=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj6); 731 XPropertySet xTableProps6_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert6); 732 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.MIDDLE_TOP,xTableProps6_assert.getPropertyValue("BackGraphicLocation")); 733 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps6_assert.getPropertyValue("BackGraphicFilter")); 734 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps6_assert.getPropertyValue("BackGraphicURL")); 735 736 Object xTable_obj7=xIndexedTables.getByIndex(6); 737 XTextTable xTable_Assert7=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj7); 738 XPropertySet xTableProps7_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert7); 739 assertEquals("verify table backgraphic location is title",com.sun.star.style.GraphicLocation.NONE,xTableProps7_assert.getPropertyValue("BackGraphicLocation")); 740 741 Object xTable_obj8=xIndexedTables.getByIndex(7); 742 XTextTable xTable_Assert8=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj8); 743 XPropertySet xTableProps8_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert8); 744 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.RIGHT_BOTTOM,xTableProps8_assert.getPropertyValue("BackGraphicLocation")); 745 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps8_assert.getPropertyValue("BackGraphicFilter")); 746 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps8_assert.getPropertyValue("BackGraphicURL")); 747 748 Object xTable_obj9=xIndexedTables.getByIndex(8); 749 XTextTable xTable_Assert9=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj9); 750 XPropertySet xTableProps9_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert9); 751 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.RIGHT_MIDDLE,xTableProps9_assert.getPropertyValue("BackGraphicLocation")); 752 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps9_assert.getPropertyValue("BackGraphicFilter")); 753 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps9_assert.getPropertyValue("BackGraphicURL")); 754 755 Object xTable_obj10=xIndexedTables.getByIndex(9); 756 XTextTable xTable_Assert10=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj10); 757 XPropertySet xTableProps10_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert10); 758 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.RIGHT_TOP,xTableProps10_assert.getPropertyValue("BackGraphicLocation")); 759 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps10_assert.getPropertyValue("BackGraphicFilter")); 760 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps10_assert.getPropertyValue("BackGraphicURL")); 761 762 Object xTable_obj11=xIndexedTables.getByIndex(10); 763 XTextTable xTable_Assert11=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj11); 764 XPropertySet xTableProps11_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTable_Assert11); 765 assertEquals("verify table backgraphic location",com.sun.star.style.GraphicLocation.AREA,xTableProps11_assert.getPropertyValue("BackGraphicLocation")); 766 assertEquals("verify table backgraphic filter","draw_jpg_Export",xTableProps11_assert.getPropertyValue("BackGraphicFilter")); 767 assertEquals("verify table backgraphic URL",FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),xTableProps11_assert.getPropertyValue("BackGraphicURL")); 768 } 769 } 770 771