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;
2307edb14cSLiu Zhe 
2407edb14cSLiu Zhe import static org.junit.Assert.*;
2507edb14cSLiu Zhe 
2607edb14cSLiu Zhe import org.junit.After;
2707edb14cSLiu Zhe import org.junit.AfterClass;
2807edb14cSLiu Zhe import org.junit.Before;
2907edb14cSLiu Zhe import org.junit.BeforeClass;
3007edb14cSLiu Zhe import org.junit.Test;
3107edb14cSLiu Zhe 
3207edb14cSLiu Zhe import org.openoffice.test.common.Testspace;
3307edb14cSLiu Zhe import org.openoffice.test.uno.UnoApp;
3407edb14cSLiu Zhe 
3507edb14cSLiu Zhe import testlib.uno.SCUtil;
3607edb14cSLiu Zhe import com.sun.star.lang.XComponent;
3707edb14cSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
3807edb14cSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
3907edb14cSLiu Zhe import com.sun.star.table.XCell;
4007edb14cSLiu Zhe import com.sun.star.uno.UnoRuntime;
4107edb14cSLiu Zhe import com.sun.star.table.XCellRange;
4207edb14cSLiu Zhe import com.sun.star.sheet.XSheetAnnotations;
4307edb14cSLiu Zhe import com.sun.star.sheet.XSheetAnnotationsSupplier;
4407edb14cSLiu Zhe import com.sun.star.sheet.XSheetOperation;
4507edb14cSLiu Zhe import com.sun.star.drawing.XDrawPage;
4607edb14cSLiu Zhe import com.sun.star.drawing.XDrawPageSupplier;
4707edb14cSLiu Zhe import com.sun.star.drawing.XShapes;
4807edb14cSLiu Zhe 
4907edb14cSLiu Zhe /**
5007edb14cSLiu Zhe  * Test delete contents
5107edb14cSLiu Zhe  * @author BinGuo 9/4/2012
5207edb14cSLiu Zhe  *
5307edb14cSLiu Zhe  */
5407edb14cSLiu Zhe 
5507edb14cSLiu Zhe public class DeleteContents {
5607edb14cSLiu Zhe 
5707edb14cSLiu Zhe 	UnoApp unoApp = new UnoApp();
5807edb14cSLiu Zhe 	XSpreadsheetDocument scDocument = null;
5907edb14cSLiu Zhe 	XComponent scComponent = null;
6007edb14cSLiu Zhe 	private String filename = "uno/sc/cell/TestDeleteContents.ods";
6107edb14cSLiu Zhe 	XDrawPage xpage = null;
6207edb14cSLiu Zhe 	XShapes xShapes = null;
6307edb14cSLiu Zhe 
6407edb14cSLiu Zhe 	@Before
setUp()6507edb14cSLiu Zhe 	public void setUp() throws Exception {
6607edb14cSLiu Zhe 		unoApp.start();
6707edb14cSLiu Zhe 	}
6807edb14cSLiu Zhe 
6907edb14cSLiu Zhe 	@After
tearDown()7007edb14cSLiu Zhe 	public void tearDown() throws Exception {
7107edb14cSLiu Zhe 		unoApp.closeDocument(scComponent);
7207edb14cSLiu Zhe 		unoApp.close();
7307edb14cSLiu Zhe 		}
7407edb14cSLiu Zhe 
7507edb14cSLiu Zhe 	@BeforeClass
setUpConnection()7607edb14cSLiu Zhe 	public static void setUpConnection() throws Exception {
7707edb14cSLiu Zhe //		unoApp.start();
7807edb14cSLiu Zhe 	}
7907edb14cSLiu Zhe 
8007edb14cSLiu Zhe 	@AfterClass
tearDownConnection()8107edb14cSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
8207edb14cSLiu Zhe //		unoApp.close();
8307edb14cSLiu Zhe 		SCUtil.clearTempDir();
8407edb14cSLiu Zhe 	}
8507edb14cSLiu Zhe 
8607edb14cSLiu Zhe 	/**
8707edb14cSLiu Zhe 	 * Open existing ODS file with contents in cell range B5:C15
8807edb14cSLiu Zhe 	 * Execute delete Text, Verify results after delete text
8907edb14cSLiu Zhe 	 * Execute delete Number, Verify results after delete number
9007edb14cSLiu Zhe 	 * Execute delete Formula, Verify results after delete formula
9107edb14cSLiu Zhe 	 * Execute delete Comment, Verify results after delete comment
9207edb14cSLiu Zhe 	 * Execute delete Format, Verify results after delete format
9307edb14cSLiu Zhe 	 * Execute delete Drawing Object, Verify results after delete object
9407edb14cSLiu Zhe 	 */
9507edb14cSLiu Zhe 
9607edb14cSLiu Zhe 	@Test
testDeleteContents()9707edb14cSLiu Zhe 	public void testDeleteContents() throws Exception {
9807edb14cSLiu Zhe 
9907edb14cSLiu Zhe 		// Prepare test data
10007edb14cSLiu Zhe 		String sample = Testspace.prepareData(filename);
10107edb14cSLiu Zhe 
10207edb14cSLiu Zhe 		// Open document
10307edb14cSLiu Zhe 		scDocument = SCUtil.openFile(sample, unoApp);
10407edb14cSLiu Zhe 
10507edb14cSLiu Zhe 		// Get current sheet
10607edb14cSLiu Zhe 		XSpreadsheet xSheet = SCUtil.getCurrentSheet(scDocument);
10707edb14cSLiu Zhe 
10807edb14cSLiu Zhe 		// Get cell range B5:C15 by position - (column, row, column, row)
10907edb14cSLiu Zhe         XCellRange xCellRange = xSheet.getCellRangeByPosition( 1, 4, 2, 14 );
11007edb14cSLiu Zhe         XSheetOperation xSheetOp = (XSheetOperation) UnoRuntime.queryInterface(XSheetOperation.class, xCellRange);
11107edb14cSLiu Zhe 
11207edb14cSLiu Zhe         //Get Cell B5
11307edb14cSLiu Zhe         XCell cellB5 = xSheet.getCellByPosition(1, 4);
11407edb14cSLiu Zhe 
11507edb14cSLiu Zhe         //Delete Text from Cell Range B5:C15
11607edb14cSLiu Zhe         xSheetOp.clearContents(4);
11707edb14cSLiu Zhe 
11807edb14cSLiu Zhe         //Verify results after execute delete 'Text' contents.
11907edb14cSLiu Zhe         double NullCellValue = 0.0;
12007edb14cSLiu Zhe         assertEquals("Verify after execute delete 'Text' contents.",NullCellValue, cellB5.getValue(),0);
12107edb14cSLiu Zhe 
12207edb14cSLiu Zhe         //Get Cell B7
12307edb14cSLiu Zhe         XCell cellB7 = xSheet.getCellByPosition(1, 6);
12407edb14cSLiu Zhe 
12507edb14cSLiu Zhe         //Delete Date & Time from Cell Range B5:C15
12607edb14cSLiu Zhe         xSheetOp.clearContents(2);
12707edb14cSLiu Zhe 
12807edb14cSLiu Zhe         //Verify results after execute delete 'Date & Time' contents.
12907edb14cSLiu Zhe         assertEquals("Verify after execute delete 'Date & Time' contents.",NullCellValue, cellB7.getValue(),0);
13007edb14cSLiu Zhe 
13107edb14cSLiu Zhe         //Get Cell B8
13207edb14cSLiu Zhe         XCell cellB8 = xSheet.getCellByPosition(1, 7);
13307edb14cSLiu Zhe 
13407edb14cSLiu Zhe         //Delete Formula from Cell Range B5:C15
13507edb14cSLiu Zhe         xSheetOp.clearContents(16);
13607edb14cSLiu Zhe 
13707edb14cSLiu Zhe         //Verify results after execute delete 'Formula' contents.
13807edb14cSLiu Zhe         assertEquals("Verify after execute delete 'Formula' contents.",NullCellValue, cellB8.getValue(),0);
13907edb14cSLiu Zhe 
14007edb14cSLiu Zhe         //Delete Comment from Cell Range B5:C15
14107edb14cSLiu Zhe         xSheetOp.clearContents(8);
14207edb14cSLiu Zhe 
14307edb14cSLiu Zhe         XSheetAnnotationsSupplier xAnnotationsSupp =
14407edb14cSLiu Zhe 		         (XSheetAnnotationsSupplier) UnoRuntime.queryInterface(
14507edb14cSLiu Zhe 		             XSheetAnnotationsSupplier.class, xSheet);
14607edb14cSLiu Zhe 		XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations();
14707edb14cSLiu Zhe 
14807edb14cSLiu Zhe         //Verify comment is deleted.
14907edb14cSLiu Zhe 		assertEquals("Verify total number of annotations after execute delete annotations."
15007edb14cSLiu Zhe 	    		  ,0, xAnnotations.getCount());
15107edb14cSLiu Zhe         //Delete contents with Formatted from Cell Range B5:C15
15207edb14cSLiu 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'. ")
15307edb14cSLiu Zhe 
15407edb14cSLiu Zhe         //Get Cell B6 and B10
15507edb14cSLiu Zhe         XCell cellB6 = xSheet.getCellByPosition(1, 5);
15607edb14cSLiu Zhe         XCell cellB10 = xSheet.getCellByPosition(1, 9);
15707edb14cSLiu Zhe 
15807edb14cSLiu Zhe         xSheetOp.clearContents(1);
15907edb14cSLiu Zhe 
16007edb14cSLiu Zhe         //Verify results after execute delete 'Number' contents.
16107edb14cSLiu Zhe         assertEquals("Verify after execute delete 'Number' contents in B6.",NullCellValue, cellB6.getValue(),0);
16207edb14cSLiu Zhe         assertEquals("Verify after execute delete 'Number' contents in B10.",NullCellValue, cellB10.getValue(),0);
16307edb14cSLiu Zhe 
16407edb14cSLiu Zhe         //Get Draw page
16507edb14cSLiu Zhe         XDrawPageSupplier xDrawPageSupplier =
16607edb14cSLiu Zhe         		(XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, xSheet);
16707edb14cSLiu Zhe         XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
16807edb14cSLiu Zhe 
16907edb14cSLiu Zhe         XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
17007edb14cSLiu Zhe 
17107edb14cSLiu Zhe         //Verify number of shape in sheet.
17207edb14cSLiu Zhe         assertEquals("Verify number of shape in sheet.",1, xShapes.getCount());
17307edb14cSLiu Zhe 
17407edb14cSLiu Zhe         //Delete drawing object from Cell Range B5:C15
17507edb14cSLiu Zhe         xSheetOp.clearContents(128);
17607edb14cSLiu Zhe 
17707edb14cSLiu Zhe         xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
17807edb14cSLiu Zhe 
17907edb14cSLiu Zhe         //Verify results after execute delete 'Objects' contents in cell range.
18007edb14cSLiu Zhe         assertEquals("Verify shape is deleted in sheet after execute delete 'Objects' contents in cell range."
18107edb14cSLiu Zhe     		  ,0, xShapes.getCount());
18207edb14cSLiu Zhe 
18307edb14cSLiu Zhe     }
18407edb14cSLiu Zhe 
18507edb14cSLiu Zhe }
18607edb14cSLiu Zhe 
18707edb14cSLiu Zhe 
188