1*eba4d44aSLiu Zhe package fvt.uno.sw.table;
2f4c702faSLiu Zhe 
3f4c702faSLiu Zhe import static org.junit.Assert.*;
4f4c702faSLiu Zhe 
5f4c702faSLiu Zhe import org.junit.After;
6f4c702faSLiu Zhe import org.junit.Before;
7f4c702faSLiu Zhe import org.junit.Ignore;
8f4c702faSLiu Zhe import org.junit.Test;
9f4c702faSLiu Zhe import org.openoffice.test.common.FileUtil;
10f4c702faSLiu Zhe import org.openoffice.test.common.Testspace;
11f4c702faSLiu Zhe import org.openoffice.test.uno.UnoApp;
12f4c702faSLiu Zhe 
13f4c702faSLiu Zhe import com.sun.star.uno.UnoRuntime;
14f4c702faSLiu Zhe import com.sun.star.text.*;
15f4c702faSLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
16f4c702faSLiu Zhe import com.sun.star.beans.PropertyValue;
17f4c702faSLiu Zhe import com.sun.star.container.XIndexAccess;
18f4c702faSLiu Zhe import com.sun.star.container.XNamed;
19f4c702faSLiu Zhe import com.sun.star.frame.XStorable;
20f4c702faSLiu Zhe 
21f4c702faSLiu Zhe 
22f4c702faSLiu Zhe public class TableName {
23f4c702faSLiu Zhe 
24f4c702faSLiu Zhe 	private static final UnoApp app = new UnoApp();
25f4c702faSLiu Zhe 	private XTextDocument xTextDocument=null;
26f4c702faSLiu Zhe 	private XMultiServiceFactory xWriterFactory=null;
27f4c702faSLiu Zhe 	private XText xText=null;
28f4c702faSLiu Zhe 	@Before
29f4c702faSLiu Zhe 	public void setUp() throws Exception {
30f4c702faSLiu Zhe 		app.start();
31f4c702faSLiu Zhe 	}
32f4c702faSLiu Zhe 
33f4c702faSLiu Zhe 	@After
34f4c702faSLiu Zhe 	public void tearDown() throws Exception {
35f4c702faSLiu Zhe 		app.close();
36f4c702faSLiu Zhe 	}
37f4c702faSLiu Zhe 	/*
38f4c702faSLiu Zhe 	 * test table border spacing to content
39f4c702faSLiu Zhe 	 * 1.new a text document and create a table
40f4c702faSLiu Zhe 	 * 2.set table name
41f4c702faSLiu Zhe 	 * 3.save to odt/doc,close it and reopen new saved document
42f4c702faSLiu Zhe 	 * 4.check the table name
43f4c702faSLiu Zhe 	 */
44932de486SLiu Zhe 	@Test@Ignore("Bug #120739 - [testUNO patch]the table name change to default name when save to doc.")
45f4c702faSLiu Zhe 	public void testtableName() throws Exception {
46f4c702faSLiu Zhe 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
47f4c702faSLiu Zhe 		xText=xTextDocument.getText();
48f4c702faSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
49f4c702faSLiu Zhe 		// get internal service factory of the document
50f4c702faSLiu Zhe 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
51f4c702faSLiu Zhe 		// Create a new table from the document's factory
52f4c702faSLiu Zhe 		XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable"));
53f4c702faSLiu Zhe 		xText.insertTextContent(xTextCursor,xTable,false);
54f4c702faSLiu Zhe 		XNamed tableName=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable);
55f4c702faSLiu Zhe 		assertEquals("assert default table name","Table1",tableName.getName());
56f4c702faSLiu Zhe 		tableName.setName("test_TableExample");
57f4c702faSLiu Zhe 		//save to odt
58f4c702faSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
59f4c702faSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
60f4c702faSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
61f4c702faSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
62f4c702faSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
63f4c702faSLiu Zhe 		aStoreProperties_odt[0].Value = true;
64f4c702faSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
65f4c702faSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
66f4c702faSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
67f4c702faSLiu Zhe 		//save to doc
68f4c702faSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
69f4c702faSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
70f4c702faSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
71f4c702faSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
72f4c702faSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
73f4c702faSLiu Zhe 		aStoreProperties_doc[0].Value = true;
74f4c702faSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
75f4c702faSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
76f4c702faSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
77f4c702faSLiu Zhe 		app.closeDocument(xTextDocument);
78f4c702faSLiu Zhe 
79f4c702faSLiu Zhe 		//reopen the odt document and assert table border spacing to content
80f4c702faSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
81f4c702faSLiu Zhe 		XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt );
82f4c702faSLiu Zhe 		XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables());
83f4c702faSLiu Zhe 		Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0);
84f4c702faSLiu Zhe 		XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt);
85f4c702faSLiu Zhe 		XNamed tableName_odt=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_odt);
86f4c702faSLiu Zhe 		assertEquals("assert default table name","test_TableExample",tableName_odt.getName());
87f4c702faSLiu Zhe 
88f4c702faSLiu Zhe 		//reopen the doc document and assert table border spacing to content
89f4c702faSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
90f4c702faSLiu Zhe 		XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc );
91f4c702faSLiu Zhe 		XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables());
92f4c702faSLiu Zhe 		Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0);
93f4c702faSLiu Zhe 		XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc);
94f4c702faSLiu Zhe 		XNamed tableName_doc=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_doc);
95f4c702faSLiu Zhe 		assertEquals("assert default table name","test_TableExample",tableName_doc.getName());
96f4c702faSLiu Zhe 
97f4c702faSLiu Zhe 	}
98f4c702faSLiu Zhe }
99f4c702faSLiu Zhe 
100