1*eba4d44aSLiu Zhe package fvt.uno.sw.table; 2*eba4d44aSLiu Zhe 3*eba4d44aSLiu Zhe import static org.junit.Assert.*; 4*eba4d44aSLiu Zhe 5*eba4d44aSLiu Zhe import org.junit.After; 6*eba4d44aSLiu Zhe import org.junit.Before; 7*eba4d44aSLiu Zhe import org.junit.Ignore; 8*eba4d44aSLiu Zhe import org.junit.Test; 9*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 10*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 11*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 12*eba4d44aSLiu Zhe 13*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 14*eba4d44aSLiu Zhe import com.sun.star.text.*; 15*eba4d44aSLiu Zhe import com.sun.star.lang.XMultiServiceFactory; 16*eba4d44aSLiu Zhe import com.sun.star.beans.PropertyValue; 17*eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet; 18*eba4d44aSLiu Zhe import com.sun.star.container.XIndexAccess; 19*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 20*eba4d44aSLiu Zhe 21*eba4d44aSLiu Zhe 22*eba4d44aSLiu Zhe public class TableCellProtect { 23*eba4d44aSLiu Zhe 24*eba4d44aSLiu Zhe private static final UnoApp app = new UnoApp(); 25*eba4d44aSLiu Zhe private XTextDocument xTextDocument=null; 26*eba4d44aSLiu Zhe private XMultiServiceFactory xWriterFactory=null; 27*eba4d44aSLiu Zhe private XText xText=null; 28*eba4d44aSLiu Zhe @Before 29*eba4d44aSLiu Zhe public void setUp() throws Exception { 30*eba4d44aSLiu Zhe app.start(); 31*eba4d44aSLiu Zhe } 32*eba4d44aSLiu Zhe 33*eba4d44aSLiu Zhe @After 34*eba4d44aSLiu Zhe public void tearDown() throws Exception { 35*eba4d44aSLiu Zhe app.close(); 36*eba4d44aSLiu Zhe } 37*eba4d44aSLiu Zhe /* 38*eba4d44aSLiu Zhe * test table border spacing to content 39*eba4d44aSLiu Zhe * 1.new a text document and create a table 40*eba4d44aSLiu Zhe * 2.set table cell protect 41*eba4d44aSLiu Zhe * 3.save to odt/doc,close it and reopen new saved document 42*eba4d44aSLiu Zhe * 4.check the table cell protect setting 43*eba4d44aSLiu Zhe */ 44*eba4d44aSLiu Zhe @Test@Ignore("Bug #120745 - [testUNO patch]table cell protect effect lost when save to doc.") 45*eba4d44aSLiu Zhe public void testtableBorderSpacingtoContent() throws Exception { 46*eba4d44aSLiu Zhe xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 47*eba4d44aSLiu Zhe xText=xTextDocument.getText(); 48*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 49*eba4d44aSLiu Zhe // get internal service factory of the document 50*eba4d44aSLiu Zhe xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 51*eba4d44aSLiu Zhe // Create a new table from the document's factory 52*eba4d44aSLiu Zhe XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 53*eba4d44aSLiu Zhe xText.insertTextContent(xTextCursor,xTable,false); 54*eba4d44aSLiu Zhe String[] cellName=xTable.getCellNames(); 55*eba4d44aSLiu Zhe int i=0; 56*eba4d44aSLiu Zhe while(cellName[i] != null) 57*eba4d44aSLiu Zhe { 58*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable.getCellByName(cellName[i])); 59*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("IsProtected",true); 60*eba4d44aSLiu Zhe i++; 61*eba4d44aSLiu Zhe if(i==4)break; 62*eba4d44aSLiu Zhe } 63*eba4d44aSLiu Zhe //save to odt 64*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 65*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 66*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 67*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 68*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 69*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 70*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 71*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 72*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 73*eba4d44aSLiu Zhe //save to doc 74*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 75*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 76*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 77*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 78*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 79*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 80*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 81*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 82*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 83*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 84*eba4d44aSLiu Zhe 85*eba4d44aSLiu Zhe //reopen the odt document and assert table border spacing to content 86*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 87*eba4d44aSLiu Zhe XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 88*eba4d44aSLiu Zhe XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 89*eba4d44aSLiu Zhe Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 90*eba4d44aSLiu Zhe XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 91*eba4d44aSLiu Zhe String[] cellName_assert_odt=xTable_Assert_odt.getCellNames(); 92*eba4d44aSLiu Zhe int j=0; 93*eba4d44aSLiu Zhe while(cellName_assert_odt[j] != null) 94*eba4d44aSLiu Zhe { 95*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_odt.getCellByName(cellName_assert_odt[j])); 96*eba4d44aSLiu Zhe assertEquals("assert table cell proptext",true,xCursorProps_assert_odt.getPropertyValue("IsProtected")); 97*eba4d44aSLiu Zhe j++; 98*eba4d44aSLiu Zhe if(j==4)break; 99*eba4d44aSLiu Zhe } 100*eba4d44aSLiu Zhe 101*eba4d44aSLiu Zhe //reopen the doc document and assert table border spacing to content 102*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 103*eba4d44aSLiu Zhe XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 104*eba4d44aSLiu Zhe XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 105*eba4d44aSLiu Zhe Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 106*eba4d44aSLiu Zhe XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 107*eba4d44aSLiu Zhe String[] cellName_assert_doc=xTable_Assert_doc.getCellNames(); 108*eba4d44aSLiu Zhe int k=0; 109*eba4d44aSLiu Zhe while(cellName_assert_doc[k] != null) 110*eba4d44aSLiu Zhe { 111*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xTable_Assert_doc.getCellByName(cellName_assert_doc[k])); 112*eba4d44aSLiu Zhe assertEquals("assert table cell proptext",true,xCursorProps_assert_doc.getPropertyValue("IsProtected")); 113*eba4d44aSLiu Zhe k++; 114*eba4d44aSLiu Zhe if(k==4)break; 115*eba4d44aSLiu Zhe } 116*eba4d44aSLiu Zhe } 117*eba4d44aSLiu Zhe } 118*eba4d44aSLiu Zhe 119