View | Details | Raw Unified | Return to issue 120817
Collapse All | Expand All

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

Return to issue 120817