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.container.XIndexAccess; 18*eba4d44aSLiu Zhe import com.sun.star.container.XNamed; 19*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 20*eba4d44aSLiu Zhe 21*eba4d44aSLiu Zhe 22*eba4d44aSLiu Zhe public class TableName { 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 name 41*eba4d44aSLiu Zhe * 3.save to odt/doc,close it and reopen new saved document 42*eba4d44aSLiu Zhe * 4.check the table name 43*eba4d44aSLiu Zhe */ 44*eba4d44aSLiu Zhe @Test@Ignore("Bug #120739 - [testUNO patch]the table name change to default name when save to doc.") 45*eba4d44aSLiu Zhe public void testtableName() 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 XNamed tableName=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable); 55*eba4d44aSLiu Zhe assertEquals("assert default table name","Table1",tableName.getName()); 56*eba4d44aSLiu Zhe tableName.setName("test_TableExample"); 57*eba4d44aSLiu Zhe //save to odt 58*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 59*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 60*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 61*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 62*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 63*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 64*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 65*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 66*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 67*eba4d44aSLiu Zhe //save to doc 68*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 69*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 70*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 71*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 72*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 73*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 74*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 75*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 76*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 77*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 78*eba4d44aSLiu Zhe 79*eba4d44aSLiu Zhe //reopen the odt document and assert table border spacing to content 80*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 81*eba4d44aSLiu Zhe XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 82*eba4d44aSLiu Zhe XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 83*eba4d44aSLiu Zhe Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 84*eba4d44aSLiu Zhe XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 85*eba4d44aSLiu Zhe XNamed tableName_odt=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_odt); 86*eba4d44aSLiu Zhe assertEquals("assert default table name","test_TableExample",tableName_odt.getName()); 87*eba4d44aSLiu Zhe 88*eba4d44aSLiu Zhe //reopen the doc document and assert table border spacing to content 89*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 90*eba4d44aSLiu Zhe XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 91*eba4d44aSLiu Zhe XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 92*eba4d44aSLiu Zhe Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 93*eba4d44aSLiu Zhe XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 94*eba4d44aSLiu Zhe XNamed tableName_doc=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_doc); 95*eba4d44aSLiu Zhe assertEquals("assert default table name","test_TableExample",tableName_doc.getName()); 96*eba4d44aSLiu Zhe 97*eba4d44aSLiu Zhe } 98*eba4d44aSLiu Zhe } 99*eba4d44aSLiu Zhe 100