1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr  *
3*07d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
5*07d7dbdcSHerbert Dürr  * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
7*07d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr  *
11*07d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr  *
13*07d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
17*07d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr  * under the License.
19*07d7dbdcSHerbert Dürr  *
20*07d7dbdcSHerbert Dürr  *************************************************************/
21*07d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.table;
23f4c702faSLiu Zhe 
24f4c702faSLiu Zhe import static org.junit.Assert.*;
25f4c702faSLiu Zhe 
26f4c702faSLiu Zhe import org.junit.After;
27f4c702faSLiu Zhe import org.junit.Before;
28f4c702faSLiu Zhe import org.junit.Ignore;
29f4c702faSLiu Zhe import org.junit.Test;
30f4c702faSLiu Zhe import org.openoffice.test.common.FileUtil;
31f4c702faSLiu Zhe import org.openoffice.test.common.Testspace;
32f4c702faSLiu Zhe import org.openoffice.test.uno.UnoApp;
33f4c702faSLiu Zhe 
34f4c702faSLiu Zhe import com.sun.star.uno.UnoRuntime;
35f4c702faSLiu Zhe import com.sun.star.text.*;
36f4c702faSLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
37f4c702faSLiu Zhe import com.sun.star.beans.PropertyValue;
38f4c702faSLiu Zhe import com.sun.star.container.XIndexAccess;
39f4c702faSLiu Zhe import com.sun.star.container.XNamed;
40f4c702faSLiu Zhe import com.sun.star.frame.XStorable;
41f4c702faSLiu Zhe 
42f4c702faSLiu Zhe 
43f4c702faSLiu Zhe public class TableName {
44f4c702faSLiu Zhe 
45f4c702faSLiu Zhe 	private static final UnoApp app = new UnoApp();
46f4c702faSLiu Zhe 	private XTextDocument xTextDocument=null;
47f4c702faSLiu Zhe 	private XMultiServiceFactory xWriterFactory=null;
48f4c702faSLiu Zhe 	private XText xText=null;
49f4c702faSLiu Zhe 	@Before
setUp()50f4c702faSLiu Zhe 	public void setUp() throws Exception {
51f4c702faSLiu Zhe 		app.start();
52f4c702faSLiu Zhe 	}
53f4c702faSLiu Zhe 
54f4c702faSLiu Zhe 	@After
tearDown()55f4c702faSLiu Zhe 	public void tearDown() throws Exception {
56f4c702faSLiu Zhe 		app.close();
57f4c702faSLiu Zhe 	}
58f4c702faSLiu Zhe 	/*
59f4c702faSLiu Zhe 	 * test table border spacing to content
60f4c702faSLiu Zhe 	 * 1.new a text document and create a table
61f4c702faSLiu Zhe 	 * 2.set table name
62f4c702faSLiu Zhe 	 * 3.save to odt/doc,close it and reopen new saved document
63f4c702faSLiu Zhe 	 * 4.check the table name
64f4c702faSLiu Zhe 	 */
65932de486SLiu Zhe 	@Test@Ignore("Bug #120739 - [testUNO patch]the table name change to default name when save to doc.")
testtableName()66f4c702faSLiu Zhe 	public void testtableName() throws Exception {
67f4c702faSLiu Zhe 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
68f4c702faSLiu Zhe 		xText=xTextDocument.getText();
69f4c702faSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
70f4c702faSLiu Zhe 		// get internal service factory of the document
71f4c702faSLiu Zhe 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
72f4c702faSLiu Zhe 		// Create a new table from the document's factory
73f4c702faSLiu Zhe 		XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable"));
74f4c702faSLiu Zhe 		xText.insertTextContent(xTextCursor,xTable,false);
75f4c702faSLiu Zhe 		XNamed tableName=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable);
76f4c702faSLiu Zhe 		assertEquals("assert default table name","Table1",tableName.getName());
77f4c702faSLiu Zhe 		tableName.setName("test_TableExample");
78f4c702faSLiu Zhe 		//save to odt
79f4c702faSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
80f4c702faSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
81f4c702faSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
82f4c702faSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
83f4c702faSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
84f4c702faSLiu Zhe 		aStoreProperties_odt[0].Value = true;
85f4c702faSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
86f4c702faSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
87f4c702faSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
88f4c702faSLiu Zhe 		//save to doc
89f4c702faSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
90f4c702faSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
91f4c702faSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
92f4c702faSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
93f4c702faSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
94f4c702faSLiu Zhe 		aStoreProperties_doc[0].Value = true;
95f4c702faSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
96f4c702faSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
97f4c702faSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
98f4c702faSLiu Zhe 		app.closeDocument(xTextDocument);
99f4c702faSLiu Zhe 
100f4c702faSLiu Zhe 		//reopen the odt document and assert table border spacing to content
101f4c702faSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
102f4c702faSLiu Zhe 		XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt );
103f4c702faSLiu Zhe 		XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables());
104f4c702faSLiu Zhe 		Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0);
105f4c702faSLiu Zhe 		XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt);
106f4c702faSLiu Zhe 		XNamed tableName_odt=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_odt);
107f4c702faSLiu Zhe 		assertEquals("assert default table name","test_TableExample",tableName_odt.getName());
108f4c702faSLiu Zhe 
109f4c702faSLiu Zhe 		//reopen the doc document and assert table border spacing to content
110f4c702faSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
111f4c702faSLiu Zhe 		XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc );
112f4c702faSLiu Zhe 		XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables());
113f4c702faSLiu Zhe 		Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0);
114f4c702faSLiu Zhe 		XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc);
115f4c702faSLiu Zhe 		XNamed tableName_doc=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_doc);
116f4c702faSLiu Zhe 		assertEquals("assert default table name","test_TableExample",tableName_doc.getName());
117f4c702faSLiu Zhe 
118f4c702faSLiu Zhe 	}
119f4c702faSLiu Zhe }
120f4c702faSLiu Zhe 
121