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