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.frame.XStorable; 40 41 42 public class TableVerticalAlignment { 43 44 private static final UnoApp app = new UnoApp(); 45 private XTextDocument xTextDocument=null; 46 private XMultiServiceFactory xWriterFactory=null; 47 private XText xText=null; 48 @Before setUp()49 public void setUp() throws Exception { 50 app.start(); 51 } 52 53 @After tearDown()54 public void tearDown() throws Exception { 55 app.close(); 56 } 57 /* 58 * test table border spacing to content 59 * 1.new a text document and create a table 60 * 2.set table cell vertical alignment 61 * 3.save to odt/doc,close it and reopen new saved document 62 * 4.check the table cell vertical alignment 63 */ 64 @Test testtableVerticalAlignment_Bottom()65 public void testtableVerticalAlignment_Bottom() 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 xText.insertTextContent(xTextCursor,xTable,false); 74 String[] cellName=xTable.getCellNames(); 75 int i=0; 76 while(cellName[i] != null) 77 { 78 XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable.getCellByName(cellName[i])); 79 xCursorProps.setPropertyValue("VertOrient",VertOrientation.BOTTOM); 80 i++; 81 if(i==4)break; 82 } 83 //save to odt 84 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 85 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 86 aStoreProperties_odt[0] = new PropertyValue(); 87 aStoreProperties_odt[1] = new PropertyValue(); 88 aStoreProperties_odt[0].Name = "Override"; 89 aStoreProperties_odt[0].Value = true; 90 aStoreProperties_odt[1].Name = "FilterName"; 91 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 92 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 93 //save to doc 94 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 95 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 96 aStoreProperties_doc[0] = new PropertyValue(); 97 aStoreProperties_doc[1] = new PropertyValue(); 98 aStoreProperties_doc[0].Name = "Override"; 99 aStoreProperties_doc[0].Value = true; 100 aStoreProperties_doc[1].Name = "FilterName"; 101 aStoreProperties_doc[1].Value = "MS Word 97"; 102 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 103 app.closeDocument(xTextDocument); 104 105 //reopen the odt document and assert table vertical alignment 106 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 107 XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 108 XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 109 Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 110 XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 111 String[] cellName_assert_odt=xTable_Assert_odt.getCellNames(); 112 int j=0; 113 while(cellName_assert_odt[j] != null) 114 { 115 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_odt.getCellByName(cellName_assert_odt[j])); 116 assertEquals("assert table border spacing to content",VertOrientation.BOTTOM,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 117 j++; 118 if(j==4)break; 119 } 120 121 //reopen the doc document and assert table vertical alignment 122 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 123 XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 124 XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 125 Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 126 XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 127 String[] cellName_assert_doc=xTable_Assert_doc.getCellNames(); 128 int k=0; 129 while(cellName_assert_doc[k] != null) 130 { 131 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_doc.getCellByName(cellName_assert_doc[k])); 132 assertEquals("assert table vertical alignment",VertOrientation.BOTTOM,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 133 k++; 134 if(k==4)break; 135 } 136 } 137 @Test testtableVerticalAlignment_Center()138 public void testtableVerticalAlignment_Center() 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 String[] cellName=xTable.getCellNames(); 148 int i=0; 149 while(cellName[i] != null) 150 { 151 XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable.getCellByName(cellName[i])); 152 xCursorProps.setPropertyValue("VertOrient",VertOrientation.CENTER); 153 i++; 154 if(i==4)break; 155 } 156 //save to odt 157 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 158 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 159 aStoreProperties_odt[0] = new PropertyValue(); 160 aStoreProperties_odt[1] = new PropertyValue(); 161 aStoreProperties_odt[0].Name = "Override"; 162 aStoreProperties_odt[0].Value = true; 163 aStoreProperties_odt[1].Name = "FilterName"; 164 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 165 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 166 //save to doc 167 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 168 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 169 aStoreProperties_doc[0] = new PropertyValue(); 170 aStoreProperties_doc[1] = new PropertyValue(); 171 aStoreProperties_doc[0].Name = "Override"; 172 aStoreProperties_doc[0].Value = true; 173 aStoreProperties_doc[1].Name = "FilterName"; 174 aStoreProperties_doc[1].Value = "MS Word 97"; 175 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 176 app.closeDocument(xTextDocument); 177 178 //reopen the odt document and assert table vertical alignment 179 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 180 XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 181 XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 182 Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 183 XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 184 String[] cellName_assert_odt=xTable_Assert_odt.getCellNames(); 185 int j=0; 186 while(cellName_assert_odt[j] != null) 187 { 188 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_odt.getCellByName(cellName_assert_odt[j])); 189 assertEquals("assert table border spacing to content",VertOrientation.CENTER,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 190 j++; 191 if(j==4)break; 192 } 193 194 //reopen the doc document and assert table vertical alignment 195 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 196 XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 197 XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 198 Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 199 XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 200 String[] cellName_assert_doc=xTable_Assert_doc.getCellNames(); 201 int k=0; 202 while(cellName_assert_doc[k] != null) 203 { 204 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_doc.getCellByName(cellName_assert_doc[k])); 205 assertEquals("assert table vertical alignment",VertOrientation.CENTER,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 206 k++; 207 if(k==4)break; 208 } 209 } 210 @Test testtableVerticalAlignment_Top()211 public void testtableVerticalAlignment_Top() throws Exception { 212 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 213 xText=xTextDocument.getText(); 214 XTextCursor xTextCursor = xText.createTextCursor(); 215 // get internal service factory of the document 216 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 217 // Create a new table from the document's factory 218 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 219 xText.insertTextContent(xTextCursor,xTable,false); 220 String[] cellName=xTable.getCellNames(); 221 int i=0; 222 while(cellName[i] != null) 223 { 224 XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable.getCellByName(cellName[i])); 225 xCursorProps.setPropertyValue("VertOrient",VertOrientation.TOP); 226 i++; 227 if(i==4)break; 228 } 229 //save to odt 230 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 231 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 232 aStoreProperties_odt[0] = new PropertyValue(); 233 aStoreProperties_odt[1] = new PropertyValue(); 234 aStoreProperties_odt[0].Name = "Override"; 235 aStoreProperties_odt[0].Value = true; 236 aStoreProperties_odt[1].Name = "FilterName"; 237 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 238 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 239 //save to doc 240 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 241 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 242 aStoreProperties_doc[0] = new PropertyValue(); 243 aStoreProperties_doc[1] = new PropertyValue(); 244 aStoreProperties_doc[0].Name = "Override"; 245 aStoreProperties_doc[0].Value = true; 246 aStoreProperties_doc[1].Name = "FilterName"; 247 aStoreProperties_doc[1].Value = "MS Word 97"; 248 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 249 app.closeDocument(xTextDocument); 250 251 //reopen the odt document and assert table vertical alignment 252 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 253 XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 254 XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 255 Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 256 XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 257 String[] cellName_assert_odt=xTable_Assert_odt.getCellNames(); 258 int j=0; 259 while(cellName_assert_odt[j] != null) 260 { 261 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_odt.getCellByName(cellName_assert_odt[j])); 262 assertEquals("assert table border spacing to content",VertOrientation.TOP,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 263 j++; 264 if(j==4)break; 265 } 266 267 //reopen the doc document and assert table vertical alignment 268 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 269 XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 270 XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 271 Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 272 XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 273 String[] cellName_assert_doc=xTable_Assert_doc.getCellNames(); 274 int k=0; 275 while(cellName_assert_doc[k] != null) 276 { 277 XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_doc.getCellByName(cellName_assert_doc[k])); 278 assertEquals("assert table vertical alignment",VertOrientation.TOP,xCursorProps_assert_odt.getPropertyValue("VertOrient")); 279 k++; 280 if(k==4)break; 281 } 282 } 283 } 284 285