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