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