xref: /trunk/test/testuno/source/fvt/uno/sc/cell/DeleteContents.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.sc.cell;
23eba4d44aSLiu Zhe 
24eba4d44aSLiu Zhe import static org.junit.Assert.*;
25eba4d44aSLiu Zhe 
26eba4d44aSLiu Zhe import org.junit.After;
27eba4d44aSLiu Zhe import org.junit.AfterClass;
28eba4d44aSLiu Zhe import org.junit.Before;
29eba4d44aSLiu Zhe import org.junit.BeforeClass;
30eba4d44aSLiu Zhe import org.junit.Test;
31eba4d44aSLiu Zhe 
32eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
33eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
34eba4d44aSLiu Zhe 
35eba4d44aSLiu Zhe import testlib.uno.SCUtil;
36eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
37eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
38eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
39eba4d44aSLiu Zhe import com.sun.star.table.XCell;
40eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
41eba4d44aSLiu Zhe import com.sun.star.table.XCellRange;
42eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotations;
43eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotationsSupplier;
44eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetOperation;
45eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPage;
46eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPageSupplier;
47eba4d44aSLiu Zhe import com.sun.star.drawing.XShapes;
48eba4d44aSLiu Zhe 
49eba4d44aSLiu Zhe /**
50eba4d44aSLiu Zhe  * Test delete contents
51eba4d44aSLiu Zhe  * @author BinGuo 9/4/2012
52eba4d44aSLiu Zhe  *
53eba4d44aSLiu Zhe  */
54eba4d44aSLiu Zhe 
55eba4d44aSLiu Zhe public class DeleteContents {
56eba4d44aSLiu Zhe 
57eba4d44aSLiu Zhe     UnoApp unoApp = new UnoApp();
58eba4d44aSLiu Zhe     XSpreadsheetDocument scDocument = null;
59eba4d44aSLiu Zhe     XComponent scComponent = null;
60eba4d44aSLiu Zhe     private String filename = "uno/sc/cell/TestDeleteContents.ods";
61eba4d44aSLiu Zhe     XDrawPage xpage = null;
62eba4d44aSLiu Zhe     XShapes xShapes = null;
63eba4d44aSLiu Zhe 
64eba4d44aSLiu Zhe     @Before
setUp()65eba4d44aSLiu Zhe     public void setUp() throws Exception {
66eba4d44aSLiu Zhe         unoApp.start();
67eba4d44aSLiu Zhe     }
68eba4d44aSLiu Zhe 
69eba4d44aSLiu Zhe     @After
tearDown()70eba4d44aSLiu Zhe     public void tearDown() throws Exception {
71eba4d44aSLiu Zhe         unoApp.closeDocument(scComponent);
72eba4d44aSLiu Zhe         unoApp.close();
73eba4d44aSLiu Zhe         }
74eba4d44aSLiu Zhe 
75eba4d44aSLiu Zhe     @BeforeClass
setUpConnection()76eba4d44aSLiu Zhe     public static void setUpConnection() throws Exception {
77eba4d44aSLiu Zhe //      unoApp.start();
78eba4d44aSLiu Zhe     }
79eba4d44aSLiu Zhe 
80eba4d44aSLiu Zhe     @AfterClass
tearDownConnection()81eba4d44aSLiu Zhe     public static void tearDownConnection() throws InterruptedException, Exception {
82eba4d44aSLiu Zhe //      unoApp.close();
83eba4d44aSLiu Zhe         SCUtil.clearTempDir();
84eba4d44aSLiu Zhe     }
85eba4d44aSLiu Zhe 
86eba4d44aSLiu Zhe     /**
87eba4d44aSLiu Zhe      * Open existing ODS file with contents in cell range B5:C15
88eba4d44aSLiu Zhe      * Execute delete Text, Verify results after delete text
89eba4d44aSLiu Zhe      * Execute delete Number, Verify results after delete number
90eba4d44aSLiu Zhe      * Execute delete Formula, Verify results after delete formula
91eba4d44aSLiu Zhe      * Execute delete Comment, Verify results after delete comment
92eba4d44aSLiu Zhe      * Execute delete Format, Verify results after delete format
93eba4d44aSLiu Zhe      * Execute delete Drawing Object, Verify results after delete object
94eba4d44aSLiu Zhe      */
95eba4d44aSLiu Zhe 
96eba4d44aSLiu Zhe     @Test
testDeleteContents()97eba4d44aSLiu Zhe     public void testDeleteContents() throws Exception {
98eba4d44aSLiu Zhe 
99eba4d44aSLiu Zhe         // Prepare test data
100eba4d44aSLiu Zhe         String sample = Testspace.prepareData(filename);
101eba4d44aSLiu Zhe 
102eba4d44aSLiu Zhe         // Open document
103eba4d44aSLiu Zhe         scDocument = SCUtil.openFile(sample, unoApp);
104eba4d44aSLiu Zhe 
105eba4d44aSLiu Zhe         // Get current sheet
106eba4d44aSLiu Zhe         XSpreadsheet xSheet = SCUtil.getCurrentSheet(scDocument);
107eba4d44aSLiu Zhe 
108eba4d44aSLiu Zhe         // Get cell range B5:C15 by position - (column, row, column, row)
109eba4d44aSLiu Zhe         XCellRange xCellRange = xSheet.getCellRangeByPosition( 1, 4, 2, 14 );
110eba4d44aSLiu Zhe         XSheetOperation xSheetOp = (XSheetOperation) UnoRuntime.queryInterface(XSheetOperation.class, xCellRange);
111eba4d44aSLiu Zhe 
112eba4d44aSLiu Zhe         //Get Cell B5
113eba4d44aSLiu Zhe         XCell cellB5 = xSheet.getCellByPosition(1, 4);
114eba4d44aSLiu Zhe 
115eba4d44aSLiu Zhe         //Delete Text from Cell Range B5:C15
116eba4d44aSLiu Zhe         xSheetOp.clearContents(4);
117eba4d44aSLiu Zhe 
118eba4d44aSLiu Zhe         //Verify results after execute delete 'Text' contents.
119eba4d44aSLiu Zhe         double NullCellValue = 0.0;
120eba4d44aSLiu Zhe         assertEquals("Verify after execute delete 'Text' contents.",NullCellValue, cellB5.getValue(),0);
121eba4d44aSLiu Zhe 
122eba4d44aSLiu Zhe         //Get Cell B7
123eba4d44aSLiu Zhe         XCell cellB7 = xSheet.getCellByPosition(1, 6);
124eba4d44aSLiu Zhe 
125eba4d44aSLiu Zhe         //Delete Date & Time from Cell Range B5:C15
126eba4d44aSLiu Zhe         xSheetOp.clearContents(2);
127eba4d44aSLiu Zhe 
128eba4d44aSLiu Zhe         //Verify results after execute delete 'Date & Time' contents.
129eba4d44aSLiu Zhe         assertEquals("Verify after execute delete 'Date & Time' contents.",NullCellValue, cellB7.getValue(),0);
130eba4d44aSLiu Zhe 
131eba4d44aSLiu Zhe         //Get Cell B8
132eba4d44aSLiu Zhe         XCell cellB8 = xSheet.getCellByPosition(1, 7);
133eba4d44aSLiu Zhe 
134eba4d44aSLiu Zhe         //Delete Formula from Cell Range B5:C15
135eba4d44aSLiu Zhe         xSheetOp.clearContents(16);
136eba4d44aSLiu Zhe 
137eba4d44aSLiu Zhe         //Verify results after execute delete 'Formula' contents.
138eba4d44aSLiu Zhe         assertEquals("Verify after execute delete 'Formula' contents.",NullCellValue, cellB8.getValue(),0);
139eba4d44aSLiu Zhe 
140eba4d44aSLiu Zhe         //Delete Comment from Cell Range B5:C15
141eba4d44aSLiu Zhe         xSheetOp.clearContents(8);
142eba4d44aSLiu Zhe 
143eba4d44aSLiu Zhe         XSheetAnnotationsSupplier xAnnotationsSupp =
144eba4d44aSLiu Zhe                  (XSheetAnnotationsSupplier) UnoRuntime.queryInterface(
145eba4d44aSLiu Zhe                      XSheetAnnotationsSupplier.class, xSheet);
146eba4d44aSLiu Zhe         XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations();
147eba4d44aSLiu Zhe 
148eba4d44aSLiu Zhe         //Verify comment is deleted.
149eba4d44aSLiu Zhe         assertEquals("Verify total number of annotations after execute delete annotations."
150eba4d44aSLiu Zhe                   ,0, xAnnotations.getCount());
151eba4d44aSLiu Zhe         //Delete contents with Formatted from Cell Range B5:C15
152eba4d44aSLiu Zhe //        xSheetOp.clearContents(512); @Ignore("#BUGID 120816 - BUG TITLE Method clearContents() clears 'Formatted' contents of the cells used does not work, If constants of com.sun.star.sheet.CellFlags is '512'. ")
153eba4d44aSLiu Zhe 
154eba4d44aSLiu Zhe         //Get Cell B6 and B10
155eba4d44aSLiu Zhe         XCell cellB6 = xSheet.getCellByPosition(1, 5);
156eba4d44aSLiu Zhe         XCell cellB10 = xSheet.getCellByPosition(1, 9);
157eba4d44aSLiu Zhe 
158eba4d44aSLiu Zhe         xSheetOp.clearContents(1);
159eba4d44aSLiu Zhe 
160eba4d44aSLiu Zhe         //Verify results after execute delete 'Number' contents.
161eba4d44aSLiu Zhe         assertEquals("Verify after execute delete 'Number' contents in B6.",NullCellValue, cellB6.getValue(),0);
162eba4d44aSLiu Zhe         assertEquals("Verify after execute delete 'Number' contents in B10.",NullCellValue, cellB10.getValue(),0);
163eba4d44aSLiu Zhe 
164eba4d44aSLiu Zhe         //Get Draw page
165eba4d44aSLiu Zhe         XDrawPageSupplier xDrawPageSupplier =
166eba4d44aSLiu Zhe                 (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, xSheet);
167eba4d44aSLiu Zhe         XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
168eba4d44aSLiu Zhe 
169eba4d44aSLiu Zhe         XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
170eba4d44aSLiu Zhe 
171eba4d44aSLiu Zhe         //Verify number of shape in sheet.
172eba4d44aSLiu Zhe         assertEquals("Verify number of shape in sheet.",1, xShapes.getCount());
173eba4d44aSLiu Zhe 
174eba4d44aSLiu Zhe         //Delete drawing object from Cell Range B5:C15
175eba4d44aSLiu Zhe         xSheetOp.clearContents(128);
176eba4d44aSLiu Zhe 
177eba4d44aSLiu Zhe         xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
178eba4d44aSLiu Zhe 
179eba4d44aSLiu Zhe         //Verify results after execute delete 'Objects' contents in cell range.
180eba4d44aSLiu Zhe         assertEquals("Verify shape is deleted in sheet after execute delete 'Objects' contents in cell range."
181eba4d44aSLiu Zhe               ,0, xShapes.getCount());
182eba4d44aSLiu Zhe 
183eba4d44aSLiu Zhe     }
184eba4d44aSLiu Zhe 
185eba4d44aSLiu Zhe }
186